anchormodel 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +5 -5
- data/README.md +88 -4
- data/anchormodel.gemspec +4 -4
- data/bin/rails +7 -0
- data/doc/Anchormodel/ActiveModelTypeValue.html +17 -13
- data/doc/Anchormodel/Attribute.html +60 -63
- data/doc/Anchormodel/ModelMixin.html +178 -14
- data/doc/Anchormodel/Version.html +4 -4
- data/doc/Anchormodel.html +28 -18
- data/doc/_index.html +1 -1
- data/doc/file.README.html +91 -9
- data/doc/index.html +91 -9
- data/doc/method_list.html +1 -1
- data/doc/top-level-namespace.html +1 -1
- data/lib/anchormodel/active_model_type_value.rb +6 -4
- data/lib/anchormodel/attribute.rb +4 -9
- data/lib/anchormodel/model_mixin.rb +53 -3
- data/lib/anchormodel/version.rb +1 -1
- data/lib/anchormodel.rb +5 -0
- data/test/active_record_model/user_test.rb +72 -2
- data/test/dummy/app/models/user.rb +3 -1
- data/test/dummy/db/migrate/20230107173151_create_users.rb +2 -0
- data/test/dummy/db/schema.rb +8 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b70771d2e2deb3240110e225980c5957665efe1d59b2dc4128c43bd092daa6e
|
4
|
+
data.tar.gz: c8030a9df0c89523d319b38528b0bcdbf238b50e95645a209198895e4d014732
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7838fd578d77d5f2b5d3d9df078ed4118f3baca165bf47dbba94636897ec4704f1eb22804930c459c29ddf803e271c24a27786b99e48ffd8e16e5598f6fbb807
|
7
|
+
data.tar.gz: a7e85cae485400d87f6d10b496a4887c0d01f8435bf2e770c0103a26dab2713a22526be3c1b945b52fb624abc0f1770a81cf5136ddd9f47ce6369bb5bfa48fc1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# 0.1.2 (25.01.2023)
|
2
|
+
|
3
|
+
- Consider empty string as nil (this is necessary to make Rails assignments work)
|
4
|
+
|
5
|
+
# 0.1.1 (24.01.2023)
|
6
|
+
|
7
|
+
- Add boolean accessor directly to all anchormodels
|
8
|
+
- Add ActiveRecord::Enum style readers, writers and scopes to the model
|
9
|
+
- Attribute#anchor_class is now called `anchormodel_class`.
|
10
|
+
|
1
11
|
# 0.1.0 (18.01.2023)
|
2
12
|
|
3
13
|
- Remove `Anchormodels::` prefix and have anchormodels in the root namespace instead.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
anchormodel (0.
|
4
|
+
anchormodel (0.1.1)
|
5
5
|
rails (~> 7.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -80,7 +80,7 @@ GEM
|
|
80
80
|
crass (1.0.6)
|
81
81
|
date (3.3.3)
|
82
82
|
erubi (1.12.0)
|
83
|
-
globalid (1.0.
|
83
|
+
globalid (1.0.1)
|
84
84
|
activesupport (>= 5.0)
|
85
85
|
i18n (1.12.0)
|
86
86
|
concurrent-ruby (~> 1.0)
|
@@ -88,7 +88,7 @@ GEM
|
|
88
88
|
loofah (2.19.1)
|
89
89
|
crass (~> 1.0.2)
|
90
90
|
nokogiri (>= 1.5.9)
|
91
|
-
mail (2.8.0)
|
91
|
+
mail (2.8.0.1)
|
92
92
|
mini_mime (>= 0.1.1)
|
93
93
|
net-imap
|
94
94
|
net-pop
|
@@ -112,7 +112,7 @@ GEM
|
|
112
112
|
net-smtp (0.3.3)
|
113
113
|
net-protocol
|
114
114
|
nio4r (2.5.8)
|
115
|
-
nokogiri (1.
|
115
|
+
nokogiri (1.14.0-x86_64-linux)
|
116
116
|
racc (~> 1.4)
|
117
117
|
parallel (1.22.1)
|
118
118
|
parser (3.2.0.0)
|
@@ -141,7 +141,7 @@ GEM
|
|
141
141
|
rails-dom-testing (2.0.3)
|
142
142
|
activesupport (>= 4.2.0)
|
143
143
|
nokogiri (>= 1.6)
|
144
|
-
rails-html-sanitizer (1.
|
144
|
+
rails-html-sanitizer (1.5.0)
|
145
145
|
loofah (~> 2.19, >= 2.19.1)
|
146
146
|
railties (7.0.4)
|
147
147
|
actionpack (= 7.0.4)
|
data/README.md
CHANGED
@@ -44,7 +44,13 @@ meaningful, making you immediately understand what they stand for.
|
|
44
44
|
This is why Anchormodel is strictly relying on String keys corresponding to the
|
45
45
|
entries of an Anchormodel.
|
46
46
|
|
47
|
-
|
47
|
+
|
48
|
+
# Installation
|
49
|
+
|
50
|
+
1. Add gem to Gemfile: `gem 'anchormodel'`
|
51
|
+
2. In `application_record.rb`, add in the class body: `include Anchormodel::ModelMixin`
|
52
|
+
|
53
|
+
# Basic example
|
48
54
|
|
49
55
|
`app/anchormodels/role.rb`:
|
50
56
|
|
@@ -73,7 +79,11 @@ end
|
|
73
79
|
```ruby
|
74
80
|
# The DB table `users` must have a String column `users.role`
|
75
81
|
class User < ApplicationRecord
|
82
|
+
# If `users.role` has an `NOT NULL` constraint, use:
|
76
83
|
belongs_to_anchormodel :role
|
84
|
+
|
85
|
+
# If `users.role` can be `NULL`, use the following instead:
|
86
|
+
belongs_to_anchormodel :role, optional: true
|
77
87
|
end
|
78
88
|
```
|
79
89
|
|
@@ -93,9 +103,83 @@ end
|
|
93
103
|
|
94
104
|
# Pretty print a user's role, e.g. using the Rails FastGettext gem:
|
95
105
|
puts("User #{@user.name} has role #{@user.role.label}")
|
106
|
+
|
107
|
+
# Check whether @user has role admin
|
108
|
+
@user.role.admin? # true if and only if the role is admin (false otherwise)
|
96
109
|
```
|
97
110
|
|
98
|
-
#
|
111
|
+
# Rails Enum style model methods
|
99
112
|
|
100
|
-
|
101
|
-
|
113
|
+
By default, Anchormodel adds three kinds of methods for each key to the model:
|
114
|
+
|
115
|
+
- a reader (getter)
|
116
|
+
- a writer (setter)
|
117
|
+
- a Rails scope
|
118
|
+
|
119
|
+
For instance:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
class User < ApplicationRecord
|
123
|
+
belongs_to_anchormodel :role # where Role has keys :guest, :manager and :admin
|
124
|
+
belongs_to_anchormodel :shape # where Shape has keys :circle and :rectangle
|
125
|
+
end
|
126
|
+
|
127
|
+
# User now implements the following methods, given that @user is retrieved as follows:
|
128
|
+
@user = User.first # for example
|
129
|
+
|
130
|
+
# Readers
|
131
|
+
@user.guest? # same as @user.role.guest?
|
132
|
+
@user.manager?
|
133
|
+
@user.admin?
|
134
|
+
@user.rectangle? # same as @user.shape.rectangle?
|
135
|
+
@user.circle?
|
136
|
+
# Writers
|
137
|
+
@user.guest! # same as @user.role = Role.find(:guest)
|
138
|
+
@user.manager!
|
139
|
+
@user.admin!
|
140
|
+
@user.rectangle! # same as @user.shape = Shape.find(:rectangle)
|
141
|
+
@user.circle!
|
142
|
+
# Scopes
|
143
|
+
User.guest # same as User.where(role: 'guest')
|
144
|
+
User.manager
|
145
|
+
User.admin
|
146
|
+
User.rectangle # same as User.where(shape: 'rectangle')
|
147
|
+
User.circle
|
148
|
+
```
|
149
|
+
|
150
|
+
This behavior is similar as the one from Rails Enums. If you want to disable it, use:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
class User < ApplicationRecord
|
154
|
+
belongs_to_anchormodel :role, model_readers: false, model_writers: false, model_scopes: false
|
155
|
+
# or, equivalent, to disable all at once:
|
156
|
+
belongs_to_anchormodel :role, model_methods: false
|
157
|
+
end
|
158
|
+
```
|
159
|
+
|
160
|
+
# Calling a column differently than the Anchormodel
|
161
|
+
|
162
|
+
If your column name (and the model's attribute) is called differently than the Anchormodel, you may give the Anchormodel's class as the second argument. For example:
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
# app/anchormodels/color.rb
|
166
|
+
class Color < Anchormodel
|
167
|
+
new :green
|
168
|
+
new :red
|
169
|
+
end
|
170
|
+
|
171
|
+
# app/models/user.rb
|
172
|
+
class User < ApplicationRecord
|
173
|
+
belongs_to_anchormodel :favorite_color, Color
|
174
|
+
end
|
175
|
+
```
|
176
|
+
|
177
|
+
## Having multiple attributes to the same Anchormodel
|
178
|
+
|
179
|
+
If you want to have multiple attributes in the same model pointing to the same Anchormodel, you need to disable `model_methods` for at least one of them (otherwise the model methods will clash in your model class):
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
# app/models/user.rb
|
183
|
+
belongs_to_anchormodel :role
|
184
|
+
belongs_to_anchormodel :secondary_role, Role, model_methods: false
|
185
|
+
```
|
data/anchormodel.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
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.2 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.2"
|
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 = "2023-01-
|
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, "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.rb".freeze, "lib/anchormodel/attribute.rb".freeze, "lib/anchormodel/model_mixin.rb".freeze, "lib/anchormodel/version.rb".freeze, "logo.svg".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]
|
14
|
+
s.date = "2023-01-25"
|
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/active_model_type_value.rb".freeze, "lib/anchormodel/attribute.rb".freeze, "lib/anchormodel/model_mixin.rb".freeze, "lib/anchormodel/version.rb".freeze, "logo.svg".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)
|
data/bin/rails
ADDED
@@ -381,12 +381,12 @@
|
|
381
381
|
<pre class="lines">
|
382
382
|
|
383
383
|
|
384
|
-
|
385
|
-
|
386
|
-
|
384
|
+
36
|
385
|
+
37
|
386
|
+
38</pre>
|
387
387
|
</td>
|
388
388
|
<td>
|
389
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value.rb', line
|
389
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value.rb', line 36</span>
|
390
390
|
|
391
391
|
<span class='kw'>def</span> <span class='id identifier rubyid_changed?'>changed?</span><span class='lparen'>(</span><span class='id identifier rubyid_old_value'>old_value</span><span class='comma'>,</span> <span class='id identifier rubyid_new_value'>new_value</span><span class='comma'>,</span> <span class='id identifier rubyid__new_value_before_type_cast'>_new_value_before_type_cast</span><span class='rparen'>)</span>
|
392
392
|
<span class='kw'>return</span> <span class='id identifier rubyid_deserialize'>deserialize</span><span class='lparen'>(</span><span class='id identifier rubyid_old_value'>old_value</span><span class='rparen'>)</span> <span class='op'>!=</span> <span class='id identifier rubyid_deserialize'>deserialize</span><span class='lparen'>(</span><span class='id identifier rubyid_new_value'>new_value</span><span class='rparen'>)</span>
|
@@ -420,17 +420,19 @@
|
|
420
420
|
<pre class="lines">
|
421
421
|
|
422
422
|
|
423
|
-
29
|
424
423
|
30
|
425
424
|
31
|
426
|
-
32
|
425
|
+
32
|
426
|
+
33
|
427
|
+
34</pre>
|
427
428
|
</td>
|
428
429
|
<td>
|
429
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value.rb', line
|
430
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value.rb', line 30</span>
|
430
431
|
|
431
432
|
<span class='kw'>def</span> <span class='id identifier rubyid_deserialize'>deserialize</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
432
|
-
<span class='
|
433
|
-
<span class='kw'>return</span> <span class='
|
433
|
+
<span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_presence'>presence</span>
|
434
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_value'>value</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='rparen'>)</span>
|
435
|
+
<span class='kw'>return</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
434
436
|
<span class='kw'>end</span></pre>
|
435
437
|
</td>
|
436
438
|
</tr>
|
@@ -477,19 +479,21 @@
|
|
477
479
|
24
|
478
480
|
25
|
479
481
|
26
|
480
|
-
27
|
482
|
+
27
|
483
|
+
28</pre>
|
481
484
|
</td>
|
482
485
|
<td>
|
483
486
|
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value.rb', line 13</span>
|
484
487
|
|
485
488
|
<span class='kw'>def</span> <span class='id identifier rubyid_serialize'>serialize</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
489
|
+
<span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_presence'>presence</span>
|
486
490
|
<span class='kw'>return</span> <span class='kw'>case</span> <span class='id identifier rubyid_value'>value</span>
|
487
491
|
<span class='kw'>when</span> <span class='const'>Symbol</span><span class='comma'>,</span> <span class='const'>String</span>
|
488
|
-
<span class='kw'>unless</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier
|
492
|
+
<span class='kw'>unless</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span><span class='period'>.</span><span class='id identifier rubyid_valid_keys'>valid_keys</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rparen'>)</span>
|
489
493
|
<span class='id identifier rubyid_fail'>fail</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Attempt to set </span><span class='embexpr_beg'>#{</span><span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> to unsupported key </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
490
494
|
<span class='kw'>end</span>
|
491
495
|
<span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
|
492
|
-
<span class='kw'>when</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier
|
496
|
+
<span class='kw'>when</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span>
|
493
497
|
<span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
|
494
498
|
<span class='kw'>when</span> <span class='kw'>nil</span>
|
495
499
|
<span class='kw'>nil</span>
|
@@ -507,7 +511,7 @@
|
|
507
511
|
</div>
|
508
512
|
|
509
513
|
<div id="footer">
|
510
|
-
Generated on Wed Jan
|
514
|
+
Generated on Wed Jan 25 12:36:40 2023 by
|
511
515
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
512
516
|
0.9.28 (ruby-3.1.3).
|
513
517
|
</div>
|
@@ -120,7 +120,7 @@
|
|
120
120
|
<li class="public ">
|
121
121
|
<span class="summary_signature">
|
122
122
|
|
123
|
-
<a href="#
|
123
|
+
<a href="#anchormodel_class-instance_method" title="#anchormodel_class (instance method)">#<strong>anchormodel_class</strong> ⇒ Object </a>
|
124
124
|
|
125
125
|
|
126
126
|
|
@@ -147,7 +147,7 @@
|
|
147
147
|
<li class="public ">
|
148
148
|
<span class="summary_signature">
|
149
149
|
|
150
|
-
<a href="#
|
150
|
+
<a href="#attribute_name-instance_method" title="#attribute_name (instance method)">#<strong>attribute_name</strong> ⇒ Object </a>
|
151
151
|
|
152
152
|
|
153
153
|
|
@@ -171,23 +171,10 @@
|
|
171
171
|
</li>
|
172
172
|
|
173
173
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
<h2>
|
181
|
-
Instance Method Summary
|
182
|
-
<small><a href="#" class="summary_toggle">collapse</a></small>
|
183
|
-
</h2>
|
184
|
-
|
185
|
-
<ul class="summary">
|
186
|
-
|
187
|
-
<li class="public ">
|
174
|
+
<li class="public ">
|
188
175
|
<span class="summary_signature">
|
189
176
|
|
190
|
-
<a href="#
|
177
|
+
<a href="#optional-instance_method" title="#optional (instance method)">#<strong>optional</strong> ⇒ Object </a>
|
191
178
|
|
192
179
|
|
193
180
|
|
@@ -195,23 +182,39 @@
|
|
195
182
|
|
196
183
|
|
197
184
|
|
185
|
+
|
186
|
+
<span class="note title readonly">readonly</span>
|
187
|
+
|
188
|
+
|
189
|
+
|
198
190
|
|
199
191
|
|
200
192
|
|
201
193
|
|
202
194
|
|
203
195
|
|
204
|
-
<span class="summary_desc"><div class='inline'>
|
205
|
-
<p>Getter for the Anchormodel class based on the name passed to the initializer.</p>
|
206
|
-
</div></span>
|
196
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
207
197
|
|
208
198
|
</li>
|
209
199
|
|
200
|
+
|
201
|
+
</ul>
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
<h2>
|
208
|
+
Instance Method Summary
|
209
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
210
|
+
</h2>
|
211
|
+
|
212
|
+
<ul class="summary">
|
210
213
|
|
211
214
|
<li class="public ">
|
212
215
|
<span class="summary_signature">
|
213
216
|
|
214
|
-
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(model_class, attribute_name,
|
217
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(model_class, attribute_name, anchormodel_class = nil, optional = false) ⇒ Attribute </a>
|
215
218
|
|
216
219
|
|
217
220
|
|
@@ -243,7 +246,7 @@
|
|
243
246
|
<div class="method_details first">
|
244
247
|
<h3 class="signature first" id="initialize-instance_method">
|
245
248
|
|
246
|
-
#<strong>initialize</strong>(model_class, attribute_name,
|
249
|
+
#<strong>initialize</strong>(model_class, attribute_name, anchormodel_class = nil, optional = false) ⇒ <tt><span class='object_link'><a href="" title="Anchormodel::Attribute (class)">Attribute</a></span></tt>
|
247
250
|
|
248
251
|
|
249
252
|
|
@@ -295,10 +298,10 @@
|
|
295
298
|
|
296
299
|
<li>
|
297
300
|
|
298
|
-
<span class='name'>
|
301
|
+
<span class='name'>anchormodel_class</span>
|
299
302
|
|
300
303
|
|
301
|
-
<span class='type'>(<tt>
|
304
|
+
<span class='type'>(<tt>Class</tt>)</span>
|
302
305
|
|
303
306
|
|
304
307
|
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
@@ -306,7 +309,7 @@
|
|
306
309
|
|
307
310
|
—
|
308
311
|
<div class='inline'>
|
309
|
-
<p>
|
312
|
+
<p>Class of the Anchormodel (omit if attribute <code>:foo_bar</code> holds an <code>FooBar</code>)</p>
|
310
313
|
</div>
|
311
314
|
|
312
315
|
</li>
|
@@ -338,20 +341,20 @@
|
|
338
341
|
<pre class="lines">
|
339
342
|
|
340
343
|
|
341
|
-
12
|
342
344
|
13
|
343
345
|
14
|
344
346
|
15
|
345
347
|
16
|
346
|
-
17
|
348
|
+
17
|
349
|
+
18</pre>
|
347
350
|
</td>
|
348
351
|
<td>
|
349
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line
|
352
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line 13</span>
|
350
353
|
|
351
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_model_class'>model_class</span><span class='comma'>,</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span><span class='comma'>,</span> <span class='id identifier
|
354
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_model_class'>model_class</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='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_optional'>optional</span> <span class='op'>=</span> <span class='kw'>false</span><span class='rparen'>)</span>
|
352
355
|
<span class='ivar'>@model_class</span> <span class='op'>=</span> <span class='id identifier rubyid_model_class'>model_class</span>
|
353
356
|
<span class='ivar'>@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>
|
354
|
-
<span class='ivar'>@
|
357
|
+
<span class='ivar'>@anchormodel_class</span> <span class='op'>=</span> <span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span>
|
355
358
|
<span class='ivar'>@optional</span> <span class='op'>=</span> <span class='id identifier rubyid_optional'>optional</span>
|
356
359
|
<span class='kw'>end</span></pre>
|
357
360
|
</td>
|
@@ -367,9 +370,9 @@
|
|
367
370
|
|
368
371
|
<span id=""></span>
|
369
372
|
<div class="method_details first">
|
370
|
-
<h3 class="signature first" id="
|
373
|
+
<h3 class="signature first" id="anchormodel_class-instance_method">
|
371
374
|
|
372
|
-
#<strong>
|
375
|
+
#<strong>anchormodel_class</strong> ⇒ <tt>Object</tt> <span class="extras">(readonly)</span>
|
373
376
|
|
374
377
|
|
375
378
|
|
@@ -390,15 +393,15 @@
|
|
390
393
|
<pre class="lines">
|
391
394
|
|
392
395
|
|
393
|
-
5
|
394
396
|
6
|
395
|
-
7
|
397
|
+
7
|
398
|
+
8</pre>
|
396
399
|
</td>
|
397
400
|
<td>
|
398
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line
|
401
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line 6</span>
|
399
402
|
|
400
|
-
<span class='kw'>def</span> <span class='id identifier
|
401
|
-
<span class='ivar'>@
|
403
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_anchormodel_class'>anchormodel_class</span>
|
404
|
+
<span class='ivar'>@anchormodel_class</span>
|
402
405
|
<span class='kw'>end</span></pre>
|
403
406
|
</td>
|
404
407
|
</tr>
|
@@ -408,9 +411,9 @@
|
|
408
411
|
|
409
412
|
<span id=""></span>
|
410
413
|
<div class="method_details ">
|
411
|
-
<h3 class="signature " id="
|
414
|
+
<h3 class="signature " id="attribute_name-instance_method">
|
412
415
|
|
413
|
-
#<strong>
|
416
|
+
#<strong>attribute_name</strong> ⇒ <tt>Object</tt> <span class="extras">(readonly)</span>
|
414
417
|
|
415
418
|
|
416
419
|
|
@@ -431,32 +434,27 @@
|
|
431
434
|
<pre class="lines">
|
432
435
|
|
433
436
|
|
437
|
+
5
|
434
438
|
6
|
435
|
-
7
|
436
|
-
8</pre>
|
439
|
+
7</pre>
|
437
440
|
</td>
|
438
441
|
<td>
|
439
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line
|
442
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line 5</span>
|
440
443
|
|
441
|
-
<span class='kw'>def</span> <span class='id identifier
|
442
|
-
<span class='ivar'>@
|
444
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_attribute_name'>attribute_name</span>
|
445
|
+
<span class='ivar'>@attribute_name</span>
|
443
446
|
<span class='kw'>end</span></pre>
|
444
447
|
</td>
|
445
448
|
</tr>
|
446
449
|
</table>
|
447
450
|
</div>
|
448
451
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
<
|
453
|
-
<h2>Instance Method Details</h2>
|
454
|
-
|
455
|
-
|
456
|
-
<div class="method_details first">
|
457
|
-
<h3 class="signature first" id="anchor_class-instance_method">
|
452
|
+
|
453
|
+
<span id=""></span>
|
454
|
+
<div class="method_details ">
|
455
|
+
<h3 class="signature " id="optional-instance_method">
|
458
456
|
|
459
|
-
#<strong>
|
457
|
+
#<strong>optional</strong> ⇒ <tt>Object</tt> <span class="extras">(readonly)</span>
|
460
458
|
|
461
459
|
|
462
460
|
|
@@ -465,8 +463,6 @@
|
|
465
463
|
</h3><div class="docstring">
|
466
464
|
<div class="discussion">
|
467
465
|
|
468
|
-
<p>Getter for the Anchormodel class based on the name passed to the initializer. We are loading the anchor class lazily, because the model mixin instanciates this statically -> avoid premature anchor class loading</p>
|
469
|
-
|
470
466
|
|
471
467
|
</div>
|
472
468
|
</div>
|
@@ -479,15 +475,15 @@
|
|
479
475
|
<pre class="lines">
|
480
476
|
|
481
477
|
|
482
|
-
|
483
|
-
|
484
|
-
|
478
|
+
7
|
479
|
+
8
|
480
|
+
9</pre>
|
485
481
|
</td>
|
486
482
|
<td>
|
487
|
-
<pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line
|
483
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/attribute.rb', line 7</span>
|
488
484
|
|
489
|
-
<span class='kw'>def</span> <span class='id identifier
|
490
|
-
<span class='ivar'>@
|
485
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_optional'>optional</span>
|
486
|
+
<span class='ivar'>@optional</span>
|
491
487
|
<span class='kw'>end</span></pre>
|
492
488
|
</td>
|
493
489
|
</tr>
|
@@ -496,10 +492,11 @@
|
|
496
492
|
|
497
493
|
</div>
|
498
494
|
|
495
|
+
|
499
496
|
</div>
|
500
497
|
|
501
498
|
<div id="footer">
|
502
|
-
Generated on Wed Jan
|
499
|
+
Generated on Wed Jan 25 12:36:40 2023 by
|
503
500
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
504
501
|
0.9.28 (ruby-3.1.3).
|
505
502
|
</div>
|