Module: RelationBuilder

Included in:
Record
Defined in:
lib/redisant/relation_builder.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
# File 'lib/redisant/relation_builder.rb', line 2

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#find_relation(name, &block) ⇒ Object



6
7
8
9
10
11
# File 'lib/redisant/relation_builder.rb', line 6

def find_relation name, &block
  return unless name
  relation = relations[name.to_s]
  return relation if relation
  relations[name.to_s] = block.call if block
end

#relationsObject



13
14
15
# File 'lib/redisant/relation_builder.rb', line 13

def relations
  @relations ||= {}
end

#setup_relationsObject



17
18
19
20
21
# File 'lib/redisant/relation_builder.rb', line 17

def setup_relations
  self.class.relation_definitions.each_pair do |name,klass|
    relations[name] = klass.new(name, self)
  end
end