Module: Cassie::Statements::Statement::Relations::ClassMethods

Included in:
Deleting, Selection, Updating
Defined in:
lib/cassie/statements/statement/relations.rb

Instance Method Summary collapse

Instance Method Details

#relations_argsObject

The enumeration of current relations’ parameters that will be used to build Relation objects when the statement is built



55
56
57
# File 'lib/cassie/statements/statement/relations.rb', line 55

def relations_args
  @relations_args ||= []
end

#where(identifier, operation, opts = {}) ⇒ Enumerable<Array<Object>>

DSL to set a ranging relation (WHERE clause) for the statement.

Defining a relation also defines an attr_accessor with the same name as the identifier (or the :value option if a symbol is used). The underlying instance variable value for this accessor will be used when determining the value for the relation.

Examples:

Range relation with implied accessor

where :username, :eq #<= gets relation value from `:username` method

Range relation with explicit accessor

where :username, :eq, value: :name #<= gets relation value from `:name` method

Range relation with multi-value, pluarlized accessr

where :phone, :in #<= gets relation value from `:phones` method

Options Hash (opts):

  • :value (Symbol, Object)

    The value to use for the ranging relation (constraint). If a [Symbol], a method with that name will be called when the statement is built. Otherwise, the value itself will be used.

  • :if (Symbol, Object)

    Determines if the relation is applied to the statement or not. If a [Symbol], a method with that name will be called when the statement is built. Otherwise, the value itself will be used.

  • :term (String)

    The argument value to use instead of a positional placeholder (?). If a [Symbol], a method with that name will be called when the statement is built. Otherwise, the value itself will be used.

Raises:

  • (StandardError)

    if there is already a getter or setter method defined for the relation value’s implied accessor (identifier or symbol :value option).



45
46
47
48
49
50
51
# File 'lib/cassie/statements/statement/relations.rb', line 45

def where(identifier, operation, opts={})
  opts[:value] ||= implied_argument_method(identifier, operation)

  define_argument_accessor(opts[:value])

  relations_args << [identifier, operation, opts.delete(:value), opts]
end