stance 0.7.1 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.rubocop.yml +2 -0
- data/Gemfile.lock +188 -68
- data/lib/stance/engine.rb +0 -6
- data/lib/stance/event.rb +22 -10
- data/lib/stance/eventable.rb +15 -20
- data/lib/stance/events.rb +12 -2
- data/lib/stance/version.rb +1 -1
- data/lib/stance.rb +3 -1
- data/stance.gemspec +3 -4
- metadata +16 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 369e98673ef67283f9b65048d4a5163eb1de066fac3178554e78c8fbd720dc41
|
|
4
|
+
data.tar.gz: 4cfdcd75169331697db547c7e922ee2f61dc4aa472b8de6f4dab522ee6038ed1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e2d23c6aa87c81f4fd6d60472aad3e5ac9fbfd93731e06e7da10dc5f9ea3796f90a6ea94f36beec46fac829474b70eaa909e836a0b91a9c30f959ffcb89704bf
|
|
7
|
+
data.tar.gz: beee74748db0d933c8af8a209ecf2e99d226df1d07f4c731cdd7ba917cdb2ce605f983eef994dda9e19bf0c530c6977570a360e1fac5cc13813313ca1057888b
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,115 +1,235 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
stance (0.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
railties (>= 6)
|
|
4
|
+
stance (0.8.1)
|
|
5
|
+
multi_json (~> 1.15)
|
|
6
|
+
rails (>= 7.0, < 8.0)
|
|
8
7
|
|
|
9
8
|
GEM
|
|
10
9
|
remote: https://rubygems.org/
|
|
11
10
|
specs:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
activesupport (= 7.
|
|
15
|
-
|
|
11
|
+
actioncable (7.1.2)
|
|
12
|
+
actionpack (= 7.1.2)
|
|
13
|
+
activesupport (= 7.1.2)
|
|
14
|
+
nio4r (~> 2.0)
|
|
15
|
+
websocket-driver (>= 0.6.1)
|
|
16
|
+
zeitwerk (~> 2.6)
|
|
17
|
+
actionmailbox (7.1.2)
|
|
18
|
+
actionpack (= 7.1.2)
|
|
19
|
+
activejob (= 7.1.2)
|
|
20
|
+
activerecord (= 7.1.2)
|
|
21
|
+
activestorage (= 7.1.2)
|
|
22
|
+
activesupport (= 7.1.2)
|
|
23
|
+
mail (>= 2.7.1)
|
|
24
|
+
net-imap
|
|
25
|
+
net-pop
|
|
26
|
+
net-smtp
|
|
27
|
+
actionmailer (7.1.2)
|
|
28
|
+
actionpack (= 7.1.2)
|
|
29
|
+
actionview (= 7.1.2)
|
|
30
|
+
activejob (= 7.1.2)
|
|
31
|
+
activesupport (= 7.1.2)
|
|
32
|
+
mail (~> 2.5, >= 2.5.4)
|
|
33
|
+
net-imap
|
|
34
|
+
net-pop
|
|
35
|
+
net-smtp
|
|
36
|
+
rails-dom-testing (~> 2.2)
|
|
37
|
+
actionpack (7.1.2)
|
|
38
|
+
actionview (= 7.1.2)
|
|
39
|
+
activesupport (= 7.1.2)
|
|
40
|
+
nokogiri (>= 1.8.5)
|
|
41
|
+
racc
|
|
42
|
+
rack (>= 2.2.4)
|
|
43
|
+
rack-session (>= 1.0.1)
|
|
16
44
|
rack-test (>= 0.6.3)
|
|
17
|
-
rails-dom-testing (~> 2.
|
|
18
|
-
rails-html-sanitizer (~> 1.
|
|
19
|
-
|
|
20
|
-
|
|
45
|
+
rails-dom-testing (~> 2.2)
|
|
46
|
+
rails-html-sanitizer (~> 1.6)
|
|
47
|
+
actiontext (7.1.2)
|
|
48
|
+
actionpack (= 7.1.2)
|
|
49
|
+
activerecord (= 7.1.2)
|
|
50
|
+
activestorage (= 7.1.2)
|
|
51
|
+
activesupport (= 7.1.2)
|
|
52
|
+
globalid (>= 0.6.0)
|
|
53
|
+
nokogiri (>= 1.8.5)
|
|
54
|
+
actionview (7.1.2)
|
|
55
|
+
activesupport (= 7.1.2)
|
|
21
56
|
builder (~> 3.1)
|
|
22
|
-
erubi (~> 1.
|
|
23
|
-
rails-dom-testing (~> 2.
|
|
24
|
-
rails-html-sanitizer (~> 1.
|
|
25
|
-
|
|
26
|
-
activesupport (= 7.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
activesupport (= 7.
|
|
30
|
-
|
|
57
|
+
erubi (~> 1.11)
|
|
58
|
+
rails-dom-testing (~> 2.2)
|
|
59
|
+
rails-html-sanitizer (~> 1.6)
|
|
60
|
+
activejob (7.1.2)
|
|
61
|
+
activesupport (= 7.1.2)
|
|
62
|
+
globalid (>= 0.3.6)
|
|
63
|
+
activemodel (7.1.2)
|
|
64
|
+
activesupport (= 7.1.2)
|
|
65
|
+
activerecord (7.1.2)
|
|
66
|
+
activemodel (= 7.1.2)
|
|
67
|
+
activesupport (= 7.1.2)
|
|
68
|
+
timeout (>= 0.4.0)
|
|
69
|
+
activestorage (7.1.2)
|
|
70
|
+
actionpack (= 7.1.2)
|
|
71
|
+
activejob (= 7.1.2)
|
|
72
|
+
activerecord (= 7.1.2)
|
|
73
|
+
activesupport (= 7.1.2)
|
|
74
|
+
marcel (~> 1.0)
|
|
75
|
+
activesupport (7.1.2)
|
|
76
|
+
base64
|
|
77
|
+
bigdecimal
|
|
31
78
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
79
|
+
connection_pool (>= 2.2.5)
|
|
80
|
+
drb
|
|
32
81
|
i18n (>= 1.6, < 2)
|
|
33
82
|
minitest (>= 5.1)
|
|
83
|
+
mutex_m
|
|
34
84
|
tzinfo (~> 2.0)
|
|
35
85
|
ast (2.4.2)
|
|
36
86
|
autotest-suffix (1.1.0)
|
|
87
|
+
base64 (0.2.0)
|
|
88
|
+
bigdecimal (3.1.5)
|
|
37
89
|
builder (3.2.4)
|
|
38
90
|
combustion (1.3.7)
|
|
39
91
|
activesupport (>= 3.0.0)
|
|
40
92
|
railties (>= 3.0.0)
|
|
41
93
|
thor (>= 0.14.6)
|
|
42
|
-
concurrent-ruby (1.
|
|
94
|
+
concurrent-ruby (1.2.2)
|
|
95
|
+
connection_pool (2.4.1)
|
|
43
96
|
crass (1.0.6)
|
|
44
|
-
|
|
45
|
-
|
|
97
|
+
date (3.3.4)
|
|
98
|
+
drb (2.2.0)
|
|
99
|
+
ruby2_keywords
|
|
100
|
+
erubi (1.12.0)
|
|
101
|
+
globalid (1.2.1)
|
|
102
|
+
activesupport (>= 6.1)
|
|
103
|
+
i18n (1.14.1)
|
|
46
104
|
concurrent-ruby (~> 1.0)
|
|
47
|
-
|
|
48
|
-
|
|
105
|
+
io-console (0.7.1)
|
|
106
|
+
irb (1.11.0)
|
|
107
|
+
rdoc
|
|
108
|
+
reline (>= 0.3.8)
|
|
109
|
+
json (2.7.1)
|
|
110
|
+
language_server-protocol (3.17.0.3)
|
|
111
|
+
loofah (2.22.0)
|
|
49
112
|
crass (~> 1.0.2)
|
|
50
|
-
nokogiri (>= 1.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
113
|
+
nokogiri (>= 1.12.0)
|
|
114
|
+
mail (2.8.1)
|
|
115
|
+
mini_mime (>= 0.1.1)
|
|
116
|
+
net-imap
|
|
117
|
+
net-pop
|
|
118
|
+
net-smtp
|
|
119
|
+
marcel (1.0.2)
|
|
120
|
+
mini_mime (1.1.5)
|
|
121
|
+
mini_portile2 (2.8.5)
|
|
122
|
+
minitest (5.20.0)
|
|
54
123
|
minitest-autotest (1.1.1)
|
|
55
124
|
minitest-server (~> 1.0)
|
|
56
125
|
path_expander (~> 1.0)
|
|
57
|
-
minitest-focus (1.
|
|
126
|
+
minitest-focus (1.4.0)
|
|
58
127
|
minitest (>= 4, < 6)
|
|
59
|
-
minitest-server (1.0.
|
|
60
|
-
minitest (~> 5.
|
|
61
|
-
mocha (1.
|
|
128
|
+
minitest-server (1.0.7)
|
|
129
|
+
minitest (~> 5.16)
|
|
130
|
+
mocha (2.1.0)
|
|
131
|
+
ruby2_keywords (>= 0.0.5)
|
|
62
132
|
multi_json (1.15.0)
|
|
63
|
-
|
|
64
|
-
|
|
133
|
+
mutex_m (0.2.0)
|
|
134
|
+
net-imap (0.4.9.1)
|
|
135
|
+
date
|
|
136
|
+
net-protocol
|
|
137
|
+
net-pop (0.1.2)
|
|
138
|
+
net-protocol
|
|
139
|
+
net-protocol (0.2.2)
|
|
140
|
+
timeout
|
|
141
|
+
net-smtp (0.4.0.1)
|
|
142
|
+
net-protocol
|
|
143
|
+
nio4r (2.7.0)
|
|
144
|
+
nokogiri (1.16.0)
|
|
145
|
+
mini_portile2 (~> 2.8.2)
|
|
65
146
|
racc (~> 1.4)
|
|
66
|
-
parallel (1.
|
|
67
|
-
parser (3.
|
|
147
|
+
parallel (1.24.0)
|
|
148
|
+
parser (3.3.0.2)
|
|
68
149
|
ast (~> 2.4.1)
|
|
150
|
+
racc
|
|
69
151
|
path_expander (1.1.1)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
152
|
+
psych (5.1.2)
|
|
153
|
+
stringio
|
|
154
|
+
racc (1.7.3)
|
|
155
|
+
rack (3.0.8)
|
|
156
|
+
rack-session (2.0.0)
|
|
157
|
+
rack (>= 3.0.0)
|
|
158
|
+
rack-test (2.1.0)
|
|
73
159
|
rack (>= 1.3)
|
|
74
|
-
|
|
75
|
-
|
|
160
|
+
rackup (2.1.0)
|
|
161
|
+
rack (>= 3)
|
|
162
|
+
webrick (~> 1.8)
|
|
163
|
+
rails (7.1.2)
|
|
164
|
+
actioncable (= 7.1.2)
|
|
165
|
+
actionmailbox (= 7.1.2)
|
|
166
|
+
actionmailer (= 7.1.2)
|
|
167
|
+
actionpack (= 7.1.2)
|
|
168
|
+
actiontext (= 7.1.2)
|
|
169
|
+
actionview (= 7.1.2)
|
|
170
|
+
activejob (= 7.1.2)
|
|
171
|
+
activemodel (= 7.1.2)
|
|
172
|
+
activerecord (= 7.1.2)
|
|
173
|
+
activestorage (= 7.1.2)
|
|
174
|
+
activesupport (= 7.1.2)
|
|
175
|
+
bundler (>= 1.15.0)
|
|
176
|
+
railties (= 7.1.2)
|
|
177
|
+
rails-dom-testing (2.2.0)
|
|
178
|
+
activesupport (>= 5.0.0)
|
|
179
|
+
minitest
|
|
76
180
|
nokogiri (>= 1.6)
|
|
77
|
-
rails-html-sanitizer (1.
|
|
78
|
-
loofah (~> 2.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
181
|
+
rails-html-sanitizer (1.6.0)
|
|
182
|
+
loofah (~> 2.21)
|
|
183
|
+
nokogiri (~> 1.14)
|
|
184
|
+
railties (7.1.2)
|
|
185
|
+
actionpack (= 7.1.2)
|
|
186
|
+
activesupport (= 7.1.2)
|
|
187
|
+
irb
|
|
188
|
+
rackup (>= 1.0.0)
|
|
83
189
|
rake (>= 12.2)
|
|
84
|
-
thor (~> 1.0)
|
|
85
|
-
zeitwerk (~> 2.
|
|
190
|
+
thor (~> 1.0, >= 1.2.2)
|
|
191
|
+
zeitwerk (~> 2.6)
|
|
86
192
|
rainbow (3.1.1)
|
|
87
|
-
rake (13.0
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
193
|
+
rake (13.1.0)
|
|
194
|
+
rdoc (6.6.2)
|
|
195
|
+
psych (>= 4.0.0)
|
|
196
|
+
regexp_parser (2.8.3)
|
|
197
|
+
reline (0.4.2)
|
|
198
|
+
io-console (~> 0.5)
|
|
199
|
+
rexml (3.2.6)
|
|
200
|
+
rubocop (1.59.0)
|
|
91
201
|
json (~> 2.3)
|
|
202
|
+
language_server-protocol (>= 3.17.0)
|
|
92
203
|
parallel (~> 1.10)
|
|
93
|
-
parser (>= 3.
|
|
204
|
+
parser (>= 3.2.2.4)
|
|
94
205
|
rainbow (>= 2.2.2, < 4.0)
|
|
95
206
|
regexp_parser (>= 1.8, < 3.0)
|
|
96
207
|
rexml (>= 3.2.5, < 4.0)
|
|
97
|
-
rubocop-ast (>= 1.
|
|
208
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
|
98
209
|
ruby-progressbar (~> 1.7)
|
|
99
|
-
unicode-display_width (>=
|
|
100
|
-
rubocop-ast (1.
|
|
101
|
-
parser (>= 3.
|
|
102
|
-
rubocop-minitest (0.
|
|
103
|
-
rubocop (>=
|
|
210
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
211
|
+
rubocop-ast (1.30.0)
|
|
212
|
+
parser (>= 3.2.1.0)
|
|
213
|
+
rubocop-minitest (0.34.3)
|
|
214
|
+
rubocop (>= 1.39, < 2.0)
|
|
215
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
|
104
216
|
rubocop-rake (0.6.0)
|
|
105
217
|
rubocop (~> 1.0)
|
|
106
|
-
ruby-progressbar (1.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
218
|
+
ruby-progressbar (1.13.0)
|
|
219
|
+
ruby2_keywords (0.0.5)
|
|
220
|
+
sqlite3 (1.7.0)
|
|
221
|
+
mini_portile2 (~> 2.8.0)
|
|
222
|
+
stringio (3.1.0)
|
|
223
|
+
thor (1.3.0)
|
|
224
|
+
timeout (0.4.1)
|
|
225
|
+
tzinfo (2.0.6)
|
|
110
226
|
concurrent-ruby (~> 1.0)
|
|
111
|
-
unicode-display_width (2.
|
|
112
|
-
|
|
227
|
+
unicode-display_width (2.5.0)
|
|
228
|
+
webrick (1.8.1)
|
|
229
|
+
websocket-driver (0.7.6)
|
|
230
|
+
websocket-extensions (>= 0.1.0)
|
|
231
|
+
websocket-extensions (0.1.5)
|
|
232
|
+
zeitwerk (2.6.12)
|
|
113
233
|
|
|
114
234
|
PLATFORMS
|
|
115
235
|
ruby
|
data/lib/stance/engine.rb
CHANGED
|
@@ -5,11 +5,5 @@ require 'rails'
|
|
|
5
5
|
module Stance
|
|
6
6
|
class Engine < ::Rails::Engine
|
|
7
7
|
isolate_namespace Stance
|
|
8
|
-
|
|
9
|
-
# initializer 'active_record.include_event_concern' do
|
|
10
|
-
# ActiveSupport.on_load(:active_record) do
|
|
11
|
-
# ActiveRecord::Base.include Stance::EventConcern
|
|
12
|
-
# end
|
|
13
|
-
# end
|
|
14
8
|
end
|
|
15
9
|
end
|
data/lib/stance/event.rb
CHANGED
|
@@ -5,9 +5,7 @@ module Stance
|
|
|
5
5
|
include ActiveSupport::Callbacks
|
|
6
6
|
|
|
7
7
|
define_callbacks :create
|
|
8
|
-
attr_reader :record, :options
|
|
9
|
-
|
|
10
|
-
delegate :subject, :name, to: :record
|
|
8
|
+
attr_reader :record, :options, :name
|
|
11
9
|
|
|
12
10
|
class << self
|
|
13
11
|
def before_create(*methods, &block)
|
|
@@ -20,14 +18,22 @@ module Stance
|
|
|
20
18
|
end
|
|
21
19
|
|
|
22
20
|
def initialize(name, subject, metadata, options)
|
|
21
|
+
@subject = subject
|
|
22
|
+
@name = name
|
|
23
|
+
@metadata = metadata
|
|
23
24
|
@options = { singleton: false, record: true, class: false }.merge(options)
|
|
24
25
|
|
|
25
26
|
attrs = { name: name, metadata: metadata }
|
|
26
|
-
if subject.is_a?(
|
|
27
|
-
attrs[:subject_type] = subject
|
|
28
|
-
else
|
|
27
|
+
if subject.is_a?(ActiveRecord::Base)
|
|
29
28
|
attrs[:subject] = subject
|
|
29
|
+
elsif subject.is_a?(Class) && subject < ActiveRecord::Base
|
|
30
|
+
attrs[:subject_type] = subject.name
|
|
31
|
+
else
|
|
32
|
+
@options[:record] = false
|
|
30
33
|
end
|
|
34
|
+
|
|
35
|
+
return unless @options[:record]
|
|
36
|
+
|
|
31
37
|
@record = Stance::EventRecord.new(attrs)
|
|
32
38
|
end
|
|
33
39
|
|
|
@@ -40,9 +46,7 @@ module Stance
|
|
|
40
46
|
if self.class.name != 'Stance::Event'
|
|
41
47
|
Rails.logger.info "Event: #{full_name}"
|
|
42
48
|
|
|
43
|
-
|
|
44
|
-
send method
|
|
45
|
-
end
|
|
49
|
+
callback_methods.each { |method| send method }
|
|
46
50
|
end
|
|
47
51
|
|
|
48
52
|
record.save if @options[:record]
|
|
@@ -53,11 +57,19 @@ module Stance
|
|
|
53
57
|
end
|
|
54
58
|
|
|
55
59
|
def full_name
|
|
56
|
-
"#{
|
|
60
|
+
"#{subject.class.name.downcase}.#{name}"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def subject
|
|
64
|
+
try(:record)&.subject || @subject
|
|
57
65
|
end
|
|
58
66
|
|
|
59
67
|
private
|
|
60
68
|
|
|
69
|
+
def callback_methods
|
|
70
|
+
public_methods(false) - Stance::Event.instance_methods(false)
|
|
71
|
+
end
|
|
72
|
+
|
|
61
73
|
# Event is a singleton and already exists.
|
|
62
74
|
def singleton_exists?
|
|
63
75
|
options[:singleton] && subject.events.active.exists?(name: name)
|
data/lib/stance/eventable.rb
CHANGED
|
@@ -5,24 +5,26 @@ module Stance
|
|
|
5
5
|
extend ActiveSupport::Concern
|
|
6
6
|
|
|
7
7
|
included do
|
|
8
|
-
has_many :events, as: :subject, class_name: 'Stance::EventRecord'
|
|
8
|
+
has_many :events, as: :subject, class_name: 'Stance::EventRecord' if respond_to?(:has_many)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
class_methods do
|
|
12
|
-
|
|
12
|
+
# An event class may also exist in one or more namespaces (see `Stance.config.namespaces`).
|
|
13
|
+
# The event will be published to all classes that define the event class, and the class which
|
|
14
|
+
# defined the event takes priority.
|
|
15
|
+
def publish_event(name, metadata = {}, subject = self)
|
|
13
16
|
name = name.to_s
|
|
14
|
-
ensure_event! name
|
|
17
|
+
subject.ensure_event! name
|
|
15
18
|
|
|
16
|
-
# Find the Event class - if any - and
|
|
17
|
-
ev = event_class(name)
|
|
19
|
+
# Find the Event class - if any - and initialize it. Falls back to Stance::Event.
|
|
20
|
+
ev = subject.event_class(name)
|
|
21
|
+
.new(name, subject, metadata, subject.events_class.events[name])
|
|
18
22
|
|
|
19
23
|
return ev if Stance.disabled_events.include?(ev.full_name)
|
|
20
24
|
|
|
21
|
-
events_class.new(ev).run_callbacks(:create) { ev.create }
|
|
25
|
+
subject.events_class.new(ev).run_callbacks(:create) { ev.create }
|
|
22
26
|
end
|
|
23
27
|
|
|
24
|
-
private
|
|
25
|
-
|
|
26
28
|
# Raise EventNotFound if the class event has not been defined.
|
|
27
29
|
def ensure_event!(name)
|
|
28
30
|
return if events_class.events.one? { |event, options| name == event && options[:class] }
|
|
@@ -35,7 +37,7 @@ module Stance
|
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
def events_class_name
|
|
38
|
-
@events_class_name ||= "#{
|
|
40
|
+
@events_class_name ||= "#{name}Events"
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
def event_class(name)
|
|
@@ -51,22 +53,14 @@ module Stance
|
|
|
51
53
|
#
|
|
52
54
|
# Returns the results of `call`ing the event class.
|
|
53
55
|
def publish_event(name, metadata = {})
|
|
54
|
-
name
|
|
55
|
-
ensure_event! name
|
|
56
|
-
|
|
57
|
-
# Find the Event class - if any - and call it. Falls back to Stance::Event.
|
|
58
|
-
ev = event_class(name).new(name, self, metadata, events_class.events[name])
|
|
59
|
-
|
|
60
|
-
return ev if Stance.disabled_events.include?(ev.full_name)
|
|
61
|
-
|
|
62
|
-
events_class.new(ev).run_callbacks(:create) { ev.create }
|
|
56
|
+
self.class.publish_event name, metadata, self
|
|
63
57
|
end
|
|
64
58
|
|
|
65
59
|
# Raise EventNotFound if the event has not been defined.
|
|
66
60
|
def ensure_event!(name)
|
|
67
61
|
return if events_class.events.one? { |event, options| name == event && !options[:class] }
|
|
68
62
|
|
|
69
|
-
raise Stance::EventNotFound, "Event `#{name}` not found"
|
|
63
|
+
raise Stance::EventNotFound, "Event `#{name}` not found in #{events_class}"
|
|
70
64
|
end
|
|
71
65
|
|
|
72
66
|
def events_class
|
|
@@ -74,9 +68,10 @@ module Stance
|
|
|
74
68
|
end
|
|
75
69
|
|
|
76
70
|
def events_class_name
|
|
77
|
-
@events_class_name ||= "#{
|
|
71
|
+
@events_class_name ||= "#{self.class.name}Events"
|
|
78
72
|
end
|
|
79
73
|
|
|
74
|
+
# The class which defines the event. There will be only one.
|
|
80
75
|
def event_class(name)
|
|
81
76
|
"#{events_class_name}::#{name.tr('.', '/').classify}".constantize
|
|
82
77
|
rescue NameError
|
data/lib/stance/events.rb
CHANGED
|
@@ -9,11 +9,21 @@ module Stance
|
|
|
9
9
|
define_callbacks :create
|
|
10
10
|
|
|
11
11
|
class << self
|
|
12
|
-
|
|
12
|
+
attr_accessor :events
|
|
13
|
+
|
|
14
|
+
def inherited(child)
|
|
15
|
+
@events ||= {}
|
|
16
|
+
child.events ||= @events.dup
|
|
17
|
+
super
|
|
18
|
+
end
|
|
13
19
|
|
|
14
20
|
def event(name, options = {})
|
|
15
21
|
@events ||= {}
|
|
16
|
-
|
|
22
|
+
sname = name.to_s
|
|
23
|
+
|
|
24
|
+
raise DuplicateEvent, "Cannot redefine event :#{sname} on #{self}" if @events.key?(sname)
|
|
25
|
+
|
|
26
|
+
@events[sname] = options
|
|
17
27
|
end
|
|
18
28
|
|
|
19
29
|
def before_create(*methods, &block)
|
data/lib/stance/version.rb
CHANGED
data/lib/stance.rb
CHANGED
|
@@ -4,7 +4,9 @@ require 'stance/version'
|
|
|
4
4
|
require 'stance/engine'
|
|
5
5
|
|
|
6
6
|
module Stance
|
|
7
|
-
class
|
|
7
|
+
class Error < StandardError; end
|
|
8
|
+
class EventNotFound < Error; end
|
|
9
|
+
class DuplicateEvent < Error; end
|
|
8
10
|
|
|
9
11
|
mattr_accessor :disabled_events
|
|
10
12
|
@@disabled_events = []
|
data/stance.gemspec
CHANGED
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
|
|
|
16
16
|
spec.metadata['homepage_uri'] = spec.homepage
|
|
17
17
|
spec.metadata['source_code_uri'] = spec.homepage
|
|
18
18
|
spec.metadata['changelog_uri'] = "#{spec.homepage}/releases"
|
|
19
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
19
20
|
|
|
20
21
|
# Specify which files should be added to the gem when it is released.
|
|
21
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
@@ -24,8 +25,6 @@ Gem::Specification.new do |spec|
|
|
|
24
25
|
end
|
|
25
26
|
spec.require_paths = ['lib']
|
|
26
27
|
|
|
27
|
-
spec.add_dependency '
|
|
28
|
-
spec.add_dependency '
|
|
29
|
-
spec.add_dependency 'railties', '>= 6'
|
|
30
|
-
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
28
|
+
spec.add_dependency 'multi_json', '~> 1.15'
|
|
29
|
+
spec.add_dependency 'rails', ['>= 7.0', '< 8.0']
|
|
31
30
|
end
|
metadata
CHANGED
|
@@ -1,57 +1,49 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stance
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joel Moss
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-01-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: activerecord
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - ">="
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '6'
|
|
20
|
-
type: :runtime
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - ">="
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '6'
|
|
27
13
|
- !ruby/object:Gem::Dependency
|
|
28
14
|
name: multi_json
|
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
|
30
16
|
requirements:
|
|
31
|
-
- - "
|
|
17
|
+
- - "~>"
|
|
32
18
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
19
|
+
version: '1.15'
|
|
34
20
|
type: :runtime
|
|
35
21
|
prerelease: false
|
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
23
|
requirements:
|
|
38
|
-
- - "
|
|
24
|
+
- - "~>"
|
|
39
25
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
26
|
+
version: '1.15'
|
|
41
27
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
28
|
+
name: rails
|
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
|
44
30
|
requirements:
|
|
45
31
|
- - ">="
|
|
46
32
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
33
|
+
version: '7.0'
|
|
34
|
+
- - "<"
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '8.0'
|
|
48
37
|
type: :runtime
|
|
49
38
|
prerelease: false
|
|
50
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
40
|
requirements:
|
|
52
41
|
- - ">="
|
|
53
42
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
43
|
+
version: '7.0'
|
|
44
|
+
- - "<"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '8.0'
|
|
55
47
|
description:
|
|
56
48
|
email:
|
|
57
49
|
- joel@developwithstyle.com
|
|
@@ -105,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
105
97
|
- !ruby/object:Gem::Version
|
|
106
98
|
version: '0'
|
|
107
99
|
requirements: []
|
|
108
|
-
rubygems_version: 3.3
|
|
100
|
+
rubygems_version: 3.5.3
|
|
109
101
|
signing_key:
|
|
110
102
|
specification_version: 4
|
|
111
103
|
summary: Event System for Rails
|