Class: Plucky::OptionsHash
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Private: The Hash that stores instance options.
-
#source ⇒ Object
readonly
Private: The Hash that stores the query options.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Public.
-
#[](key) ⇒ Object
Public.
-
#[]=(key, value) ⇒ Object
Public.
-
#fields? ⇒ Boolean
Public.
-
#initialize(hash = {}, options = {}) ⇒ OptionsHash
constructor
Public.
- #initialize_copy(original) ⇒ Object
-
#key_normalizer ⇒ Object
Private.
-
#keys ⇒ Object
Public.
-
#merge(other) ⇒ Object
Public.
-
#merge!(other) ⇒ Object
Public.
-
#normalized_key(key) ⇒ Object
Private.
-
#normalized_value(key, value) ⇒ Object
Private.
-
#to_hash ⇒ Object
Public.
-
#value_normalizer ⇒ Object
Private.
Constructor Details
#initialize(hash = {}, options = {}) ⇒ OptionsHash
Public
16 17 18 19 20 |
# File 'lib/plucky/options_hash.rb', line 16 def initialize(hash={}, ={}) @source = {} @options = hash.each { |key, value| self[key] = value } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Private: The Hash that stores instance options
13 14 15 |
# File 'lib/plucky/options_hash.rb', line 13 def @options end |
#source ⇒ Object (readonly)
Private: The Hash that stores the query options
10 11 12 |
# File 'lib/plucky/options_hash.rb', line 10 def source @source end |
Instance Method Details
#==(other) ⇒ Object
Public
47 48 49 |
# File 'lib/plucky/options_hash.rb', line 47 def ==(other) @source == other.source end |
#[](key) ⇒ Object
Public
31 32 33 |
# File 'lib/plucky/options_hash.rb', line 31 def [](key) @source[key] end |
#[]=(key, value) ⇒ Object
Public
36 37 38 39 |
# File 'lib/plucky/options_hash.rb', line 36 def []=(key, value) key = normalized_key(key) @source[key] = normalized_value(key, value) end |
#fields? ⇒ Boolean
Public
57 58 59 |
# File 'lib/plucky/options_hash.rb', line 57 def fields? !self[:fields].nil? end |
#initialize_copy(original) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/plucky/options_hash.rb', line 22 def initialize_copy(original) super @source = @source.dup @source.each do |key, value| self[key] = value.clone if value.duplicable? end end |
#key_normalizer ⇒ Object
Private
83 84 85 86 87 |
# File 'lib/plucky/options_hash.rb', line 83 def key_normalizer @key_normalizer ||= @options.fetch(:key_normalizer) { Normalizers::OptionsHashKey.new } end |
#keys ⇒ Object
Public
42 43 44 |
# File 'lib/plucky/options_hash.rb', line 42 def keys @source.keys end |
#merge(other) ⇒ Object
Public
62 63 64 |
# File 'lib/plucky/options_hash.rb', line 62 def merge(other) self.class.new(to_hash.merge(other.to_hash)) end |
#merge!(other) ⇒ Object
Public
67 68 69 70 |
# File 'lib/plucky/options_hash.rb', line 67 def merge!(other) other.to_hash.each { |key, value| self[key] = value } self end |
#normalized_key(key) ⇒ Object
Private
73 74 75 |
# File 'lib/plucky/options_hash.rb', line 73 def normalized_key(key) key_normalizer.call(key) end |
#normalized_value(key, value) ⇒ Object
Private
78 79 80 |
# File 'lib/plucky/options_hash.rb', line 78 def normalized_value(key, value) value_normalizer.call(key, value) end |
#to_hash ⇒ Object
Public
52 53 54 |
# File 'lib/plucky/options_hash.rb', line 52 def to_hash @source end |
#value_normalizer ⇒ Object
Private
90 91 92 93 94 95 96 |
# File 'lib/plucky/options_hash.rb', line 90 def value_normalizer @value_normalizer ||= @options.fetch(:value_normalizer) { Normalizers::OptionsHashValue.new({ :key_normalizer => key_normalizer, }) } end |