Module: ConfigManager::ClassMethods

Defined in:
app/models/config_manager.rb

Instance Method Summary collapse

Instance Method Details

#default_for(key) ⇒ Object



27
28
29
# File 'app/models/config_manager.rb', line 27

def default_for(key)
  fields[key.to_s].default
end

#fieldsObject



9
10
11
# File 'app/models/config_manager.rb', line 9

def fields
  @fields ||= Hash.new { Item.new }
end

#setting(name, type = :object, default = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/config_manager.rb', line 13

def setting(name, type = :object, default = nil)
  raise "Invalid type: #{type}" unless Item::VALID_TYPES.include? type

  item = Item.new
  item.name = name.to_s
  item.ruby_type = type
  item.default = default
  fields[name.to_s] = item

  add_setting_reader(item)
  add_setting_writer(item)
  add_setting_validation(item)
end