class Trestle::Scopes::Scope

Attributes

block[R]
name[R]
options[R]

Public Class Methods

new(admin, name, options={}, &block) click to toggle source
# File lib/trestle/scopes/scope.rb, line 6
def initialize(admin, name, options={}, &block)
  @admin, @name, @options, @block = admin, name, options, block
end

Public Instance Methods

active?(params) click to toggle source
# File lib/trestle/scopes/scope.rb, line 42
def active?(params)
  active_scopes = Array(params[:scope])

  if active_scopes.any?
    active_scopes.include?(to_param.to_s)
  else
    default?
  end
end
apply(collection) click to toggle source
# File lib/trestle/scopes/scope.rb, line 26
def apply(collection)
  if @block
    if @block.arity == 1
      @admin.instance_exec(collection, &@block)
    else
      @admin.instance_exec(&@block)
    end
  else
    collection.public_send(name)
  end
end
count(collection) click to toggle source
# File lib/trestle/scopes/scope.rb, line 38
def count(collection)
  @admin.count(@admin.merge_scopes(collection, apply(collection)))
end
default?() click to toggle source
# File lib/trestle/scopes/scope.rb, line 22
def default?
  @options[:default] == true
end
group() click to toggle source
# File lib/trestle/scopes/scope.rb, line 18
def group
  @options[:group]
end
label() click to toggle source
# File lib/trestle/scopes/scope.rb, line 14
def label
  @options[:label] || @admin.t("scopes.#{name}", default: name.to_s.humanize.titleize)
end
to_param() click to toggle source
# File lib/trestle/scopes/scope.rb, line 10
def to_param
  name unless default?
end