Class: Uuids::Queries::ByUuid

Inherits:
Hexx::Scope
  • Object
show all
Defined in:
app/queries/by_uuid.rb

Overview

The query selects records by uuids.

Examples:

Selects records by an array of uuids

ByUuid.select(
  MyModel,
  [
    "20547204-3875-0234-7d52-437523057235",
    "04702362-355e-9237-5e32-da2057054720"
  ]
)

Selects records by a list of uuids

ByUuid.select(
  MyModel,
  "20547204-3875-0234-7d52-437523057235",
  "04702362-355e-9237-5e32-da2057054720"
)

Selects all records when no values given

result =  ByUuid.select MyModel
result == MyModel.all # => true

Instance Method Summary collapse

Constructor Details

#initialize(model, *values) ⇒ ByUuid

Initializes the query object.

Parameters:

  • model (ActiveRecord::Base, #uuids)

    The model for selecting records of.

  • values (Array<String>, nil)

    The values to select records by.



38
39
40
41
# File 'app/queries/by_uuid.rb', line 38

def initialize(model, *values)
  super(model)
  @values = values.flatten
end

Instance Method Details

#selectActiveRecord::Relation

Runs and returns the query

Returns:

  • (ActiveRecord::Relation)

    The updated scope.



46
47
48
# File 'app/queries/by_uuid.rb', line 46

def select
  values.any? ? by_uuid : model.all
end