Class: JSONAPI::Sideposting::Processor
- Inherits:
-
Object
- Object
- JSONAPI::Sideposting::Processor
- Defined in:
- lib/json_api/sideposting/processor.rb
Instance Attribute Summary collapse
-
#created_records ⇒ Object
readonly
Returns the value of attribute created_records.
-
#lid_resolver ⇒ Object
readonly
Returns the value of attribute lid_resolver.
Instance Method Summary collapse
- #create_all! ⇒ Object
-
#initialize(included:, controller:, lid_resolver: nil) ⇒ Processor
constructor
A new instance of Processor.
Constructor Details
#initialize(included:, controller:, lid_resolver: nil) ⇒ Processor
Returns a new instance of Processor.
27 28 29 30 31 32 33 34 35 |
# File 'lib/json_api/sideposting/processor.rb', line 27 def initialize(included:, controller:, lid_resolver: nil) raise ArgumentError, "included is required" if included.blank? raise ArgumentError, "controller is required" if controller.nil? @included = Array(included).map { |item| symbolize_item(item) } @controller = controller @lid_resolver = lid_resolver || LidResolver.new @created_records = [] end |
Instance Attribute Details
#created_records ⇒ Object (readonly)
Returns the value of attribute created_records.
51 52 53 |
# File 'lib/json_api/sideposting/processor.rb', line 51 def created_records @created_records end |
#lid_resolver ⇒ Object (readonly)
Returns the value of attribute lid_resolver.
51 52 53 |
# File 'lib/json_api/sideposting/processor.rb', line 51 def lid_resolver @lid_resolver end |
Instance Method Details
#create_all! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/json_api/sideposting/processor.rb', line 37 def create_all! @included.each_with_index do |item, index| record = create_one(item, index) @created_records << record lid = item[:lid].to_s.presence next unless lid resource_class = resource_class_for(item[:type]) type_name = RelationshipHelpers.resource_type_name(resource_class) @lid_resolver.add(lid, type: type_name, id: record.id) end @created_records end |