anchormodel 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +36 -1
- data/VERSION +1 -1
- data/anchormodel.gemspec +5 -5
- data/doc/Anchormodel/ActiveModelTypeValueSingle.html +615 -0
- data/doc/Anchormodel/Attribute.html +3 -3
- data/doc/Anchormodel/ModelMixin.html +3 -3
- data/doc/Anchormodel/Util.html +496 -0
- data/doc/Anchormodel/Version.html +3 -3
- data/doc/Anchormodel.html +5 -5
- data/doc/AnchormodelGenerator.html +201 -0
- data/doc/_index.html +51 -4
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +35 -4
- data/doc/frames.html +5 -10
- data/doc/index.html +35 -4
- data/doc/method_list.html +17 -9
- data/doc/top-level-namespace.html +4 -4
- data/lib/anchormodel/simple_form_inputs/anchormodel_input.rb +21 -0
- data/lib/anchormodel/simple_form_inputs/anchormodel_radio_buttons_input.rb +23 -0
- data/lib/anchormodel/simple_form_inputs/helpers/anchormodel_inputs_common.rb +49 -0
- data/lib/anchormodel.rb +3 -0
- metadata +9 -4
- data/pkg/anchormodel-0.1.3.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0321a1c26ba215c332b2b496cefda3a5a1459f82599dc2655e16368e53af351e
|
4
|
+
data.tar.gz: 4361b8edc741f1509f460fc579d1f3e3ded9e59f0ae1d8ff623da6bee6502f4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a18303288bcf7aac1a46d6de54f4adc631a8ff535c37a401a39beda41f762cf2cf94d11a266367e80026fefddb3fb0174b826be9f0f5e6fb4e036286e99d4f89
|
7
|
+
data.tar.gz: 22a389c15f1cc54f9e7fb9b20b9b54683db85cbcbbd16cfc9fb42c900221665d1969c79cbfe8a3f290efaf8a472f1e2d3fed9f050b2c27b2d818abc12c3f0a03
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -35,7 +35,7 @@ are regular classes and can easily be extended.
|
|
35
35
|
|
36
36
|
### ActiveEnum
|
37
37
|
|
38
|
-
The gem (
|
38
|
+
The gem [ActiveEnum](https://github.com/adzap/active_enum) allows to create
|
39
39
|
Enum-like classes that can be extended. However it only supports Integer keys. I
|
40
40
|
find this unsatisfactory, as debugging with tools like `psql` or `mysql` is made
|
41
41
|
unnecessarily hard when you only see numbers. Keys for enums should be
|
@@ -116,6 +116,41 @@ puts("User #{@user.name} has role #{@user.role.label}")
|
|
116
116
|
@user.role.admin? # true if and only if the role is admin (false otherwise)
|
117
117
|
```
|
118
118
|
|
119
|
+
Your form could look something like this:
|
120
|
+
|
121
|
+
```erb
|
122
|
+
<%= form_with(model: user) do |form| %>
|
123
|
+
<%# ... %>
|
124
|
+
<%= form.collection_select :role, Role.all, :key, :label %>
|
125
|
+
<%# ... %>
|
126
|
+
<% end %>
|
127
|
+
```
|
128
|
+
|
129
|
+
## Using Anchormodel with Simpleform
|
130
|
+
|
131
|
+
Anchormodel has built-in support for the [simple_form](https://github.com/heartcombo/simple_form) gem by providing an input for the type `:anchormodel` which displays anchormodel attributes as a collection select.
|
132
|
+
|
133
|
+
After SimpleForm is installed, you can write your form as:
|
134
|
+
|
135
|
+
```erb
|
136
|
+
<%= simple_form_for user do |f| %>
|
137
|
+
<%# ... %>
|
138
|
+
<%= f.input :role %>
|
139
|
+
<%# ... %>
|
140
|
+
<% end %>
|
141
|
+
```
|
142
|
+
|
143
|
+
Or, if you prefer radio buttons instead:
|
144
|
+
|
145
|
+
|
146
|
+
```erb
|
147
|
+
<%= simple_form_for user do |f| %>
|
148
|
+
<%# ... %>
|
149
|
+
<%= f.input :role, as: :anchormodel_radio_buttons %>
|
150
|
+
<%# ... %>
|
151
|
+
<% end %>
|
152
|
+
```
|
153
|
+
|
119
154
|
# Rails Enum style model methods
|
120
155
|
|
121
156
|
By default, Anchormodel adds three kinds of methods for each key to the model:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/anchormodel.gemspec
CHANGED
@@ -2,21 +2,21 @@
|
|
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.5 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.5".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-04-
|
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, "
|
14
|
+
s.date = "2024-04-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, "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]
|
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.5.
|
19
|
+
s.rubygems_version = "3.5.9".freeze
|
20
20
|
s.summary = "Bringing object-oriented programming to Rails enums".freeze
|
21
21
|
|
22
22
|
s.specification_version = 4
|