Class: SequelRelation::RelationshipManager

Inherits:
Object
  • Object
show all
Defined in:
lib/ramaze/contrib/sequel/relation.rb

Constant Summary collapse

TODO =
{}

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ RelationshipManager

Returns a new instance of RelationshipManager.



31
32
33
# File 'lib/ramaze/contrib/sequel/relation.rb', line 31

def initialize(&block)
  instance_eval(&block)
end

Instance Method Details

#belongs_to(model) ⇒ Object



67
68
69
# File 'lib/ramaze/contrib/sequel/relation.rb', line 67

def belongs_to(model)
  todo :many_to_one, singular_sym(model), :class => model
end

#finalizeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ramaze/contrib/sequel/relation.rb', line 35

def finalize
  TODO.keys.each do |model|
    model.create_table unless model.table_exists?
  end

  TODO.each do |model, instructions|
    instructions.each do |args|
      model.send(*args)
    end
  end

=begin
 # uncomment for debugging

  pp TODO

  TODO.keys.each do |model|
    puts "the #{model}"
    assoc = model.send(:association_reflections)
    assoc.each do |key, reflection|
      puts "  #{reflection[:type]} => #{key}"
    end
  end
=end
end

#has_many(model) ⇒ Object



71
72
73
74
# File 'lib/ramaze/contrib/sequel/relation.rb', line 71

def has_many(model)
  todo :create_join, model
  todo :many_to_many, plural_sym(model), :class => model
end

#has_one(model) ⇒ Object



76
77
78
# File 'lib/ramaze/contrib/sequel/relation.rb', line 76

def has_one(model)
  todo :many_to_one, singular_sym(model), :class => model
end

#the(left_model, &block) ⇒ Object



61
62
63
64
65
# File 'lib/ramaze/contrib/sequel/relation.rb', line 61

def the(left_model, &block)
  @left = left_model
  TODO[@left] = []
  instance_eval(&block)
end

#todo(method, *args) ⇒ Object



80
81
82
# File 'lib/ramaze/contrib/sequel/relation.rb', line 80

def todo(method, *args)
  TODO[@left] << [method, *args]
end