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



65
66
67
# File 'lib/ramaze/contrib/sequel/relation.rb', line 65

def belongs_to(model)
  todo :belongs_to, model.to_s.downcase.to_sym
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
# 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

  return # remove this line 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

#has_many(model) ⇒ Object



69
70
71
72
# File 'lib/ramaze/contrib/sequel/relation.rb', line 69

def has_many(model)
  todo :create_join, model
  todo :many_to_many, model.to_s.downcase.pluralize.to_sym
end

#has_one(model) ⇒ Object



74
75
76
# File 'lib/ramaze/contrib/sequel/relation.rb', line 74

def has_one(model)
  todo :belongs_to, model.to_s.downcase.to_sym
end

#the(left_model, &block) ⇒ Object



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

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

#todo(method, *args) ⇒ Object



78
79
80
# File 'lib/ramaze/contrib/sequel/relation.rb', line 78

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