instance-based permissible_events has been removed in favor or events(:permissible => true)
This commit is contained in:
parent
9346e6a859
commit
6ab03be38b
|
@ -15,6 +15,7 @@
|
|||
* **DSL change**: `:on_transition` renamed to `:after`
|
||||
* **DSL change**: transition `:after` binding changed (see [issue #59](https://github.com/aasm/aasm/issues/59), thanks to [@stiff](https://github.com/stiff))
|
||||
* **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)
|
||||
|
||||
## 3.9.0 (not yet released)
|
||||
|
||||
|
|
|
@ -125,6 +125,24 @@ job.aasm.events.map(&:name)
|
|||
# => [:run]
|
||||
```
|
||||
|
||||
Retrieving the list of permissible events has now been integrated into the `events` method. Change from
|
||||
|
||||
```ruby
|
||||
job = Job.new
|
||||
|
||||
job.aasm.permissible_events
|
||||
# => [:run]
|
||||
```
|
||||
|
||||
to
|
||||
|
||||
```ruby
|
||||
job = Job.new
|
||||
|
||||
job.aasm.events(:permissible => true)
|
||||
# => [:run]
|
||||
```
|
||||
|
||||
|
||||
## Could
|
||||
|
||||
|
|
|
@ -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.permissible_events instead!"
|
||||
aasm.permissible_events
|
||||
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)
|
||||
end
|
||||
|
||||
# TODO remove this method in v4.0.0
|
||||
|
|
|
@ -35,7 +35,7 @@ module AASM
|
|||
def states(options={})
|
||||
if options[:permissible]
|
||||
# ugliness level 1000
|
||||
permissible_event_names = permissible_events.map(&:name)
|
||||
permissible_event_names = events(:permissible => true).map(&:name)
|
||||
transitions = @instance.class.aasm.events.values_at(*permissible_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)}
|
||||
|
@ -44,17 +44,17 @@ module AASM
|
|||
end
|
||||
end
|
||||
|
||||
# QUESTION: shouldn't events and permissible_events be the same thing?
|
||||
# QUESTION: shouldn't events return objects instead of strings?
|
||||
def events(state=current_state)
|
||||
def events(options={})
|
||||
state = options[:state] || current_state
|
||||
events = @instance.class.aasm.events.values.select {|e| e.transitions_from_state?(state) }
|
||||
end
|
||||
|
||||
# filters the results of events_for_current_state so that only those that
|
||||
# are really currently possible (given transition guards) are shown.
|
||||
# QUESTION: what about events.permissible ?
|
||||
def permissible_events
|
||||
events.select{ |e| @instance.send("may_#{e.name}?") }
|
||||
if options[:permissible]
|
||||
# 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}?") }
|
||||
end
|
||||
|
||||
events
|
||||
end
|
||||
|
||||
def state_object_for_name(name)
|
||||
|
|
|
@ -100,7 +100,7 @@ describe 'permissible events' do
|
|||
let(:foo) {Foo.new}
|
||||
|
||||
it 'work' do
|
||||
expect(foo.aasm.permissible_events).to include(:close)
|
||||
expect(foo.aasm.permissible_events).not_to include(:null)
|
||||
expect(foo.aasm.events(:permissible => true)).to include(:close)
|
||||
expect(foo.aasm.events(:permissible => true)).not_to include(:null)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue