miau 1.0.2 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,255 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ miau (1.0.3)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (7.1.2)
11
+ actionpack (= 7.1.2)
12
+ activesupport (= 7.1.2)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ zeitwerk (~> 2.6)
16
+ actionmailbox (7.1.2)
17
+ actionpack (= 7.1.2)
18
+ activejob (= 7.1.2)
19
+ activerecord (= 7.1.2)
20
+ activestorage (= 7.1.2)
21
+ activesupport (= 7.1.2)
22
+ mail (>= 2.7.1)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.1.2)
27
+ actionpack (= 7.1.2)
28
+ actionview (= 7.1.2)
29
+ activejob (= 7.1.2)
30
+ activesupport (= 7.1.2)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
35
+ rails-dom-testing (~> 2.2)
36
+ actionpack (7.1.2)
37
+ actionview (= 7.1.2)
38
+ activesupport (= 7.1.2)
39
+ nokogiri (>= 1.8.5)
40
+ racc
41
+ rack (>= 2.2.4)
42
+ rack-session (>= 1.0.1)
43
+ rack-test (>= 0.6.3)
44
+ rails-dom-testing (~> 2.2)
45
+ rails-html-sanitizer (~> 1.6)
46
+ actiontext (7.1.2)
47
+ actionpack (= 7.1.2)
48
+ activerecord (= 7.1.2)
49
+ activestorage (= 7.1.2)
50
+ activesupport (= 7.1.2)
51
+ globalid (>= 0.6.0)
52
+ nokogiri (>= 1.8.5)
53
+ actionview (7.1.2)
54
+ activesupport (= 7.1.2)
55
+ builder (~> 3.1)
56
+ erubi (~> 1.11)
57
+ rails-dom-testing (~> 2.2)
58
+ rails-html-sanitizer (~> 1.6)
59
+ activejob (7.1.2)
60
+ activesupport (= 7.1.2)
61
+ globalid (>= 0.3.6)
62
+ activemodel (7.1.2)
63
+ activesupport (= 7.1.2)
64
+ activerecord (7.1.2)
65
+ activemodel (= 7.1.2)
66
+ activesupport (= 7.1.2)
67
+ timeout (>= 0.4.0)
68
+ activestorage (7.1.2)
69
+ actionpack (= 7.1.2)
70
+ activejob (= 7.1.2)
71
+ activerecord (= 7.1.2)
72
+ activesupport (= 7.1.2)
73
+ marcel (~> 1.0)
74
+ activesupport (7.1.2)
75
+ base64
76
+ bigdecimal
77
+ concurrent-ruby (~> 1.0, >= 1.0.2)
78
+ connection_pool (>= 2.2.5)
79
+ drb
80
+ i18n (>= 1.6, < 2)
81
+ minitest (>= 5.1)
82
+ mutex_m
83
+ tzinfo (~> 2.0)
84
+ appraisal (2.5.0)
85
+ bundler
86
+ rake
87
+ thor (>= 0.14.0)
88
+ ast (2.4.2)
89
+ base64 (0.2.0)
90
+ benchmark-ips (2.13.0)
91
+ bigdecimal (3.1.5)
92
+ builder (3.2.4)
93
+ concurrent-ruby (1.2.2)
94
+ connection_pool (2.4.1)
95
+ crass (1.0.6)
96
+ date (3.3.4)
97
+ docile (1.4.0)
98
+ drb (2.2.0)
99
+ ruby2_keywords
100
+ dryer-config (7.1.0)
101
+ erubi (1.12.0)
102
+ globalid (1.2.1)
103
+ activesupport (>= 6.1)
104
+ i18n (1.14.1)
105
+ concurrent-ruby (~> 1.0)
106
+ io-console (0.7.1)
107
+ irb (1.11.0)
108
+ rdoc
109
+ reline (>= 0.3.8)
110
+ json (2.7.1)
111
+ language_server-protocol (3.17.0.3)
112
+ lint_roller (1.1.0)
113
+ loofah (2.22.0)
114
+ crass (~> 1.0.2)
115
+ nokogiri (>= 1.12.0)
116
+ mail (2.8.1)
117
+ mini_mime (>= 0.1.1)
118
+ net-imap
119
+ net-pop
120
+ net-smtp
121
+ marcel (1.0.2)
122
+ mini_mime (1.1.5)
123
+ minitest (5.20.0)
124
+ mutex_m (0.2.0)
125
+ net-imap (0.4.9.1)
126
+ date
127
+ net-protocol
128
+ net-pop (0.1.2)
129
+ net-protocol
130
+ net-protocol (0.2.2)
131
+ timeout
132
+ net-smtp (0.4.0.1)
133
+ net-protocol
134
+ nio4r (2.7.0)
135
+ nokogiri (1.16.0-x86_64-linux)
136
+ racc (~> 1.4)
137
+ observr (1.0.5)
138
+ parallel (1.24.0)
139
+ parser (3.3.0.0)
140
+ ast (~> 2.4.1)
141
+ racc
142
+ psych (5.1.2)
143
+ stringio
144
+ racc (1.7.3)
145
+ rack (3.0.8)
146
+ rack-session (2.0.0)
147
+ rack (>= 3.0.0)
148
+ rack-test (2.1.0)
149
+ rack (>= 1.3)
150
+ rackup (2.1.0)
151
+ rack (>= 3)
152
+ webrick (~> 1.8)
153
+ rails (7.1.2)
154
+ actioncable (= 7.1.2)
155
+ actionmailbox (= 7.1.2)
156
+ actionmailer (= 7.1.2)
157
+ actionpack (= 7.1.2)
158
+ actiontext (= 7.1.2)
159
+ actionview (= 7.1.2)
160
+ activejob (= 7.1.2)
161
+ activemodel (= 7.1.2)
162
+ activerecord (= 7.1.2)
163
+ activestorage (= 7.1.2)
164
+ activesupport (= 7.1.2)
165
+ bundler (>= 1.15.0)
166
+ railties (= 7.1.2)
167
+ rails-dom-testing (2.2.0)
168
+ activesupport (>= 5.0.0)
169
+ minitest
170
+ nokogiri (>= 1.6)
171
+ rails-html-sanitizer (1.6.0)
172
+ loofah (~> 2.21)
173
+ nokogiri (~> 1.14)
174
+ railties (7.1.2)
175
+ actionpack (= 7.1.2)
176
+ activesupport (= 7.1.2)
177
+ irb
178
+ rackup (>= 1.0.0)
179
+ rake (>= 12.2)
180
+ thor (~> 1.0, >= 1.2.2)
181
+ zeitwerk (~> 2.6)
182
+ rainbow (3.1.1)
183
+ rake (13.1.0)
184
+ rdoc (6.6.2)
185
+ psych (>= 4.0.0)
186
+ regexp_parser (2.8.3)
187
+ reline (0.4.2)
188
+ io-console (~> 0.5)
189
+ rexml (3.2.6)
190
+ ricecream (0.2.1)
191
+ rubocop (1.59.0)
192
+ json (~> 2.3)
193
+ language_server-protocol (>= 3.17.0)
194
+ parallel (~> 1.10)
195
+ parser (>= 3.2.2.4)
196
+ rainbow (>= 2.2.2, < 4.0)
197
+ regexp_parser (>= 1.8, < 3.0)
198
+ rexml (>= 3.2.5, < 4.0)
199
+ rubocop-ast (>= 1.30.0, < 2.0)
200
+ ruby-progressbar (~> 1.7)
201
+ unicode-display_width (>= 2.4.0, < 3.0)
202
+ rubocop-ast (1.30.0)
203
+ parser (>= 3.2.1.0)
204
+ rubocop-performance (1.20.1)
205
+ rubocop (>= 1.48.1, < 2.0)
206
+ rubocop-ast (>= 1.30.0, < 2.0)
207
+ ruby-progressbar (1.13.0)
208
+ ruby2_keywords (0.0.5)
209
+ simplecov (0.22.0)
210
+ docile (~> 1.1)
211
+ simplecov-html (~> 0.11)
212
+ simplecov_json_formatter (~> 0.1)
213
+ simplecov-html (0.12.3)
214
+ simplecov_json_formatter (0.1.4)
215
+ standard (1.33.0)
216
+ language_server-protocol (~> 3.17.0.2)
217
+ lint_roller (~> 1.0)
218
+ rubocop (~> 1.59.0)
219
+ standard-custom (~> 1.0.0)
220
+ standard-performance (~> 1.3)
221
+ standard-custom (1.0.2)
222
+ lint_roller (~> 1.0)
223
+ rubocop (~> 1.50)
224
+ standard-performance (1.3.0)
225
+ lint_roller (~> 1.1)
226
+ rubocop-performance (~> 1.20.1)
227
+ stringio (3.1.0)
228
+ thor (1.3.0)
229
+ timeout (0.4.1)
230
+ tzinfo (2.0.6)
231
+ concurrent-ruby (~> 1.0)
232
+ unicode-display_width (2.5.0)
233
+ webrick (1.8.1)
234
+ websocket-driver (0.7.6)
235
+ websocket-extensions (>= 0.1.0)
236
+ websocket-extensions (0.1.5)
237
+ zeitwerk (2.6.12)
238
+
239
+ PLATFORMS
240
+ x86_64-linux
241
+
242
+ DEPENDENCIES
243
+ appraisal
244
+ benchmark-ips
245
+ dryer-config (~> 7.0)
246
+ miau!
247
+ minitest
248
+ observr
249
+ rails (~> 7.0)
250
+ ricecream
251
+ simplecov
252
+ standard
253
+
254
+ BUNDLED WITH
255
+ 2.5.3
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 7.1"
6
+
7
+ group :test do
8
+ gem "observr"
9
+ gem "standard", require: false
10
+ gem "simplecov", require: false
11
+ gem "benchmark-ips"
12
+ end
13
+
14
+ gemspec path: "../"
@@ -0,0 +1,253 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ miau (1.0.3)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (7.1.2)
11
+ actionpack (= 7.1.2)
12
+ activesupport (= 7.1.2)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ zeitwerk (~> 2.6)
16
+ actionmailbox (7.1.2)
17
+ actionpack (= 7.1.2)
18
+ activejob (= 7.1.2)
19
+ activerecord (= 7.1.2)
20
+ activestorage (= 7.1.2)
21
+ activesupport (= 7.1.2)
22
+ mail (>= 2.7.1)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.1.2)
27
+ actionpack (= 7.1.2)
28
+ actionview (= 7.1.2)
29
+ activejob (= 7.1.2)
30
+ activesupport (= 7.1.2)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
35
+ rails-dom-testing (~> 2.2)
36
+ actionpack (7.1.2)
37
+ actionview (= 7.1.2)
38
+ activesupport (= 7.1.2)
39
+ nokogiri (>= 1.8.5)
40
+ racc
41
+ rack (>= 2.2.4)
42
+ rack-session (>= 1.0.1)
43
+ rack-test (>= 0.6.3)
44
+ rails-dom-testing (~> 2.2)
45
+ rails-html-sanitizer (~> 1.6)
46
+ actiontext (7.1.2)
47
+ actionpack (= 7.1.2)
48
+ activerecord (= 7.1.2)
49
+ activestorage (= 7.1.2)
50
+ activesupport (= 7.1.2)
51
+ globalid (>= 0.6.0)
52
+ nokogiri (>= 1.8.5)
53
+ actionview (7.1.2)
54
+ activesupport (= 7.1.2)
55
+ builder (~> 3.1)
56
+ erubi (~> 1.11)
57
+ rails-dom-testing (~> 2.2)
58
+ rails-html-sanitizer (~> 1.6)
59
+ activejob (7.1.2)
60
+ activesupport (= 7.1.2)
61
+ globalid (>= 0.3.6)
62
+ activemodel (7.1.2)
63
+ activesupport (= 7.1.2)
64
+ activerecord (7.1.2)
65
+ activemodel (= 7.1.2)
66
+ activesupport (= 7.1.2)
67
+ timeout (>= 0.4.0)
68
+ activestorage (7.1.2)
69
+ actionpack (= 7.1.2)
70
+ activejob (= 7.1.2)
71
+ activerecord (= 7.1.2)
72
+ activesupport (= 7.1.2)
73
+ marcel (~> 1.0)
74
+ activesupport (7.1.2)
75
+ base64
76
+ bigdecimal
77
+ concurrent-ruby (~> 1.0, >= 1.0.2)
78
+ connection_pool (>= 2.2.5)
79
+ drb
80
+ i18n (>= 1.6, < 2)
81
+ minitest (>= 5.1)
82
+ mutex_m
83
+ tzinfo (~> 2.0)
84
+ appraisal (2.5.0)
85
+ bundler
86
+ rake
87
+ thor (>= 0.14.0)
88
+ ast (2.4.2)
89
+ base64 (0.2.0)
90
+ benchmark-ips (2.13.0)
91
+ bigdecimal (3.1.5)
92
+ builder (3.2.4)
93
+ concurrent-ruby (1.2.2)
94
+ connection_pool (2.4.1)
95
+ crass (1.0.6)
96
+ date (3.3.4)
97
+ docile (1.4.0)
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)
104
+ concurrent-ruby (~> 1.0)
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
+ lint_roller (1.1.0)
112
+ loofah (2.22.0)
113
+ crass (~> 1.0.2)
114
+ nokogiri (>= 1.12.0)
115
+ mail (2.8.1)
116
+ mini_mime (>= 0.1.1)
117
+ net-imap
118
+ net-pop
119
+ net-smtp
120
+ marcel (1.0.2)
121
+ mini_mime (1.1.5)
122
+ minitest (5.20.0)
123
+ mutex_m (0.2.0)
124
+ net-imap (0.4.9.1)
125
+ date
126
+ net-protocol
127
+ net-pop (0.1.2)
128
+ net-protocol
129
+ net-protocol (0.2.2)
130
+ timeout
131
+ net-smtp (0.4.0.1)
132
+ net-protocol
133
+ nio4r (2.7.0)
134
+ nokogiri (1.16.0-x86_64-linux)
135
+ racc (~> 1.4)
136
+ observr (1.0.5)
137
+ parallel (1.24.0)
138
+ parser (3.3.0.0)
139
+ ast (~> 2.4.1)
140
+ racc
141
+ psych (5.1.2)
142
+ stringio
143
+ racc (1.7.3)
144
+ rack (3.0.8)
145
+ rack-session (2.0.0)
146
+ rack (>= 3.0.0)
147
+ rack-test (2.1.0)
148
+ rack (>= 1.3)
149
+ rackup (2.1.0)
150
+ rack (>= 3)
151
+ webrick (~> 1.8)
152
+ rails (7.1.2)
153
+ actioncable (= 7.1.2)
154
+ actionmailbox (= 7.1.2)
155
+ actionmailer (= 7.1.2)
156
+ actionpack (= 7.1.2)
157
+ actiontext (= 7.1.2)
158
+ actionview (= 7.1.2)
159
+ activejob (= 7.1.2)
160
+ activemodel (= 7.1.2)
161
+ activerecord (= 7.1.2)
162
+ activestorage (= 7.1.2)
163
+ activesupport (= 7.1.2)
164
+ bundler (>= 1.15.0)
165
+ railties (= 7.1.2)
166
+ rails-dom-testing (2.2.0)
167
+ activesupport (>= 5.0.0)
168
+ minitest
169
+ nokogiri (>= 1.6)
170
+ rails-html-sanitizer (1.6.0)
171
+ loofah (~> 2.21)
172
+ nokogiri (~> 1.14)
173
+ railties (7.1.2)
174
+ actionpack (= 7.1.2)
175
+ activesupport (= 7.1.2)
176
+ irb
177
+ rackup (>= 1.0.0)
178
+ rake (>= 12.2)
179
+ thor (~> 1.0, >= 1.2.2)
180
+ zeitwerk (~> 2.6)
181
+ rainbow (3.1.1)
182
+ rake (13.1.0)
183
+ rdoc (6.6.2)
184
+ psych (>= 4.0.0)
185
+ regexp_parser (2.8.3)
186
+ reline (0.4.2)
187
+ io-console (~> 0.5)
188
+ rexml (3.2.6)
189
+ ricecream (0.2.1)
190
+ rubocop (1.59.0)
191
+ json (~> 2.3)
192
+ language_server-protocol (>= 3.17.0)
193
+ parallel (~> 1.10)
194
+ parser (>= 3.2.2.4)
195
+ rainbow (>= 2.2.2, < 4.0)
196
+ regexp_parser (>= 1.8, < 3.0)
197
+ rexml (>= 3.2.5, < 4.0)
198
+ rubocop-ast (>= 1.30.0, < 2.0)
199
+ ruby-progressbar (~> 1.7)
200
+ unicode-display_width (>= 2.4.0, < 3.0)
201
+ rubocop-ast (1.30.0)
202
+ parser (>= 3.2.1.0)
203
+ rubocop-performance (1.20.1)
204
+ rubocop (>= 1.48.1, < 2.0)
205
+ rubocop-ast (>= 1.30.0, < 2.0)
206
+ ruby-progressbar (1.13.0)
207
+ ruby2_keywords (0.0.5)
208
+ simplecov (0.22.0)
209
+ docile (~> 1.1)
210
+ simplecov-html (~> 0.11)
211
+ simplecov_json_formatter (~> 0.1)
212
+ simplecov-html (0.12.3)
213
+ simplecov_json_formatter (0.1.4)
214
+ standard (1.33.0)
215
+ language_server-protocol (~> 3.17.0.2)
216
+ lint_roller (~> 1.0)
217
+ rubocop (~> 1.59.0)
218
+ standard-custom (~> 1.0.0)
219
+ standard-performance (~> 1.3)
220
+ standard-custom (1.0.2)
221
+ lint_roller (~> 1.0)
222
+ rubocop (~> 1.50)
223
+ standard-performance (1.3.0)
224
+ lint_roller (~> 1.1)
225
+ rubocop-performance (~> 1.20.1)
226
+ stringio (3.1.0)
227
+ thor (1.3.0)
228
+ timeout (0.4.1)
229
+ tzinfo (2.0.6)
230
+ concurrent-ruby (~> 1.0)
231
+ unicode-display_width (2.5.0)
232
+ webrick (1.8.1)
233
+ websocket-driver (0.7.6)
234
+ websocket-extensions (>= 0.1.0)
235
+ websocket-extensions (0.1.5)
236
+ zeitwerk (2.6.12)
237
+
238
+ PLATFORMS
239
+ x86_64-linux
240
+
241
+ DEPENDENCIES
242
+ appraisal
243
+ benchmark-ips
244
+ miau!
245
+ minitest
246
+ observr
247
+ rails (~> 7.1)
248
+ ricecream
249
+ simplecov
250
+ standard
251
+
252
+ BUNDLED WITH
253
+ 2.5.3
@@ -4,8 +4,9 @@ class ApplicationPolicy
4
4
  attr_accessor :user, :resource
5
5
 
6
6
  def self.miau(actions, meth = nil, &block)
7
+ kls = name.underscore[0..-8] # remove "_policy"
7
8
  [actions].flatten.each { |action|
8
- Miau::PolicyStorage.instance.add(self, action, meth)
9
+ Miau::PolicyStorage.instance.add_policy(kls, action, meth)
9
10
  }
10
11
  end
11
12
  end
data/lib/miau/error.rb CHANGED
@@ -11,4 +11,7 @@ module Miau
11
11
 
12
12
  class AuthorizationNotPerformedError < Error
13
13
  end
14
+
15
+ class OverwriteError < Error
16
+ end
14
17
  end
data/lib/miau/run.rb ADDED
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "singleton"
4
+ require "yaml"
5
+
6
+ module Miau
7
+ class PolicyRun
8
+ include Singleton
9
+
10
+ # return instance of policy (may be nil) and the method
11
+ # klass and action are symbols
12
+ # Priority:
13
+ # - method of <klass>Policy
14
+ # - method of <klass>Policy specified by "miau action, method"
15
+ # - method of ApplicationPolicy (independent of klass)
16
+ # - method of ApplicationPolicy specified by "miau action, method"
17
+ # - nil
18
+ # returns method_name[s]
19
+
20
+ def find_policy(policy, klass, action)
21
+ return action if policy.respond_to?(action)
22
+
23
+ hsh = PolicyStorage.instance.policies[klass]
24
+ return nil unless hsh
25
+
26
+ hsh[action]
27
+ end
28
+
29
+ def run(klass, action, user, resource)
30
+ policy = PolicyStorage.instance.find_or_create_policy(klass)
31
+ meth = find_policy policy, klass, action if policy
32
+ meth ||= find_policy ApplicationPolicy, :application, action
33
+
34
+ unless meth
35
+ msg = "class <#{klass}> action <#{action}>"
36
+ raise NotDefinedError, msg
37
+ end
38
+
39
+ policy.user = user
40
+ policy.resource = resource
41
+ [meth].flatten.each { |m|
42
+ return false unless policy.send(m)
43
+ }
44
+ true
45
+ end
46
+ end
47
+ end
data/lib/miau/storage.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "singleton"
4
+ require "yaml"
4
5
 
5
6
  module Miau
6
7
  class PolicyStorage
@@ -28,72 +29,35 @@ module Miau
28
29
  @instances = {}
29
30
  end
30
31
 
31
- def add(klass, action, meth)
32
- kls = klass.name.underscore[0..-8] # remove "_policy"
32
+ def add_policy(kls, action, meth)
33
33
  kls = kls.to_sym
34
+ action = action.to_sym
34
35
  @policies[kls] ||= {}
35
- @instances[kls] ||= klass.new
36
- @policies[kls][action.to_sym] = meth.to_sym
37
- end
38
-
39
- # return instance of policy (may be nil) and the method
40
- # klass and action are symbols
41
- # Priority:
42
- # - method of <klass>Policy
43
- # - method of <klass>Policy specified by "miau action, method"
44
- # - method of ApplicationPolicy (independent of klass)
45
- # - method of ApplicationPolicy specified by "miau action, method"
46
- # - nil
47
-
48
- # returns policy: [instance, method]
49
- def find_policy(klass, action)
50
- kls = instance_of(klass)
51
- act = policy_method(klass, action)
52
- return [kls, act] if kls.respond_to?(act)
53
-
54
- klass = :application
55
- kls = instance_of(klass)
56
- act = policy_method(klass, action)
57
- return [kls, act] if kls.respond_to?(act)
58
-
59
- # return nil
60
- end
61
-
62
- def run(klass, action, user, resource)
63
- arr = find_policy(klass, action)
64
- unless arr
65
- msg = "class <#{klass}> action <#{action}>"
66
- raise Miau::NotDefinedError, msg
36
+ if @policies[kls][action]
37
+ raise OverwriteError, "Can't overwrite policy(#{kls}, #{action})"
67
38
  end
68
39
 
69
- policy, meth = arr
70
- policy.user = user
71
- policy.resource = resource
72
- policy.send(meth)
73
- end
74
-
75
- def to_yaml
76
- "# === @policies ===\n" + YAML.dump(@policies) +
77
- "# === @instances ===\n" + YAML.dump(@instances)
40
+ if meth.is_a?(Array)
41
+ meths = [meth].flatten.collect { |m| m.to_sym }
42
+ @policies[kls][action] = meths
43
+ else
44
+ @policies[kls][action] = meth.to_sym
45
+ end
78
46
  end
79
47
 
80
- private
81
-
82
- def instance_of(klass)
48
+ def find_or_create_policy(klass)
83
49
  res = @instances[klass]
84
- return res if res
50
+ return res unless res.nil?
85
51
 
86
52
  name = "#{klass.to_s.camelcase}Policy"
87
53
  return nil unless Object.const_defined?(name)
88
54
 
89
- @instances[klass] = name.constantize.new
55
+ instances[klass] = name.constantize.new
90
56
  end
91
57
 
92
- def policy_method(klass, action)
93
- act = @policies[klass]
94
- return action unless act
95
-
96
- act[action] || action
58
+ def to_yaml
59
+ "# === @policies ===\n" + YAML.dump(@policies) +
60
+ "# === @instances ===\n" + YAML.dump(@instances)
97
61
  end
98
62
  end
99
63
  end
data/lib/miau/version.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Miau
4
- VERSION = "1.0.2" # 2023-11-05
4
+ VERSION = "1.1.1" # 2024-01-06
5
+ # VERSION = "1.1.0" # 2024-01-06
6
+ # VERSION = "1.0.3" # 2023-12-13
7
+ # VERSION = "1.0.2" # 2023-11-05
5
8
  # VERSION = "1.0.1" # 2023-04-24
6
9
  # VERSION = "1.0.0" # 2022-01-23
7
10
  # VERSION = "0.1.2" # 2021-12-10