Class: ActiveAdmin::ResourceCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/active_admin/resource_collection.rb

Overview

This is a container for resources, which acts much like a Hash. It's assumed that an added resource responds to `resource_name`.

Defined Under Namespace

Classes: ConfigMismatch, IncorrectClass

Instance Method Summary collapse

Constructor Details

#initializeResourceCollection

Returns a new instance of ResourceCollection.


10
11
12
# File 'lib/active_admin/resource_collection.rb', line 10

def initialize
  @collection = {}
end

Instance Method Details

#[](obj) ⇒ Object


28
29
30
# File 'lib/active_admin/resource_collection.rb', line 28

def [](obj)
  @collection[obj] || find_resource(obj)
end

#add(resource) ⇒ Object


14
15
16
17
18
19
20
21
# File 'lib/active_admin/resource_collection.rb', line 14

def add(resource)
  if match = @collection[resource.resource_name]
    raise_if_mismatched! match, resource
    match
  else
    @collection[resource.resource_name] = resource
  end
end

#each(&block) ⇒ Object

Changes `each` to pass in the value, instead of both the key and value.


24
25
26
# File 'lib/active_admin/resource_collection.rb', line 24

def each(&block)
  values.each &block
end