Module: OceanDynamo::Associations::ClassMethods

Defined in:
lib/ocean-dynamo/associations/associations.rb

Overview


Class methods

Instance Method Summary collapse

Instance Method Details

#clear_relationsObject



59
60
61
# File 'lib/ocean-dynamo/associations/associations.rb', line 59

def clear_relations
  self.relations = Hash.new
end

#define_class_if_not_defined(class_name) ⇒ Object



70
71
72
# File 'lib/ocean-dynamo/associations/associations.rb', line 70

def define_class_if_not_defined(class_name)
  Object.const_set(class_name, Class.new(OceanDynamo::Table)) unless const_defined?(class_name)
end

#dynamo_schemaObject



64
65
66
67
# File 'lib/ocean-dynamo/associations/associations.rb', line 64

def dynamo_schema(*)
  clear_relations
  super
end

#register_relation(klass, value) ⇒ Object



52
53
54
# File 'lib/ocean-dynamo/associations/associations.rb', line 52

def register_relation(klass, value)
  relations[klass] = value
end

#relates_to(klass) ⇒ Object



45
46
47
# File 'lib/ocean-dynamo/associations/associations.rb', line 45

def relates_to(klass)
  relations[klass]
end

#relations_of_type(rel_type) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/ocean-dynamo/associations/associations.rb', line 34

def relations_of_type(rel_type)
  relations.inject([]) do |acc, rel|
    kl, type = rel
    acc << kl if type == rel_type
    acc
  end
end