formtastic_tristate_radio 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/Gemfile.lock +162 -0
- data/MIT-LICENSE +20 -0
- data/README.md +8 -13
- data/config/locales/active_admin.yml +60 -0
- data/config/locales/formtastic.yml +48 -0
- data/formtastic_tristate_radio.gemspec +60 -0
- data/lib/formtastic_tristate_radio/missing_translation_error.rb +1 -1
- data/lib/formtastic_tristate_radio/version.rb +1 -1
- metadata +27 -13
- data/config/locales/active_admin.en.yml +0 -5
- data/config/locales/active_admin.ru.yml +0 -7
- data/config/locales/formtastic.en.yml +0 -4
- data/config/locales/formtastic.ru.yml +0 -6
- data/lib/tasks/formtastic_tristate_radio_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fdf4d000b01b98679b7b2e4eb9bbb8ac43e2bdec9dfe79aba6e07ed580f0cbf
|
4
|
+
data.tar.gz: 7734d39327b809b599b058362e091df2e6153749ff6cfad5a7cb7ac91756e1a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e67a6dfe2440683e483d9d2bb677b66a87d335625a1ca7622888e641b3b0c36d8602ef502708d2098e78b4d3f15985ca59b6105d17f661adb4e72ea5661f07a1
|
7
|
+
data.tar.gz: 9fcd6fe99ddfba81237d17305abcc6e1de6febcc05765c442c265bdb5293adaea88bd9364affac0c374929a4ebc1113cba8c98ad7eb82dd11440cde462fa7606
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
formtastic_tristate_radio (0.2.3)
|
5
|
+
formtastic (>= 3, < 5)
|
6
|
+
rails (>= 4, < 7)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actioncable (6.1.4.1)
|
12
|
+
actionpack (= 6.1.4.1)
|
13
|
+
activesupport (= 6.1.4.1)
|
14
|
+
nio4r (~> 2.0)
|
15
|
+
websocket-driver (>= 0.6.1)
|
16
|
+
actionmailbox (6.1.4.1)
|
17
|
+
actionpack (= 6.1.4.1)
|
18
|
+
activejob (= 6.1.4.1)
|
19
|
+
activerecord (= 6.1.4.1)
|
20
|
+
activestorage (= 6.1.4.1)
|
21
|
+
activesupport (= 6.1.4.1)
|
22
|
+
mail (>= 2.7.1)
|
23
|
+
actionmailer (6.1.4.1)
|
24
|
+
actionpack (= 6.1.4.1)
|
25
|
+
actionview (= 6.1.4.1)
|
26
|
+
activejob (= 6.1.4.1)
|
27
|
+
activesupport (= 6.1.4.1)
|
28
|
+
mail (~> 2.5, >= 2.5.4)
|
29
|
+
rails-dom-testing (~> 2.0)
|
30
|
+
actionpack (6.1.4.1)
|
31
|
+
actionview (= 6.1.4.1)
|
32
|
+
activesupport (= 6.1.4.1)
|
33
|
+
rack (~> 2.0, >= 2.0.9)
|
34
|
+
rack-test (>= 0.6.3)
|
35
|
+
rails-dom-testing (~> 2.0)
|
36
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
37
|
+
actiontext (6.1.4.1)
|
38
|
+
actionpack (= 6.1.4.1)
|
39
|
+
activerecord (= 6.1.4.1)
|
40
|
+
activestorage (= 6.1.4.1)
|
41
|
+
activesupport (= 6.1.4.1)
|
42
|
+
nokogiri (>= 1.8.5)
|
43
|
+
actionview (6.1.4.1)
|
44
|
+
activesupport (= 6.1.4.1)
|
45
|
+
builder (~> 3.1)
|
46
|
+
erubi (~> 1.4)
|
47
|
+
rails-dom-testing (~> 2.0)
|
48
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
49
|
+
activejob (6.1.4.1)
|
50
|
+
activesupport (= 6.1.4.1)
|
51
|
+
globalid (>= 0.3.6)
|
52
|
+
activemodel (6.1.4.1)
|
53
|
+
activesupport (= 6.1.4.1)
|
54
|
+
activerecord (6.1.4.1)
|
55
|
+
activemodel (= 6.1.4.1)
|
56
|
+
activesupport (= 6.1.4.1)
|
57
|
+
activestorage (6.1.4.1)
|
58
|
+
actionpack (= 6.1.4.1)
|
59
|
+
activejob (= 6.1.4.1)
|
60
|
+
activerecord (= 6.1.4.1)
|
61
|
+
activesupport (= 6.1.4.1)
|
62
|
+
marcel (~> 1.0.0)
|
63
|
+
mini_mime (>= 1.1.0)
|
64
|
+
activesupport (6.1.4.1)
|
65
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
66
|
+
i18n (>= 1.6, < 2)
|
67
|
+
minitest (>= 5.1)
|
68
|
+
tzinfo (~> 2.0)
|
69
|
+
zeitwerk (~> 2.3)
|
70
|
+
builder (3.2.4)
|
71
|
+
concurrent-ruby (1.1.9)
|
72
|
+
crass (1.0.6)
|
73
|
+
diff-lcs (1.4.4)
|
74
|
+
erubi (1.10.0)
|
75
|
+
formtastic (4.0.0)
|
76
|
+
actionpack (>= 5.2.0)
|
77
|
+
globalid (0.5.2)
|
78
|
+
activesupport (>= 5.0)
|
79
|
+
i18n (1.8.11)
|
80
|
+
concurrent-ruby (~> 1.0)
|
81
|
+
loofah (2.12.0)
|
82
|
+
crass (~> 1.0.2)
|
83
|
+
nokogiri (>= 1.5.9)
|
84
|
+
mail (2.7.1)
|
85
|
+
mini_mime (>= 0.1.1)
|
86
|
+
marcel (1.0.2)
|
87
|
+
method_source (1.0.0)
|
88
|
+
mini_mime (1.1.2)
|
89
|
+
minitest (5.14.4)
|
90
|
+
nio4r (2.5.8)
|
91
|
+
nokogiri (1.12.5-x86_64-darwin)
|
92
|
+
racc (~> 1.4)
|
93
|
+
racc (1.6.0)
|
94
|
+
rack (2.2.3)
|
95
|
+
rack-test (1.1.0)
|
96
|
+
rack (>= 1.0, < 3)
|
97
|
+
rails (6.1.4.1)
|
98
|
+
actioncable (= 6.1.4.1)
|
99
|
+
actionmailbox (= 6.1.4.1)
|
100
|
+
actionmailer (= 6.1.4.1)
|
101
|
+
actionpack (= 6.1.4.1)
|
102
|
+
actiontext (= 6.1.4.1)
|
103
|
+
actionview (= 6.1.4.1)
|
104
|
+
activejob (= 6.1.4.1)
|
105
|
+
activemodel (= 6.1.4.1)
|
106
|
+
activerecord (= 6.1.4.1)
|
107
|
+
activestorage (= 6.1.4.1)
|
108
|
+
activesupport (= 6.1.4.1)
|
109
|
+
bundler (>= 1.15.0)
|
110
|
+
railties (= 6.1.4.1)
|
111
|
+
sprockets-rails (>= 2.0.0)
|
112
|
+
rails-dom-testing (2.0.3)
|
113
|
+
activesupport (>= 4.2.0)
|
114
|
+
nokogiri (>= 1.6)
|
115
|
+
rails-html-sanitizer (1.4.2)
|
116
|
+
loofah (~> 2.3)
|
117
|
+
railties (6.1.4.1)
|
118
|
+
actionpack (= 6.1.4.1)
|
119
|
+
activesupport (= 6.1.4.1)
|
120
|
+
method_source
|
121
|
+
rake (>= 0.13)
|
122
|
+
thor (~> 1.0)
|
123
|
+
rake (13.0.6)
|
124
|
+
rspec (3.10.0)
|
125
|
+
rspec-core (~> 3.10.0)
|
126
|
+
rspec-expectations (~> 3.10.0)
|
127
|
+
rspec-mocks (~> 3.10.0)
|
128
|
+
rspec-core (3.10.1)
|
129
|
+
rspec-support (~> 3.10.0)
|
130
|
+
rspec-expectations (3.10.1)
|
131
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
132
|
+
rspec-support (~> 3.10.0)
|
133
|
+
rspec-mocks (3.10.2)
|
134
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
135
|
+
rspec-support (~> 3.10.0)
|
136
|
+
rspec-support (3.10.3)
|
137
|
+
sprockets (4.0.2)
|
138
|
+
concurrent-ruby (~> 1.0)
|
139
|
+
rack (> 1, < 3)
|
140
|
+
sprockets-rails (3.2.2)
|
141
|
+
actionpack (>= 4.0)
|
142
|
+
activesupport (>= 4.0)
|
143
|
+
sprockets (>= 3.0.0)
|
144
|
+
thor (1.1.0)
|
145
|
+
tzinfo (2.0.4)
|
146
|
+
concurrent-ruby (~> 1.0)
|
147
|
+
websocket-driver (0.7.5)
|
148
|
+
websocket-extensions (>= 0.1.0)
|
149
|
+
websocket-extensions (0.1.5)
|
150
|
+
yard (0.9.26)
|
151
|
+
zeitwerk (2.5.1)
|
152
|
+
|
153
|
+
PLATFORMS
|
154
|
+
x86_64-darwin-17
|
155
|
+
|
156
|
+
DEPENDENCIES
|
157
|
+
formtastic_tristate_radio!
|
158
|
+
rspec (~> 3)
|
159
|
+
yard (>= 0.9.20, < 1)
|
160
|
+
|
161
|
+
BUNDLED WITH
|
162
|
+
2.2.27
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2021 Sergey Pedan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -27,8 +27,7 @@ Some may consider this practice questionable — I don’t think so. In real
|
|
27
27
|
For a Boolean column with 3 possible states:
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
f.input :am_i_awake,
|
31
|
-
f.input :is_this_a_dream, as: :tristate_radio, null: "Reality is a persistent hallucination"
|
30
|
+
f.input :am_i_awake, as: :tristate_radio
|
32
31
|
```
|
33
32
|
|
34
33
|
You get (HTML is simplified, actually there are more classes etc.):
|
@@ -40,13 +39,6 @@ You get (HTML is simplified, actually there are more classes etc.):
|
|
40
39
|
<input name="am_i_awake" type="radio" value="false"> <label>No</label>
|
41
40
|
<input name="am_i_awake" type="radio" value="null"> <label>Unset</label>
|
42
41
|
</fieldset>
|
43
|
-
|
44
|
-
<fieldset>
|
45
|
-
<legend>Is this a dream?</legend>
|
46
|
-
<input name="is_this_a_dream" type="radio" value="true"> <label>Yes</label>
|
47
|
-
<input name="is_this_a_dream" type="radio" value="false"> <label>No</label>
|
48
|
-
<input name="is_this_a_dream" type="radio" value="null"> <label>Reality is a persistent hallucination</label>
|
49
|
-
</fieldset>
|
50
42
|
```
|
51
43
|
|
52
44
|
|
@@ -106,15 +98,17 @@ end
|
|
106
98
|
which will result in:
|
107
99
|
|
108
100
|
```html
|
109
|
-
<input
|
101
|
+
<input type="radio" name="am_i_awake" value="true">
|
102
|
+
<input type="radio" name="am_i_awake" value="false">
|
103
|
+
<input type="radio" name="am_i_awake" value="__unset">
|
110
104
|
```
|
111
105
|
|
112
|
-
Mind that for
|
106
|
+
Mind that for your custom value to work, you also need to configure `ActiveModel` to recognize that value as `nil`. Currently that is done [like so](https://github.com/sergeypedan/formtastic-tristate-radio/blob/master/config/initializers/activemodel_type_boolean.rb#L9).
|
113
107
|
|
114
108
|
|
115
109
|
## Documentation
|
116
110
|
|
117
|
-
Low-level methods are properly documented in RubyDoc [here](https://www.rubydoc.info/gems/formtastic_tristate_radio/).
|
111
|
+
Low-level methods are properly documented in RubyDoc [here](https://www.rubydoc.info/gems/formtastic_tristate_radio/TristateRadioInput).
|
118
112
|
|
119
113
|
|
120
114
|
## Dependencies
|
@@ -136,7 +130,7 @@ In Ruby any String is cast to `true`:
|
|
136
130
|
|
137
131
|
Web form params are passed as plain text and are interpreted as String by Rack.
|
138
132
|
|
139
|
-
So how Boolean values
|
133
|
+
So how are Boolean values transfered as strings if a `"no"` or `"0"` and even `""` is truthy in Ruby?
|
140
134
|
|
141
135
|
Frameworks just have a list of string values to be recognized and mapped to Boolean values:
|
142
136
|
|
@@ -193,6 +187,7 @@ ActiveModel::Type::Boolean.new.cast(:nil) #=> nil
|
|
193
187
|
|
194
188
|
## Roadmap
|
195
189
|
|
190
|
+
- [ ] Remove `require_relative "../app/models/active_record/base"` from main file
|
196
191
|
- [x] Make the gem configurable
|
197
192
|
- [x] Pull the key used for “unset” choice value into configuration
|
198
193
|
- [ ] Load translations from gem
|
@@ -0,0 +1,60 @@
|
|
1
|
+
---
|
2
|
+
ca:
|
3
|
+
active_admin:
|
4
|
+
status_tag:
|
5
|
+
:null: No establert
|
6
|
+
---
|
7
|
+
de:
|
8
|
+
active_admin:
|
9
|
+
status_tag:
|
10
|
+
:null: Nicht eingestellt
|
11
|
+
---
|
12
|
+
fr:
|
13
|
+
active_admin:
|
14
|
+
status_tag:
|
15
|
+
:null: Pas défini
|
16
|
+
---
|
17
|
+
it:
|
18
|
+
active_admin:
|
19
|
+
status_tag:
|
20
|
+
:null: Sconosciuto
|
21
|
+
---
|
22
|
+
ja:
|
23
|
+
active_admin:
|
24
|
+
status_tag:
|
25
|
+
:null: 不明
|
26
|
+
---
|
27
|
+
en:
|
28
|
+
active_admin:
|
29
|
+
status_tag:
|
30
|
+
:null: Unset
|
31
|
+
---
|
32
|
+
es:
|
33
|
+
active_admin:
|
34
|
+
status_tag:
|
35
|
+
:null: No establecido
|
36
|
+
---
|
37
|
+
pl:
|
38
|
+
active_admin:
|
39
|
+
status_tag:
|
40
|
+
:null: Nie ustawiony
|
41
|
+
---
|
42
|
+
pt-BR:
|
43
|
+
active_admin:
|
44
|
+
status_tag:
|
45
|
+
:null: Não configurado
|
46
|
+
---
|
47
|
+
pt:
|
48
|
+
active_admin:
|
49
|
+
status_tag:
|
50
|
+
:null: Não configurado
|
51
|
+
---
|
52
|
+
ru:
|
53
|
+
active_admin:
|
54
|
+
status_tag:
|
55
|
+
:null: Неизвестно
|
56
|
+
---
|
57
|
+
tr:
|
58
|
+
active_admin:
|
59
|
+
status_tag:
|
60
|
+
:null: Ayarlanmadı
|
@@ -0,0 +1,48 @@
|
|
1
|
+
---
|
2
|
+
ca:
|
3
|
+
formtastic:
|
4
|
+
:null: No establert
|
5
|
+
---
|
6
|
+
de:
|
7
|
+
formtastic:
|
8
|
+
:null: Nicht eingestellt
|
9
|
+
---
|
10
|
+
fr:
|
11
|
+
formtastic:
|
12
|
+
:null: Pas défini
|
13
|
+
---
|
14
|
+
it:
|
15
|
+
formtastic:
|
16
|
+
:null: Sconosciuto
|
17
|
+
---
|
18
|
+
ja:
|
19
|
+
formtastic:
|
20
|
+
:null: 不明
|
21
|
+
---
|
22
|
+
en:
|
23
|
+
formtastic:
|
24
|
+
:null: Unset
|
25
|
+
---
|
26
|
+
es:
|
27
|
+
formtastic:
|
28
|
+
:null: No establecido
|
29
|
+
---
|
30
|
+
pl:
|
31
|
+
formtastic:
|
32
|
+
:null: Nie ustawiony
|
33
|
+
---
|
34
|
+
pt-BR:
|
35
|
+
formtastic:
|
36
|
+
:null: Não configurado
|
37
|
+
---
|
38
|
+
pt:
|
39
|
+
formtastic:
|
40
|
+
:null: Não configurado
|
41
|
+
---
|
42
|
+
ru:
|
43
|
+
formtastic:
|
44
|
+
:null: Неизвестно
|
45
|
+
---
|
46
|
+
tr:
|
47
|
+
formtastic:
|
48
|
+
:null: Ayarlanmadı
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# https://guides.rubygems.org/name-your-gem/
|
4
|
+
# https://bundler.io/guides/creating_gem.html
|
5
|
+
# https://guides.rubyonrails.org/engines.html
|
6
|
+
# https://guides.rubyonrails.org/plugins.html
|
7
|
+
|
8
|
+
require_relative "lib/formtastic_tristate_radio/version"
|
9
|
+
|
10
|
+
Gem::Specification.new do |spec|
|
11
|
+
spec.name = "formtastic_tristate_radio"
|
12
|
+
spec.version = FormtasticTristateRadio::VERSION
|
13
|
+
spec.authors = ["Sergey Pedan"]
|
14
|
+
spec.email = ["sergey.pedan@gmail.com"]
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.summary = "Have 3-state radiobuttons instead of a 2-state checkbox for your Boolean columns which can store NULL"
|
18
|
+
spec.description = <<~HEREDOC
|
19
|
+
#{spec.summary}.
|
20
|
+
|
21
|
+
What the gem does?
|
22
|
+
|
23
|
+
1. Provides a custom Formtastic input type `:tristate_radio` which renders 3 radios (“Yes”, “No”, “Unset”) instead of a checkbox (only where you put it).
|
24
|
+
1. Teaches Rails recognize `"null"` and `"nil"` param values as `nil`. See “[How it works](#how-it-works)” ☟ section for technical details on this.
|
25
|
+
1. Encourages you to add translations for ActiveAdmin “status tag” so that `nil` be correctly translated as “Unset” instead of “False”.
|
26
|
+
|
27
|
+
Does not change controls, you need to turn it on via `as: :tristate_radio` option.
|
28
|
+
|
29
|
+
By defenition Boolean values have 2 states: True & False.
|
30
|
+
|
31
|
+
However, if you store a Boolean value in a database column with no `NOT NULL` restriction, it aquires a 3<sup>d</sup> possible state: `null`.
|
32
|
+
|
33
|
+
Some may consider this practice questionable — I don’t think so. In real life you always have a case when the answer to your question may be only “yes” or “no”, but you don’t know the answer yet. Using a string type column, storing there `"yes"`, `"no"` and `"unset"` + using a state machine + validations — feels overkill to me.
|
34
|
+
HEREDOC
|
35
|
+
|
36
|
+
spec.homepage = "https://github.com/sergeypedan/formtastic-tristate-radio"
|
37
|
+
spec.extra_rdoc_files = ["README.md", "CHANGELOG.md"]
|
38
|
+
spec.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
spec.metadata = { "changelog_uri" => "#{spec.homepage}/blob/master/CHANGELOG.md",
|
40
|
+
"documentation_uri" => "https://www.rubydoc.info/gems/#{spec.name}",
|
41
|
+
"homepage_uri" => spec.homepage,
|
42
|
+
"source_code_uri" => spec.homepage }
|
43
|
+
|
44
|
+
spec.require_paths = ["app/inputs", "app/models/active_record", "config/initializers", "config/locales", "lib"]
|
45
|
+
spec.bindir = "exe"
|
46
|
+
spec.executables = []
|
47
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
48
|
+
`git ls-files`.split("\n")
|
49
|
+
.reject { |f| %w[bin spec test].any? { |dir| f.start_with? dir } }
|
50
|
+
.reject { |f| f.start_with? "." }
|
51
|
+
end
|
52
|
+
|
53
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
54
|
+
|
55
|
+
spec.add_dependency "formtastic", ">= 3", "< 5"
|
56
|
+
spec.add_dependency "rails", ">= 4", "< 7"
|
57
|
+
|
58
|
+
spec.add_development_dependency "rspec", "~> 3"
|
59
|
+
spec.add_development_dependency "yard", ">= 0.9.20", "< 1"
|
60
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formtastic_tristate_radio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Pedan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: formtastic
|
@@ -70,7 +70,7 @@ dependencies:
|
|
70
70
|
requirements:
|
71
71
|
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
73
|
+
version: 0.9.20
|
74
74
|
- - "<"
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '1'
|
@@ -80,13 +80,26 @@ dependencies:
|
|
80
80
|
requirements:
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
83
|
+
version: 0.9.20
|
84
84
|
- - "<"
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '1'
|
87
|
-
description:
|
88
|
-
|
89
|
-
|
87
|
+
description: |
|
88
|
+
Have 3-state radiobuttons instead of a 2-state checkbox for your Boolean columns which can store NULL.
|
89
|
+
|
90
|
+
What the gem does?
|
91
|
+
|
92
|
+
1. Provides a custom Formtastic input type `:tristate_radio` which renders 3 radios (“Yes”, “No”, “Unset”) instead of a checkbox (only where you put it).
|
93
|
+
1. Teaches Rails recognize `"null"` and `"nil"` param values as `nil`. See “[How it works](#how-it-works)” ☟ section for technical details on this.
|
94
|
+
1. Encourages you to add translations for ActiveAdmin “status tag” so that `nil` be correctly translated as “Unset” instead of “False”.
|
95
|
+
|
96
|
+
Does not change controls, you need to turn it on via `as: :tristate_radio` option.
|
97
|
+
|
98
|
+
By defenition Boolean values have 2 states: True & False.
|
99
|
+
|
100
|
+
However, if you store a Boolean value in a database column with no `NOT NULL` restriction, it aquires a 3<sup>d</sup> possible state: `null`.
|
101
|
+
|
102
|
+
Some may consider this practice questionable — I don’t think so. In real life you always have a case when the answer to your question may be only “yes” or “no”, but you don’t know the answer yet. Using a string type column, storing there `"yes"`, `"no"` and `"unset"` + using a state machine + validations — feels overkill to me.
|
90
103
|
email:
|
91
104
|
- sergey.pedan@gmail.com
|
92
105
|
executables: []
|
@@ -96,22 +109,23 @@ extra_rdoc_files:
|
|
96
109
|
- CHANGELOG.md
|
97
110
|
files:
|
98
111
|
- CHANGELOG.md
|
112
|
+
- Gemfile
|
113
|
+
- Gemfile.lock
|
114
|
+
- MIT-LICENSE
|
99
115
|
- README.md
|
100
116
|
- Rakefile
|
101
117
|
- app/inputs/tristate_radio_input.rb
|
102
118
|
- app/models/active_record/base.rb
|
103
119
|
- config/initializers/activemodel_type_boolean.rb
|
104
|
-
- config/locales/active_admin.
|
105
|
-
- config/locales/
|
106
|
-
- config/locales/formtastic.en.yml
|
107
|
-
- config/locales/formtastic.ru.yml
|
120
|
+
- config/locales/active_admin.yml
|
121
|
+
- config/locales/formtastic.yml
|
108
122
|
- config/routes.rb
|
123
|
+
- formtastic_tristate_radio.gemspec
|
109
124
|
- lib/formtastic_tristate_radio.rb
|
110
125
|
- lib/formtastic_tristate_radio/configuration.rb
|
111
126
|
- lib/formtastic_tristate_radio/engine.rb
|
112
127
|
- lib/formtastic_tristate_radio/missing_translation_error.rb
|
113
128
|
- lib/formtastic_tristate_radio/version.rb
|
114
|
-
- lib/tasks/formtastic_tristate_radio_tasks.rake
|
115
129
|
homepage: https://github.com/sergeypedan/formtastic-tristate-radio
|
116
130
|
licenses:
|
117
131
|
- MIT
|
@@ -124,11 +138,11 @@ post_install_message:
|
|
124
138
|
rdoc_options:
|
125
139
|
- "--charset=UTF-8"
|
126
140
|
require_paths:
|
127
|
-
- lib
|
128
141
|
- app/inputs
|
129
142
|
- app/models/active_record
|
130
143
|
- config/initializers
|
131
144
|
- config/locales
|
145
|
+
- lib
|
132
146
|
required_ruby_version: !ruby/object:Gem::Requirement
|
133
147
|
requirements:
|
134
148
|
- - ">="
|