Module: StateMachineButtons::Renderer

Defined in:
lib/state_machine_buttons/renderer.rb

Instance Method Summary collapse

Instance Method Details

#state_events_buttons(object, state_method: :state, controller:, action:, parameters: {}, without: nil, namespace: nil, model_param_name: nil, button_options: {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/state_machine_buttons/renderer.rb', line 5

def state_events_buttons(object, state_method: :state, controller:, action:, parameters: {}, without: nil, namespace: nil, model_param_name: nil, button_options: {})
  model_name = object.model.model_name.name.underscore
  model_param_name ||= model_name
  excepted_actions = without.is_a?(Array) ? without.map(&:to_sym) : [without.to_sym] if without
  transitions = object.model.send("#{state_method}_transitions").reject do |t|
    excepted_actions.present? && excepted_actions.include?(t.event)
  end
  (:div, class: 'btn-group-vertical') do
    transitions.each do |event|
      button(
        event: event.event,
        model_name: model_name,
        object: object,
        state_method: state_method,
        controller: controller,
        action: action,
        namespace: namespace,
        parameters: parameters,
        model_param_name: model_param_name,
        form_options: button_options
      )
    end
  end
end