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 ⇒ Array
readonly
The constraints.
Instance Method Summary collapse
-
#add_constraints(constraints) ⇒ void
Add constraints, usually from the ‘elm-package.json`.
-
#add_dependencies(dependencies) ⇒ void
Adds dependencies, usually from any ‘elm-package.json` file.
-
#add_package(package) ⇒ void
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_package_dependencies(package, version) ⇒ void
Adds a package’s dependencies to the cache.
-
#add_ref_dependency(package, ref) ⇒ void
Adds a dependency by git reference.
-
#add_version(package, version) ⇒ void
Adds a version and it’s dependencies to the cache.
-
#elm_dependencies(package) ⇒ Hash
Gets the ‘elm-package.json` for a package.
-
#elm_package(package) ⇒ Hash
Retruns the contents of the ‘elm-pacakge.json` of the given package.
-
#elm_package_path(package) ⇒ String
Retruns the path of the ‘elm-pacakge.json` of the given package.
-
#initialize(cache, git_resolver) ⇒ Resolver
constructor
Initializes a resolver with a chace and git resolver.
Constructor Details
#initialize(cache, git_resolver) ⇒ Resolver
Initializes a resolver with a chace and git resolver.
14 15 16 17 18 |
# File 'lib/elm_install/resolver.rb', line 14 def initialize(cache, git_resolver) @git_resolver = git_resolver @constraints = [] @cache = cache end |
Instance Attribute Details
#constraints ⇒ Array (readonly)
Returns The constraints.
8 9 10 |
# File 'lib/elm_install/resolver.rb', line 8 def constraints @constraints end |
Instance Method Details
#add_constraints(constraints) ⇒ void
This method returns an undefined value.
Add constraints, usually from the ‘elm-package.json`.
25 26 27 28 29 |
# File 'lib/elm_install/resolver.rb', line 25 def add_constraints(constraints) @constraints = add_dependencies(constraints) do |package, constraint| [package, constraint] end end |
#add_dependencies(dependencies) ⇒ void
This method returns an undefined value.
Adds dependencies, usually from any ‘elm-package.json` file.
:reek:NestedIterators { max_allowed_nesting: 2 }
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/elm_install/resolver.rb', line 39 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) ⇒ void
This method returns an undefined value.
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
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/elm_install/resolver.rb', line 76 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_package_dependencies(package, version) ⇒ void
This method returns an undefined value.
Adds a package’s dependencies to the cache.
95 96 97 98 99 100 |
# File 'lib/elm_install/resolver.rb', line 95 def add_package_dependencies(package, version) add_dependencies(elm_dependencies(package)) do |dep_package, constraint| add_package(dep_package) @cache.dependency(package, version, [dep_package, constraint]) end end |
#add_ref_dependency(package, ref) ⇒ void
This method returns an undefined value.
Adds a dependency by git reference.
58 59 60 61 62 63 64 65 |
# File 'lib/elm_install/resolver.rb', line 58 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_package_dependencies(package, version) [[package, "= #{version}"]] end |
#add_version(package, version) ⇒ void
This method returns an undefined value.
Adds a version and it’s dependencies to the cache.
108 109 110 111 112 113 114 |
# File 'lib/elm_install/resolver.rb', line 108 def add_version(package, version) @git_resolver .repository(package) .checkout(version) add_package_dependencies(package, version) end |
#elm_dependencies(package) ⇒ Hash
Gets the ‘elm-package.json` for a package.
121 122 123 124 125 |
# File 'lib/elm_install/resolver.rb', line 121 def elm_dependencies(package) ElmPackage.dependencies elm_package_path(package) rescue {} end |
#elm_package(package) ⇒ Hash
Retruns the contents of the ‘elm-pacakge.json` of the given package.
132 133 134 |
# File 'lib/elm_install/resolver.rb', line 132 def elm_package(package) ElmPackage.read elm_package_path(package) end |
#elm_package_path(package) ⇒ String
Retruns the path of the ‘elm-pacakge.json` of the given package.
141 142 143 |
# File 'lib/elm_install/resolver.rb', line 141 def elm_package_path(package) File.join(@git_resolver.repository_path(package), 'elm-package.json') end |