Class: LockJar::Domain::Lockfile
- Inherits:
-
Object
- Object
- LockJar::Domain::Lockfile
- Defined in:
- lib/lock_jar/domain/lockfile.rb
Instance Attribute Summary collapse
-
#excludes ⇒ Object
Returns the value of attribute excludes.
-
#force_utf8 ⇒ Object
readonly
Returns the value of attribute force_utf8.
-
#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
Instance Method Summary collapse
-
#initialize ⇒ Lockfile
constructor
A new instance of Lockfile.
- #to_hash ⇒ Object
- #to_yaml ⇒ Object
- #write(path) ⇒ Object
Constructor Details
#initialize ⇒ Lockfile
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/lock_jar/domain/lockfile.rb', line 45 def initialize @force_utf8 ||= RUBY_VERSION =~ /^1.9/ @groups = { 'default' => {} } @maps = [] @excludes = [] @remote_repositories = [] @gems = [] @merged = [] @version = LockJar::VERSION # default version end |
Instance Attribute Details
#excludes ⇒ Object
Returns the value of attribute excludes.
23 24 25 |
# File 'lib/lock_jar/domain/lockfile.rb', line 23 def excludes @excludes end |
#force_utf8 ⇒ Object (readonly)
Returns the value of attribute force_utf8.
25 26 27 |
# File 'lib/lock_jar/domain/lockfile.rb', line 25 def force_utf8 @force_utf8 end |
#gems ⇒ Object
Returns the value of attribute gems.
23 24 25 |
# File 'lib/lock_jar/domain/lockfile.rb', line 23 def gems @gems end |
#groups ⇒ Object
Returns the value of attribute groups.
23 24 25 |
# File 'lib/lock_jar/domain/lockfile.rb', line 23 def groups @groups end |
#local_repository ⇒ Object
Returns the value of attribute local_repository.
23 24 25 |
# File 'lib/lock_jar/domain/lockfile.rb', line 23 def local_repository @local_repository end |
#maps ⇒ Object
Returns the value of attribute maps.
23 24 25 |
# File 'lib/lock_jar/domain/lockfile.rb', line 23 def maps @maps end |
#merged ⇒ Object
Returns the value of attribute merged.
23 24 25 |
# File 'lib/lock_jar/domain/lockfile.rb', line 23 def merged @merged end |
#remote_repositories ⇒ Object
Returns the value of attribute remote_repositories.
23 24 25 |
# File 'lib/lock_jar/domain/lockfile.rb', line 23 def remote_repositories @remote_repositories end |
#version ⇒ Object
Returns the value of attribute version.
23 24 25 |
# File 'lib/lock_jar/domain/lockfile.rb', line 23 def version @version end |
Class Method Details
.read(path) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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 = lock_data['remote_repositories'] || lock_data['repositories'] || [] lockfile.gems = lock_data['gems'] || [] lockfile end |
Instance Method Details
#to_hash ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/lock_jar/domain/lockfile.rb', line 57 def to_hash lock_data = { 'version' => @version } unless local_repository.nil? lock_data['local_repository'] = local_repository if @force_utf8 lock_data['local_repository'] = lock_data['local_repository'].force_encoding("UTF-8") end end unless merged.empty? lock_data['merged'] = merged end if maps.size > 0 lock_data['maps'] = maps end if excludes.size > 0 lock_data['excludes'] = excludes if @force_utf8 lock_data['excludes'].map! { |exclude| exclude.force_encoding("UTF-8") } end end unless gems.empty? lock_data['gems'] = gems end lock_data['groups'] = groups #if @force_utf8 # lock_data['groups'].each do |group, group_notations| # group_notations.map! { |notation| notation.force_encoding("UTF-8") } # end #end if remote_repositories.size > 0 lock_data['remote_repositories'] = remote_repositories end lock_data end |
#to_yaml ⇒ Object
103 104 105 |
# File 'lib/lock_jar/domain/lockfile.rb', line 103 def to_yaml to_hash.to_yaml end |
#write(path) ⇒ Object
107 108 109 110 111 |
# File 'lib/lock_jar/domain/lockfile.rb', line 107 def write( path ) File.open( path, "w") do |f| f.write( to_yaml ) end end |