Class: Jav::Resources::Controls::Action

Inherits:
BaseControl show all
Defined in:
lib/jav/resources/controls/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseControl

#action?, #actions_list?, #back_button?, #color, #delete_button?, #detach_button?, #edit_button?, #icon, #link_to?, #style, #title

Constructor Details

#initialize(klass, record: nil, resource: nil, view: nil, **args) ⇒ Action

Returns a new instance of Action.



7
8
9
10
11
12
13
14
# File 'lib/jav/resources/controls/action.rb', line 7

def initialize(klass, record: nil, resource: nil, view: nil, **args)
  super(**args)

  @klass = klass
  @resource = resource
  @record = record
  @view = view
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/jav/resources/controls/action.rb', line 5

def klass
  @klass
end

Instance Method Details

#actionObject



16
17
18
19
20
21
22
23
# File 'lib/jav/resources/controls/action.rb', line 16

def action
  @instance ||= @klass.new(
    model: @record,
    resource: @resource,
    view: @view,
    arguments: @resource.get_action_arguments(klass)
  )
end

#labelObject



32
33
34
# File 'lib/jav/resources/controls/action.rb', line 32

def label
  @args[:label] || action.action_name
end

#pathObject



25
26
27
28
29
30
# File 'lib/jav/resources/controls/action.rb', line 25

def path
  Jav::Services::URIService.parse(@resource.record_path)
                           .append_paths("actions")
                           .append_query(action_id: action.param_id)
                           .to_s
end