In Files
Parent
- Object
Included Modules
- Enumerable
Information
Index
Index tracks the name and location of each library in an environment.
Public Class Methods
Public Instance Methods
each(&block)
click to toggle source
Look through the environment table.
# File lib/roll/environment.rb, line 120
120: def each(&block)
121: @table.each(&block)
122: end
file()
click to toggle source
Environment file (full-path).
# File lib/roll/environment.rb, line 98
98: def file
99: @file ||= ::Config.find_config('roll', name, 'index').first
100: end
name()
click to toggle source
Current ledger name.
# File lib/roll/environment.rb, line 93
93: def name
94: @name
95: end
reload()
click to toggle source
Load the environment file.
# File lib/roll/environment.rb, line 103
103: def reload
104: if file && File.exist?(file)
105: File.readlines(file).each do |line|
106: line = line.strip
107: next if line.empty?
108: name, path = *line.split(/\s+/)
109: @table[name.strip] << path.strip
110: end
111: end
112: end
reset(index)
click to toggle source
# File lib/roll/environment.rb, line 115
115: def reset(index)
116: @table = index
117: end
save()
click to toggle source
Save environment file.
# File lib/roll/environment.rb, line 147
147: def save
148: out = to_s
149: #max = @table.map{ |name, paths| name.size }.max
150: #@table.map do |name, paths|
151: # paths.each do |path|
152: # out << "%-#{max}s %s\n" % [name, path]
153: # end
154: #end
155: file = File.join(::Config::CONFIG_HOME, 'roll', name, 'index')
156: if File.exist?(file)
157: data = File.read(file)
158: if out != data
159: File.open(file, 'w'){ |f| f << out }
160: #puts "updated: #{name}"
161: true
162: else
163: #puts "current: #{name}"
164: false
165: end
166: else
167: dir = File.dirname(file)
168: FileUtils.mkdir_p(dir) unless File.exist?(dir)
169: File.open(file, 'w'){ |f| f << out }
170: #puts "created: #{name}"
171: true
172: end
173: @file = file
174: end
size()
click to toggle source
Number of entries.
# File lib/roll/environment.rb, line 125
125: def size
126: @table.size
127: end
Disabled; run with --debug to generate this.