Created
October 30, 2012 01:48
-
-
Save DylanLacey/3977844 to your computer and use it in GitHub Desktop.
MTData Consistent AR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MTData | |
module CityNamespaceMixin | |
def self.included(base) | |
base.establish_connection "mtdata" | |
base.table_name = "#{$CITY_NAME}].[dbo].[Place" | |
end | |
end | |
class Perth | |
$CITY_NAME = "Perth" | |
class Place < ActiveRecord::Base | |
include CityNamespaceMixin | |
end | |
end | |
class Brisbane | |
$CITY_NAME = "Brisbane" | |
class Place < ActiveRecord::Base | |
include CityNamespaceMixin | |
end | |
end | |
end | |
USAGE Desired: place = MTData::Brisbane::Place.first | |
place = MTData::Perth::Place.first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment