Class: ActiveAdmin::ResourceCollection
- Inherits:
-
Object
- Object
- ActiveAdmin::ResourceCollection
- 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
- #[](obj) ⇒ Object
- #add(resource) ⇒ Object
-
#each(&block) ⇒ Object
Changes ‘each` to pass in the value, instead of both the key and value.
-
#initialize ⇒ ResourceCollection
constructor
A new instance of ResourceCollection.
Constructor Details
#initialize ⇒ ResourceCollection
Returns a new instance of ResourceCollection.
9 10 11 |
# File 'lib/active_admin/resource_collection.rb', line 9 def initialize @collection = {} end |
Instance Method Details
#[](obj) ⇒ Object
27 28 29 |
# File 'lib/active_admin/resource_collection.rb', line 27 def [](obj) @collection[obj] || find_resource(obj) end |
#add(resource) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/active_admin/resource_collection.rb', line 13 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.
23 24 25 |
# File 'lib/active_admin/resource_collection.rb', line 23 def each(&block) values.each &block end |