Module: OceanDynamo::Associations::ClassMethods

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

Overview


Class methods

Instance Method Summary collapse

Instance Method Details

#clear_relationsObject



49
50
51
# File 'lib/ocean-dynamo/associations/associations.rb', line 49

def clear_relations
  self.relations = Hash.new
end

#define_class_if_not_defined(class_name) ⇒ Object



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

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



54
55
56
57
# File 'lib/ocean-dynamo/associations/associations.rb', line 54

def dynamo_schema(*)
  clear_relations
  super
end

#register_relation(klass, value) ⇒ Object



42
43
44
# File 'lib/ocean-dynamo/associations/associations.rb', line 42

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

#relates_to(klass) ⇒ Object



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

def relates_to(klass)
  relations[klass]
end

#relations_of_type(rel_type) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/ocean-dynamo/associations/associations.rb', line 24

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