Skip to content

Instantly share code, notes, and snippets.

@odigity
Created October 9, 2015 17:49
Show Gist options
  • Select an option

  • Save odigity/02c17bf347ecf38607c9 to your computer and use it in GitHub Desktop.

Select an option

Save odigity/02c17bf347ecf38607c9 to your computer and use it in GitHub Desktop.
Sequel model class config example
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
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