module Dynamo::Record::Marshalers::ClassMethods

Public Instance Methods

composite_integer_attr(name, opts = {}) click to toggle source
# File lib/dynamo/record/marshalers.rb, line 14
def composite_integer_attr(name, opts = {})
  composite_attr(name, opts)
  define_readers(name, opts[:parts], :to_i) if opts.key? :parts
end
composite_string_attr(name, opts = {}) click to toggle source
# File lib/dynamo/record/marshalers.rb, line 19
def composite_string_attr(name, opts = {})
  composite_attr(name, opts)
  define_readers(name, opts[:parts], :to_s) if opts.key? :parts
end

Private Instance Methods

composite_attr(name, opts = {}) click to toggle source
# File lib/dynamo/record/marshalers.rb, line 26
def composite_attr(name, opts = {})
  opts[:dynamodb_type] = 'S'

  # It is very unfortunate that Aws::Record used `attr`
  attr(name, Aws::Record::Marshalers::StringMarshaler.new(opts), opts)
end
define_readers(name, parts, cast_function) click to toggle source
# File lib/dynamo/record/marshalers.rb, line 33
def define_readers(name, parts, cast_function)
  parts.each_with_index do |part, i|
    raise "#{part} already defined" unless parts.find_index(part) == i
    next if method_defined?(part)

    define_method(part) do
      # @data is used internally by Aws::Record to store all of the attributes
      @data.get_attribute(name).split(COMPOSITE_DELIMETER)[i].send(cast_function)
    end
  end
end