Method: Caprese::Query#get_record

Defined in:
lib/caprese/controller/concerns/query.rb

#get_record(scope, column, value) ⇒ APIRecord

Gets a record in a scope using a column/value to search by

Examples:

get_record(:orders, :id, '1e0da61f-0229-4035-99a5-3e5c37a221fb')
  # => Order.find_by(id: '1e0da61f-0229-4035-99a5-3e5c37a221fb')

Parameters:

  • scope (Symbol, Relation)

    the scope to find the record in if Symbol, call record_scope for that type and use it if Relation, use it as a scope

  • column (Symbol)

    the name of the column to find the record by

  • value (Value)

    the value to match to a column/row value

Returns:

  • (APIRecord)

    the record that was found



134
135
136
137
138
# File 'lib/caprese/controller/concerns/query.rb', line 134

def get_record(scope, column, value)
  scope = record_scope(scope.to_sym) unless scope.respond_to?(:find_by)

  scope.find_by(column => value) unless scope.empty?
end