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
-
.fs_or_classpath(path) ⇒ Object
rubocop:enable Metrics/PerceivedComplexity.
-
.read(path) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
Instance Method Summary collapse
-
#initialize ⇒ Lockfile
constructor
A new instance of Lockfile.
- #to_hash ⇒ Object (also: #to_h)
- #to_yaml ⇒ Object
- #write(path) ⇒ Object
Constructor Details
#initialize ⇒ Lockfile
Returns a new instance of Lockfile.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/lock_jar/domain/lockfile.rb', line 68 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
.fs_or_classpath(path) ⇒ Object
rubocop:enable Metrics/PerceivedComplexity
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/lock_jar/domain/lockfile.rb', line 48 def self.fs_or_classpath(path) if File.exist? path YAML.load_file(path) # Lookup of Jarfile.lock in the classpath elsif Naether.platform == 'java' || path.start_with?('classpath:') stream = java.lang.Object.java_class.resource_as_stream("/#{path.gsub('classpath:', '')}") if stream reader = java.io.BufferedReader.new(java.io.InputStreamReader.new(stream)) lines = '' while (line = reader.read_line) lines << line << "\n" end reader.close YAML.load(lines) end end end |
.read(path) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lock_jar/domain/lockfile.rb', line 28 def self.read(path) lock_data = fs_or_classpath(path) fail "lockfile #{path} not found" if lock_data.nil? Lockfile.new.tap do |lockfile| 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'] || [] end end |
Instance Method Details
#to_hash ⇒ Object Also known as: to_h
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/lock_jar/domain/lockfile.rb', line 79 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
102 103 104 |
# File 'lib/lock_jar/domain/lockfile.rb', line 102 def to_yaml to_hash.to_yaml end |
#write(path) ⇒ Object
106 107 108 109 110 |
# File 'lib/lock_jar/domain/lockfile.rb', line 106 def write(path) File.open(path, 'w') do |f| f.write(to_yaml) end end |