Class: Carioca::Services::Settings
- Defined in:
- lib/carioca/services/configuration.rb
Overview
Note:
please do not use Standalone ( dependancy of Configuration class )
settings Hash record utilities class
Instance Attribute Summary collapse
-
#config_file ⇒ Object
the name of the config file in YAML format.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Settings
constructor
constructor (pre-open the config file in default:YAML).
-
#save! ⇒ TrueClass, FalseClass
save the Hash(self) in the file named by @config_file.
Methods inherited from Hash
#deep_symbolize, #method_missing
Constructor Details
#initialize(options = {}) ⇒ Settings
constructor (pre-open the config file in default:YAML)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/carioca/services/configuration.rb', line 77 def initialize( = {}) @config_file = [:config_file] @xml_input = [:xml_input] @content = [:content] @force_array = [:force_array] newsets = {} if @config_file then @content = File::readlines(@config_file).join if File::exist?(@config_file) end if [:xml_input] then newsets = XmlSimple.xml_in( @content, { 'ForceArray' => @force_array, 'KeepRoot' => true, }).deep_symbolize_keys else newsets = YAML::load(@content).deep_symbolize_keys end newsets = newsets[[:context].to_sym] if [:context] && newsets[[:context].to_sym] deep_merge!(self, newsets) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Hash
Instance Attribute Details
#config_file ⇒ Object
the name of the config file in YAML format
69 70 71 |
# File 'lib/carioca/services/configuration.rb', line 69 def config_file @config_file end |
Instance Method Details
#save! ⇒ TrueClass, FalseClass
Note:
TODO save in XML format
save the Hash(self) in the file named by @config_file
101 102 103 104 105 106 107 |
# File 'lib/carioca/services/configuration.rb', line 101 def save! res = false File.open(@config_file, "w") do |f| res = true if f.write(self.to_yaml) end return res end |