Module: AbAdmin::Models::Settings
- Extended by:
- ActiveSupport::Concern
- Included in:
- Settings
- Defined in:
- lib/ab_admin/models/settings.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#all ⇒ Object
54 55 56 57 58 59 |
# File 'lib/ab_admin/models/settings.rb', line 54 def all @paths.each do |path| @data.deep_merge!(YAML.load_file(path)) end @data end |
#editable ⇒ Object
33 34 35 36 |
# File 'lib/ab_admin/models/settings.rb', line 33 def editable return {} unless editable_path YAML.load_file(editable_path) rescue {} end |
#initialize ⇒ Object
28 29 30 31 |
# File 'lib/ab_admin/models/settings.rb', line 28 def initialize @data = {} @paths = find_paths end |
#save(raw_config) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ab_admin/models/settings.rb', line 38 def save(raw_config) config = {} raw_config.each do |root_key, root_value| if root_value.is_a?(Hash) config[root_key] ||= {} root_value.each do |key, value| config[root_key][key] = typecast_value(value) end else config[root_key] = typecast_value(root_value) end end return unless editable_path File.open(editable_path, 'w') { |file| file.write config.to_yaml } and self.class.load_config end |