Class: ElmInstall::Populator
- Inherits:
-
Object
- Object
- ElmInstall::Populator
- Defined in:
- lib/elm_install/populator.rb
Overview
This class is responsible for populating the ‘elm-stuff` directory.
Class Method Summary collapse
-
.exact_dependencies(solution) ⇒ void
Returns the exact dependencies from the solution.
-
.version_and_ref(value) ⇒ Array
Retruns the version and the ref from the given string.
Instance Method Summary collapse
-
#copy_package(package, package_path) ⇒ void
Copies the given package from it’s repository to the given path.
-
#initialize(git_resolver) ⇒ Populator
constructor
Initializes a new populator.
-
#populate(solution) ⇒ void
Populates ‘elm-stuff` from the given solution.
-
#resolve_package(package, version_str) ⇒ void
Resolves and copies a package and it’s version to ‘elm-stuff/packages` directory.
-
#write_exact_dependencies(solution) ⇒ void
Writes the ‘elm-stuff/exact-dependencies.json` file.
Constructor Details
#initialize(git_resolver) ⇒ Populator
Initializes a new populator.
7 8 9 |
# File 'lib/elm_install/populator.rb', line 7 def initialize(git_resolver) @git_resolver = git_resolver end |
Class Method Details
.exact_dependencies(solution) ⇒ void
This method returns an undefined value.
Returns the exact dependencies from the solution.
78 79 80 81 82 83 84 |
# File 'lib/elm_install/populator.rb', line 78 def self.exact_dependencies(solution) solution.each_with_object({}) do |(key, value), memo| version, = version_and_ref value memo[GitCloneUrl.parse(key).path.sub(%r{^/}, '')] = version end end |
.version_and_ref(value) ⇒ Array
Retruns the version and the ref from the given string.
91 92 93 94 95 96 97 98 |
# File 'lib/elm_install/populator.rb', line 91 def self.version_and_ref(value) match = value.match(/(.+)\+(.+)/) version = match ? match[1] : value ref = match ? match[2] : value [version, ref] end |
Instance Method Details
#copy_package(package, package_path) ⇒ void
This method returns an undefined value.
Copies the given package from it’s repository to the given path.
53 54 55 56 57 58 59 |
# File 'lib/elm_install/populator.rb', line 53 def copy_package(package, package_path) repository_path = File.join(@git_resolver.repository_path(package), '.') FileUtils.mkdir_p(package_path) FileUtils.cp_r(repository_path, package_path) FileUtils.rm_rf(File.join(package_path, '.git')) end |
#populate(solution) ⇒ void
This method returns an undefined value.
Populates ‘elm-stuff` from the given solution.
16 17 18 19 20 21 22 |
# File 'lib/elm_install/populator.rb', line 16 def populate(solution) solution.each do |package, version| resolve_package package, version end write_exact_dependencies(solution) end |
#resolve_package(package, version_str) ⇒ void
This method returns an undefined value.
Resolves and copies a package and it’s version to ‘elm-stuff/packages` directory.
:reek:TooManyStatements { max_statements: 9 }
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/elm_install/populator.rb', line 33 def resolve_package(package, version_str) version, ref = self.class.version_and_ref(version_str) package_name, package_path = Utils.package_version_path package, version @git_resolver.repository(package).checkout(ref) Logger.dot "#{package_name.bold} - #{version.bold} (#{ref})" FileUtils.rm_rf(package_path) if Dir.exist?(package_path) copy_package package, package_path end |
#write_exact_dependencies(solution) ⇒ void
This method returns an undefined value.
Writes the ‘elm-stuff/exact-dependencies.json` file.
66 67 68 69 70 71 |
# File 'lib/elm_install/populator.rb', line 66 def write_exact_dependencies(solution) File.binwrite( File.join('elm-stuff', 'exact-dependencies.json'), JSON.pretty_generate(self.class.exact_dependencies(solution)) ) end |