blob: c78c81a752e311cf799f4d09f118fef95533b03f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  | 
class Referential < ActiveRecord::Base
  validates_presence_of :name 
  validates_presence_of :slug
  before_create :create_schema 
  before_destroy :destroy_schema
  def lines
    Chouette::Line.scoped
  end
  def networks
    Chouette::Network.scoped
  end
  def companies
    Chouette::Company.scoped
  end
  def stop_areas
    Chouette::StopArea.scoped
  end
  def time_tables
    Chouette::TimeTable.scoped
  end
  
  def connection_links
    Chouette::ConnectionLink.scoped
  end
  def switch
    raise "Referential not created" if new_record?
    Apartment::Database.switch(slug)
    self
  end
  private 
  def create_schema
    Apartment::Database.create slug
  end
  def destroy_schema
    Apartment::Database.drop slug
  end
  
end
  |