Created
October 9, 2015 17:49
-
-
Save odigity/02c17bf347ecf38607c9 to your computer and use it in GitHub Desktop.
Sequel model class config example
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.configure_class(table:, filter: {}, &block) | |
| ds = db[table] | |
| ds = ds.filter filter unless filter.blank? | |
| ds = ds.filter &block if block_given? | |
| set_dataset(ds) | |
| fixture_keys.each { |k| FixtureDependencies.class_map[k] = self } | |
| end | |
| def self.fixture_keys | |
| # PorcIO::ID::Models::User -> [ :user, :porc_io/id/models/user ] | |
| [ singularize(table_name).to_sym, "porc_io/id/models/#{singularize(table_name)}".to_sym ] | |
| end |
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
| OAuth2Request = Class.new(Base) | |
| class OAuth2Request | |
| configure_class(table: :oauth2_requests) | |
| configure_class(table: :oauth2_requests, filter: :active) | |
| configure_class(table: :oauth2_requests, filter: {active: true}}) | |
| configure_class(table: :oauth2_requests) {created_at > Time.yesterday} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment