class Desertcart::Searcher

Public Instance Methods

deserialized_resource(hash:) click to toggle source
# File lib/desertcart/searcher.rb, line 25
def deserialized_resource(hash:)
  searcher_deserializer.deserialize(
    hash: hash,
    resource: resource_class.new
  )
end
ledger_namespace_path() click to toggle source
# File lib/desertcart/searcher.rb, line 53
def ledger_namespace_path
  @ledger_namespace_path ||= nil
end
ledger_resource_type() click to toggle source
# File lib/desertcart/searcher.rb, line 64
def ledger_resource_type
  @ledger_resource_type ||= client.class.ledger_resource_type_for(
    resource_class: resource_class
  )
end
ledger_resources_path() click to toggle source
# File lib/desertcart/searcher.rb, line 57
def ledger_resources_path
  @ledger_resources_path ||= [
    ledger_namespace_path,
    ledger_resource_type.pluralize
  ].compact.join('/')
end
next?() click to toggle source
# File lib/desertcart/searcher.rb, line 16
def next?
  case response.status
  when 200
    response.body.dig('meta', 'pagination', 'next_page')
  else
    false
  end
end
resource_class() click to toggle source
# File lib/desertcart/searcher.rb, line 39
def resource_class
  @resource_class ||= self.class.inferred_resource_class
end
resources() click to toggle source
# File lib/desertcart/searcher.rb, line 5
def resources
  case response.status
  when 200
    response.body
            .fetch(ledger_resource_type.pluralize)
            .map { |o| deserialized_resource(hash: o) }
  else
    []
  end
end
response() click to toggle source
# File lib/desertcart/searcher.rb, line 32
def response
  @response ||= client.read(
    path: ledger_resources_path,
    params: query
  )
end
searcher_deserializer() click to toggle source
# File lib/desertcart/searcher.rb, line 49
def searcher_deserializer
  searcher_deserializer_class.new
end
searcher_deserializer_class() click to toggle source
# File lib/desertcart/searcher.rb, line 43
def searcher_deserializer_class
  @searcher_deserializer_class ||= self.class.inferred_serialization_class(
    type: 'SearcherDeserializer'
  )
end