yml configuration file objectification

SETTING = Rails.application.config_for('settings/setting')

class Setting < OpenStruct

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

    if hash
      hash.each do |k, v|
        @table[k.to_sym] = v.is_a?(Hash) ? self.class.new(v) : v
        @hash_table[k.to_sym] = v

        new_ostruct_member(k)
      end
    end
  end

  def to_hash
    @hash_table
  end

end

Settings = Setting.new SETTING

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326422354&siteId=291194637