Class: AasmProgressable::State
- Inherits:
-
Object
- Object
- AasmProgressable::State
- Defined in:
- app/helpers/aasm_progressable/helper.rb
Overview
Internal class to manage display attribute associated with each model state, such as the name to display, and if the state has been completed yet or not.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
the internal ID for the state (as a string).
-
#name ⇒ Object
readonly
name displayed to the user.
Class Method Summary collapse
-
.create_all(object) ⇒ Object
Returns an Array of State instances corresponding to the states of a model instance.
Instance Method Summary collapse
-
#html_class ⇒ Object
html_class may contain complete, previous, active, next, or incomplete.
-
#initialize(id, name, status_classes) ⇒ State
constructor
A new instance of State.
- #is?(status_class) ⇒ Boolean
Constructor Details
#initialize(id, name, status_classes) ⇒ State
Returns a new instance of State.
14 15 16 17 18 |
# File 'app/helpers/aasm_progressable/helper.rb', line 14 def initialize(id, name, status_classes) @id = id.to_s @name = name @status_classes = status_classes end |
Instance Attribute Details
#id ⇒ Object (readonly)
the internal ID for the state (as a string)
11 12 13 |
# File 'app/helpers/aasm_progressable/helper.rb', line 11 def id @id end |
#name ⇒ Object (readonly)
name displayed to the user
12 13 14 |
# File 'app/helpers/aasm_progressable/helper.rb', line 12 def name @name end |
Class Method Details
.create_all(object) ⇒ Object
Returns an Array of State instances corresponding to the states of a model instance. The State instances are returned in the order given by the ‘aasm_state_order` declaration in the model.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/helpers/aasm_progressable/helper.rb', line 32 def self.create_all(object) localizer = AASM::Localizer.new state_order = object.aasm_state_order current_state = object.aasm.current_state current_state_index = state_order.index(current_state) object.aasm_state_order.each_with_index.map do |state, index| status_classes = [] status_classes << :complete if index < current_state_index status_classes << :previous if index == current_state_index - 1 status_classes << :active if index == current_state_index status_classes << :next if index == current_state_index + 1 status_classes << :incomplete if index > current_state_index name = localizer.human_state_name(object.class, state) State.new(state, name, status_classes) end end |
Instance Method Details
#html_class ⇒ Object
html_class may contain complete, previous, active, next, or incomplete.
21 22 23 |
# File 'app/helpers/aasm_progressable/helper.rb', line 21 def html_class @status_classes.join(' ') end |
#is?(status_class) ⇒ Boolean
25 26 27 |
# File 'app/helpers/aasm_progressable/helper.rb', line 25 def is?(status_class) @status_classes.include? status_class end |