Class: LockJar::Domain::Lockfile
- Inherits:
-
Object
- Object
- LockJar::Domain::Lockfile
- Defined in:
- lib/lock_jar/domain/lockfile.rb
Overview
Class representation of the lock file
Instance Attribute Summary collapse
-
#excludes ⇒ Object
Returns the value of attribute excludes.
-
#gems ⇒ Object
Returns the value of attribute gems.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#local_repository ⇒ Object
Returns the value of attribute local_repository.
-
#maps ⇒ Object
Returns the value of attribute maps.
-
#merged ⇒ Object
Returns the value of attribute merged.
-
#remote_repositories ⇒ Object
Returns the value of attribute remote_repositories.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.read(path) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
Instance Method Summary collapse
-
#initialize ⇒ Lockfile
constructor
rubocop:enable Metrics/PerceivedComplexity.
- #to_hash ⇒ Object (also: #to_h)
- #to_yaml ⇒ Object
- #write(path) ⇒ Object
Constructor Details
#initialize ⇒ Lockfile
rubocop:enable Metrics/PerceivedComplexity
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lock_jar/domain/lockfile.rb', line 47 def initialize @groups = { 'default' => {} } @maps = [] @excludes = [] @remote_repositories = Set.new @gems = [] @merged = [] @version = LockJar::VERSION # default version end |
Instance Attribute Details
#excludes ⇒ Object
Returns the value of attribute excludes.
24 25 26 |
# File 'lib/lock_jar/domain/lockfile.rb', line 24 def excludes @excludes end |
#gems ⇒ Object
Returns the value of attribute gems.
24 25 26 |
# File 'lib/lock_jar/domain/lockfile.rb', line 24 def gems @gems end |
#groups ⇒ Object
Returns the value of attribute groups.
24 25 26 |
# File 'lib/lock_jar/domain/lockfile.rb', line 24 def groups @groups end |
#local_repository ⇒ Object
Returns the value of attribute local_repository.
24 25 26 |
# File 'lib/lock_jar/domain/lockfile.rb', line 24 def local_repository @local_repository end |
#maps ⇒ Object
Returns the value of attribute maps.
24 25 26 |
# File 'lib/lock_jar/domain/lockfile.rb', line 24 def maps @maps end |
#merged ⇒ Object
Returns the value of attribute merged.
24 25 26 |
# File 'lib/lock_jar/domain/lockfile.rb', line 24 def merged @merged end |
#remote_repositories ⇒ Object
Returns the value of attribute remote_repositories.
24 25 26 |
# File 'lib/lock_jar/domain/lockfile.rb', line 24 def remote_repositories @remote_repositories end |
#version ⇒ Object
Returns the value of attribute version.
24 25 26 |
# File 'lib/lock_jar/domain/lockfile.rb', line 24 def version @version end |
Class Method Details
.read(path) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lock_jar/domain/lockfile.rb', line 28 def self.read(path) lockfile = Lockfile.new lock_data = YAML.load_file(path) lockfile.version = lock_data['version'] || LockJar::VERSION lockfile.merged = lock_data['merged'] lockfile.local_repository = lock_data['local_repository'] lockfile.merged = lock_data['merged'] || [] lockfile.maps = lock_data['maps'] || [] lockfile.excludes = lock_data['excludes'] || [] lockfile.groups = lock_data['groups'] || lock_data['scopes'] || {} lockfile.remote_repositories = Set.new(Array(lock_data['remote_repositories'] || lock_data['repositories'])) lockfile.gems = lock_data['gems'] || [] lockfile end |
Instance Method Details
#to_hash ⇒ Object Also known as: to_h
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/lock_jar/domain/lockfile.rb', line 58 def to_hash lock_data = { 'version' => @version } lock_data['local_repository'] = local_repository unless local_repository.nil? lock_data['merged'] = merged unless merged.empty? lock_data['maps'] = maps if maps.size > 0 lock_data['excludes'] = excludes if excludes.size > 0 lock_data['gems'] = gems unless gems.empty? lock_data['groups'] = groups if remote_repositories.size > 0 lock_data['remote_repositories'] = remote_repositories.to_a end lock_data end |
#to_yaml ⇒ Object
81 82 83 |
# File 'lib/lock_jar/domain/lockfile.rb', line 81 def to_yaml to_hash.to_yaml end |
#write(path) ⇒ Object
85 86 87 88 89 |
# File 'lib/lock_jar/domain/lockfile.rb', line 85 def write(path) File.open(path, 'w') do |f| f.write(to_yaml) end end |