Class: Mongo::Model::Assignment::Dsl

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDsl

Returns a new instance of Dsl.



3
4
5
# File 'lib/mongo_db/model/assignment.rb', line 3

def initialize
  @attributes = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(attribute_name, *args) ⇒ Object (protected)



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mongo_db/model/assignment.rb', line 17

def method_missing attribute_name, *args
  attribute_name.must_be.a Symbol

  args.size.must_be.in 1..2
  if args.first.is_a? Class
    type, mass_assignment = args
    mass_assignment ||= false
    type.must.respond_to :cast
  else
    type, mass_assignment = nil, args.first
  end

  attributes[attribute_name] = [type, mass_assignment]
end

Class Method Details

.const_missing(name) ⇒ Object



7
8
9
10
# File 'lib/mongo_db/model/assignment.rb', line 7

def self.const_missing name
  # BasicObject doesn't have access to any constants like String, Symbol, ...
  ::Object.const_get name
end

Instance Method Details

#to_hObject



12
# File 'lib/mongo_db/model/assignment.rb', line 12

def to_h; attributes end