Class: ActiveAdmin::Resource::BelongsTo
- Inherits:
-
Object
- Object
- 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.
12 13 14 15 |
# File 'lib/active_admin/resource/belongs_to.rb', line 12 def initialize(owner_resource, target_name, = {}) @owner, @target_name = owner_resource, target_name @options = end |
Instance Attribute Details
#owner ⇒ Object (readonly)
The resource which initiated this relationship
10 11 12 |
# File 'lib/active_admin/resource/belongs_to.rb', line 10 def owner @owner end |
Instance Method Details
#namespace ⇒ Object
23 24 25 |
# File 'lib/active_admin/resource/belongs_to.rb', line 23 def namespace @owner.namespace end |
#optional? ⇒ Boolean
27 28 29 |
# File 'lib/active_admin/resource/belongs_to.rb', line 27 def optional? @options[:optional] end |
#target ⇒ Object
Returns the target resource class or raises an exception if it doesn’t exist
18 19 20 21 |
# File 'lib/active_admin/resource/belongs_to.rb', line 18 def target namespace.resources.find_by_key(@target_name.to_s.camelize) or raise TargetNotFound, "Could not find registered resource #{@target_name} in #{namespace.name} with #{namespace.resources.inspect}" end |