Class: RBS::Collection::Config::Lockfile
- Inherits:
-
Object
- Object
- RBS::Collection::Config::Lockfile
- Defined in:
- sig/collection/config/lockfile.rbs,
lib/rbs/collection/config/lockfile.rb
Overview
Lockfile represents the rbs_collection.lock.yaml, that contains configurations and resolved gems with their sources
Instance Attribute Summary collapse
-
#gemfile_lock_path ⇒ Pathname?
readonly
Relative to lockfile_dir.
-
#gems ⇒ Hash[String, library]
readonly
Returns the value of attribute gems.
-
#lockfile_dir ⇒ Pathname
readonly
Path of the directory where lockfile is saved in.
-
#lockfile_path ⇒ Pathname
readonly
Returns the value of attribute lockfile_path.
-
#path ⇒ Pathname
readonly
Relative to lockfile_dir.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Class Method Summary collapse
Instance Method Summary collapse
-
#check_rbs_availability! ⇒ void
Validates if directories are set up correctly.
-
#fullpath ⇒ Pathname
lockfile_dir+path. - #gemfile_lock_fullpath ⇒ Object
-
#initialize(lockfile_path:, path:, gemfile_lock_path:) ⇒ Lockfile
constructor
A new instance of Lockfile.
- #library_data(lib) ⇒ library_data
- #to_lockfile ⇒ lockfile_data
Constructor Details
#initialize(lockfile_path:, path:, gemfile_lock_path:) ⇒ Lockfile
Returns a new instance of Lockfile.
9 10 11 12 13 14 15 16 |
# File 'lib/rbs/collection/config/lockfile.rb', line 9 def initialize(lockfile_path:, path:, gemfile_lock_path:) @lockfile_path = lockfile_path @lockfile_dir = lockfile_path.parent @path = path @gemfile_lock_path = gemfile_lock_path @gems = {} end |
Instance Attribute Details
#gemfile_lock_path ⇒ Pathname? (readonly)
Relative to lockfile_dir
43 44 45 |
# File 'sig/collection/config/lockfile.rbs', line 43 def gemfile_lock_path @gemfile_lock_path end |
#gems ⇒ Hash[String, library] (readonly)
Returns the value of attribute gems.
7 8 9 |
# File 'lib/rbs/collection/config/lockfile.rb', line 7 def gems @gems end |
#lockfile_dir ⇒ Pathname (readonly)
Path of the directory where lockfile is saved in
lockfile_path.parent
35 36 37 |
# File 'sig/collection/config/lockfile.rbs', line 35 def lockfile_dir @lockfile_dir end |
#lockfile_path ⇒ Pathname (readonly)
Returns the value of attribute lockfile_path.
7 8 9 |
# File 'lib/rbs/collection/config/lockfile.rb', line 7 def lockfile_path @lockfile_path end |
#path ⇒ Pathname (readonly)
Relative to lockfile_dir
39 40 41 |
# File 'sig/collection/config/lockfile.rbs', line 39 def path @path end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
7 8 9 |
# File 'lib/rbs/collection/config/lockfile.rb', line 7 def sources @sources end |
Class Method Details
.from_lockfile(lockfile_path:, data:) ⇒ Lockfile
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rbs/collection/config/lockfile.rb', line 42 def self.from_lockfile(lockfile_path:, data:) path = Pathname(data["path"]) if p = data["gemfile_lock_path"] gemfile_lock_path = Pathname(p) end lockfile = Lockfile.new(lockfile_path: lockfile_path, path: path, gemfile_lock_path: gemfile_lock_path) if gems = data["gems"] gems.each do |gem| src = gem["source"] source = Sources.from_config_entry(src, base_directory: lockfile_path.dirname) lockfile.gems[gem["name"]] = { name: gem["name"], version: gem["version"], source: source } end end lockfile end |
Instance Method Details
#check_rbs_availability! ⇒ void
This method returns an undefined value.
Validates if directories are set up correctly
- Ensures if
pathis a directory - Ensures if
gitsources are set up correctly
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'sig/collection/config/lockfile.rbs', line 66 def check_rbs_availability! raise CollectionNotAvailable unless fullpath.exist? gems.each_value do |gem| source = gem[:source] case source when Sources::Git = fullpath.join(gem[:name], gem[:version], Sources::Git::METADATA_FILENAME) raise CollectionNotAvailable unless .exist? raise CollectionNotAvailable unless library_data(gem) == YAML.load(.read) when Sources::Local raise CollectionNotAvailable unless fullpath.join(gem[:name], gem[:version]).symlink? end end end |
#fullpath ⇒ Pathname
lockfile_dir + path
51 52 53 |
# File 'sig/collection/config/lockfile.rbs', line 51 def fullpath lockfile_dir + path end |
#gemfile_lock_fullpath ⇒ Object
22 23 24 25 26 |
# File 'lib/rbs/collection/config/lockfile.rb', line 22 def gemfile_lock_fullpath if gemfile_lock_path lockfile_dir + gemfile_lock_path end end |
#library_data(lib) ⇒ library_data
65 66 67 68 69 70 71 |
# File 'lib/rbs/collection/config/lockfile.rb', line 65 def library_data(lib) { "name" => lib[:name], "version" => lib[:version], "source" => lib[:source].to_lockfile } end |
#to_lockfile ⇒ lockfile_data
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rbs/collection/config/lockfile.rb', line 28 def to_lockfile # @type var data: lockfile_data data = { "path" => path.to_s, "gems" => gems.each_value.sort_by {|g| g[:name] }.map {|hash| library_data(hash) }, "gemfile_lock_path" => gemfile_lock_path.to_s } data.delete("gems") if gems.empty? data end |