Class: Filch::Scopes
- Inherits:
-
Object
- Object
- Filch::Scopes
- Defined in:
- lib/filch.rb
Overview
similar to Filch::Associations, except doesn’t use predicates, and ransackable_scopes must be defined.
class Foo < ApplicationRecord
scope :managers, -> { where(position: 'Manager') }
scope :store_managers, -> { where(position: 'StoreManager') }
def self.ransackable_scopes
%w[managers, store_managers]
end
end
defaults to ransackable_scopes
Instance Method Summary collapse
- #default ⇒ Object
-
#initialize(model) ⇒ Scopes
constructor
A new instance of Scopes.
-
#scopes ⇒ Object
can be defined on the model class Foo < ApplicationRecord def self.filch_scopes %w[managers, store_managers].
Constructor Details
#initialize(model) ⇒ Scopes
Returns a new instance of Scopes.
291 292 293 |
# File 'lib/filch.rb', line 291 def initialize(model) @model = model end |
Instance Method Details
#default ⇒ Object
308 309 310 311 |
# File 'lib/filch.rb', line 308 def default default_hash = {} default_hash end |
#scopes ⇒ Object
can be defined on the model
class Foo < ApplicationRecord
def self.filch_scopes
%w[managers, store_managers]
299 300 301 302 303 304 305 306 |
# File 'lib/filch.rb', line 299 def scopes scopes_hash = Hash.new(default) if @model.methods.include?(:filch_scopes) scopes_hash = scopes_hash.merge(@model.filch_scopes) end scopes_hash[:all] = @model ? @model.ransackable_scopes : [] scopes_hash end |