class DynamoDbFramework::AttributesBuilder
Attributes
attributes[R]
Public Class Methods
new()
click to toggle source
# File lib/dynamodb_framework/dynamodb_attributes_builder.rb, line 5 def initialize @attributes = [] end
Public Instance Methods
add(*options)
click to toggle source
# File lib/dynamodb_framework/dynamodb_attributes_builder.rb, line 51 def add(*options) if options.length == 1 && options[0].is_a?(Hash) add_from_hash(options[0]) elsif options.length == 3 add_from_args(options[0], options[1], options[2]) else add_from_args(options[0], options[1]) end end
add_from_args(name, type, key = nil)
click to toggle source
# 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)
click to toggle source
# File lib/dynamodb_framework/dynamodb_attributes_builder.rb, line 30 def add_from_hash(options) type_symbol = :S if options[:type] == 'number' || options[:type] == :N || options[:type] == :number type_symbol = :N elsif options[:type] == 'binary' || options[:type] == :B || options[:type] == :binary type_symbol = :B elsif options[:type] == 'bool' || options[:type] == 'boolean' || options[:type] == :BOOL || options[:type] == :bool || options[:type] == :boolean type_symbol = :BOOL end if options[:key] == 'hash' || options[:key] == :hash || options[:key] == 'partition' || options[:key] == :partition key = :hash elsif options[:key] == 'range' || options[:key] == :range key = :range else key = nil end @attributes.push({ :name => options[:name], :type => type_symbol, :key => key }) end
contains(name:)
click to toggle source
# File lib/dynamodb_framework/dynamodb_attributes_builder.rb, line 63 def contains(name:) @attributes.detect { |a| a[:name] == name } != nil end