module OceanDynamo::BelongsTo

Public Class Methods

included(base) click to toggle source
# File lib/ocean-dynamo/associations/belongs_to.rb, line 4
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

type_check_foreign_key(name, value) click to toggle source
# File lib/ocean-dynamo/associations/belongs_to.rb, line 196
def type_check_foreign_key(name, value)
  return unless value
  return if value.is_a?(String)
  raise AssociationTypeMismatch, "Foreign key #{name} must be nil or a string"
end
type_check_target(target_class, value, composite_key) click to toggle source
# File lib/ocean-dynamo/associations/belongs_to.rb, line 203
def type_check_target(target_class, value, composite_key)
  return nil unless value
  if value.kind_of?(target_class)
    foreign_key = value.hash_key
    foreign_key += ':' + value.range_key if composite_key
    return [value, foreign_key]
  else
    raise AssociationTypeMismatch, "can't save a #{value.class} in a #{target_class} foreign key"
  end
end