state_machines-activemodel 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.idea/.rakeTasks +7 -0
  4. data/.idea/cssxfire.xml +9 -0
  5. data/.idea/encodings.xml +5 -0
  6. data/.idea/misc.xml +5 -0
  7. data/.idea/modules.xml +9 -0
  8. data/.idea/scopes/scope_settings.xml +5 -0
  9. data/.idea/state_machine2_activemodel.iml +32 -0
  10. data/.idea/vcs.xml +7 -0
  11. data/.idea/workspace.xml +50 -0
  12. data/.rspec +3 -0
  13. data/.travis.yml +19 -0
  14. data/Appraisals +34 -0
  15. data/Gemfile +4 -0
  16. data/LICENSE.txt +23 -0
  17. data/README.md +86 -0
  18. data/Rakefile +10 -0
  19. data/gemfiles/active_model_3.2.gemfile +7 -0
  20. data/gemfiles/active_model_3.2.gemfile.lock +50 -0
  21. data/gemfiles/active_model_4.0.gemfile +7 -0
  22. data/gemfiles/active_model_4.0.gemfile.lock +56 -0
  23. data/gemfiles/active_model_4.0_obs.gemfile +8 -0
  24. data/gemfiles/active_model_4.0_obs.gemfile.lock +59 -0
  25. data/gemfiles/active_model_4.1.gemfile +7 -0
  26. data/gemfiles/active_model_4.1.gemfile.lock +57 -0
  27. data/gemfiles/active_model_4.1_obs.gemfile +8 -0
  28. data/gemfiles/active_model_4.1_obs.gemfile.lock +60 -0
  29. data/gemfiles/active_model_edge.gemfile +7 -0
  30. data/gemfiles/active_model_edge.gemfile.lock +62 -0
  31. data/gemfiles/active_model_edge_obs.gemfile +8 -0
  32. data/gemfiles/active_model_edge_obs.gemfile.lock +65 -0
  33. data/lib/state_machines-activemodel.rb +1 -0
  34. data/lib/state_machines/integrations/active_model.rb +593 -0
  35. data/lib/state_machines/integrations/active_model/locale.rb +11 -0
  36. data/lib/state_machines/integrations/active_model/observer.rb +33 -0
  37. data/lib/state_machines/integrations/active_model/observer_update.rb +42 -0
  38. data/lib/state_machines/integrations/version.rb +7 -0
  39. data/spec/active_model_spec.rb +639 -0
  40. data/spec/integration_spec.rb +27 -0
  41. data/spec/observer_spec.rb +519 -0
  42. data/spec/spec_helper.rb +8 -0
  43. data/spec/support/en.yml +5 -0
  44. data/spec/support/helpers.rb +64 -0
  45. data/spec/support/migration_helpers.rb +43 -0
  46. data/state_machines-activemodel.gemspec +27 -0
  47. metadata +182 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f11ff8fca94c8ac107ae350fc15b495e60382aa2
4
+ data.tar.gz: 3b4f9a5a1faef97c4e0c17056f4b9f1dbcfc5f4a
5
+ SHA512:
6
+ metadata.gz: f66365a5bb8cd800eb6e5aca5f8cd460d918a203da9ea0b1bf258a1bb01b78a2d4642c16af47e5d16519ade297f22984f443b5c2faa967fe487878efaecbac74
7
+ data.tar.gz: e834da143cca6992e98b286f9f82203983b58dade11b58f6bd18bcc6e5a46d5bbee1f8987aff7a961f26be781866f165a52a4ca65be9792349bfeb4e34ecd947
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.idea/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="CssXFireSettings">
4
+ <general autoClear="false" autoExpand="false" />
5
+ <strategy useRoutes="false" mediaReduce="false" fileReduce="false" currentDocumentsReduce="false" resolveVariables="true" resolveMixins="true" />
6
+ <routes />
7
+ </component>
8
+ </project>
9
+
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
4
+ </project>
5
+
data/.idea/misc.xml ADDED
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 1.9.3-p448" project-jdk-type="RUBY_SDK" />
4
+ </project>
5
+
data/.idea/modules.xml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/state_machine2_activemodel.iml" filepath="$PROJECT_DIR$/.idea/state_machine2_activemodel.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
9
+
@@ -0,0 +1,5 @@
1
+ <component name="DependencyValidationManager">
2
+ <state>
3
+ <option name="SKIP_IMPORT_STATEMENTS" value="false" />
4
+ </state>
5
+ </component>
@@ -0,0 +1,32 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="gem" name="Ruby Gem">
5
+ <configuration>
6
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$/../state_machine2_activemodel" />
7
+ <option name="GEM_APP_TEST_PATH" value="" />
8
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/../state_machine2_activemodel/lib" />
9
+ </configuration>
10
+ </facet>
11
+ </component>
12
+ <component name="NewModuleRootManager">
13
+ <content url="file://$MODULE_DIR$" />
14
+ <orderEntry type="inheritedJdk" />
15
+ <orderEntry type="sourceFolder" forTests="false" />
16
+ <orderEntry type="module-library">
17
+ <library name="state_machines-activemodel (v[path], /home/abdelkader/RubymineProjects/gems/state_machines-activemodel) [path][gem]">
18
+ <CLASSES>
19
+ <root url="file://$MODULE_DIR$/lib" />
20
+ <root url="file://$MODULE_DIR$/.idea" />
21
+ <root url="file://$MODULE_DIR$/gemfiles" />
22
+ </CLASSES>
23
+ <SOURCES>
24
+ <root url="file://$MODULE_DIR$/lib" />
25
+ <root url="file://$MODULE_DIR$/.idea" />
26
+ <root url="file://$MODULE_DIR$/gemfiles" />
27
+ </SOURCES>
28
+ </library>
29
+ </orderEntry>
30
+ </component>
31
+ </module>
32
+
data/.idea/vcs.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="" />
5
+ </component>
6
+ </project>
7
+
@@ -0,0 +1,50 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ChangeListManager">
4
+ <option name="TRACKING_ENABLED" value="true" />
5
+ <option name="SHOW_DIALOG" value="false" />
6
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
7
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
8
+ <option name="LAST_RESOLUTION" value="IGNORE" />
9
+ </component>
10
+ <component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
11
+ <component name="CreatePatchCommitExecutor">
12
+ <option name="PATCH_PATH" value="" />
13
+ </component>
14
+ <component name="DaemonCodeAnalyzer">
15
+ <disable_hints />
16
+ </component>
17
+ <component name="ProjectLevelVcsManager" settingsEditedManually="false">
18
+ <OptionsSetting value="true" id="Add" />
19
+ <OptionsSetting value="true" id="Remove" />
20
+ <OptionsSetting value="true" id="Checkout" />
21
+ <OptionsSetting value="true" id="Update" />
22
+ <OptionsSetting value="true" id="Status" />
23
+ <OptionsSetting value="true" id="Edit" />
24
+ <ConfirmationsSetting value="0" id="Add" />
25
+ <ConfirmationsSetting value="0" id="Remove" />
26
+ </component>
27
+ <component name="ProjectReloadState">
28
+ <option name="STATE" value="0" />
29
+ </component>
30
+ <component name="RunManager">
31
+ <list size="0" />
32
+ </component>
33
+ <component name="ShelveChangesManager" show_recycled="false" />
34
+ <component name="TaskManager">
35
+ <task active="true" id="Default" summary="Default task" />
36
+ <servers />
37
+ </component>
38
+ <component name="VcsContentAnnotationSettings">
39
+ <option name="myLimit" value="2678400000" />
40
+ </component>
41
+ <component name="VcsManagerConfiguration">
42
+ <option name="myTodoPanelSettings">
43
+ <TodoPanelSettings />
44
+ </option>
45
+ </component>
46
+ <component name="XDebuggerManager">
47
+ <breakpoint-manager />
48
+ </component>
49
+ </project>
50
+
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem install bundler
4
+ - bundle install
5
+ script: bundle exec rake
6
+ rvm:
7
+ - 1.9.3
8
+ - 2.0.0
9
+ - 2.1.1
10
+ - jruby-19mode
11
+ - rbx-2
12
+ gemfile:
13
+ - gemfiles/active_model_3.2.gemfile
14
+ - gemfiles/active_model_4.0_obs.gemfile
15
+ - gemfiles/active_model_4.0.gemfile
16
+ - gemfiles/active_model_4.1_obs.gemfile
17
+ - gemfiles/active_model_4.1.gemfile
18
+ - gemfiles/active_model_edge_obs.gemfile
19
+ - gemfiles/active_model_edge.gemfile
data/Appraisals ADDED
@@ -0,0 +1,34 @@
1
+ # ActiveModel integrations
2
+ appraise "active_model_3.2" do
3
+ gem "activemodel", "~> 3.2.0"
4
+ end
5
+
6
+ appraise "active_model_4.0_obs" do
7
+ gem "activemodel", "~> 4.0.0"
8
+ gem 'rails-observers'
9
+ end
10
+
11
+
12
+ appraise "active_model_4.0" do
13
+ gem "activemodel", "~> 4.0.0"
14
+ end
15
+
16
+ appraise 'active_model_4.1_obs' do
17
+ gem 'activemodel', '~> 4.1.0'
18
+ gem 'rails-observers'
19
+ end
20
+
21
+ appraise 'active_model_4.1' do
22
+ gem 'activemodel', '~> 4.1.0'
23
+ end
24
+
25
+ appraise 'active_model_edge_obs' do
26
+ gem 'activemodel', github: 'rails/rails'
27
+ gem 'rails-observers'
28
+ end
29
+
30
+ appraise 'active_model_edge' do
31
+ gem 'activemodel', github: 'rails/rails'
32
+ end
33
+
34
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in state_machine2_activemodel.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2006-2012 Aaron Pfeifer
2
+ Copyright (c) 2014 Abdelkader Boudih
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # StateMachines ActiveModel Integration
2
+
3
+ The ActiveModel integration is useful for both standalone usage and for providing
4
+ the base implementation for ORMs which implement the ActiveModel API. This
5
+ integration adds support for validation errors, dirty attribute tracking, and
6
+ observers.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'state_machine2_activemodel'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install state_machine2_activemodel
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+
26
+ class Vehicle
27
+ include ActiveModel::Dirty
28
+ include ActiveModel::Validations
29
+ include ActiveModel::Observing
30
+
31
+ attr_accessor :state
32
+ define_attribute_methods [:state]
33
+
34
+ state_machine :initial => :parked do
35
+ before_transition :parked => any - :parked, :do => :put_on_seatbelt
36
+ after_transition any => :parked do |vehicle, transition|
37
+ vehicle.seatbelt = 'off'
38
+ end
39
+ around_transition :benchmark
40
+
41
+ event :ignite do
42
+ transition :parked => :idling
43
+ end
44
+
45
+ state :first_gear, :second_gear do
46
+ validates_presence_of :seatbelt_on
47
+ end
48
+ end
49
+
50
+ def put_on_seatbelt
51
+ ...
52
+ end
53
+
54
+ def benchmark
55
+ ...
56
+ yield
57
+ ...
58
+ end
59
+ end
60
+
61
+ class VehicleObserver < ActiveModel::Observer
62
+ # Callback for :ignite event *before* the transition is performed
63
+ def before_ignite(vehicle, transition)
64
+ # log message
65
+ end
66
+
67
+ # Generic transition callback *after* the transition is performed
68
+ def after_transition(vehicle, transition)
69
+ Audit.log(vehicle, transition)
70
+ end
71
+
72
+ # Generic callback after the transition fails to perform
73
+ def after_failure_to_transition(vehicle, transition)
74
+ Audit.error(vehicle, transition)
75
+ end
76
+ end
77
+
78
+ ```
79
+
80
+ ## Contributing
81
+
82
+ 1. Fork it ( https://github.com/seuros/state_machines-activemodel/fork )
83
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
84
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
85
+ 4. Push to the branch (`git push origin my-new-feature`)
86
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ desc 'Default: run all tests.'
10
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activemodel", "~> 3.2.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ state_machines-activemodel (0.0.1)
5
+ activemodel (>= 3.2)
6
+ state_machines
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (3.2.17)
12
+ activesupport (= 3.2.17)
13
+ builder (~> 3.0.0)
14
+ activesupport (3.2.17)
15
+ i18n (~> 0.6, >= 0.6.4)
16
+ multi_json (~> 1.0)
17
+ appraisal (1.0.0)
18
+ bundler
19
+ rake
20
+ thor (>= 0.14.0)
21
+ builder (3.0.4)
22
+ diff-lcs (1.2.5)
23
+ i18n (0.6.9)
24
+ multi_json (1.9.3)
25
+ rake (10.3.1)
26
+ rspec (3.0.0.beta2)
27
+ rspec-core (= 3.0.0.beta2)
28
+ rspec-expectations (= 3.0.0.beta2)
29
+ rspec-mocks (= 3.0.0.beta2)
30
+ rspec-core (3.0.0.beta2)
31
+ rspec-support (= 3.0.0.beta2)
32
+ rspec-expectations (3.0.0.beta2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (= 3.0.0.beta2)
35
+ rspec-mocks (3.0.0.beta2)
36
+ rspec-support (= 3.0.0.beta2)
37
+ rspec-support (3.0.0.beta2)
38
+ state_machines (0.0.1)
39
+ thor (0.19.1)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ activemodel (~> 3.2.0)
46
+ appraisal (>= 1)
47
+ bundler (>= 1.6)
48
+ rake (>= 10)
49
+ rspec (= 3.0.0.beta2)
50
+ state_machines-activemodel!
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activemodel", "~> 4.0.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ state_machines-activemodel (0.0.1)
5
+ activemodel (>= 3.2)
6
+ state_machines
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (4.0.4)
12
+ activesupport (= 4.0.4)
13
+ builder (~> 3.1.0)
14
+ activesupport (4.0.4)
15
+ i18n (~> 0.6, >= 0.6.9)
16
+ minitest (~> 4.2)
17
+ multi_json (~> 1.3)
18
+ thread_safe (~> 0.1)
19
+ tzinfo (~> 0.3.37)
20
+ appraisal (1.0.0)
21
+ bundler
22
+ rake
23
+ thor (>= 0.14.0)
24
+ builder (3.1.4)
25
+ diff-lcs (1.2.5)
26
+ i18n (0.6.9)
27
+ minitest (4.7.5)
28
+ multi_json (1.9.3)
29
+ rake (10.3.1)
30
+ rspec (3.0.0.beta2)
31
+ rspec-core (= 3.0.0.beta2)
32
+ rspec-expectations (= 3.0.0.beta2)
33
+ rspec-mocks (= 3.0.0.beta2)
34
+ rspec-core (3.0.0.beta2)
35
+ rspec-support (= 3.0.0.beta2)
36
+ rspec-expectations (3.0.0.beta2)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (= 3.0.0.beta2)
39
+ rspec-mocks (3.0.0.beta2)
40
+ rspec-support (= 3.0.0.beta2)
41
+ rspec-support (3.0.0.beta2)
42
+ state_machines (0.0.1)
43
+ thor (0.19.1)
44
+ thread_safe (0.3.3)
45
+ tzinfo (0.3.39)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ activemodel (~> 4.0.0)
52
+ appraisal (>= 1)
53
+ bundler (>= 1.6)
54
+ rake (>= 10)
55
+ rspec (= 3.0.0.beta2)
56
+ state_machines-activemodel!