class Amoeba::Config
Constants
- DEFAULTS
Public Class Methods
new(klass)
click to toggle source
# File lib/amoeba/config.rb, line 35 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 116 def clone(value = nil) enable push_value_to_array(value, :clones) end
disable()
click to toggle source
# File lib/amoeba/config.rb, line 46 def disable @config[:enabled] = false end
enable()
click to toggle source
# File lib/amoeba/config.rb, line 42 def enable @config[:enabled] = true end
exclude_association(value = nil, options = {})
click to toggle source
# File lib/amoeba/config.rb, line 105 def exclude_association(value = nil, options = {}) enable @config[:includes] = {} value = value.is_a?(Array) ? value.map! { |v| [v, options] }.to_h : { value => options } push_value_to_hash(value, :excludes) end
exclude_associations(*values)
click to toggle source
# File lib/amoeba/config.rb, line 112 def exclude_associations(*values) values.flatten.each { |v| exclude_association(v) } end
fill_hash_value_for(config_key, key, val)
click to toggle source
# File lib/amoeba/config.rb, line 90 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 94 def include_association(value = nil, options = {}) enable @config[:excludes] = {} value = value.is_a?(Array) ? value.map! { |v| [v, options] }.to_h : { value => options } push_value_to_hash(value, :includes) end
include_associations(*values)
click to toggle source
# File lib/amoeba/config.rb, line 101 def include_associations(*values) values.flatten.each { |v| include_association(v) } end
propagate(style = :submissive)
click to toggle source
# File lib/amoeba/config.rb, line 54 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 69 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 59 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 79 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 50 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 121 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 150 def remapper(value) @config[:remap_method] = value.to_sym end
through(value)
click to toggle source
# File lib/amoeba/config.rb, line 146 def through(value) @config[:dup_method] = value.to_sym end