Created
June 28, 2019 04:24
-
-
Save abhianair/ab4f04bbbfeccce7b346bba73ed0fc7f to your computer and use it in GitHub Desktop.
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
Data.with_schema('schema_name').all |
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
def self.with_schema(schema_name) | |
class_name = self.name + schema_name.camelize | |
table_name = self.table_name | |
if !Object.const_defined?(class_name) | |
Object.const_set( | |
class_name, Class.new(self) do | |
self.table_name = "#{schema_name}.#{table_name}" | |
end | |
) | |
end | |
class_name.constantize | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment