Class: Hyrax::CustomQueries::FindBySourceIdentifier

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/custom_queries/find_by_source_identifier.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_service:) ⇒ FindBySourceIdentifier

Returns a new instance of FindBySourceIdentifier.



12
13
14
# File 'app/services/hyrax/custom_queries/find_by_source_identifier.rb', line 12

def initialize(query_service:)
  @query_service = query_service
end

Instance Attribute Details

#query_serviceObject (readonly)

Returns the value of attribute query_service.



16
17
18
# File 'app/services/hyrax/custom_queries/find_by_source_identifier.rb', line 16

def query_service
  @query_service
end

Class Method Details

.queriesObject



8
9
10
# File 'app/services/hyrax/custom_queries/find_by_source_identifier.rb', line 8

def self.queries
  [:find_by_model_and_property_value]
end

Instance Method Details

#find_by_model_and_property_value(model:, property:, value:) ⇒ NilClass, Valkyrie::Resource

Note:

This is not a real estate transaction nor a Zillow lookup.

Parameters:

  • model (Class, #internal_resource)
  • property (#to_s)

    the name of the property we’re attempting to query.

  • value (#to_s)

    the propety’s value that we’re trying to match.

Returns:

  • (NilClass)

    when no record was found

  • (Valkyrie::Resource)

    when a record was found



30
31
32
33
34
35
# File 'app/services/hyrax/custom_queries/find_by_source_identifier.rb', line 30

def find_by_model_and_property_value(model:, property:, value:)
  sql_query = sql_for_find_by_model_and_property_value
  # NOTE: Do we need to ask the model for it's internal_resource?
  # TODO: no => undefined method `internal_resource' for Image:Class
  query_service.run_query(sql_query, model, property, value).first
end