class Amoeba::Config
Constants
- DEFAULTS
Public Class Methods
new(klass)
click to toggle source
# File lib/amoeba/config.rb, line 51 def initialize(klass) @klass = klass @config = self.class::DEFAULTS.deep_dup end
Public Instance Methods
clone(value = nil)
click to toggle source
# File lib/amoeba/config.rb, line 144 def clone(value = nil) enable push_value_to_array(value, :clones) end
deep_dup()
click to toggle source
# File lib/amoeba/config.rb, line 27 def deep_dup each_with_object(dup) do |(key, value), hash| hash[key.deep_dup] = value.deep_dup end end
disable()
click to toggle source
# File lib/amoeba/config.rb, line 62 def disable @config[:enabled] = false end
enable()
click to toggle source
# File lib/amoeba/config.rb, line 58 def enable @config[:enabled] = true end
exclude_association(value = nil, options = {})
click to toggle source
# File lib/amoeba/config.rb, line 127 def exclude_association(value = nil, options = {}) enable @config[:includes] = {} value = value.is_a?(Array) ? Hash[value.map! { |v| [v, options] }] : { value => options } push_value_to_hash(value, :excludes) end
exclude_associations(*values)
click to toggle source
# File lib/amoeba/config.rb, line 134 def exclude_associations(*values) values.flatten.each { |v| exclude_association(v) } end
exclude_field(value = nil)
click to toggle source
TODO: remove this method in v3.0.0
# File lib/amoeba/config.rb, line 139 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)
click to toggle source
# 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, options = {})
click to toggle source
# File lib/amoeba/config.rb, line 110 def include_association(value = nil, options = {}) enable @config[:excludes] = {} value = value.is_a?(Array) ? Hash[value.map! { |v| [v, options] }] : { value => options } push_value_to_hash(value, :includes) end
include_associations(*values)
click to toggle source
# File lib/amoeba/config.rb, line 117 def include_associations(*values) values.flatten.each { |v| include_association(v) } end
include_field(value = nil)
click to toggle source
TODO: remove this method in v3.0.0
# File lib/amoeba/config.rb, line 122 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/amoeba/config.rb, line 75 def push_value_to_array(value, key) res = @config[key] if value.is_a?(::Array) res = value elsif value res << value end @config[key] = res.uniq end
push_value_to_hash(value, config_key)
click to toggle source
# 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)
click to toggle source
# File lib/amoeba/config.rb, line 66 def raised(style = :submissive) @config[:raised] = style end
Also aliased as: upbringing
recognize(value = nil)
click to toggle source
# File lib/amoeba/config.rb, line 149 def recognize(value = nil) enable push_value_to_array(value, :known_macros) end
remapper(value)
click to toggle source
# File lib/amoeba/config.rb, line 178 def remapper(value) @config[:remap_method] = value.to_sym end
through(value)
click to toggle source
# File lib/amoeba/config.rb, line 174 def through(value) @config[:dup_method] = value.to_sym end