Class: ActiveAdmin::Resource::BelongsTo
- Defined in:
- lib/active_admin/resource/belongs_to.rb
Defined Under Namespace
Classes: TargetNotFound
Instance Attribute Summary collapse
-
#owner ⇒ Object
readonly
The resource which initiated this relationship.
Instance Method Summary collapse
-
#initialize(owner_resource, target_name, options = {}) ⇒ BelongsTo
constructor
A new instance of BelongsTo.
- #namespace ⇒ Object
- #optional? ⇒ Boolean
-
#target ⇒ Object
Returns the target resource class or raises an exception if it doesn’t exist.
Constructor Details
#initialize(owner_resource, target_name, options = {}) ⇒ BelongsTo
Returns a new instance of BelongsTo.
10 11 12 13 |
# File 'lib/active_admin/resource/belongs_to.rb', line 10 def initialize(owner_resource, target_name, = {}) @owner, @target_name = owner_resource, target_name = end |
Instance Attribute Details
#owner ⇒ Object (readonly)
The resource which initiated this relationship
8 9 10 |
# File 'lib/active_admin/resource/belongs_to.rb', line 8 def owner @owner end |
Instance Method Details
#namespace ⇒ Object
21 22 23 |
# File 'lib/active_admin/resource/belongs_to.rb', line 21 def namespace @owner.namespace end |
#optional? ⇒ Boolean
25 26 27 |
# File 'lib/active_admin/resource/belongs_to.rb', line 25 def optional? [:optional] end |
#target ⇒ Object
Returns the target resource class or raises an exception if it doesn’t exist
16 17 18 19 |
# File 'lib/active_admin/resource/belongs_to.rb', line 16 def target namespace.resources[@target_name.to_s.camelize] or raise TargetNotFound, "Could not find registered resource #{@target_name} in #{namespace.name} with #{namespace.resources.keys.inspect}" end |