Class: Commutator::Expressions::ProjectionExpression

Inherits:
Object
  • Object
show all
Defined in:
lib/commutator/expressions/projection_expression.rb

Overview

See: goo.gl/bOKUjK

Constructs composable ProjectionExpression for use in DynamoDB API calls. Call to_s when sending to DynamoDB.

Note: path passes its arguments to the Statement constructor. Read the docs there for placeholder syntax.

Usage: exp = Commutator::Expressions::ProjectionExpression.new

.path('token_channel')
.path('ts.items[2]')
.path('#?', names: ['count'])
.path('#?.hey', names: ['size'])

Later…

exp.path(‘another_one’)

The expression above would produce the following with ‘to_s`

“token_channel, ts.items, #NAME_d61a1061060c9e9691027c42d6766b90,

#NAME_1eb3b08a347050ee467a2e24e6c15349.hey, another_one"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute_names: nil, &block) ⇒ ProjectionExpression

Returns a new instance of ProjectionExpression.



30
31
32
# File 'lib/commutator/expressions/projection_expression.rb', line 30

def initialize(attribute_names: nil, &block)
  @attribute_names = attribute_names || AttributeNames.new
end

Instance Attribute Details

#attribute_namesObject (readonly)

Returns the value of attribute attribute_names.



28
29
30
# File 'lib/commutator/expressions/projection_expression.rb', line 28

def attribute_names
  @attribute_names
end

Instance Method Details

#path(p, names: []) ⇒ Object



38
39
40
41
42
43
# File 'lib/commutator/expressions/projection_expression.rb', line 38

def path(p, names: [])
  names.each { |n| attribute_names.add(n) }
  statements << Statement.new(p, names: names)

  self
end

#statementsObject



34
35
36
# File 'lib/commutator/expressions/projection_expression.rb', line 34

def statements
  @statements ||= []
end

#to_sObject



45
46
47
# File 'lib/commutator/expressions/projection_expression.rb', line 45

def to_s
  statements.join(', ')
end