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, target_name, options = {}) ⇒ BelongsTo
constructor
A new instance of BelongsTo.
- #namespace ⇒ Object
- #optional? ⇒ Boolean
- #required? ⇒ Boolean
- #resource ⇒ Object
-
#target ⇒ Object
Returns the target resource class or raises an exception if it doesn’t exist.
- #to_param ⇒ Object
Constructor Details
#initialize(owner, target_name, options = {}) ⇒ BelongsTo
Returns a new instance of BelongsTo.
17 18 19 |
# File 'lib/active_admin/resource/belongs_to.rb', line 17 def initialize(owner, target_name, = {}) @owner, @target_name, @options = owner, target_name, end |
Instance Attribute Details
#owner ⇒ Object (readonly)
The resource which initiated this relationship
15 16 17 |
# File 'lib/active_admin/resource/belongs_to.rb', line 15 def owner @owner end |
Instance Method Details
#namespace ⇒ Object
31 32 33 |
# File 'lib/active_admin/resource/belongs_to.rb', line 31 def namespace @owner.namespace end |
#optional? ⇒ Boolean
35 36 37 |
# File 'lib/active_admin/resource/belongs_to.rb', line 35 def optional? @options[:optional] end |
#required? ⇒ Boolean
39 40 41 |
# File 'lib/active_admin/resource/belongs_to.rb', line 39 def required? !optional? end |
#resource ⇒ Object
26 27 28 29 |
# File 'lib/active_admin/resource/belongs_to.rb', line 26 def resource namespace.resources[@options[:class_name]] || namespace.resources[@target_name.to_s.camelize] end |
#target ⇒ Object
Returns the target resource class or raises an exception if it doesn’t exist
22 23 24 |
# File 'lib/active_admin/resource/belongs_to.rb', line 22 def target resource or raise TargetNotFound.new (@options[:class_name] || @target_name.to_s.camelize), namespace end |
#to_param ⇒ Object
43 44 45 |
# File 'lib/active_admin/resource/belongs_to.rb', line 43 def to_param :"#{@target_name}_id" end |