Module: ScopieRails::Controller

Extended by:
ActiveSupport::Concern
Defined in:
lib/scopie_rails/controller.rb

Instance Method Summary collapse

Instance Method Details

#apply_scopes(target, scopie: default_scopie, hash: params) ⇒ Object

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


28
29
30
# 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) ⇒ Object

Returns the scopes used in this action.



33
34
35
# 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_scopieObject



9
10
11
# File 'lib/scopie_rails/controller.rb', line 9

def default_scopie
  @default_scopie ||= find_scopie_class.new(self)
end

#find_scopie_classObject



37
38
39
40
41
42
43
# 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