Module: Mongo::Model::Assignment

Defined in:
lib/mongo_db/model/assignment.rb

Defined Under Namespace

Modules: ClassMethods Classes: Dsl

Instance Method Summary collapse

Instance Method Details

#set(attributes, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mongo_db/model/assignment.rb', line 33

def set attributes, options = {}
  if rules = self.class._assign
    force = options[:force]
    attributes.each do |n, v|
      n = n.to_sym
      if rule = rules[n]
        type, mass_assignment = rule
        if mass_assignment or force
          v = type.cast(v) if type
          send "#{n}=", v
        end
      end
    end
  else
    attributes.each{|n, v| send "#{n}=", v}
  end
  self
end

#set!(attributes, options = {}) ⇒ Object



52
53
54
# File 'lib/mongo_db/model/assignment.rb', line 52

def set! attributes, options = {}
  set attributes, options.merge(force: true)
end