anchormodel 0.1.5 → 0.2.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 +9 -0
- data/Gemfile.lock +6 -6
- data/README.md +78 -2
- data/VERSION +1 -1
- data/anchormodel.gemspec +4 -4
- data/doc/Anchormodel/ActiveModelTypeValueMulti.html +410 -0
- data/doc/Anchormodel/ActiveModelTypeValueSingle.html +113 -31
- data/doc/Anchormodel/Attribute.html +109 -9
- data/doc/Anchormodel/ModelMixin.html +3 -92
- data/doc/Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html +267 -0
- data/doc/Anchormodel/SimpleFormInputs/Helpers.html +124 -0
- data/doc/Anchormodel/SimpleFormInputs.html +124 -0
- data/doc/Anchormodel/Util.html +131 -15
- data/doc/Anchormodel/Version.html +3 -3
- data/doc/Anchormodel.html +97 -32
- data/doc/AnchormodelCheckBoxesInput.html +140 -0
- data/doc/AnchormodelGenerator.html +3 -3
- data/doc/AnchormodelInput.html +140 -0
- data/doc/AnchormodelRadioButtonsInput.html +140 -0
- data/doc/_index.html +16 -4
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +77 -5
- data/doc/frames.html +1 -1
- data/doc/index.html +77 -5
- data/doc/method_list.html +49 -9
- data/doc/top-level-namespace.html +4 -4
- data/lib/anchormodel/active_model_type_value_multi.rb +31 -0
- data/lib/anchormodel/active_model_type_value_single.rb +4 -2
- data/lib/anchormodel/attribute.rb +7 -1
- data/lib/anchormodel/model_mixin.rb +7 -0
- data/lib/anchormodel/simple_form_inputs/anchormodel_check_boxes_input.rb +23 -0
- data/lib/anchormodel/simple_form_inputs/helpers/anchormodel_inputs_common.rb +7 -3
- data/lib/anchormodel/util.rb +57 -7
- data/lib/anchormodel.rb +7 -0
- data/test/active_record_model/user_test.rb +73 -9
- data/test/dummy/app/anchormodels/animal.rb +6 -0
- data/test/dummy/app/models/user.rb +1 -0
- data/test/dummy/db/migrate/20240425182000_add_animals_to_users.rb +5 -0
- data/test/dummy/db/schema.rb +2 -1
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed4bd0c17821f7d02d71d71b648f09c271e9a7e6aa5cddaf6f0cb6ec374655d6
|
4
|
+
data.tar.gz: 8d0f1e82b272fd47e18615706e6a9223d578d4f393192ef7b455f0bb1256e61f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 119574b8aa308a71fb3d2b71778486701bc77455938e52f940e64ce28c12927c33a28557315737f9d2faced63535c43b990359a802ce9be0a9b48b2bb4714ccb
|
7
|
+
data.tar.gz: 41fd2339af1acbaa8a59cd7ea41966c30adb22dc710e2bd7a9dec56d5c6aadfd2032837e6ad8be07d9b78db3c6c9db0c7bb80d5309df6bc563e956861ba08048
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# 0.2.1 (22.05.2024)
|
2
|
+
|
3
|
+
- Stop enforcing include_blank for SimpleForm, due to https://github.com/heartcombo/simple_form/issues/1427
|
4
|
+
|
5
|
+
# 0.2.0 (27.04.2024)
|
6
|
+
|
7
|
+
- Add support for multiple anchormodels (`belongs_to_anchormodels`)
|
8
|
+
- Implement YourAnchormodelclass.form_collection
|
9
|
+
|
1
10
|
# 0.1.5 (24.04.2024)
|
2
11
|
|
3
12
|
- Enhance documentation
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
anchormodel (0.1.
|
4
|
+
anchormodel (0.2.1.edge)
|
5
5
|
rails (~> 7.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -102,7 +102,7 @@ GEM
|
|
102
102
|
builder
|
103
103
|
minitest (>= 5.0)
|
104
104
|
ruby-progressbar
|
105
|
-
net-imap (0.4.
|
105
|
+
net-imap (0.4.11)
|
106
106
|
date
|
107
107
|
net-protocol
|
108
108
|
net-pop (0.1.2)
|
@@ -111,8 +111,8 @@ GEM
|
|
111
111
|
timeout
|
112
112
|
net-smtp (0.5.0)
|
113
113
|
net-protocol
|
114
|
-
nio4r (2.7.
|
115
|
-
nokogiri (1.16.
|
114
|
+
nio4r (2.7.3)
|
115
|
+
nokogiri (1.16.5-x86_64-linux)
|
116
116
|
racc (~> 1.4)
|
117
117
|
parallel (1.22.1)
|
118
118
|
parser (3.2.0.0)
|
@@ -120,7 +120,7 @@ GEM
|
|
120
120
|
pry (0.14.1)
|
121
121
|
coderay (~> 1.1)
|
122
122
|
method_source (~> 1.0)
|
123
|
-
racc (1.
|
123
|
+
racc (1.8.0)
|
124
124
|
rack (2.2.5)
|
125
125
|
rack-test (2.1.0)
|
126
126
|
rack (>= 1.3)
|
@@ -187,7 +187,7 @@ GEM
|
|
187
187
|
webrick (~> 1.7.0)
|
188
188
|
yard-activesupport-concern (0.0.1)
|
189
189
|
yard (>= 0.8)
|
190
|
-
zeitwerk (2.6.
|
190
|
+
zeitwerk (2.6.14)
|
191
191
|
|
192
192
|
PLATFORMS
|
193
193
|
x86_64-linux
|
data/README.md
CHANGED
@@ -223,6 +223,82 @@ If you want to have multiple attributes in the same model pointing to the same A
|
|
223
223
|
|
224
224
|
```ruby
|
225
225
|
# app/models/user.rb
|
226
|
-
|
227
|
-
|
226
|
+
belongs_to_anchormodel :role
|
227
|
+
belongs_to_anchormodel :secondary_role, Role, model_methods: false
|
228
|
+
```
|
229
|
+
|
230
|
+
# Attaching multiple Anchormodels to an attribute (similar to a has_many collection)
|
231
|
+
|
232
|
+
Collections of Anchormodels are supported. Assuming that your `User` can have multiple `Role` anchormodels, your code can look as follows:
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
# app/models/user.rb
|
236
|
+
belongs_to_anchormodels :roles
|
237
|
+
```
|
238
|
+
|
239
|
+
The method is deliberately called `belongs_to...` and not `has_many...` in order to indicate that the key is stored in a column of the model in which you are calling it. The rule of thumb for using a collection of Anchormodels is:
|
240
|
+
|
241
|
+
- Your column should be of type `string`, just like with the singular `belongs_to_anchormodel`.
|
242
|
+
- Anchormodels will be stored in string form, separated by the `,` character
|
243
|
+
- When reading the attribute, you will get a `Set`, thus duplicates are avoided.
|
244
|
+
|
245
|
+
Example usage for a User model with multiple roles as shown above:
|
246
|
+
|
247
|
+
```ruby
|
248
|
+
u = User.first
|
249
|
+
u.roles = %i[moderator admin] # this will replace the user's roles by the two specified
|
250
|
+
u.roles # this will return a set of two Role Anchormodel instances, moderator and role
|
251
|
+
u.guest! # this will add the role `guest` to the user's roles
|
252
|
+
u.guest? # this will query whether the role `guest` is part of the user's roles
|
253
|
+
User.moderator # This will return all users that have the moderator role as part of their roles
|
254
|
+
```
|
255
|
+
|
256
|
+
For modifying a collection of Anchormodels, the following methods are implemented, the first three accepting a String, Symbol or Anchormodel:
|
257
|
+
|
258
|
+
```ruby
|
259
|
+
u.roles.add(:moderator) # same as u.moderator!
|
260
|
+
u.roles << :moderator # alias of add
|
261
|
+
u.roles.delete(:moderator)
|
262
|
+
u.roles.clear
|
263
|
+
```
|
264
|
+
|
265
|
+
Note that no other methods of Set are overwritten at this point - if you use any other methods mutating the underlying Set, your changes will not be applied.
|
266
|
+
|
267
|
+
## Basic rails form for a collection of Anchormodels
|
268
|
+
|
269
|
+
```erb
|
270
|
+
<%= form_with(model: user) do |form| %>
|
271
|
+
<%# ... %>
|
272
|
+
<%= form.collection_select :role, Role.all, :key, :label, multiple: true %>
|
273
|
+
<%# ... %>
|
274
|
+
<% end %>
|
275
|
+
```
|
276
|
+
|
277
|
+
If you get an error due to unpermitted params, make sure, you are allowing array-style parameters: `params.require(:user).permit(roles: [])`
|
278
|
+
|
279
|
+
## SimpleForm for a collection of Anchormodels
|
280
|
+
|
281
|
+
Anchormodel's [simple_form](https://github.com/heartcombo/simple_form) support also includes collections of Anchormodels.
|
282
|
+
|
283
|
+
Just like in the single Anchormodel implementation, a select input can be provided with:
|
284
|
+
|
285
|
+
```erb
|
286
|
+
<%= simple_form_for user do |f| %>
|
287
|
+
<%# ... %>
|
288
|
+
<%= f.input :role %>
|
289
|
+
<%# ... %>
|
290
|
+
<% end %>
|
291
|
+
```
|
292
|
+
|
293
|
+
The input figures out automatically that it is operating on a collection, so the form code is the same as for a single Anchormodel.
|
294
|
+
|
295
|
+
However, radio buttons are unsuitable for collections, so use check boxes instead:
|
296
|
+
|
297
|
+
|
298
|
+
```erb
|
299
|
+
<%= simple_form_for user do |f| %>
|
300
|
+
<%# ... %>
|
301
|
+
<%= f.input :role, as: :anchormodel_check_boxes %>
|
302
|
+
<%# ... %>
|
303
|
+
<% end %>
|
228
304
|
```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1
|
1
|
+
0.2.1
|
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.2.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.2.1".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 = "2024-
|
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/ActiveModelTypeValueSingle.html".freeze, "doc/Anchormodel/Attribute.html".freeze, "doc/Anchormodel/ModelMixin.html".freeze, "doc/Anchormodel/Util.html".freeze, "doc/Anchormodel/Version.html".freeze, "doc/AnchormodelGenerator.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/simple_form_inputs/anchormodel_input.rb".freeze, "lib/anchormodel/simple_form_inputs/anchormodel_radio_buttons_input.rb".freeze, "lib/anchormodel/simple_form_inputs/helpers/anchormodel_inputs_common.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, "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 = "2024-05-22"
|
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/ActiveModelTypeValueMulti.html".freeze, "doc/Anchormodel/ActiveModelTypeValueSingle.html".freeze, "doc/Anchormodel/Attribute.html".freeze, "doc/Anchormodel/ModelMixin.html".freeze, "doc/Anchormodel/SimpleFormInputs.html".freeze, "doc/Anchormodel/SimpleFormInputs/Helpers.html".freeze, "doc/Anchormodel/SimpleFormInputs/Helpers/AnchormodelInputsCommon.html".freeze, "doc/Anchormodel/Util.html".freeze, "doc/Anchormodel/Version.html".freeze, "doc/AnchormodelCheckBoxesInput.html".freeze, "doc/AnchormodelGenerator.html".freeze, "doc/AnchormodelInput.html".freeze, "doc/AnchormodelRadioButtonsInput.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_multi.rb".freeze, "lib/anchormodel/active_model_type_value_single.rb".freeze, "lib/anchormodel/attribute.rb".freeze, "lib/anchormodel/model_mixin.rb".freeze, "lib/anchormodel/simple_form_inputs/anchormodel_check_boxes_input.rb".freeze, "lib/anchormodel/simple_form_inputs/anchormodel_input.rb".freeze, "lib/anchormodel/simple_form_inputs/anchormodel_radio_buttons_input.rb".freeze, "lib/anchormodel/simple_form_inputs/helpers/anchormodel_inputs_common.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, "test/active_record_model/user_test.rb".freeze, "test/dummy/.gitignore".freeze, "test/dummy/Rakefile".freeze, "test/dummy/app/anchormodels/animal.rb".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/migrate/20240425182000_add_animals_to_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)
|
@@ -0,0 +1,410 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Class: Anchormodel::ActiveModelTypeValueMulti
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.34
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "Anchormodel::ActiveModelTypeValueMulti";
|
19
|
+
relpath = '../';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="../class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="../_index.html">Index (A)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">ActiveModelTypeValueMulti</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="../class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Class: Anchormodel::ActiveModelTypeValueMulti
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
<dl>
|
70
|
+
<dt>Inherits:</dt>
|
71
|
+
<dd>
|
72
|
+
<span class="inheritName"><span class='object_link'><a href="ActiveModelTypeValueSingle.html" title="Anchormodel::ActiveModelTypeValueSingle (class)">ActiveModelTypeValueSingle</a></span></span>
|
73
|
+
|
74
|
+
<ul class="fullTree">
|
75
|
+
<li>Object</li>
|
76
|
+
|
77
|
+
<li class="next">ActiveModel::Type::Value</li>
|
78
|
+
|
79
|
+
<li class="next"><span class='object_link'><a href="ActiveModelTypeValueSingle.html" title="Anchormodel::ActiveModelTypeValueSingle (class)">ActiveModelTypeValueSingle</a></span></li>
|
80
|
+
|
81
|
+
<li class="next">Anchormodel::ActiveModelTypeValueMulti</li>
|
82
|
+
|
83
|
+
</ul>
|
84
|
+
<a href="#" class="inheritanceTree">show all</a>
|
85
|
+
|
86
|
+
</dd>
|
87
|
+
</dl>
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
<dl>
|
100
|
+
<dt>Defined in:</dt>
|
101
|
+
<dd>lib/anchormodel/active_model_type_value_multi.rb</dd>
|
102
|
+
</dl>
|
103
|
+
|
104
|
+
</div>
|
105
|
+
|
106
|
+
<div class="docstring">
|
107
|
+
<div class="discussion">
|
108
|
+
|
109
|
+
|
110
|
+
</div>
|
111
|
+
</div>
|
112
|
+
<div class="tags">
|
113
|
+
|
114
|
+
|
115
|
+
</div>
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
<h2>Instance Attribute Summary</h2>
|
122
|
+
|
123
|
+
<h3 class="inherited">Attributes inherited from <span class='object_link'><a href="ActiveModelTypeValueSingle.html" title="Anchormodel::ActiveModelTypeValueSingle (class)">ActiveModelTypeValueSingle</a></span></h3>
|
124
|
+
<p class="inherited"><span class='object_link'><a href="ActiveModelTypeValueSingle.html#attribute-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#attribute (method)">#attribute</a></span></p>
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
<h2>
|
129
|
+
Instance Method Summary
|
130
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
131
|
+
</h2>
|
132
|
+
|
133
|
+
<ul class="summary">
|
134
|
+
|
135
|
+
<li class="public ">
|
136
|
+
<span class="summary_signature">
|
137
|
+
|
138
|
+
<a href="#cast-instance_method" title="#cast (instance method)">#<strong>cast</strong>(values) ⇒ Object </a>
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
</span>
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
<span class="summary_desc"><div class='inline'>
|
153
|
+
<p>This converts DB or input to an Anchormodel instance.</p>
|
154
|
+
</div></span>
|
155
|
+
|
156
|
+
</li>
|
157
|
+
|
158
|
+
|
159
|
+
<li class="public ">
|
160
|
+
<span class="summary_signature">
|
161
|
+
|
162
|
+
<a href="#serializable%3F-instance_method" title="#serializable? (instance method)">#<strong>serializable?</strong>(values) ⇒ Boolean </a>
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
</span>
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
177
|
+
|
178
|
+
</li>
|
179
|
+
|
180
|
+
|
181
|
+
<li class="public ">
|
182
|
+
<span class="summary_signature">
|
183
|
+
|
184
|
+
<a href="#serialize-instance_method" title="#serialize (instance method)">#<strong>serialize</strong>(values) ⇒ Object </a>
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
</span>
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
<span class="summary_desc"><div class='inline'>
|
199
|
+
<p>This converts an Anchormodel instance to string for DB.</p>
|
200
|
+
</div></span>
|
201
|
+
|
202
|
+
</li>
|
203
|
+
|
204
|
+
|
205
|
+
</ul>
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
<h3 class="inherited">Methods inherited from <span class='object_link'><a href="ActiveModelTypeValueSingle.html" title="Anchormodel::ActiveModelTypeValueSingle (class)">ActiveModelTypeValueSingle</a></span></h3>
|
218
|
+
<p class="inherited"><span class='object_link'><a href="ActiveModelTypeValueSingle.html#changed_in_place%3F-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#changed_in_place? (method)">#changed_in_place?</a></span>, <span class='object_link'><a href="ActiveModelTypeValueSingle.html#initialize-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#initialize (method)">#initialize</a></span>, <span class='object_link'><a href="ActiveModelTypeValueSingle.html#type-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#type (method)">#type</a></span></p>
|
219
|
+
|
220
|
+
<div id="constructor_details" class="method_details_list">
|
221
|
+
<h2>Constructor Details</h2>
|
222
|
+
|
223
|
+
<p class="notice">This class inherits a constructor from <span class='object_link'><a href="ActiveModelTypeValueSingle.html#initialize-instance_method" title="Anchormodel::ActiveModelTypeValueSingle#initialize (method)">Anchormodel::ActiveModelTypeValueSingle</a></span></p>
|
224
|
+
|
225
|
+
</div>
|
226
|
+
|
227
|
+
|
228
|
+
<div id="instance_method_details" class="method_details_list">
|
229
|
+
<h2>Instance Method Details</h2>
|
230
|
+
|
231
|
+
|
232
|
+
<div class="method_details first">
|
233
|
+
<h3 class="signature first" id="cast-instance_method">
|
234
|
+
|
235
|
+
#<strong>cast</strong>(values) ⇒ <tt>Object</tt>
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
</h3><div class="docstring">
|
242
|
+
<div class="discussion">
|
243
|
+
|
244
|
+
<p>This converts DB or input to an Anchormodel instance</p>
|
245
|
+
|
246
|
+
|
247
|
+
</div>
|
248
|
+
</div>
|
249
|
+
<div class="tags">
|
250
|
+
|
251
|
+
|
252
|
+
</div><table class="source_code">
|
253
|
+
<tr>
|
254
|
+
<td>
|
255
|
+
<pre class="lines">
|
256
|
+
|
257
|
+
|
258
|
+
3
|
259
|
+
4
|
260
|
+
5</pre>
|
261
|
+
</td>
|
262
|
+
<td>
|
263
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_multi.rb', line 3</span>
|
264
|
+
|
265
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_cast'>cast</span><span class='lparen'>(</span><span class='id identifier rubyid_values'>values</span><span class='rparen'>)</span>
|
266
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>,</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_to_set'>to_set</span>
|
267
|
+
<span class='kw'>end</span></pre>
|
268
|
+
</td>
|
269
|
+
</tr>
|
270
|
+
</table>
|
271
|
+
</div>
|
272
|
+
|
273
|
+
<div class="method_details ">
|
274
|
+
<h3 class="signature " id="serializable?-instance_method">
|
275
|
+
|
276
|
+
#<strong>serializable?</strong>(values) ⇒ <tt>Boolean</tt>
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
</h3><div class="docstring">
|
283
|
+
<div class="discussion">
|
284
|
+
|
285
|
+
|
286
|
+
</div>
|
287
|
+
</div>
|
288
|
+
<div class="tags">
|
289
|
+
|
290
|
+
<p class="tag_title">Returns:</p>
|
291
|
+
<ul class="return">
|
292
|
+
|
293
|
+
<li>
|
294
|
+
|
295
|
+
|
296
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
</li>
|
301
|
+
|
302
|
+
</ul>
|
303
|
+
|
304
|
+
</div><table class="source_code">
|
305
|
+
<tr>
|
306
|
+
<td>
|
307
|
+
<pre class="lines">
|
308
|
+
|
309
|
+
|
310
|
+
21
|
311
|
+
22
|
312
|
+
23
|
313
|
+
24
|
314
|
+
25
|
315
|
+
26
|
316
|
+
27
|
317
|
+
28
|
318
|
+
29
|
319
|
+
30</pre>
|
320
|
+
</td>
|
321
|
+
<td>
|
322
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_multi.rb', line 21</span>
|
323
|
+
|
324
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_serializable?'>serializable?</span><span class='lparen'>(</span><span class='id identifier rubyid_values'>values</span><span class='rparen'>)</span>
|
325
|
+
<span class='kw'>return</span> <span class='kw'>case</span> <span class='id identifier rubyid_values'>values</span>
|
326
|
+
<span class='kw'>when</span> <span class='const'>Enumerable</span>
|
327
|
+
<span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>,</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
328
|
+
<span class='kw'>when</span> <span class='const'>String</span>
|
329
|
+
<span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>,</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span>
|
330
|
+
<span class='kw'>else</span>
|
331
|
+
<span class='kw'>false</span>
|
332
|
+
<span class='kw'>end</span>
|
333
|
+
<span class='kw'>end</span></pre>
|
334
|
+
</td>
|
335
|
+
</tr>
|
336
|
+
</table>
|
337
|
+
</div>
|
338
|
+
|
339
|
+
<div class="method_details ">
|
340
|
+
<h3 class="signature " id="serialize-instance_method">
|
341
|
+
|
342
|
+
#<strong>serialize</strong>(values) ⇒ <tt>Object</tt>
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
</h3><div class="docstring">
|
349
|
+
<div class="discussion">
|
350
|
+
|
351
|
+
<p>This converts an Anchormodel instance to string for DB</p>
|
352
|
+
|
353
|
+
|
354
|
+
</div>
|
355
|
+
</div>
|
356
|
+
<div class="tags">
|
357
|
+
|
358
|
+
|
359
|
+
</div><table class="source_code">
|
360
|
+
<tr>
|
361
|
+
<td>
|
362
|
+
<pre class="lines">
|
363
|
+
|
364
|
+
|
365
|
+
8
|
366
|
+
9
|
367
|
+
10
|
368
|
+
11
|
369
|
+
12
|
370
|
+
13
|
371
|
+
14
|
372
|
+
15
|
373
|
+
16
|
374
|
+
17
|
375
|
+
18
|
376
|
+
19</pre>
|
377
|
+
</td>
|
378
|
+
<td>
|
379
|
+
<pre class="code"><span class="info file"># File 'lib/anchormodel/active_model_type_value_multi.rb', line 8</span>
|
380
|
+
|
381
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_serialize'>serialize</span><span class='lparen'>(</span><span class='id identifier rubyid_values'>values</span><span class='rparen'>)</span>
|
382
|
+
<span class='kw'>return</span> <span class='kw'>case</span> <span class='id identifier rubyid_values'>values</span>
|
383
|
+
<span class='kw'>when</span> <span class='const'>Enumerable</span>
|
384
|
+
<span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>,</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
385
|
+
<span class='kw'>when</span> <span class='const'>String</span>
|
386
|
+
<span class='id identifier rubyid_values'>values</span>
|
387
|
+
<span class='kw'>when</span> <span class='kw'>nil</span>
|
388
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_end'>'</span></span>
|
389
|
+
<span class='kw'>else</span>
|
390
|
+
<span class='id identifier rubyid_fail'>fail</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 type </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
391
|
+
<span class='kw'>end</span>
|
392
|
+
<span class='kw'>end</span></pre>
|
393
|
+
</td>
|
394
|
+
</tr>
|
395
|
+
</table>
|
396
|
+
</div>
|
397
|
+
|
398
|
+
</div>
|
399
|
+
|
400
|
+
</div>
|
401
|
+
|
402
|
+
<div id="footer">
|
403
|
+
Generated on Wed May 22 11:24:43 2024 by
|
404
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
405
|
+
0.9.34 (ruby-3.2.2).
|
406
|
+
</div>
|
407
|
+
|
408
|
+
</div>
|
409
|
+
</body>
|
410
|
+
</html>
|