Class: Cequel::Metal::RowSpecification Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cequel/metal/row_specification.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Encapsulates a row specification (‘WHERE` clause) constructed from a column ane one or more values to match

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column, value) ⇒ RowSpecification

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RowSpecification.

Parameters:

  • column (Symbol)

    column name

  • value (Object, Array)

    value or values to match

Since:

  • 1.0.0



30
31
32
# File 'lib/cequel/metal/row_specification.rb', line 30

def initialize(column, value)
  @column, @value = column, value
end

Instance Attribute Details

#columnSymbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns column name.

Returns:

  • (Symbol)

    column name

Since:

  • 1.0.0



22
23
24
# File 'lib/cequel/metal/row_specification.rb', line 22

def column
  @column
end

#valueObject, Array (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns value or values to match.

Returns:

  • (Object, Array)

    value or values to match

Since:

  • 1.0.0



24
25
26
# File 'lib/cequel/metal/row_specification.rb', line 24

def value
  @value
end

Class Method Details

.build(column_values) ⇒ Array<RowSpecification>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build one or more row specifications

Parameters:

  • column_values (Hash)

    map of column name to value or values

Returns:

Since:

  • 1.0.0



17
18
19
# File 'lib/cequel/metal/row_specification.rb', line 17

def self.build(column_values)
  column_values.map { |column, value| new(column, value) }
end

Instance Method Details

#cqlString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns row specification as CQL fragment.

Returns:

  • (String)

    row specification as CQL fragment

Since:

  • 1.0.0



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cequel/metal/row_specification.rb', line 37

def cql
  value = if Enumerable === @value && @value.count == 1
            @value.first
          else
            @value
          end

  if Array === value
    ["#{@column} IN ?", value]
  else
    ["#{@column} = ?", value]
  end
end