Class: FieldsReader

Inherits:
Object
  • Object
show all
Defined in:
lib/fields_reader.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.init(reload = false) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/fields_reader.rb', line 9

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

.method_missing(mth, *args) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/fields_reader.rb', line 18

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

.write_backObject



26
27
28
29
# File 'lib/fields_reader.rb', line 26

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