Sha256: c28d69f7ca73c52c6936ed241c5c76ebc8c51ed7785bfa27681907797d7329eb

Contents?: true

Size: 755 Bytes

Versions: 4

Compression:

Stored size: 755 Bytes

Contents

require 'yaml'

class FieldsReader

  YAML_PATH = File.join(RAILS_ROOT, "config", "fields_dictionary.yml")

  class << self

    def init reload=false
      raise "Missing Config File, Please Check Whether #{YAML_PATH} exists." unless File.exists?(YAML_PATH)
      if reload 
        @@config = YAML.load_file(YAML_PATH)["configs"]
      else
        @@config ||= YAML.load_file(YAML_PATH)["configs"]
      end
    end

    def method_missing mth, *args
      if mth.to_s =~ /^(.*)=$/ 
        @@config[$1] = args.first
      else
        @@config.respond_to?(mth) ? @@config.send(mth) : @@config[mth.to_s]
      end
    end

    def write_back
      File.open(YAML_PATH,'w'){|f| YAML.dump({"configs" => @@config},f)}
      init(true)
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sga_fields_synchronizer-0.1.3 lib/fields_reader.rb
sga_fields_synchronizer-0.1.2 lib/fields_reader.rb
sga_fields_synchronizer-0.1.1 lib/fields_reader.rb
sga_fields_synchronizer-0.1.0 lib/fields_reader.rb