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_commit_hooks! ⇒ Object
45
46
47
|
# File 'lib/handlers/savings.rb', line 45
def after_commit_hooks!
AfterCommitHooks.handle(@klass)
end
|
#after_save_hooks! ⇒ Object
#after_validations_hooks! ⇒ Object
#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
@klass.validate!
after_validations_hooks!
block ? save_with_block!(block) : save_without_block!
after_save_hooks!
end
after_commit_hooks!
@resource
rescue ActiveRecord::RecordInvalid => e
e.record.errors.add(e.record.class.name, '')
raise ActiveRecord::RecordInvalid.new(e.record)
end
|
#save_with_block!(block) ⇒ Object
30
31
32
33
34
|
# File 'lib/handlers/savings.rb', line 30
def save_with_block!(block)
@klass.instance_eval(&block)
@resource = @klass.instance_variable_get(:@resource)
@resource
end
|
#save_without_block! ⇒ Object
36
37
38
|
# File 'lib/handlers/savings.rb', line 36
def save_without_block!
@resource.update!(@params)
end
|