module Cassie::Statements::Statement::Assignments::ClassMethods

Public Instance Methods

assignments_args() click to toggle source

The enumeration of current assignments' parameters that will be used to build Assignment objects when the statement is built

# File lib/cassie/statements/statement/assignments.rb, line 65
def assignments_args
  @assignments_args ||= []
end
set(identifier, opts={}) click to toggle source

DSL to set an assigment (SET or VALUES clause) for UPDATE and INSERT statements.

Defining an assigment 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 assigment.

@param [String, Symbol] identifier The column name to set. @param [Hash] opts options for the assigment @option opts [Symbol, Object] :value The value to use for the assigment (constraint). If a [Symbol], a method with that name will be called when the statement is built. Otherwise, the value itself will be used. @option opts [Symbol, Object] :if Determines if the assigment 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. @option opts [String] :term 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. @return [Enumerable<Array<Object>>] The enumeration of current assigments' parameters @raise [StandardError] if there is already a getter or setter method defined for the

assigment value's implied accessor (+identifier+ or symbol +:value+ option).

@example Assigment with implied accessor

set :username #<= gets assigment value from `:username` method

@example Assigment with explicit accessor

set :username, value: :name #<= gets assigment value from `:name` method
# File lib/cassie/statements/statement/assignments.rb, line 55
def set(identifier, opts={})
  opts[:value] ||= identifier.to_sym

  define_argument_accessor(opts[:value])

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