module ActiveAdmin::Resource::Scopes

Public Instance Methods

default_scope(context = nil) click to toggle source
# File lib/active_admin/resource/scopes.rb, line 16
def default_scope(context = nil)
  scopes.detect do |scope|
    if scope.default_block.is_a?(Proc)
      render_in_context(context, scope.default_block)
    else
      scope.default_block
    end
  end
end
get_scope_by_id(id) click to toggle source

Returns a scope for this object by its identifier

# File lib/active_admin/resource/scopes.rb, line 11
def get_scope_by_id(id)
  id = id.to_s
  scopes.find{|s| s.id == id }
end
scope(*args, &block) click to toggle source

Create a new scope object for this resource. If you want to internationalize the scope name, you can add to your i18n files a key like “active_admin.scopes.scope_method”.

# File lib/active_admin/resource/scopes.rb, line 29
def scope(*args, &block)
  default_options = {show_count: namespace.scopes_show_count}
  options = default_options.merge(args.extract_options!)
  title = args[0] rescue nil
  method = args[1] rescue nil

  options[:localizer] ||= ActiveAdmin::Localizers.resource(self)
  scope = ActiveAdmin::Scope.new(title, method, options, &block)

  # Finds and replaces a scope by the same name if it already exists
  existing_scope_index = scopes.index{|existing_scope| existing_scope.id == scope.id }
  if existing_scope_index
    scopes.delete_at(existing_scope_index)
    scopes.insert(existing_scope_index, scope)
  else
    self.scopes << scope
  end

  scope
end
scopes() click to toggle source

Return an array of scopes for this resource

# File lib/active_admin/resource/scopes.rb, line 6
def scopes
  @scopes ||= []
end