Module: Serpentine::ControllerHelper

Extended by:
ActiveSupport::Concern
Defined in:
lib/serpentine.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#apply_scope_if?(operator) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/serpentine.rb', line 35

def apply_scope_if?(operator)
  operator && (operator.respond_to?(:call) ? operator.call(params) : send(operator))
end

#apply_scope_unless?(operator) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/serpentine.rb', line 39

def apply_scope_unless?(operator)
  operator && (operator.respond_to?(:call) ? !operator.call(params) : !send(operator))
end

#apply_scopes!Object



21
22
23
24
25
26
27
# File 'lib/serpentine.rb', line 21

def apply_scopes!
  self.class.collection_filters.each do |callback|
    if apply_scopes?(callback.options)
      self.collection = send callback.name
    end
  end
end

#apply_scopes?(options) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/serpentine.rb', line 29

def apply_scopes?(options)
  apply_scope_if?(options[:if]) ||
  apply_scope_unless?(options[:unless]) ||
  !options[:if] && !options[:unless]
end

#collection=(collection) ⇒ Object



43
44
45
# File 'lib/serpentine.rb', line 43

def collection=(collection)
  @collection = collection
end