anchormodel 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -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 +5 -5
- 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 +4 -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 +65 -1
- 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 +3 -1
- 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: c228e4a1d684b6404a0f1376566680fecb2b458b5e0d5f9df0b41ab11b3facba
|
4
|
+
data.tar.gz: db3a4648ac8d41ca4bed6d9d540777e4c9a42b9e52e3500df2d5826429ef5b59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5a8c1d45cba54da1a1061f9c680111cbdfbe00daa33e95883540777f96bfa3f070cadfc07ffaff6898d65d8111004851e4054475e6d611e5a1d48804e635e48
|
7
|
+
data.tar.gz: bf2fcc0048940551e969112f4ad522743bddc8d4c1fd84c3a45d6fc0161e99dc006db06c0480ebbd19afef3cbaa403d6b9dcbaf4dec294b14271c4de6bdbf697
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# Unreleased
|
2
|
+
|
3
|
+
- Add boolean accessor directly to all anchormodels
|
4
|
+
- Add ActiveRecord::Enum style readers, writers and scopes to the model
|
5
|
+
- Attribute#anchor_class is now called `anchormodel_class`.
|
6
|
+
|
1
7
|
# 0.1.0 (18.01.2023)
|
2
8
|
|
3
9
|
- 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.edge)
|
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.1 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.1"
|
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-24"
|
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
@@ -429,8 +429,8 @@
|
|
429
429
|
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value.rb', line 29</span>
|
430
430
|
|
431
431
|
<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='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
|
433
|
-
<span class='kw'>return</span> <span class='ivar'>@attribute</span><span class='period'>.</span><span class='id identifier
|
432
|
+
<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>
|
433
|
+
<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
434
|
<span class='kw'>end</span></pre>
|
435
435
|
</td>
|
436
436
|
</tr>
|
@@ -485,11 +485,11 @@
|
|
485
485
|
<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>
|
486
486
|
<span class='kw'>return</span> <span class='kw'>case</span> <span class='id identifier rubyid_value'>value</span>
|
487
487
|
<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
|
488
|
+
<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
489
|
<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
490
|
<span class='kw'>end</span>
|
491
491
|
<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
|
492
|
+
<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
493
|
<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
494
|
<span class='kw'>when</span> <span class='kw'>nil</span>
|
495
495
|
<span class='kw'>nil</span>
|
@@ -507,7 +507,7 @@
|
|
507
507
|
</div>
|
508
508
|
|
509
509
|
<div id="footer">
|
510
|
-
Generated on
|
510
|
+
Generated on Tue Jan 24 20:27:59 2023 by
|
511
511
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
512
512
|
0.9.28 (ruby-3.1.3).
|
513
513
|
</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
|
499
|
+
Generated on Tue Jan 24 20:27:59 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>
|