Class: Plutonium::Action::ConditionContext

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/plutonium/action/condition_context.rb

Overview

Evaluation scope for an action’s ‘condition:` proc.

Exposes the contextual record as both ‘object` and `record`, and delegates everything else to the request’s **view context** — the object render components forward their helpers to — so a condition can use current_user, params, request, allowed_to?, resource_record!, etc. directly, exactly like the ‘condition:` procs on inputs/displays/columns.

Delegating to the view context (not a render component) matters: the component exposes params/request only as PRIVATE methods, which a delegator can’t forward; the view context exposes them publicly.

‘record`/`object` is the row/shown record for record and collection-record actions, and nil for resource/bulk actions (no single record in scope) — so guard with `object&.…` in conditions shared across action kinds.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view_context, record) ⇒ ConditionContext

Returns a new instance of ConditionContext.



27
28
29
30
# File 'lib/plutonium/action/condition_context.rb', line 27

def initialize(view_context, record)
  super(view_context)
  @record = record
end

Instance Attribute Details

#recordObject (readonly) Also known as: object

Returns the value of attribute record.



24
25
26
# File 'lib/plutonium/action/condition_context.rb', line 24

def record
  @record
end