Sha256: c5c693e44e3528e0622be8f7ec6d9325d17a9c00ab53d976b031bdaf807c70f2
Contents?: true
Size: 1.04 KB
Versions: 30
Compression:
Stored size: 1.04 KB
Contents
module Mongoo class AttributeProxy def initialize(curr_hash, path, doc) @curr_hash = curr_hash @path = path @doc = doc end def unset @doc.unset @path.join(".") end def mod(opts={}, &block) builder = ModifierBuilder.new(opts.merge(:key_prefix => "#{@path.join(".")}."), @doc) block.call(builder) builder.run! end def mod!(opts={}, &block) mod(opts.merge(:safe => true), &block) end 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 end end
Version data entries
30 entries across 30 versions & 1 rubygems