Class: ActiveAdmin::Scope
- Inherits:
-
Object
- Object
- ActiveAdmin::Scope
- Defined in:
- lib/active_admin/scope.rb
Instance Attribute Summary collapse
-
#default_block ⇒ Object
readonly
Returns the value of attribute default_block.
-
#display_if_block ⇒ Object
readonly
Returns the value of attribute display_if_block.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#scope_block ⇒ Object
readonly
Returns the value of attribute scope_block.
-
#scope_method ⇒ Object
readonly
Returns the value of attribute scope_method.
-
#show_count ⇒ Object
readonly
Returns the value of attribute show_count.
Instance Method Summary collapse
-
#initialize(name, method = nil, options = {}, &block) ⇒ Scope
constructor
Create a Scope.
- #name ⇒ Object
Constructor Details
#initialize(name, method = nil, options = {}, &block) ⇒ Scope
Create a Scope
Examples:
Scope.new(:published)
# => Scope with name 'Published' and scope method :published
Scope.new('Published', :public)
# => Scope with name 'Published' and scope method :public
Scope.new 'Published', :public, if: proc { current_admin_user.can? :manage, resource_class } do |articles|
articles.where published: true
end
# => Scope with name 'Published' and scope method :public, optionally displaying the scope per the :if block
Scope.new('Published') { |articles| articles.where(published: true) }
# => Scope with name 'Published' using a block to scope
Scope.new ->{Date.today.strftime '%A'}, :published_today
# => Scope with dynamic title using the :published_today scope method
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/active_admin/scope.rb', line 27 def initialize(name, method = nil, = {}, &block) @name, @scope_method = name, method.try(:to_sym) if name.is_a? Proc raise "A string/symbol is required as the second argument if your label is a proc." unless method @id = ActiveAdmin::Dependency.rails.parameterize method.to_s else @scope_method ||= name.to_sym @id = ActiveAdmin::Dependency.rails.parameterize name.to_s end @scope_method = nil if @scope_method == :all @scope_method, @scope_block = nil, block if block_given? @show_count = .fetch(:show_count, true) @display_if_block = [:if] || proc{ true } @default_block = [:default] || proc{ false } end |
Instance Attribute Details
#default_block ⇒ Object (readonly)
Returns the value of attribute default_block.
4 5 6 |
# File 'lib/active_admin/scope.rb', line 4 def default_block @default_block end |
#display_if_block ⇒ Object (readonly)
Returns the value of attribute display_if_block.
4 5 6 |
# File 'lib/active_admin/scope.rb', line 4 def display_if_block @display_if_block end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/active_admin/scope.rb', line 4 def id @id end |
#scope_block ⇒ Object (readonly)
Returns the value of attribute scope_block.
4 5 6 |
# File 'lib/active_admin/scope.rb', line 4 def scope_block @scope_block end |
#scope_method ⇒ Object (readonly)
Returns the value of attribute scope_method.
4 5 6 |
# File 'lib/active_admin/scope.rb', line 4 def scope_method @scope_method end |
#show_count ⇒ Object (readonly)
Returns the value of attribute show_count.
4 5 6 |
# File 'lib/active_admin/scope.rb', line 4 def show_count @show_count end |
Instance Method Details
#name ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/active_admin/scope.rb', line 46 def name case @name when Proc then @name.call.to_s when String then @name when Symbol then @name.to_s.titleize else @name.to_s end end |