state_machines-activemodel 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/cssxfire.xml +9 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/state_machine2_activemodel.iml +32 -0
- data/.idea/vcs.xml +7 -0
- data/.idea/workspace.xml +50 -0
- data/.rspec +3 -0
- data/.travis.yml +19 -0
- data/Appraisals +34 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +86 -0
- data/Rakefile +10 -0
- data/gemfiles/active_model_3.2.gemfile +7 -0
- data/gemfiles/active_model_3.2.gemfile.lock +50 -0
- data/gemfiles/active_model_4.0.gemfile +7 -0
- data/gemfiles/active_model_4.0.gemfile.lock +56 -0
- data/gemfiles/active_model_4.0_obs.gemfile +8 -0
- data/gemfiles/active_model_4.0_obs.gemfile.lock +59 -0
- data/gemfiles/active_model_4.1.gemfile +7 -0
- data/gemfiles/active_model_4.1.gemfile.lock +57 -0
- data/gemfiles/active_model_4.1_obs.gemfile +8 -0
- data/gemfiles/active_model_4.1_obs.gemfile.lock +60 -0
- data/gemfiles/active_model_edge.gemfile +7 -0
- data/gemfiles/active_model_edge.gemfile.lock +62 -0
- data/gemfiles/active_model_edge_obs.gemfile +8 -0
- data/gemfiles/active_model_edge_obs.gemfile.lock +65 -0
- data/lib/state_machines-activemodel.rb +1 -0
- data/lib/state_machines/integrations/active_model.rb +593 -0
- data/lib/state_machines/integrations/active_model/locale.rb +11 -0
- data/lib/state_machines/integrations/active_model/observer.rb +33 -0
- data/lib/state_machines/integrations/active_model/observer_update.rb +42 -0
- data/lib/state_machines/integrations/version.rb +7 -0
- data/spec/active_model_spec.rb +639 -0
- data/spec/integration_spec.rb +27 -0
- data/spec/observer_spec.rb +519 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/en.yml +5 -0
- data/spec/support/helpers.rb +64 -0
- data/spec/support/migration_helpers.rb +43 -0
- data/state_machines-activemodel.gemspec +27 -0
- metadata +182 -0
data/spec/spec_helper.rb
ADDED
data/spec/support/en.yml
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Creates a new ActiveModel model (and the associated table)
|
2
|
+
|
3
|
+
class Bar
|
4
|
+
|
5
|
+
end
|
6
|
+
|
7
|
+
def new_model(&block)
|
8
|
+
# Simple ActiveModel superclass
|
9
|
+
parent = Class.new do
|
10
|
+
def self.model_attribute(name)
|
11
|
+
define_method(name) { instance_variable_defined?("@#{name}") ? instance_variable_get("@#{name}") : nil }
|
12
|
+
define_method("#{name}=") do |value|
|
13
|
+
send("#{name}_will_change!") if self.class <= ActiveModel::Dirty && value != send(name)
|
14
|
+
instance_variable_set("@#{name}", value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.create
|
19
|
+
object = new
|
20
|
+
object.save
|
21
|
+
object
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(attrs = {})
|
25
|
+
attrs.each {|attr, value| send("#{attr}=", value)}
|
26
|
+
@changed_attributes = {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def attributes
|
30
|
+
@attributes ||= {}
|
31
|
+
end
|
32
|
+
|
33
|
+
def save
|
34
|
+
@changed_attributes = {}
|
35
|
+
true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
model = Class.new(parent) do
|
40
|
+
def self.name
|
41
|
+
'Bar::Foo'
|
42
|
+
end
|
43
|
+
|
44
|
+
model_attribute :state
|
45
|
+
end
|
46
|
+
model.class_eval(&block) if block_given?
|
47
|
+
model
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# Creates a new ActiveModel observer
|
52
|
+
def new_observer(model, &block)
|
53
|
+
observer = Class.new(ActiveModel::Observer) do
|
54
|
+
attr_accessor :notifications
|
55
|
+
|
56
|
+
def initialize
|
57
|
+
super
|
58
|
+
@notifications = []
|
59
|
+
end
|
60
|
+
end
|
61
|
+
observer.observe(model)
|
62
|
+
observer.class_eval(&block) if block_given?
|
63
|
+
observer
|
64
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
def assert(obj)
|
2
|
+
expect(obj).to be_truthy
|
3
|
+
end
|
4
|
+
|
5
|
+
def assert_equal(value, obj)
|
6
|
+
expect(obj).to eq(value)
|
7
|
+
end
|
8
|
+
|
9
|
+
def assert_not_equal(value, obj)
|
10
|
+
expect(obj).to_not eq(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def assert_not_nil(obj)
|
15
|
+
expect(obj).to_not be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_nil(obj)
|
19
|
+
expect(obj).to be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def assert_raise(exception, &block)
|
23
|
+
expect(block).to raise_error(exception)
|
24
|
+
end
|
25
|
+
|
26
|
+
def assert_nothing_raised(&block)
|
27
|
+
expect(block).to_not raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def assert_same(value, obj)
|
32
|
+
expect(obj).to eq(value)
|
33
|
+
end
|
34
|
+
|
35
|
+
def assert_not_same(value, obj)
|
36
|
+
expect(obj).to_not eq(value)
|
37
|
+
end
|
38
|
+
|
39
|
+
def assert_instance_of(klass, obj)
|
40
|
+
expect(obj).to be_a klass
|
41
|
+
end
|
42
|
+
|
43
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'state_machines/integrations/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'state_machines-activemodel'
|
8
|
+
spec.version = StateMachines::Integrations::ActiveModel::VERSION
|
9
|
+
spec.authors = ['Abdelkader Boudih', 'Aaron Pfeifer']
|
10
|
+
spec.email = ['terminale@gmail.com']
|
11
|
+
spec.summary = %q(ActiveModel integration for State Machines)
|
12
|
+
spec.description = %q(Adds support for creating state machines for attributes on ActiveModel)
|
13
|
+
spec.homepage = 'https://github.com/seuros/state_machines-activemodel'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.test_files = spec.files.grep(/^spec\//)
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'state_machines' , '>= 0'
|
21
|
+
spec.add_dependency 'activemodel' , '>= 3.2'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '>= 1.6'
|
24
|
+
spec.add_development_dependency 'rake', '>= 10'
|
25
|
+
spec.add_development_dependency 'appraisal', '>= 1'
|
26
|
+
spec.add_development_dependency 'rspec' , '3.0.0.beta2'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: state_machines-activemodel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Abdelkader Boudih
|
8
|
+
- Aaron Pfeifer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: state_machines
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activemodel
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.2'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.2'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.6'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.6'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '10'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '10'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: appraisal
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 3.0.0.beta2
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 3.0.0.beta2
|
98
|
+
description: Adds support for creating state machines for attributes on ActiveModel
|
99
|
+
email:
|
100
|
+
- terminale@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".idea/.rakeTasks"
|
107
|
+
- ".idea/cssxfire.xml"
|
108
|
+
- ".idea/encodings.xml"
|
109
|
+
- ".idea/misc.xml"
|
110
|
+
- ".idea/modules.xml"
|
111
|
+
- ".idea/scopes/scope_settings.xml"
|
112
|
+
- ".idea/state_machine2_activemodel.iml"
|
113
|
+
- ".idea/vcs.xml"
|
114
|
+
- ".idea/workspace.xml"
|
115
|
+
- ".rspec"
|
116
|
+
- ".travis.yml"
|
117
|
+
- Appraisals
|
118
|
+
- Gemfile
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- gemfiles/active_model_3.2.gemfile
|
123
|
+
- gemfiles/active_model_3.2.gemfile.lock
|
124
|
+
- gemfiles/active_model_4.0.gemfile
|
125
|
+
- gemfiles/active_model_4.0.gemfile.lock
|
126
|
+
- gemfiles/active_model_4.0_obs.gemfile
|
127
|
+
- gemfiles/active_model_4.0_obs.gemfile.lock
|
128
|
+
- gemfiles/active_model_4.1.gemfile
|
129
|
+
- gemfiles/active_model_4.1.gemfile.lock
|
130
|
+
- gemfiles/active_model_4.1_obs.gemfile
|
131
|
+
- gemfiles/active_model_4.1_obs.gemfile.lock
|
132
|
+
- gemfiles/active_model_edge.gemfile
|
133
|
+
- gemfiles/active_model_edge.gemfile.lock
|
134
|
+
- gemfiles/active_model_edge_obs.gemfile
|
135
|
+
- gemfiles/active_model_edge_obs.gemfile.lock
|
136
|
+
- lib/state_machines-activemodel.rb
|
137
|
+
- lib/state_machines/integrations/active_model.rb
|
138
|
+
- lib/state_machines/integrations/active_model/locale.rb
|
139
|
+
- lib/state_machines/integrations/active_model/observer.rb
|
140
|
+
- lib/state_machines/integrations/active_model/observer_update.rb
|
141
|
+
- lib/state_machines/integrations/version.rb
|
142
|
+
- spec/active_model_spec.rb
|
143
|
+
- spec/integration_spec.rb
|
144
|
+
- spec/observer_spec.rb
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
- spec/support/en.yml
|
147
|
+
- spec/support/helpers.rb
|
148
|
+
- spec/support/migration_helpers.rb
|
149
|
+
- state_machines-activemodel.gemspec
|
150
|
+
homepage: https://github.com/seuros/state_machines-activemodel
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
metadata: {}
|
154
|
+
post_install_message:
|
155
|
+
rdoc_options: []
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
requirements: []
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 2.2.2
|
171
|
+
signing_key:
|
172
|
+
specification_version: 4
|
173
|
+
summary: ActiveModel integration for State Machines
|
174
|
+
test_files:
|
175
|
+
- spec/active_model_spec.rb
|
176
|
+
- spec/integration_spec.rb
|
177
|
+
- spec/observer_spec.rb
|
178
|
+
- spec/spec_helper.rb
|
179
|
+
- spec/support/en.yml
|
180
|
+
- spec/support/helpers.rb
|
181
|
+
- spec/support/migration_helpers.rb
|
182
|
+
has_rdoc:
|