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.
-
#target_name ⇒ Object
readonly
The name of the relation.
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.
21 22 23 24 25 |
# File 'lib/active_admin/resource/belongs_to.rb', line 21 def initialize(owner, target_name, = {}) @owner = owner @target_name = target_name @options = end |
Instance Attribute Details
#owner ⇒ Object (readonly)
The resource which initiated this relationship
16 17 18 |
# File 'lib/active_admin/resource/belongs_to.rb', line 16 def owner @owner end |
#target_name ⇒ Object (readonly)
The name of the relation
19 20 21 |
# File 'lib/active_admin/resource/belongs_to.rb', line 19 def target_name @target_name end |
Instance Method Details
#namespace ⇒ Object
37 38 39 |
# File 'lib/active_admin/resource/belongs_to.rb', line 37 def namespace @owner.namespace end |
#optional? ⇒ Boolean
41 42 43 |
# File 'lib/active_admin/resource/belongs_to.rb', line 41 def optional? @options[:optional] end |
#required? ⇒ Boolean
45 46 47 |
# File 'lib/active_admin/resource/belongs_to.rb', line 45 def required? !optional? end |
#resource ⇒ Object
32 33 34 35 |
# File 'lib/active_admin/resource/belongs_to.rb', line 32 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
28 29 30 |
# File 'lib/active_admin/resource/belongs_to.rb', line 28 def target resource or raise TargetNotFound.new (@options[:class_name] || @target_name.to_s.camelize), namespace end |
#to_param ⇒ Object
49 50 51 |
# File 'lib/active_admin/resource/belongs_to.rb', line 49 def to_param (@options[:param] || "#{@target_name}_id").to_sym end |