Class: RailsCom::Setting

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/rails_com/utils/setting.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Setting

Returns a new instance of Setting.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rails_com/utils/setting.rb', line 3

def initialize(hash = {})
  @table = {}
  @hash_table = {}

  hash.each do |k, v|
    if v.is_a?(Hash)
      @table[k.to_sym] = self.class.new(v)
    elsif v.is_a?(Array)
      @table[k.to_sym] = v.map { |h| h.is_a?(Hash) ? self.class.new(h) : h }
    else
      @table[k.to_sym] = v
    end
    @hash_table[k.to_sym] = v
    new_ostruct_member!(k)
  end
end

Instance Method Details

#to_hashObject



20
21
22
# File 'lib/rails_com/utils/setting.rb', line 20

def to_hash
  @hash_table.with_indifferent_access
end