From ef70ac53d9266feabd4090cdff71321af2c4cec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20B=C3=B6ttger?= Date: Sun, 16 Nov 2014 22:59:35 +0100 Subject: [PATCH] aasm_human_event_name is deprecated, use aasm.human_event_name instead --- CHANGELOG.md | 4 ++++ lib/aasm/aasm.rb | 8 ++++++-- lib/aasm/base.rb | 5 +++++ spec/unit/localizer_spec.rb | 12 ++++++------ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a49ebe..424e41a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 4.1.0 (not yet released) + + * `aasm_human_event_name` is deprecated, use `aasm.human_event_name` instead + ## 4.0.0 * support `if` and `unless` guard syntax: (see [issue #179](https://github.com/aasm/aasm/issues/179) and [issue #181](https://github.com/aasm/aasm/issues/181)), thanks to [@bigtunacan](https://github.com/bigtunacan) diff --git a/lib/aasm/aasm.rb b/lib/aasm/aasm.rb index a3222e7..c57cb1b 100644 --- a/lib/aasm/aasm.rb +++ b/lib/aasm/aasm.rb @@ -1,5 +1,8 @@ module AASM + # provide a state machine for the including class + # make sure to load class methods as well + # initialize persistence for the state machine def self.included(base) #:nodoc: base.extend AASM::ClassMethods @@ -26,9 +29,10 @@ module AASM @aasm end - # aasm.event(:event_name).human? + # deprecated, remove in version 4.1 def aasm_human_event_name(event) # event_name? - AASM::Localizer.new.human_event_name(self, event) + warn '[DEPRECATION] AASM: aasm_human_event_name is deprecated, use aasm.human_event_name instead' + aasm.human_event_name(event) end end # ClassMethods diff --git a/lib/aasm/base.rb b/lib/aasm/base.rb index 669bdba..a4b3d54 100644 --- a/lib/aasm/base.rb +++ b/lib/aasm/base.rb @@ -85,6 +85,11 @@ module AASM @state_machine.events.values end + # aasm.event(:event_name).human? + def human_event_name(event) # event_name? + AASM::Localizer.new.human_event_name(@klass, event) + end + def states_for_select states.map { |state| state.for_select } end diff --git a/spec/unit/localizer_spec.rb b/spec/unit/localizer_spec.rb index a40f510..728e777 100644 --- a/spec/unit/localizer_spec.rb +++ b/spec/unit/localizer_spec.rb @@ -67,13 +67,13 @@ describe AASM::Localizer, "new style" do end end - context 'aasm_human_event_name' do + context 'aasm.human_event_name' do it 'should return translated event name' do - expect(LocalizerTestModel.aasm_human_event_name(:close)).to eq("Let's close it!") + expect(LocalizerTestModel.aasm.human_event_name(:close)).to eq("Let's close it!") end it 'should return humanized event name' do - expect(LocalizerTestModel.aasm_human_event_name(:open)).to eq("Open") + expect(LocalizerTestModel.aasm.human_event_name(:open)).to eq("Open") end end end @@ -102,13 +102,13 @@ describe AASM::Localizer, "deprecated style" do end end - context 'aasm_human_event_name' do + context 'aasm.human_event_name' do it 'should return translated event name' do - expect(LocalizerTestModel.aasm_human_event_name(:close)).to eq("Let's close it!") + expect(LocalizerTestModel.aasm.human_event_name(:close)).to eq("Let's close it!") end it 'should return humanized event name' do - expect(LocalizerTestModel.aasm_human_event_name(:open)).to eq("Open") + expect(LocalizerTestModel.aasm.human_event_name(:open)).to eq("Open") end end end