Class: ActiveAdmin::Decorator
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ActiveAdmin::Decorator
- Defined in:
- lib/activeadmin/decorator.rb,
lib/activeadmin/decorator/association.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Association
Class Method Summary collapse
-
.decorate(*args) ⇒ Object
Utility method for ActiveAdmin.
-
.decorates_association(association, relation: association, with: nil) ⇒ Object
use in decorator to decorate association.
Instance Method Summary collapse
Class Method Details
.decorate(*args) ⇒ Object
Utility method for ActiveAdmin
10 11 12 13 |
# File 'lib/activeadmin/decorator.rb', line 10 def decorate(*args) object = args[0] Association.decorate(object, with: self) end |
.decorates_association(association, relation: association, with: nil) ⇒ Object
use in decorator to decorate association
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/activeadmin/decorator.rb', line 16 def decorates_association(association, relation: association, with: nil) # rubocop:disable Metrics/MethodLength raise ArgumentError, "relation must be a Symbol or Proc" unless relation.is_a?(Symbol) || relation.is_a?(Proc) define_method(association) do if instance_variable_defined?("@#{association}_decorated") then instance_variable_get("@#{association}_decorated") else result = if relation.is_a?(Proc) then relation.call(model) elsif relation.is_a?(Symbol) then model.send(relation) end instance_variable_set("@#{association}_decorated", Association.decorate(result, with:, parent: self)) end end end |
Instance Method Details
#model ⇒ Object
33 |
# File 'lib/activeadmin/decorator.rb', line 33 def model = __getobj__ |
#nil? ⇒ Boolean
35 |
# File 'lib/activeadmin/decorator.rb', line 35 def nil? = model.nil? |