Class: Handlers::Savings
- Inherits:
-
Base
- Object
- Base
- Handlers::Savings
show all
- Defined in:
- lib/handlers/savings.rb
Instance Method Summary
collapse
Methods inherited from Base
handle, #initialize, #raise_error, #upper
Constructor Details
This class inherits a constructor from Handlers::Base
Instance Method Details
#after_save_hooks! ⇒ Object
25
26
27
|
# File 'lib/handlers/savings.rb', line 25
def after_save_hooks!
Delegates.handle(@klass)
end
|
#before_save_hooks! ⇒ Object
39
40
41
|
# File 'lib/handlers/savings.rb', line 39
def before_save_hooks!
Polymorphs.handle(@klass)
end
|
#save!(&block) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/handlers/savings.rb', line 11
def save!(&block)
ActiveRecord::Base.transaction do
return save_associated_forms! unless upper('@@associated_forms').nil?
@klass.validate!
before_save_hooks!
block ? save_with_block!(block) : save_without_block!
after_save_hooks!
@resource
end
rescue ActiveRecord::RecordInvalid => e
e.record.errors.add(e.record.class.name, '')
raise ActiveRecord::RecordInvalid.new(e.record)
end
|
43
44
45
|
# File 'lib/handlers/savings.rb', line 43
def save_associated_forms!
Associates.new(@klass).save_associated_forms!
end
|
#save_with_block!(block) ⇒ Object
29
30
31
32
33
|
# File 'lib/handlers/savings.rb', line 29
def save_with_block!(block)
@klass.instance_eval(&block)
@resource = @klass.instance_variable_get(:@resource)
@resource.try(:save!)
end
|
#save_without_block! ⇒ Object
35
36
37
|
# File 'lib/handlers/savings.rb', line 35
def save_without_block!
@resource.update!(@params)
end
|