Class: IOSBox::Config
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- IOSBox::Config
- Defined in:
- lib/ios-box/config.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
6 7 8 |
# File 'lib/ios-box/config.rb', line 6 def file @file end |
Class Method Details
.load(file) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ios-box/config.rb', line 8 def self.load(file) if File.exists?(file) config = self.new(YAML.load(File.read(file))) else config = self.new end config.file = file config end |
Instance Method Details
#save(file = nil) ⇒ Object
19 20 21 22 |
# File 'lib/ios-box/config.rb', line 19 def save(file = nil) puts "Saving config to #{file || @file}" File.open(file || @file, 'w') {|io| io.puts @table.to_yaml } end |
#to_a ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ios-box/config.rb', line 24 def to_a res = [] @table.collect do |k,v| if v.kind_of?(Hash) res << ["#{k.to_s}:", ""] v.each {|k,v| res << [" #{k.to_s}", v]} else res << [k.to_s, v] end end res end |