Class: ElmInstall::Resolver
- Inherits:
-
Object
- Object
- ElmInstall::Resolver
- Defined in:
- lib/elm_install/resolver.rb
Overview
Resolves git dependencies into the cache.
Instance Attribute Summary collapse
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
Instance Method Summary collapse
-
#add_constraints(constraints) ⇒ Object
Add constraints, usually from the ‘elm-package.json`.
-
#add_dependencies(dependencies) ⇒ Object
Adds dependencies, usually from any ‘elm-package.json` file.
-
#add_package(package) ⇒ Object
Adds a package to the cache, the following things happens: * If there is no local repository it will be cloned * Getting all the tags and adding the valid ones to the cache * Checking out and getting the ‘elm-package.json` for each version and adding them recursivly.
-
#add_ref_dependency(package, ref) ⇒ Object
Adds a dependency by git reference.
-
#add_version(package, version) ⇒ Object
Adds a version and it’s dependencies to the cache.
-
#elm_dependencies(package) ⇒ Object
Gets the ‘elm-package.json` for a package.
- #elm_package(package) ⇒ Object
- #elm_package_path(package) ⇒ Object
-
#initialize(cache, git_resolver) ⇒ Resolver
constructor
Initializes a resolver for a chace.
Constructor Details
#initialize(cache, git_resolver) ⇒ Resolver
Initializes a resolver for a chace.
10 11 12 13 14 |
# File 'lib/elm_install/resolver.rb', line 10 def initialize(cache, git_resolver) @git_resolver = git_resolver @constraints = [] @cache = cache end |
Instance Attribute Details
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
7 8 9 |
# File 'lib/elm_install/resolver.rb', line 7 def constraints @constraints end |
Instance Method Details
#add_constraints(constraints) ⇒ Object
Add constraints, usually from the ‘elm-package.json`.
17 18 19 20 21 |
# File 'lib/elm_install/resolver.rb', line 17 def add_constraints(constraints) @constraints = add_dependencies(constraints) do |package, constraint| [package, constraint] end end |
#add_dependencies(dependencies) ⇒ Object
Adds dependencies, usually from any ‘elm-package.json` file.
:reek:NestedIterators { max_allowed_nesting: 2 } :reek:TooManyStatements { max_statements: 6 }
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/elm_install/resolver.rb', line 27 def add_dependencies(dependencies) dependencies.flat_map do |package, constraint| add_package(package) constraints = Utils.transform_constraint(constraint) next add_ref_dependency(package, constraint) if constraints.empty? constraints.map do |dependency| yield package, dependency end end end |
#add_package(package) ⇒ Object
Adds a package to the cache, the following things happens:
-
If there is no local repository it will be cloned
-
Getting all the tags and adding the valid ones to the cache
-
Checking out and getting the ‘elm-package.json` for each version and adding them recursivly
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/elm_install/resolver.rb', line 58 def add_package(package) return if @git_resolver.package?(package) && @cache.key?(package) @git_resolver .repository(package) . .map(&:name) .each do |version| @cache.ensure_version(package, version) add_version(package, version) end end |
#add_ref_dependency(package, ref) ⇒ Object
Adds a dependency by git reference.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/elm_install/resolver.rb', line 41 def add_ref_dependency(package, ref) @git_resolver.repository(package).checkout(ref) pkg_version = elm_package(package)['version'] version = "#{pkg_version}+#{ref}" @cache.ensure_version(package, version) add_dependencies(elm_dependencies(package)) do |dep_package, constraint| add_package(dep_package) @cache.dependency(package, version, [dep_package, constraint]) end [[package, "= #{version}"]] end |
#add_version(package, version) ⇒ Object
Adds a version and it’s dependencies to the cache.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/elm_install/resolver.rb', line 72 def add_version(package, version) @git_resolver .repository(package) .checkout(version) add_dependencies(elm_dependencies(package)) do |dep_package, constraint| add_package(dep_package) @cache.dependency(package, version, [dep_package, constraint]) end end |
#elm_dependencies(package) ⇒ Object
Gets the ‘elm-package.json` for a package.
84 85 86 87 88 |
# File 'lib/elm_install/resolver.rb', line 84 def elm_dependencies(package) ElmPackage.dependencies elm_package_path(package) rescue [] end |
#elm_package(package) ⇒ Object
90 91 92 |
# File 'lib/elm_install/resolver.rb', line 90 def elm_package(package) ElmPackage.read elm_package_path(package) end |
#elm_package_path(package) ⇒ Object
94 95 96 |
# File 'lib/elm_install/resolver.rb', line 94 def elm_package_path(package) File.join(@git_resolver.repository_path(package), 'elm-package.json') end |