Sha256: 46eb20ca90bbc9d58faefbb179dc4f6d25ddad938d4026014fd5281b0697619f
Contents?: true
Size: 1.36 KB
Versions: 75
Compression:
Stored size: 1.36 KB
Contents
module Alula module ApiOperations module List def self.extended(base) base.include(InstanceMethods) end def method_missing(method, *args, &block) QueryInterface.new(self).send(method, *args, &block) end def list(filters = {}, opts = {}) response = Alula::Client.request(:get, resource_url, filters, opts) if response.ok? list = ListObject.construct_from_response(self, response, opts) list = build_and_merge_list_relationships(list, response.data['included']) if response.data['included'] list else error_class = AlulaError.for_response(response) raise error_class end end def build_and_merge_list_relationships(collection, relations) relations.each do |relation| model = Alula.class_from_resource_type(relation['type']) model = model.new.construct_from(relation) key = { type: model.get_type, id: model.id }.freeze # # TODO: Remove this line. This makes us ignore unknown relationships unless get_relationship(model.get_type).nil? collection.select{ |m| m.link_matchers.include?(key) } .each { |m| m.add_model_to_relationship(model) } end end collection end module InstanceMethods end end end end
Version data entries
75 entries across 75 versions & 1 rubygems