Class: DynamoDbFramework::AttributesBuilder
- Inherits:
-
Object
- Object
- DynamoDbFramework::AttributesBuilder
- Defined in:
- lib/dynamodb_framework/dynamodb_attributes_builder.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #add(*options) ⇒ Object
- #add_from_args(name, type, key = nil) ⇒ Object
- #add_from_hash(options) ⇒ Object
- #contains(name:) ⇒ Object
-
#initialize ⇒ AttributesBuilder
constructor
A new instance of AttributesBuilder.
Constructor Details
#initialize ⇒ AttributesBuilder
Returns a new instance of AttributesBuilder.
5 6 7 |
# File 'lib/dynamodb_framework/dynamodb_attributes_builder.rb', line 5 def initialize @attributes = [] end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/dynamodb_framework/dynamodb_attributes_builder.rb', line 3 def attributes @attributes end |
Instance Method Details
#add(*options) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dynamodb_framework/dynamodb_attributes_builder.rb', line 51 def add(*) if .length == 1 && [0].is_a?(Hash) add_from_hash([0]) elsif .length == 3 add_from_args([0], [1], [2]) else add_from_args([0], [1]) end end |
#add_from_args(name, type, key = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dynamodb_framework/dynamodb_attributes_builder.rb', line 9 def add_from_args(name, type, key = nil) type_symbol = :S if type == 'number' || type == :N || type == :number type_symbol = :N elsif type == 'binary' || type == :B || type == :binary type_symbol = :B elsif type == 'bool' || type == 'boolean' || type == :BOOL || type == :bool || type == :boolean type_symbol = :BOOL end if key == 'hash' || key == :hash || key == 'partition' || key == :partition key = :hash elsif key == 'range' || key == :range key = :range else key = nil end @attributes.push({ :name => name, :type => type_symbol, :key => key }) end |
#add_from_hash(options) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dynamodb_framework/dynamodb_attributes_builder.rb', line 30 def add_from_hash() type_symbol = :S if [:type] == 'number' || [:type] == :N || [:type] == :number type_symbol = :N elsif [:type] == 'binary' || [:type] == :B || [:type] == :binary type_symbol = :B elsif [:type] == 'bool' || [:type] == 'boolean' || [:type] == :BOOL || [:type] == :bool || [:type] == :boolean type_symbol = :BOOL end if [:key] == 'hash' || [:key] == :hash || [:key] == 'partition' || [:key] == :partition key = :hash elsif [:key] == 'range' || [:key] == :range key = :range else key = nil end @attributes.push({ :name => [:name], :type => type_symbol, :key => key }) end |
#contains(name:) ⇒ Object
63 64 65 |
# File 'lib/dynamodb_framework/dynamodb_attributes_builder.rb', line 63 def contains(name:) @attributes.detect { |a| a[:name] == name } != nil end |