anchormodel 0.1.3 → 0.1.4
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/CHANGELOG.md +5 -0
- data/Gemfile.lock +26 -24
- data/VERSION +1 -0
- data/anchormodel.gemspec +15 -15
- data/doc/Anchormodel/Attribute.html +3 -3
- data/doc/Anchormodel/ModelMixin.html +19 -284
- data/doc/Anchormodel/Version.html +4 -60
- data/doc/Anchormodel.html +5 -5
- data/doc/_index.html +25 -5
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +14 -6
- data/doc/frames.html +10 -5
- data/doc/index.html +14 -6
- data/doc/method_list.html +43 -19
- data/doc/top-level-namespace.html +4 -4
- data/lib/anchormodel/{active_model_type_value.rb → active_model_type_value_single.rb} +22 -9
- data/lib/anchormodel/model_mixin.rb +4 -82
- data/lib/anchormodel/util.rb +93 -0
- data/lib/anchormodel/version.rb +1 -7
- data/lib/anchormodel.rb +2 -1
- data/pkg/anchormodel-0.1.3.gem +0 -0
- data/test/active_record_model/user_test.rb +19 -0
- metadata +12 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 393936de0294a0c3ee8d3096a38c365bce1843b4812e670034ac9037cdd61453
|
4
|
+
data.tar.gz: 130e1ae1bdf5fd50dcc1c27d9c0fd7e1b81e2923088f2bf0c81ef4d7e57ccfc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a9b9e0a451d772fb0c54ae36c9f437b8aab77a74eae058f381b65ba01cc62719ec0adbd5e56b674585bc5071aa239e74e1e540591a3b70bd308c66ec8bd54da
|
7
|
+
data.tar.gz: f5f5326a0a77605c3a3b5b1e7139e24f5de82b4acb91d59a0624ae3965db0c2dc5dd0b0a0458b96b727bb7560a1495928ea7664b16b432427665449998eaf910
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
anchormodel (0.1.
|
4
|
+
anchormodel (0.1.4.edge)
|
5
5
|
rails (~> 7.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -78,41 +78,41 @@ GEM
|
|
78
78
|
coderay (1.1.3)
|
79
79
|
concurrent-ruby (1.1.10)
|
80
80
|
crass (1.0.6)
|
81
|
-
date (3.3.
|
81
|
+
date (3.3.4)
|
82
82
|
erubi (1.12.0)
|
83
|
-
globalid (1.
|
84
|
-
activesupport (>=
|
83
|
+
globalid (1.2.1)
|
84
|
+
activesupport (>= 6.1)
|
85
85
|
i18n (1.12.0)
|
86
86
|
concurrent-ruby (~> 1.0)
|
87
87
|
json (2.6.3)
|
88
|
-
loofah (2.
|
88
|
+
loofah (2.22.0)
|
89
89
|
crass (~> 1.0.2)
|
90
|
-
nokogiri (>= 1.
|
91
|
-
mail (2.8.
|
90
|
+
nokogiri (>= 1.12.0)
|
91
|
+
mail (2.8.1)
|
92
92
|
mini_mime (>= 0.1.1)
|
93
93
|
net-imap
|
94
94
|
net-pop
|
95
95
|
net-smtp
|
96
|
-
marcel (1.0.
|
96
|
+
marcel (1.0.4)
|
97
97
|
method_source (1.0.0)
|
98
|
-
mini_mime (1.1.
|
98
|
+
mini_mime (1.1.5)
|
99
99
|
minitest (5.17.0)
|
100
100
|
minitest-reporters (1.5.0)
|
101
101
|
ansi
|
102
102
|
builder
|
103
103
|
minitest (>= 5.0)
|
104
104
|
ruby-progressbar
|
105
|
-
net-imap (0.
|
105
|
+
net-imap (0.4.10)
|
106
106
|
date
|
107
107
|
net-protocol
|
108
108
|
net-pop (0.1.2)
|
109
109
|
net-protocol
|
110
|
-
net-protocol (0.2.
|
110
|
+
net-protocol (0.2.2)
|
111
111
|
timeout
|
112
|
-
net-smtp (0.
|
112
|
+
net-smtp (0.5.0)
|
113
113
|
net-protocol
|
114
|
-
nio4r (2.
|
115
|
-
nokogiri (1.
|
114
|
+
nio4r (2.7.1)
|
115
|
+
nokogiri (1.16.4-x86_64-linux)
|
116
116
|
racc (~> 1.4)
|
117
117
|
parallel (1.22.1)
|
118
118
|
parser (3.2.0.0)
|
@@ -120,9 +120,9 @@ GEM
|
|
120
120
|
pry (0.14.1)
|
121
121
|
coderay (~> 1.1)
|
122
122
|
method_source (~> 1.0)
|
123
|
-
racc (1.
|
123
|
+
racc (1.7.3)
|
124
124
|
rack (2.2.5)
|
125
|
-
rack-test (2.0
|
125
|
+
rack-test (2.1.0)
|
126
126
|
rack (>= 1.3)
|
127
127
|
rails (7.0.4)
|
128
128
|
actioncable (= 7.0.4)
|
@@ -138,11 +138,13 @@ GEM
|
|
138
138
|
activesupport (= 7.0.4)
|
139
139
|
bundler (>= 1.15.0)
|
140
140
|
railties (= 7.0.4)
|
141
|
-
rails-dom-testing (2.0
|
142
|
-
activesupport (>=
|
141
|
+
rails-dom-testing (2.2.0)
|
142
|
+
activesupport (>= 5.0.0)
|
143
|
+
minitest
|
143
144
|
nokogiri (>= 1.6)
|
144
|
-
rails-html-sanitizer (1.
|
145
|
-
loofah (~> 2.
|
145
|
+
rails-html-sanitizer (1.6.0)
|
146
|
+
loofah (~> 2.21)
|
147
|
+
nokogiri (~> 1.14)
|
146
148
|
railties (7.0.4)
|
147
149
|
actionpack (= 7.0.4)
|
148
150
|
activesupport (= 7.0.4)
|
@@ -172,20 +174,20 @@ GEM
|
|
172
174
|
rubocop (>= 1.33.0, < 2.0)
|
173
175
|
ruby-progressbar (1.11.0)
|
174
176
|
sqlite3 (1.6.0-x86_64-linux)
|
175
|
-
thor (1.
|
176
|
-
timeout (0.
|
177
|
+
thor (1.3.1)
|
178
|
+
timeout (0.4.1)
|
177
179
|
tzinfo (2.0.5)
|
178
180
|
concurrent-ruby (~> 1.0)
|
179
181
|
unicode-display_width (2.4.2)
|
180
182
|
webrick (1.7.0)
|
181
|
-
websocket-driver (0.7.
|
183
|
+
websocket-driver (0.7.6)
|
182
184
|
websocket-extensions (>= 0.1.0)
|
183
185
|
websocket-extensions (0.1.5)
|
184
186
|
yard (0.9.28)
|
185
187
|
webrick (~> 1.7.0)
|
186
188
|
yard-activesupport-concern (0.0.1)
|
187
189
|
yard (>= 0.8)
|
188
|
-
zeitwerk (2.6.
|
190
|
+
zeitwerk (2.6.13)
|
189
191
|
|
190
192
|
PLATFORMS
|
191
193
|
x86_64-linux
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.4
|
data/anchormodel.gemspec
CHANGED
@@ -2,33 +2,33 @@
|
|
2
2
|
# This file is auto-generated via: 'rake gemspec'.
|
3
3
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: anchormodel 0.1.
|
5
|
+
# stub: anchormodel 0.1.4 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "anchormodel".freeze
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.4".freeze
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Sandro Kalbermatter".freeze]
|
14
|
-
s.date = "
|
15
|
-
s.files = [".gitignore".freeze, ".ruby-version".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "Gemfile.lock".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "anchormodel.gemspec".freeze, "bin/rails".freeze, "doc/Anchormodel.html".freeze, "doc/Anchormodel/ActiveModelTypeValue.html".freeze, "doc/Anchormodel/Attribute.html".freeze, "doc/Anchormodel/ModelMixin.html".freeze, "doc/Anchormodel/Version.html".freeze, "doc/_index.html".freeze, "doc/class_list.html".freeze, "doc/css/common.css".freeze, "doc/css/full_list.css".freeze, "doc/css/style.css".freeze, "doc/file.README.html".freeze, "doc/file_list.html".freeze, "doc/frames.html".freeze, "doc/index.html".freeze, "doc/js/app.js".freeze, "doc/js/full_list.js".freeze, "doc/js/jquery.js".freeze, "doc/method_list.html".freeze, "doc/top-level-namespace.html".freeze, "lib/anchormodel.rb".freeze, "lib/anchormodel/
|
14
|
+
s.date = "2024-04-23"
|
15
|
+
s.files = [".gitignore".freeze, ".ruby-version".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "Gemfile.lock".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "anchormodel.gemspec".freeze, "bin/rails".freeze, "doc/Anchormodel.html".freeze, "doc/Anchormodel/ActiveModelTypeValue.html".freeze, "doc/Anchormodel/Attribute.html".freeze, "doc/Anchormodel/ModelMixin.html".freeze, "doc/Anchormodel/Version.html".freeze, "doc/_index.html".freeze, "doc/class_list.html".freeze, "doc/css/common.css".freeze, "doc/css/full_list.css".freeze, "doc/css/style.css".freeze, "doc/file.README.html".freeze, "doc/file_list.html".freeze, "doc/frames.html".freeze, "doc/index.html".freeze, "doc/js/app.js".freeze, "doc/js/full_list.js".freeze, "doc/js/jquery.js".freeze, "doc/method_list.html".freeze, "doc/top-level-namespace.html".freeze, "lib/anchormodel.rb".freeze, "lib/anchormodel/active_model_type_value_single.rb".freeze, "lib/anchormodel/attribute.rb".freeze, "lib/anchormodel/model_mixin.rb".freeze, "lib/anchormodel/util.rb".freeze, "lib/anchormodel/version.rb".freeze, "lib/generators/anchormodel/USAGE".freeze, "lib/generators/anchormodel/anchormodel_generator.rb".freeze, "lib/generators/anchormodel/templates/anchormodel.rb.erb".freeze, "logo.svg".freeze, "pkg/anchormodel-0.1.3.gem".freeze, "test/active_record_model/user_test.rb".freeze, "test/dummy/.gitignore".freeze, "test/dummy/Rakefile".freeze, "test/dummy/app/anchormodels/locale.rb".freeze, "test/dummy/app/anchormodels/role.rb".freeze, "test/dummy/app/helpers/application_helper.rb".freeze, "test/dummy/app/models/application_record.rb".freeze, "test/dummy/app/models/concerns/.keep".freeze, "test/dummy/app/models/user.rb".freeze, "test/dummy/bin/rails".freeze, "test/dummy/bin/rake".freeze, "test/dummy/bin/setup".freeze, "test/dummy/config.ru".freeze, "test/dummy/config/application.rb".freeze, "test/dummy/config/boot.rb".freeze, "test/dummy/config/credentials.yml.enc".freeze, "test/dummy/config/database.yml".freeze, "test/dummy/config/environment.rb".freeze, "test/dummy/config/environments/test.rb".freeze, "test/dummy/config/initializers/content_security_policy.rb".freeze, "test/dummy/config/initializers/filter_parameter_logging.rb".freeze, "test/dummy/config/initializers/inflections.rb".freeze, "test/dummy/config/initializers/permissions_policy.rb".freeze, "test/dummy/config/locales/en.yml".freeze, "test/dummy/config/puma.rb".freeze, "test/dummy/config/routes.rb".freeze, "test/dummy/db/migrate/20230107173151_create_users.rb".freeze, "test/dummy/db/schema.rb".freeze, "test/dummy/db/seeds.rb".freeze, "test/dummy/lib/tasks/.keep".freeze, "test/dummy/log/.keep".freeze, "test/dummy/tmp/.keep".freeze, "test/dummy/tmp/pids/.keep".freeze, "test/test_helper.rb".freeze]
|
16
16
|
s.homepage = "https://github.com/kalsan/anchormodel".freeze
|
17
17
|
s.licenses = ["LGPL-3.0-or-later".freeze]
|
18
18
|
s.required_ruby_version = Gem::Requirement.new(">= 3.0.0".freeze)
|
19
|
-
s.rubygems_version = "3.
|
19
|
+
s.rubygems_version = "3.5.6".freeze
|
20
20
|
s.summary = "Bringing object-oriented programming to Rails enums".freeze
|
21
21
|
|
22
22
|
s.specification_version = 4
|
23
23
|
|
24
|
-
s.add_runtime_dependency(%q<rails>.freeze, ["~> 7.0"])
|
25
|
-
s.add_development_dependency(%q<rake>.freeze, ["~> 13.0.6"])
|
26
|
-
s.add_development_dependency(%q<pry>.freeze, ["~> 0.14.1"])
|
27
|
-
s.add_development_dependency(%q<rubocop>.freeze, ["~> 1.43.0"])
|
28
|
-
s.add_development_dependency(%q<rubocop-rails>.freeze, ["~> 2.17.4"])
|
29
|
-
s.add_development_dependency(%q<yard>.freeze, ["~> 0.9.28"])
|
30
|
-
s.add_development_dependency(%q<yard-activesupport-concern>.freeze, ["~> 0.0.1"])
|
31
|
-
s.add_development_dependency(%q<minitest>.freeze, ["~> 5.17.0"])
|
32
|
-
s.add_development_dependency(%q<minitest-reporters>.freeze, ["~> 1.5.0"])
|
33
|
-
s.add_development_dependency(%q<sqlite3>.freeze, ["~> 1.6.0"])
|
24
|
+
s.add_runtime_dependency(%q<rails>.freeze, ["~> 7.0".freeze])
|
25
|
+
s.add_development_dependency(%q<rake>.freeze, ["~> 13.0.6".freeze])
|
26
|
+
s.add_development_dependency(%q<pry>.freeze, ["~> 0.14.1".freeze])
|
27
|
+
s.add_development_dependency(%q<rubocop>.freeze, ["~> 1.43.0".freeze])
|
28
|
+
s.add_development_dependency(%q<rubocop-rails>.freeze, ["~> 2.17.4".freeze])
|
29
|
+
s.add_development_dependency(%q<yard>.freeze, ["~> 0.9.28".freeze])
|
30
|
+
s.add_development_dependency(%q<yard-activesupport-concern>.freeze, ["~> 0.0.1".freeze])
|
31
|
+
s.add_development_dependency(%q<minitest>.freeze, ["~> 5.17.0".freeze])
|
32
|
+
s.add_development_dependency(%q<minitest-reporters>.freeze, ["~> 1.5.0".freeze])
|
33
|
+
s.add_development_dependency(%q<sqlite3>.freeze, ["~> 1.6.0".freeze])
|
34
34
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Class: Anchormodel::Attribute
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.36
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -496,9 +496,9 @@
|
|
496
496
|
</div>
|
497
497
|
|
498
498
|
<div id="footer">
|
499
|
-
Generated on
|
499
|
+
Generated on Tue Apr 23 17:20:43 2024 by
|
500
500
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
501
|
-
0.9.
|
501
|
+
0.9.36 (ruby-3.2.2).
|
502
502
|
</div>
|
503
503
|
|
504
504
|
</div>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Anchormodel::ModelMixin
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.36
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -117,7 +117,7 @@
|
|
117
117
|
<li class="public ">
|
118
118
|
<span class="summary_signature">
|
119
119
|
|
120
|
-
<a href="#belongs_to_anchormodel-class_method" title="belongs_to_anchormodel (class method)">.<strong>belongs_to_anchormodel</strong>(
|
120
|
+
<a href="#belongs_to_anchormodel-class_method" title="belongs_to_anchormodel (class method)">.<strong>belongs_to_anchormodel</strong>(*args, **kwargs) ⇒ Object </a>
|
121
121
|
|
122
122
|
|
123
123
|
|
@@ -151,7 +151,7 @@
|
|
151
151
|
<div class="method_details first">
|
152
152
|
<h3 class="signature first" id="belongs_to_anchormodel-class_method">
|
153
153
|
|
154
|
-
.<strong>belongs_to_anchormodel</strong>(
|
154
|
+
.<strong>belongs_to_anchormodel</strong>(*args, **kwargs) ⇒ <tt>Object</tt>
|
155
155
|
|
156
156
|
|
157
157
|
|
@@ -160,141 +160,20 @@
|
|
160
160
|
</h3><div class="docstring">
|
161
161
|
<div class="discussion">
|
162
162
|
|
163
|
-
<p>Creates an attribute linking to an Anchormodel. The attribute should be present in the DB and the column should be named the same as <code>attribute_name
|
163
|
+
<p>Creates an attribute linking to an Anchormodel. The attribute should be present in the DB and the column should be of type String and named the same as <code>attribute_name</code>.</p>
|
164
164
|
|
165
165
|
|
166
166
|
</div>
|
167
167
|
</div>
|
168
168
|
<div class="tags">
|
169
|
-
<p class="tag_title">Parameters:</p>
|
170
|
-
<ul class="param">
|
171
169
|
|
172
|
-
<li>
|
173
|
-
|
174
|
-
<span class='name'>attribute_name</span>
|
175
|
-
|
176
|
-
|
177
|
-
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
—
|
182
|
-
<div class='inline'>
|
183
|
-
<p>The name and database column of the attribute</p>
|
184
|
-
</div>
|
185
|
-
|
186
|
-
</li>
|
187
|
-
|
188
|
-
<li>
|
189
|
-
|
190
|
-
<span class='name'>anchormodel_class</span>
|
191
|
-
|
192
|
-
|
193
|
-
<span class='type'>(<tt>Class</tt>)</span>
|
194
|
-
|
195
|
-
|
196
|
-
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
197
|
-
|
198
|
-
|
199
|
-
—
|
200
|
-
<div class='inline'>
|
201
|
-
<p>Class of the Anchormodel (omit if attribute <code>:foo_bar</code> holds a <code>FooBar</code>)</p>
|
202
|
-
</div>
|
203
|
-
|
204
|
-
</li>
|
205
|
-
|
206
|
-
<li>
|
207
|
-
|
208
|
-
<span class='name'>optional</span>
|
209
|
-
|
210
|
-
|
211
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
212
|
-
|
213
|
-
|
214
|
-
<em class="default">(defaults to: <tt>false</tt>)</em>
|
215
|
-
|
216
|
-
|
217
|
-
—
|
218
|
-
<div class='inline'>
|
219
|
-
<p>If true, a presence validation is added to the model.</p>
|
220
|
-
</div>
|
221
|
-
|
222
|
-
</li>
|
223
|
-
|
224
|
-
<li>
|
225
|
-
|
226
|
-
<span class='name'>model_readers</span>
|
227
|
-
|
228
|
-
|
229
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
230
|
-
|
231
|
-
|
232
|
-
<em class="default">(defaults to: <tt>true</tt>)</em>
|
233
|
-
|
234
|
-
|
235
|
-
—
|
236
|
-
<div class='inline'>
|
237
|
-
<p>If true, the model is given an ActiveRecord::Enum style method <code>my_model.my_key?</code> reader for each key in the anchormodel</p>
|
238
|
-
</div>
|
239
|
-
|
240
|
-
</li>
|
241
|
-
|
242
|
-
<li>
|
243
|
-
|
244
|
-
<span class='name'>model_writers</span>
|
245
|
-
|
246
|
-
|
247
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
248
|
-
|
249
|
-
|
250
|
-
<em class="default">(defaults to: <tt>true</tt>)</em>
|
251
|
-
|
252
|
-
|
253
|
-
—
|
254
|
-
<div class='inline'>
|
255
|
-
<p>If true, the model is given an ActiveRecord::Enum style method <code>my_model.my_key!</code> writer for each key in the anchormodel</p>
|
256
|
-
</div>
|
257
|
-
|
258
|
-
</li>
|
259
|
-
|
260
|
-
<li>
|
261
|
-
|
262
|
-
<span class='name'>model_scopes</span>
|
263
|
-
|
264
|
-
|
265
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
266
|
-
|
267
|
-
|
268
|
-
<em class="default">(defaults to: <tt>true</tt>)</em>
|
269
|
-
|
270
|
-
|
271
|
-
—
|
272
|
-
<div class='inline'>
|
273
|
-
<p>If true, the model is given an ActiveRecord::Enum style scope <code>MyModel.mykey</code> for each key in the anchormodel</p>
|
274
|
-
</div>
|
275
|
-
|
276
|
-
</li>
|
277
|
-
|
278
|
-
<li>
|
279
|
-
|
280
|
-
<span class='name'>model_methods</span>
|
281
|
-
|
282
|
-
|
283
|
-
<span class='type'>(<tt>Boolean</tt>, <tt>NilClass</tt>)</span>
|
284
|
-
|
285
|
-
|
286
|
-
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
287
|
-
|
288
|
-
|
289
|
-
—
|
290
|
-
<div class='inline'>
|
291
|
-
<p>If non-nil, this mass-assigns and overrides <code>model_readers</code>, <code>model_writers</code> and <code>model_scopes</code></p>
|
292
|
-
</div>
|
293
|
-
|
294
|
-
</li>
|
295
|
-
|
296
|
-
</ul>
|
297
170
|
|
171
|
+
<p class="tag_title">See Also:</p>
|
172
|
+
<ul class="see">
|
173
|
+
|
174
|
+
<li>Parameters</li>
|
175
|
+
|
176
|
+
</ul>
|
298
177
|
|
299
178
|
</div><table class="source_code">
|
300
179
|
<tr>
|
@@ -302,159 +181,15 @@
|
|
302
181
|
<pre class="lines">
|
303
182
|
|
304
183
|
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
23
|
309
|
-
24
|
310
|
-
25
|
311
|
-
26
|
312
|
-
27
|
313
|
-
28
|
314
|
-
29
|
315
|
-
30
|
316
|
-
31
|
317
|
-
32
|
318
|
-
33
|
319
|
-
34
|
320
|
-
35
|
321
|
-
36
|
322
|
-
37
|
323
|
-
38
|
324
|
-
39
|
325
|
-
40
|
326
|
-
41
|
327
|
-
42
|
328
|
-
43
|
329
|
-
44
|
330
|
-
45
|
331
|
-
46
|
332
|
-
47
|
333
|
-
48
|
334
|
-
49
|
335
|
-
50
|
336
|
-
51
|
337
|
-
52
|
338
|
-
53
|
339
|
-
54
|
340
|
-
55
|
341
|
-
56
|
342
|
-
57
|
343
|
-
58
|
344
|
-
59
|
345
|
-
60
|
346
|
-
61
|
347
|
-
62
|
348
|
-
63
|
349
|
-
64
|
350
|
-
65
|
351
|
-
66
|
352
|
-
67
|
353
|
-
68
|
354
|
-
69
|
355
|
-
70
|
356
|
-
71
|
357
|
-
72
|
358
|
-
73
|
359
|
-
74
|
360
|
-
75
|
361
|
-
76
|
362
|
-
77
|
363
|
-
78
|
364
|
-
79
|
365
|
-
80
|
366
|
-
81
|
367
|
-
82
|
368
|
-
83
|
369
|
-
84
|
370
|
-
85
|
371
|
-
86
|
372
|
-
87
|
373
|
-
88
|
374
|
-
89
|
375
|
-
90
|
376
|
-
91
|
377
|
-
92
|
378
|
-
93
|
379
|
-
94</pre>
|
184
|
+
14
|
185
|
+
15
|
186
|
+
16</pre>
|
380
187
|
</td>
|
381
188
|
<td>
|
382
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/model_mixin.rb', line
|
383
|
-
|
384
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_belongs_to_anchormodel'>belongs_to_anchormodel</span><span class='lparen'>(</span><span class='
|
385
|
-
|
386
|
-
<span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span> <span class='op'>||=</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_classify'>classify</span><span class='period'>.</span><span class='id identifier rubyid_constantize'>constantize</span>
|
387
|
-
<span class='id identifier rubyid_attribute_name'>attribute_name</span> <span class='op'>=</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
388
|
-
<span class='id identifier rubyid_attribute'>attribute</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Attribute.html" title="Anchormodel::Attribute (class)">Attribute</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Attribute.html#initialize-instance_method" title="Anchormodel::Attribute#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='comma'>,</span> <span class='id identifier rubyid_optional'>optional</span><span class='rparen'>)</span>
|
389
|
-
|
390
|
-
<span class='comment'># Mass configurations if model_methods was specfied
|
391
|
-
</span> <span class='kw'>unless</span> <span class='id identifier rubyid_model_methods'>model_methods</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
392
|
-
<span class='id identifier rubyid_model_readers'>model_readers</span> <span class='op'>=</span> <span class='id identifier rubyid_model_methods'>model_methods</span>
|
393
|
-
<span class='id identifier rubyid_model_writers'>model_writers</span> <span class='op'>=</span> <span class='id identifier rubyid_model_methods'>model_methods</span>
|
394
|
-
<span class='id identifier rubyid_model_scopes'>model_scopes</span> <span class='op'>=</span> <span class='id identifier rubyid_model_methods'>model_methods</span>
|
395
|
-
<span class='kw'>end</span>
|
396
|
-
|
397
|
-
<span class='comment'># Register attribute
|
398
|
-
</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_attributes'>anchormodel_attributes</span> <span class='op'>=</span> <span class='id identifier rubyid_anchormodel_attributes'>anchormodel_attributes</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='lbrace'>{</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span> <span class='op'>=></span> <span class='id identifier rubyid_attribute'>attribute</span> <span class='rbrace'>}</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span>
|
399
|
-
|
400
|
-
<span class='comment'># Add presence validation if required
|
401
|
-
</span> <span class='kw'>unless</span> <span class='id identifier rubyid_optional'>optional</span>
|
402
|
-
<span class='id identifier rubyid_validates'>validates</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='label'>presence:</span> <span class='kw'>true</span>
|
403
|
-
<span class='kw'>end</span>
|
404
|
-
|
405
|
-
<span class='comment'># Make casting work
|
406
|
-
</span> <span class='comment'># Define serializer/deserializer
|
407
|
-
</span> <span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="ActiveModelTypeValue.html" title="Anchormodel::ActiveModelTypeValue (class)">ActiveModelTypeValue</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="ActiveModelTypeValue.html#initialize-instance_method" title="Anchormodel::ActiveModelTypeValue#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_attribute'>attribute</span><span class='rparen'>)</span>
|
408
|
-
|
409
|
-
<span class='comment'># Overwrite reader to force building anchors at every retrieval
|
410
|
-
</span> <span class='id identifier rubyid_define_method'>define_method</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
411
|
-
<span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span><span class='period'>.</span><span class='id identifier rubyid_deserialize'>deserialize</span><span class='lparen'>(</span><span class='id identifier rubyid_read_attribute'>read_attribute</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
412
|
-
<span class='kw'>end</span>
|
413
|
-
|
414
|
-
<span class='comment'># Override writer to fail early when an invalid target value is specified
|
415
|
-
</span> <span class='id identifier rubyid_define_method'>define_method</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>=</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_new_value'>new_value</span><span class='op'>|</span>
|
416
|
-
<span class='id identifier rubyid_write_attribute'>write_attribute</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span><span class='period'>.</span><span class='id identifier rubyid_serialize'>serialize</span><span class='lparen'>(</span><span class='id identifier rubyid_new_value'>new_value</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
417
|
-
<span class='kw'>end</span>
|
418
|
-
|
419
|
-
<span class='comment'># Supply serializer and deserializer
|
420
|
-
</span> <span class='id identifier rubyid_attribute'>attribute</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier rubyid_active_model_type_value'>active_model_type_value</span>
|
421
|
-
|
422
|
-
<span class='comment'># Create ActiveRecord::Enum style reader directly in the model if asked to do so
|
423
|
-
</span> <span class='comment'># For a model User with anchormodel Role with keys :admin and :guest, this creates user.admin? and user.guest? (returning true iff role is admin/guest)
|
424
|
-
</span> <span class='kw'>if</span> <span class='id identifier rubyid_model_readers'>model_readers</span>
|
425
|
-
<span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_entry'>entry</span><span class='op'>|</span>
|
426
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>?</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
427
|
-
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Anchormodel reader </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>? already defined for </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>, add `model_readers: false` to `belongs_to_anchormodel :</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>`.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
428
|
-
<span class='kw'>end</span>
|
429
|
-
<span class='id identifier rubyid_define_method'>define_method</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>?</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
430
|
-
<span class='id identifier rubyid_public_send'>public_send</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span> <span class='op'>==</span> <span class='id identifier rubyid_entry'>entry</span>
|
431
|
-
<span class='kw'>end</span>
|
432
|
-
<span class='kw'>end</span>
|
433
|
-
<span class='kw'>end</span>
|
434
|
-
|
435
|
-
<span class='comment'># Create ActiveRecord::Enum style writer directly in the model if asked to do so
|
436
|
-
</span> <span class='comment'># For a model User with anchormodel Role with keys :admin and :guest, this creates user.admin! and user.guest! (setting the role to admin/guest)
|
437
|
-
</span> <span class='kw'>if</span> <span class='id identifier rubyid_model_writers'>model_writers</span>
|
438
|
-
<span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_entry'>entry</span><span class='op'>|</span>
|
439
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>!</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
440
|
-
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Anchormodel writer </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>! already defined for </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>, add `model_writers: false` to `belongs_to_anchormodel :</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>`.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
441
|
-
<span class='kw'>end</span>
|
442
|
-
<span class='id identifier rubyid_define_method'>define_method</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>!</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
443
|
-
<span class='id identifier rubyid_public_send'>public_send</span><span class='lparen'>(</span><span class='symbol'>:"#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>=</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_entry'>entry</span><span class='rparen'>)</span>
|
444
|
-
<span class='kw'>end</span>
|
445
|
-
<span class='kw'>end</span>
|
446
|
-
<span class='kw'>end</span>
|
447
|
-
|
448
|
-
<span class='comment'># Create ActiveRecord::Enum style scope directly in the model class if asked to do so
|
449
|
-
</span> <span class='comment'># For a model User with anchormodel Role with keys :admin and :guest, this creates user.admin! and user.guest! (setting the role to admin/guest)
|
450
|
-
</span> <span class='kw'>if</span> <span class='id identifier rubyid_model_scopes'>model_scopes</span>
|
451
|
-
<span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_entry'>entry</span><span class='op'>|</span>
|
452
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
453
|
-
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Anchormodel scope </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'> already defined for </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'>, add `model_scopes: false` to `belongs_to_anchormodel :</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>`.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
454
|
-
<span class='kw'>end</span>
|
455
|
-
<span class='id identifier rubyid_scope'>scope</span><span class='lparen'>(</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='tlambda'>-></span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute_name'>attribute_name</span> <span class='op'>=></span> <span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='rparen'>)</span>
|
456
|
-
<span class='kw'>end</span>
|
457
|
-
<span class='kw'>end</span>
|
189
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/model_mixin.rb', line 14</span>
|
190
|
+
|
191
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_belongs_to_anchormodel'>belongs_to_anchormodel</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_kwargs'>kwargs</span><span class='rparen'>)</span>
|
192
|
+
<span class='const'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Util.html" title="Anchormodel::Util (module)">Util</a></span></span><span class='period'>.</span><span class='id identifier rubyid_install_methods_in_model'><span class='object_link'><a href="Util.html#install_methods_in_model-class_method" title="Anchormodel::Util.install_methods_in_model (method)">install_methods_in_model</a></span></span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_kwargs'>kwargs</span><span class='rparen'>)</span>
|
458
193
|
<span class='kw'>end</span></pre>
|
459
194
|
</td>
|
460
195
|
</tr>
|
@@ -466,9 +201,9 @@
|
|
466
201
|
</div>
|
467
202
|
|
468
203
|
<div id="footer">
|
469
|
-
Generated on
|
204
|
+
Generated on Tue Apr 23 17:20:43 2024 by
|
470
205
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
471
|
-
0.9.
|
206
|
+
0.9.36 (ruby-3.2.2).
|
472
207
|
</div>
|
473
208
|
|
474
209
|
</div>
|