Class: DataMapper::Unlazy::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-unlazy/model.rb

Instance Method Summary collapse

Constructor Details

#initialize(model, data = nil) ⇒ Model

Returns a new instance of Model.



14
15
16
17
18
19
20
# File 'lib/dm-unlazy/model.rb', line 14

def initialize (model, data = nil)
	@model = model.new

	if data
		@model.attributes = Hash[data.each_pair.to_a]
	end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dm-unlazy/model.rb', line 22

def method_missing (id, *args, &block)
	result = @model.__send__ id, *args, &block

	if Associations::OneToMany::Collection === result
		class << result.source
			def saved?
				true
			end
		end

		result.reload

		class << result.source
			remove_method :saved?
		end
	end

	result
end