Skip to content

Commit

Permalink
Add repo_path DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Oct 17, 2020
1 parent 4f44a14 commit 17311fa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/steep/project/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class TargetDSL
attr_reader :vendor_dir
attr_reader :strictness_level
attr_reader :typing_option_hash
attr_reader :repo_paths

def initialize(name, sources: [], libraries: [], signatures: [], ignored_sources: [])
def initialize(name, sources: [], libraries: [], signatures: [], ignored_sources: [], repo_paths: [])
@name = name
@sources = sources
@libraries = libraries
Expand All @@ -20,6 +21,7 @@ def initialize(name, sources: [], libraries: [], signatures: [], ignored_sources
@vendor_dir = nil
@strictness_level = :default
@typing_option_hash = {}
@repo_paths = []
end

def initialize_copy(other)
Expand All @@ -31,6 +33,7 @@ def initialize_copy(other)
@vendor_dir = other.vendor_dir
@strictness_level = other.strictness_level
@typing_option_hash = other.typing_option_hash
@repo_paths = other.repo_paths.dup
end

def check(*args)
Expand Down Expand Up @@ -75,6 +78,10 @@ def vendor(dir = "vendor/sigs", stdlib: nil, gems: nil)

@vendor_dir = Pathname(dir)
end

def repo_path(*paths)
@repo_paths.push(*paths.map {|s| Pathname(s) })
end
end

attr_reader :project
Expand Down Expand Up @@ -120,6 +127,7 @@ def target(name, template: nil, &block)
signature_patterns: target.signatures,
options: Options.new.tap do |options|
options.libraries.push(*target.libraries)
options.repository_paths.push(*target.repo_paths)
options.vendor_path = target.vendor_dir

case target.strictness_level
Expand Down
2 changes: 2 additions & 0 deletions lib/steep/project/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ class Options
attr_accessor :allow_unknown_method_calls
attr_accessor :vendor_path
attr_reader :libraries
attr_reader :repository_paths

def initialize
apply_default_typing_options!
self.vendor_path = nil

@libraries = []
@repository_paths = []
end

def apply_default_typing_options!
Expand Down
2 changes: 2 additions & 0 deletions lib/steep/project/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def environment
@environment ||= RBS::Environment.new().yield_self do |env|
core_root = options.vendor_path ? nil : RBS::EnvironmentLoader::DEFAULT_CORE_ROOT
repo = RBS::Repository.new(no_stdlib: !core_root)
options.repository_paths.each do |path|
repo.add(path)
end
loader = RBS::EnvironmentLoader.new(core_root: core_root, repository: repo)
if core_root
Expand Down
13 changes: 13 additions & 0 deletions test/steepfile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,17 @@ def test_invalid_template
end
end
end

def test_repo_path
in_tmpdir do
project = Project.new(steepfile_path: current_dir + "Steepfile")

Project::DSL.parse(project, <<EOF)
target :app do
repo_path "vendor/rbs/internal"
end
EOF
assert_equal [Pathname("vendor/rbs/internal")], project.targets[0].options.repository_paths
end
end
end

0 comments on commit 17311fa

Please sign in to comment.