Class: Gemstar::LockFile
- Inherits:
-
Object
- Object
- Gemstar::LockFile
- Defined in:
- lib/gemstar/lock_file.rb
Instance Attribute Summary collapse
-
#dependency_graph ⇒ Object
readonly
Returns the value of attribute dependency_graph.
-
#dependency_requirements ⇒ Object
readonly
Returns the value of attribute dependency_requirements.
-
#direct_dependencies ⇒ Object
readonly
Returns the value of attribute direct_dependencies.
-
#direct_dependency_requirements ⇒ Object
readonly
Returns the value of attribute direct_dependency_requirements.
-
#spec_sources ⇒ Object
readonly
Returns the value of attribute spec_sources.
-
#specs ⇒ Object
readonly
Returns the value of attribute specs.
Instance Method Summary collapse
-
#initialize(path: nil, content: nil) ⇒ LockFile
constructor
A new instance of LockFile.
- #origins_for(gem_name) ⇒ Object
- #platform_for(gem_name) ⇒ Object
- #source_for(gem_name) ⇒ Object
Constructor Details
#initialize(path: nil, content: nil) ⇒ LockFile
Returns a new instance of LockFile.
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/gemstar/lock_file.rb', line 3 def initialize(path: nil, content: nil) @path = path parsed = content ? parse_content(content) : parse_lockfile(path) @specs = parsed[:specs] @dependency_graph = parsed[:dependency_graph] @dependency_requirements = parsed[:dependency_requirements] @direct_dependencies = parsed[:direct_dependencies] @direct_dependency_requirements = parsed[:direct_dependency_requirements] @spec_sources = parsed[:spec_sources] end |
Instance Attribute Details
#dependency_graph ⇒ Object (readonly)
Returns the value of attribute dependency_graph.
15 16 17 |
# File 'lib/gemstar/lock_file.rb', line 15 def dependency_graph @dependency_graph end |
#dependency_requirements ⇒ Object (readonly)
Returns the value of attribute dependency_requirements.
16 17 18 |
# File 'lib/gemstar/lock_file.rb', line 16 def dependency_requirements @dependency_requirements end |
#direct_dependencies ⇒ Object (readonly)
Returns the value of attribute direct_dependencies.
17 18 19 |
# File 'lib/gemstar/lock_file.rb', line 17 def direct_dependencies @direct_dependencies end |
#direct_dependency_requirements ⇒ Object (readonly)
Returns the value of attribute direct_dependency_requirements.
18 19 20 |
# File 'lib/gemstar/lock_file.rb', line 18 def direct_dependency_requirements @direct_dependency_requirements end |
#spec_sources ⇒ Object (readonly)
Returns the value of attribute spec_sources.
19 20 21 |
# File 'lib/gemstar/lock_file.rb', line 19 def spec_sources @spec_sources end |
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
14 15 16 |
# File 'lib/gemstar/lock_file.rb', line 14 def specs @specs end |
Instance Method Details
#origins_for(gem_name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gemstar/lock_file.rb', line 21 def origins_for(gem_name) if direct_dependencies.include?(gem_name) return [{ type: :direct, path: [gem_name], requirement: direct_dependency_requirements[gem_name] }] end direct_dependencies.filter_map do |root_dependency| path = shortest_path_from(root_dependency, gem_name) next if path.nil? parent_name = path[-2] { type: :transitive, path: path, requirement: dependency_requirements.dig(parent_name, gem_name) } end end |
#platform_for(gem_name) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gemstar/lock_file.rb', line 47 def platform_for(gem_name) version = specs[gem_name].to_s parts = version.split("-") return nil if parts.length < 2 1.upto(parts.length - 1) do |index| candidate_version = parts[0...index].join("-") candidate_platform = parts[index..].join("-") next unless plausible_platform_suffix?(candidate_platform) begin Gem::Version.new(candidate_version) return candidate_platform rescue ArgumentError next end end nil end |
#source_for(gem_name) ⇒ Object
43 44 45 |
# File 'lib/gemstar/lock_file.rb', line 43 def source_for(gem_name) spec_sources[gem_name] end |