Module: Flatter::Mapper::Persistence
- Extended by:
- ActiveSupport::Concern
- Included in:
- Flatter::Mapper
- Defined in:
- lib/flatter/mapper/persistence.rb
Instance Method Summary collapse
- #apply(params) ⇒ Object
- #errors ⇒ Object
- #run_save! ⇒ Object
- #run_validations! ⇒ Object
- #save ⇒ Object
- #valid? ⇒ Boolean
- #with_callbacks(type, chain = self_mountings, &block) ⇒ Object
Instance Method Details
#apply(params) ⇒ Object
11 12 13 14 |
# File 'lib/flatter/mapper/persistence.rb', line 11 def apply(params) write(params) valid? && save end |
#errors ⇒ Object
79 80 81 |
# File 'lib/flatter/mapper/persistence.rb', line 79 def errors trait? ? mounter.errors : super end |
#run_save! ⇒ Object
32 33 34 |
# File 'lib/flatter/mapper/persistence.rb', line 32 def run_save! with_callbacks(:save){ save_target } end |
#run_validations! ⇒ Object
22 23 24 25 |
# File 'lib/flatter/mapper/persistence.rb', line 22 def run_validations! errors.clear with_callbacks(:validate) end |
#save ⇒ Object
27 28 29 30 |
# File 'lib/flatter/mapper/persistence.rb', line 27 def save results = mappers_chain(:save).map(&:run_save!) results.all? end |
#valid? ⇒ Boolean
16 17 18 19 20 |
# File 'lib/flatter/mapper/persistence.rb', line 16 def valid?(*) mappers_chain(:validate).each(&:run_validations!) consolidate_errors! errors.empty? end |
#with_callbacks(type, chain = self_mountings, &block) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/flatter/mapper/persistence.rb', line 46 def with_callbacks(type, chain = self_mountings, &block) current = chain.shift current.run_callbacks(type) do chain.present? ? with_callbacks(type, chain, &block) : (yield if block_given?) end end |