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
55 56 57 58 59 60 |
# File 'lib/ab_admin/models/settings.rb', line 55 def all @paths.each do |path| @data.deep_merge!(YAML.load_file(path)) end @data end |
#editable ⇒ Object
34 35 36 37 |
# File 'lib/ab_admin/models/settings.rb', line 34 def editable return {} unless editable_path YAML.load_file(editable_path) rescue {} end |
#initialize ⇒ Object
29 30 31 32 |
# File 'lib/ab_admin/models/settings.rb', line 29 def initialize @data = {} @paths = find_paths end |
#save(raw_config) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ab_admin/models/settings.rb', line 39 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 |