Class: Encore::Persister::Instance
- Inherits:
-
Object
- Object
- Encore::Persister::Instance
- Includes:
- ErrorsParser, LinksParser
- Defined in:
- lib/encore/persister/instance.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #active_records ⇒ Object
-
#initialize(model, payload, options = {}) ⇒ Instance
constructor
A new instance of Instance.
- #persist! ⇒ Object
Methods included from ErrorsParser
Methods included from LinksParser
Constructor Details
#initialize(model, payload, options = {}) ⇒ Instance
Returns a new instance of Instance.
14 15 16 17 18 19 20 |
# File 'lib/encore/persister/instance.rb', line 14 def initialize(model, payload, = {}) @model = model @payload = payload @options = @errors = [] @ids = Set.new end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
12 13 14 |
# File 'lib/encore/persister/instance.rb', line 12 def errors @errors end |
Instance Method Details
#active_records ⇒ Object
34 35 36 |
# File 'lib/encore/persister/instance.rb', line 34 def active_records active_record_class.where(id: @ids.to_a.compact) end |
#persist! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/encore/persister/instance.rb', line 22 def persist! @model.transaction do procces_payload!(action) if @errors.any? || @ids.empty? raise ActiveRecord::Rollback end true end end |