Class: Amoeba::Config
- Inherits:
-
Object
- Object
- Amoeba::Config
- Defined in:
- lib/amoeba/config.rb
Constant Summary collapse
- DEFAULTS =
{ enabled: false, inherit: false, do_preproc: false, parenting: false, raised: false, dup_method: :dup, remap_method: nil, includes: [], excludes: [], clones: [], customizations: [], overrides: [], null_fields: [], coercions: {}, prefixes: {}, suffixes: {}, regexes: {}, known_macros: [:has_one, :has_many, :has_and_belongs_to_many] }
Instance Method Summary collapse
- #clone(value = nil) ⇒ Object
- #disable ⇒ Object
- #enable ⇒ Object
- #exclude_association(value = nil) ⇒ Object
-
#exclude_field(value = nil) ⇒ Object
TODO remove this method in v3.0.0.
- #fill_hash_value_for(config_key, key, val) ⇒ Object
- #include_association(value = nil) ⇒ Object
-
#include_field(value = nil) ⇒ Object
TODO remove this method in v3.0.0.
-
#initialize(klass) ⇒ Config
constructor
A new instance of Config.
- #propagate(style = :submissive) ⇒ Object
- #push_array_value_to_hash(value, config_key) ⇒ Object
- #push_value_to_array(value, key) ⇒ Object
- #push_value_to_hash(value, config_key) ⇒ Object
- #raised(style = :submissive) ⇒ Object
- #recognize(value = nil) ⇒ Object
- #remapper(value) ⇒ Object
- #through(value) ⇒ Object
- #upbringing ⇒ Object
Constructor Details
#initialize(klass) ⇒ Config
Returns a new instance of Config.
51 52 53 54 |
# File 'lib/amoeba/config.rb', line 51 def initialize(klass) @klass = klass @config = self.class::DEFAULTS.deep_dup end |
Instance Method Details
#clone(value = nil) ⇒ Object
134 135 136 137 |
# File 'lib/amoeba/config.rb', line 134 def clone(value = nil) @config[:enabled] = true push_value_to_array(value, :clones) end |
#disable ⇒ Object
62 63 64 |
# File 'lib/amoeba/config.rb', line 62 def disable @config[:enabled] = false end |
#enable ⇒ Object
58 59 60 |
# File 'lib/amoeba/config.rb', line 58 def enable @config[:enabled] = true end |
#exclude_association(value = nil) ⇒ Object
122 123 124 125 126 |
# File 'lib/amoeba/config.rb', line 122 def exclude_association(value = nil) @config[:enabled] = true @config[:includes] = [] push_value_to_array(value, :excludes) end |
#exclude_field(value = nil) ⇒ Object
TODO remove this method in v3.0.0
129 130 131 132 |
# File 'lib/amoeba/config.rb', line 129 def exclude_field(value = nil) warn "exclude_field is deprecated and will be removed in version 3.0.0; please use exclude_association instead" exclude_association(value) end |
#fill_hash_value_for(config_key, key, val) ⇒ Object
106 107 108 |
# File 'lib/amoeba/config.rb', line 106 def fill_hash_value_for(config_key, key, val) @config[config_key][key] = val if val || (!val.nil? && config_key == :coercions) end |
#include_association(value = nil) ⇒ Object
110 111 112 113 114 |
# File 'lib/amoeba/config.rb', line 110 def include_association(value = nil) @config[:enabled] = true @config[:excludes] = [] push_value_to_array(value, :includes) end |
#include_field(value = nil) ⇒ Object
TODO remove this method in v3.0.0
117 118 119 120 |
# File 'lib/amoeba/config.rb', line 117 def include_field(value = nil) warn "include_field is deprecated and will be removed in version 3.0.0; please use include_association instead" include_association(value) end |
#propagate(style = :submissive) ⇒ Object
70 71 72 73 |
# File 'lib/amoeba/config.rb', line 70 def propagate(style = :submissive) @config[:parenting] ||= style @config[:inherit] = true end |
#push_array_value_to_hash(value, config_key) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/amoeba/config.rb', line 85 def push_array_value_to_hash(value, config_key) @config[config_key] = {} value.each do |definition| definition.each do |key, val| fill_hash_value_for(config_key, key, val) end end end |
#push_value_to_array(value, key) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/amoeba/config.rb', line 75 def push_value_to_array(value, key) res = @config[key] if value.is_a?(::Array) res = value else res << value if value end @config[key] = res.uniq end |
#push_value_to_hash(value, config_key) ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/amoeba/config.rb', line 95 def push_value_to_hash(value, config_key) if value.is_a?(Array) push_array_value_to_hash(value, config_key) else value.each do |key, val| fill_hash_value_for(config_key, key, val) end end @config[config_key] end |
#raised(style = :submissive) ⇒ Object
66 67 68 |
# File 'lib/amoeba/config.rb', line 66 def raised(style = :submissive) @config[:raised] = style end |
#recognize(value = nil) ⇒ Object
139 140 141 142 |
# File 'lib/amoeba/config.rb', line 139 def recognize(value = nil) @config[:enabled] = true push_value_to_array(value, :known_macros) end |
#remapper(value) ⇒ Object
168 169 170 |
# File 'lib/amoeba/config.rb', line 168 def remapper(value) @config[:remap_method] = value.to_sym end |
#through(value) ⇒ Object
164 165 166 |
# File 'lib/amoeba/config.rb', line 164 def through(value) @config[:dup_method] = value.to_sym end |
#upbringing ⇒ Object
56 |
# File 'lib/amoeba/config.rb', line 56 alias_method :upbringing, :raised |