Skip to content

Instantly share code, notes, and snippets.

@DylanLacey
Created October 30, 2012 01:48
Show Gist options
  • Save DylanLacey/3977844 to your computer and use it in GitHub Desktop.
Save DylanLacey/3977844 to your computer and use it in GitHub Desktop.
MTData Consistent AR
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