Module: Intellihash::Mixins

Defined in:
lib/intellihash/mixins.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **kwargs, &block) ⇒ Object (private)



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/intellihash/mixins.rb', line 41

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

Instance Method Details

#default_formatObject



23
24
25
# File 'lib/intellihash/mixins.rb', line 23

def default_format
  @default_format ||= Intellihash.configuration.default_format
end

#default_format=(other) ⇒ Object



27
28
29
# File 'lib/intellihash/mixins.rb', line 27

def default_format=(other)
  @default_format = FORMATTER.member?(other) ? other : FORMATTER[:symbol]
end

#intelligentObject



5
6
7
# File 'lib/intellihash/mixins.rb', line 5

def intelligent
  @intelligent = @intelligent.nil? ? Intellihash.configuration.intelligent_by_default : @intelligent
end

#is_intelligent=(value) ⇒ Object



9
10
11
12
# File 'lib/intellihash/mixins.rb', line 9

def is_intelligent=(value)
  # Ensure this is a boolean
  @intelligent = value == true
end

#is_intelligent?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/intellihash/mixins.rb', line 19

def is_intelligent?
  intelligent
end

#to_intellihashObject



14
15
16
17
# File 'lib/intellihash/mixins.rb', line 14

def to_intellihash
  @intelligent = true
  self
end