Class: ActiveAdmin::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, active_admin_config.resource_class ) } ) { |articles| articles.where(:published => true) }
# => Scope with name 'Published' and scope method :public, optionally displaying the scope per the :if block, using a block

Scope.new('Published') { |articles| articles.where(:published => true) }
# => Scope with name 'Published' using a block to scope


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_admin/scope.rb', line 22

def initialize(name, method = nil, options = {}, &block)
  @name = name.is_a?( String ) ? name : name.to_s.titleize
  @scope_method = method
  # Scope ':all' means no scoping
  @scope_method ||= name.to_sym unless name.to_sym == :all
  @id = @name.gsub(' ', '').underscore
  if block_given?
    @scope_method = nil
    @scope_block = block
  end

  @display_if_block = options[:if]
end

Instance Attribute Details

#display_if_blockObject (readonly)

Returns the display if block. If the block was not explicitly defined a default block always returning true will be returned.



38
39
40
# File 'lib/active_admin/scope.rb', line 38

def display_if_block
  @display_if_block
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/active_admin/scope.rb', line 4

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/active_admin/scope.rb', line 4

def name
  @name
end

#scope_blockObject (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_methodObject (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