renamed permissible states and events to permitted states events
This commit is contained in:
parent
0fb28e50b6
commit
488bda0c42
|
@ -17,6 +17,7 @@
|
|||
* **DSL change**: instance-based events inspection now returns event instances (instead of the event names as symbol)
|
||||
* **DSL change**: instance-based permissible_events has been removed in favor or events(:permissible => true)
|
||||
* **DSL change**: class-based events now returns a list of Event instances (instead of a hash with event names as keys)
|
||||
* **DSL change**: renamed permissible states and events to permitted states events
|
||||
|
||||
## 3.9.0 (not yet released)
|
||||
|
||||
|
|
|
@ -578,7 +578,7 @@ end
|
|||
|
||||
### Inspection
|
||||
|
||||
AASM supports a couple of methods to find out which states or events are provided or permissible.
|
||||
AASM supports a couple of methods to find out which states or events are provided or permitted.
|
||||
|
||||
Given this `Job` class:
|
||||
|
||||
|
@ -589,11 +589,11 @@ Job.aasm.states.map(&:name)
|
|||
|
||||
job = Job.new
|
||||
|
||||
# show all permissible (reachable / possible) states
|
||||
job.aasm.states(:permissible => true).map(&:name)
|
||||
# show all permitted (reachable / possible) states
|
||||
job.aasm.states(:permitted => true).map(&:name)
|
||||
=> [:running]
|
||||
job.run
|
||||
job.aasm.states(:permissible => true).map(&:name)
|
||||
job.aasm.states(:permitted => true).map(&:name)
|
||||
=> [:cleaning, :sleeping]
|
||||
|
||||
# show all possible (triggerable) events (allowed by transitions)
|
||||
|
|
|
@ -125,7 +125,7 @@ job.aasm.events.map(&:name)
|
|||
# => [:run]
|
||||
```
|
||||
|
||||
Retrieving the list of permissible events has now been integrated into the `events` method. Change from
|
||||
Retrieving the list of permitted events has now been integrated into the `events` method. Change from
|
||||
|
||||
```ruby
|
||||
job = Job.new
|
||||
|
@ -139,7 +139,7 @@ to
|
|||
```ruby
|
||||
job = Job.new
|
||||
|
||||
job.aasm.events(:permissible => true)
|
||||
job.aasm.events(:permitted => true)
|
||||
# => [:run]
|
||||
```
|
||||
|
||||
|
|
|
@ -127,8 +127,8 @@ module AASM
|
|||
|
||||
# TODO remove this method in v4.0.0
|
||||
def aasm_permissible_events_for_current_state
|
||||
warn "#aasm_permissible_events_for_current_state is deprecated and will be removed in version 4.0.0; please use #aasm.events(:permissible => true) instead!"
|
||||
aasm.events(:permissible => true)
|
||||
warn "#aasm_permissible_events_for_current_state is deprecated and will be removed in version 4.0.0; please use #aasm.events(:permitted => true) instead!"
|
||||
aasm.events(:permitted => true)
|
||||
end
|
||||
|
||||
# TODO remove this method in v4.0.0
|
||||
|
|
|
@ -33,10 +33,10 @@ module AASM
|
|||
end
|
||||
|
||||
def states(options={})
|
||||
if options[:permissible]
|
||||
if options[:permitted]
|
||||
# ugliness level 1000
|
||||
permissible_event_names = events(:permissible => true).map(&:name)
|
||||
transitions = @instance.class.aasm.state_machine.events.values_at(*permissible_event_names).compact.map {|e| e.transitions_from_state(current_state) }
|
||||
permitted_event_names = events(:permitted => true).map(&:name)
|
||||
transitions = @instance.class.aasm.state_machine.events.values_at(*permitted_event_names).compact.map {|e| e.transitions_from_state(current_state) }
|
||||
tos = transitions.map {|t| t[0] ? t[0].to : nil}.flatten.compact.map(&:to_sym).uniq
|
||||
@instance.class.aasm.states.select {|s| tos.include?(s.name.to_sym)}
|
||||
else
|
||||
|
@ -48,7 +48,7 @@ module AASM
|
|||
state = options[:state] || current_state
|
||||
events = @instance.class.aasm.events.select {|e| e.transitions_from_state?(state) }
|
||||
|
||||
if options[:permissible]
|
||||
if options[:permitted]
|
||||
# filters the results of events_for_current_state so that only those that
|
||||
# are really currently possible (given transition guards) are shown.
|
||||
events.select! { |e| @instance.send("may_#{e.name}?") }
|
||||
|
|
|
@ -24,13 +24,13 @@ describe 'inspection for common cases' do
|
|||
expect(states).to include(:closed)
|
||||
expect(states).to include(:final)
|
||||
|
||||
states = foo.aasm.states(:permissible => true)
|
||||
states = foo.aasm.states(:permitted => true)
|
||||
expect(states).to include(:closed)
|
||||
expect(states).not_to include(:open)
|
||||
expect(states).not_to include(:final)
|
||||
|
||||
foo.close
|
||||
expect(foo.aasm.states(:permissible => true)).to be_empty
|
||||
expect(foo.aasm.states(:permitted => true)).to be_empty
|
||||
end
|
||||
|
||||
it "delivers all states for subclasses" do
|
||||
|
@ -39,12 +39,12 @@ describe 'inspection for common cases' do
|
|||
expect(states).to include(:closed)
|
||||
expect(states).to include(:foo)
|
||||
|
||||
states = two.aasm.states(:permissible => true)
|
||||
states = two.aasm.states(:permitted => true)
|
||||
expect(states).to include(:closed)
|
||||
expect(states).not_to include(:open)
|
||||
|
||||
two.close
|
||||
expect(two.aasm.states(:permissible => true)).to be_empty
|
||||
expect(two.aasm.states(:permitted => true)).to be_empty
|
||||
end
|
||||
|
||||
it "delivers all events" do
|
||||
|
@ -96,11 +96,11 @@ describe 'aasm.from_states_for_state' do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'permissible events' do
|
||||
describe 'permitted events' do
|
||||
let(:foo) {Foo.new}
|
||||
|
||||
it 'work' do
|
||||
expect(foo.aasm.events(:permissible => true)).to include(:close)
|
||||
expect(foo.aasm.events(:permissible => true)).not_to include(:null)
|
||||
expect(foo.aasm.events(:permitted => true)).to include(:close)
|
||||
expect(foo.aasm.events(:permitted => true)).not_to include(:null)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue