module Intellihash::Mixins
Constants
- FORMATTER
Public Instance Methods
default_format()
click to toggle source
# File lib/intellihash/mixins.rb, line 25 def default_format return @default_format if frozen? @default_format ||= Intellihash.configuration.default_format end
default_format=(other)
click to toggle source
# File lib/intellihash/mixins.rb, line 31 def default_format=(other) @default_format = FORMATTER.member?(other) ? other : FORMATTER[:symbol] end
freeze()
click to toggle source
Calls superclass method
# File lib/intellihash/mixins.rb, line 35 def freeze # Touch these attributes if it hasn't already happened, ensure they're not nil intelligent default_format super end
intelligent()
click to toggle source
# File lib/intellihash/mixins.rb, line 5 def intelligent return @intelligent if frozen? @intelligent = @intelligent.nil? ? Intellihash.configuration.intelligent_by_default : @intelligent end
is_intelligent=(value)
click to toggle source
# File lib/intellihash/mixins.rb, line 11 def is_intelligent=(value) # Ensure this is a boolean @intelligent = value == true end
is_intelligent?()
click to toggle source
# File lib/intellihash/mixins.rb, line 21 def is_intelligent? intelligent end
to_intellihash()
click to toggle source
# File lib/intellihash/mixins.rb, line 16 def to_intellihash @intelligent = true self end
Private Instance Methods
fetch_where_present(method_name)
click to toggle source
# File lib/intellihash/mixins.rb, line 85 def fetch_where_present(method_name) return send(:[], method_name.to_sym) if member?(method_name.to_sym) return send(:[], method_name.to_s) if member?(method_name.to_s) end
format(value)
click to toggle source
# File lib/intellihash/mixins.rb, line 81 def format(value) FORMATTER.include?(value) ? FORMATTER[value] : FORMATTER[:symbol] end
key_retrieve_from(options)
click to toggle source
# File lib/intellihash/mixins.rb, line 76 def key_retrieve_from(options) from_option = options.fetch(:from) { default_format } format(from_option) end
key_store_as()
click to toggle source
# File lib/intellihash/mixins.rb, line 71 def key_store_as key_format = default_format == :any ? FORMATTER[:symbol] : FORMATTER[default_format] key_format || FORMATTER[:symbol] end
method_missing(method_name, *args, **kwargs, &block)
click to toggle source
Calls superclass method
# File lib/intellihash/mixins.rb, line 53 def method_missing(method_name, *args, **kwargs, &block) super unless respond_to?(:is_intelligent?) && is_intelligent? if method_name[-1] == '=' send(:store, method_name[0, method_name.size - 1].send(key_store_as), args.first) else format_method = key_retrieve_from(kwargs) case format_method when :any then fetch_where_present(method_name) else send(:[], method_name.send(format_method)) end end end
respond_to_missing?(*)
click to toggle source
Calls superclass method
# File lib/intellihash/mixins.rb, line 67 def respond_to_missing?(*) is_intelligent? ? true : super end