Module: AASM::Persistence::ActiveRecordPersistence::ClassMethods
- Defined in:
- lib/persistence/active_record_persistence.rb
Instance Method Summary collapse
-
#aasm_column(column_name = nil) ⇒ Object
Maps to the aasm_column in the database.
- #aasm_integers ⇒ Object
-
#aasm_state_integer(value) ⇒ Object
Get state integer by symbol if integers are set.
-
#aasm_state_name(value) ⇒ Object
Get state name by integer if integers are set.
- #calculate_in_state(state, *args) ⇒ Object
- #count_in_state(state, *args) ⇒ Object
- #find_in_state(number, state, *args) ⇒ Object
Instance Method Details
#aasm_column(column_name = nil) ⇒ Object
Maps to the aasm_column in the database. Deafults to “aasm_state”. You can write:
create_table :foos do |t|
t.string :name
t.string :aasm_state
end
class Foo < ActiveRecord::Base
include AASM
end
OR:
create_table :foos do |t|
t.string :name
t.string :status
end
class Foo < ActiveRecord::Base
include AASM
aasm_column :status
end
This method is both a getter and a setter
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/persistence/active_record_persistence.rb', line 80 def aasm_column(column_name=nil) if column_name AASM::StateMachine[self].config.column = column_name.to_sym # @aasm_column = column_name.to_sym else AASM::StateMachine[self].config.column ||= :aasm_state # @aasm_column ||= :aasm_state end # @aasm_column AASM::StateMachine[self].config.column end |
#aasm_integers ⇒ Object
110 111 112 |
# File 'lib/persistence/active_record_persistence.rb', line 110 def aasm_integers AASM::StateMachine[self].integers end |
#aasm_state_integer(value) ⇒ Object
Get state integer by symbol if integers are set
120 121 122 |
# File 'lib/persistence/active_record_persistence.rb', line 120 def aasm_state_integer(value) aasm_integers.setted? && value.is_a?(Symbol) ? aasm_integers.by_state(value) : value end |
#aasm_state_name(value) ⇒ Object
Get state name by integer if integers are set
115 116 117 |
# File 'lib/persistence/active_record_persistence.rb', line 115 def aasm_state_name(value) aasm_integers.setted? && value.is_a?(Integer) ? aasm_integers.by_integer(value) : value.to_s end |
#calculate_in_state(state, *args) ⇒ Object
104 105 106 107 108 |
# File 'lib/persistence/active_record_persistence.rb', line 104 def calculate_in_state(state, *args) with_state_scope state do calculate(*args) end end |
#count_in_state(state, *args) ⇒ Object
98 99 100 101 102 |
# File 'lib/persistence/active_record_persistence.rb', line 98 def count_in_state(state, *args) with_state_scope state do count(*args) end end |
#find_in_state(number, state, *args) ⇒ Object
92 93 94 95 96 |
# File 'lib/persistence/active_record_persistence.rb', line 92 def find_in_state(number, state, *args) with_state_scope state do find(number, *args) end end |