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, route_method: nil, parameters: {}, without: nil, namespace: nil, model_param_name: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/state_machine_buttons/renderer.rb', line 5

def state_events_buttons(object, state_method: :state, route_method: nil, parameters: {}, without: nil, namespace: nil, model_param_name: nil)
  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, model_name: model_name, object: object, state_method: state_method, route_method: route_method, namespace: namespace, parameters: parameters, model_param_name: model_param_name
    end
  end
end