Class: LockJar::Domain::Lockfile

Inherits:
Object
  • Object
show all
Defined in:
lib/lock_jar/domain/lockfile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLockfile

Returns a new instance of 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

#excludesObject

Returns the value of attribute excludes.



23
24
25
# File 'lib/lock_jar/domain/lockfile.rb', line 23

def excludes
  @excludes
end

#force_utf8Object (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

#gemsObject

Returns the value of attribute gems.



23
24
25
# File 'lib/lock_jar/domain/lockfile.rb', line 23

def gems
  @gems
end

#groupsObject

Returns the value of attribute groups.



23
24
25
# File 'lib/lock_jar/domain/lockfile.rb', line 23

def groups
  @groups
end

#local_repositoryObject

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

#mapsObject

Returns the value of attribute maps.



23
24
25
# File 'lib/lock_jar/domain/lockfile.rb', line 23

def maps
  @maps
end

#mergedObject

Returns the value of attribute merged.



23
24
25
# File 'lib/lock_jar/domain/lockfile.rb', line 23

def merged
  @merged
end

#remote_repositoriesObject

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

#versionObject

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_hashObject



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_yamlObject



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