Method: Mongoo::AttributeProxy#method_missing

Defined in:
lib/mongoo/attribute_proxy.rb

#method_missing(name, *args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mongoo/attribute_proxy.rb', line 24

def method_missing(name, *args)
  name_s = name.to_s
  setter = false
  setter = true if name_s =~ /\=$/
  name_s.gsub!(/\=$/, '')
  
  if val = @curr_hash[name_s]
    key = (@path + [name_s]).join(".")
    if val.is_a?(Hash) && !@doc.known_attribute?(key)
      if setter
        super
      else
        AttributeProxy.new(val, (@path + [name_s]), @doc)
      end
    else
      setter ? @doc.set(key, args[0]) : @doc.get(key)
    end
  else
    super
  end
end