Class: AppCfg::ModelSource

Inherits:
Source
  • Object
show all
Defined in:
lib/appcfg/sources/model_source.rb

Instance Method Summary collapse

Methods inherited from Source

add, clear, list, reload_sources!, #to_hash

Constructor Details

#initialize(options = {}) ⇒ ModelSource

Returns a new instance of ModelSource.



3
4
5
# File 'lib/appcfg/sources/model_source.rb', line 3

def initialize(options = {})
  @model_class = options[:class]
end

Instance Method Details

#reload_data!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/appcfg/sources/model_source.rb', line 7

def reload_data!
  @hash = {}
  @model_class.all.each do |instance|
    #@hash[instance.key] = instance.value
    hsh = @hash
    idx = {}
    arr = instance.key.split('.')
    arr.each_with_index do |x,i|
      hsh[x] ||= {}
      if arr.size-1 == i
        hsh[x] = instance.value
      else
        hsh = hsh[x]
      end
    end
  end
end