module ScopieRails::Controller

Public Instance Methods

apply_scopes(target, scopie: default_scopie, hash: params) click to toggle source

Receives an object where scopes will be applied to.

class GraduationsScopie < Scopie::Base
  has_scope :featured, type: :boolean
  has_scope :by_degree, :by_period
end

class GraduationsController < ApplicationController
  include ScopieRails::Controller

  def index
    @graduations = apply_scopes(Graduation).all
  end
end
# File lib/scopie_rails/controller.rb, line 28
def apply_scopes(target, scopie: default_scopie, hash: params)
  Scopie.apply_scopes(target, hash, method: hash[:action], scopie: scopie)
end
current_scopes(scopie: default_scopie, hash: params) click to toggle source

Returns the scopes used in this action.

# File lib/scopie_rails/controller.rb, line 33
def current_scopes(scopie: default_scopie, hash: params)
  Scopie.current_scopes(hash, method: hash[:action], scopie: scopie)
end
default_scopie() click to toggle source
# File lib/scopie_rails/controller.rb, line 9
def default_scopie
  @default_scopie ||= find_scopie_class.new(self)
end
find_scopie_class() click to toggle source
# File lib/scopie_rails/controller.rb, line 37
def find_scopie_class
  return scopie_class if scopie_class

  scopie_name = params[:controller] + ScopieRails::SCOPIE_SUFFIX

  self.scopie_class = scopie_name.camelize.constantize
end