Module: SmartSettings::Attributes
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/smart_settings/attributes.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
53
54
55
|
# File 'lib/smart_settings/attributes.rb', line 53
def method_missing(method, *args, &block)
group_exists?(method) ? group(method) : super
end
|
Instance Method Details
#all ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/smart_settings/attributes.rb', line 32
def all
except = setting_groups.values.flatten + [:var]
single = attributes.symbolize_keys.except(*except)
groups = Hash[setting_groups.keys.map { |s| [s, group(s)] }]
single.merge(groups)
end
|
#group(name) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/smart_settings/attributes.rb', line 44
def group(name)
return unless group_exists?(name)
keys = setting_groups[name]
data = attributes.symbolize_keys.select { |k, _v| k.in? keys }
Hash[data.map { |k, v| [k.to_s.sub("#{name}_", '').to_sym, v] }]
end
|
#group_exists?(name) ⇒ Boolean
40
41
42
|
# File 'lib/smart_settings/attributes.rb', line 40
def group_exists?(name)
setting_groups.key? name
end
|