formtastic_tristate_radio 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 8fdf4d000b01b98679b7b2e4eb9bbb8ac43e2bdec9dfe79aba6e07ed580f0cbf
4
- data.tar.gz: 7734d39327b809b599b058362e091df2e6153749ff6cfad5a7cb7ac91756e1a2
2
+ SHA1:
3
+ metadata.gz: 6cb90abb9a912c583ace9c1ce3c7fabdf27e3b0b
4
+ data.tar.gz: fd220427f9e5d0f573c3533d186c85c47dffd581
5
5
  SHA512:
6
- metadata.gz: e67a6dfe2440683e483d9d2bb677b66a87d335625a1ca7622888e641b3b0c36d8602ef502708d2098e78b4d3f15985ca59b6105d17f661adb4e72ea5661f07a1
7
- data.tar.gz: 9fcd6fe99ddfba81237d17305abcc6e1de6febcc05765c442c265bdb5293adaea88bd9364affac0c374929a4ebc1113cba8c98ad7eb82dd11440cde462fa7606
6
+ metadata.gz: 47c7eb5acfd279ce25b9b61216951004aa76c472260d01053ffc91925c2ea078c2428287593e746e62239b984a90b3f3f6f2a299ae2f928024b5702c4e19202f
7
+ data.tar.gz: 0f76c972c65fd6d2e1e78b69e7d5b1868345d0a04a3755a7b39719fc9fffc16e7b0fa5776861202d2638ecfa267a5ee1431493576b5d6467fbba2096d95fb0a1
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "formtastic"
4
-
5
3
  # It may also be appropriate to put this file in `app/inputs`
6
4
  class TristateRadioInput < Formtastic::Inputs::RadioInput
7
5
 
8
- # No equals `:null`.
6
+ # Now equals `:null`.
9
7
  # Should equal one of `ActiveModel::Type::Boolean::NULL_VALUES`
10
8
  #
11
9
  # Mind ActiveAdmin [status resolving logic](https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/views/components/status_tag.rb#L51):
@@ -14,37 +12,6 @@ class TristateRadioInput < Formtastic::Inputs::RadioInput
14
12
  #
15
13
  UNSET_KEY = FormtasticTristateRadio.config.unset_key
16
14
 
17
- I18N_EXAMPLE_ACTIVEADMIN = <<~YAML.chomp
18
- ru:
19
- active_admin:
20
- status_tag:
21
- :yes: Да
22
- :no: Нет
23
- :#{UNSET_KEY}: Неизвестно
24
- YAML
25
-
26
- I18N_EXAMPLE_FORMTASTIC = <<~YAML.chomp
27
- ru:
28
- formtastic:
29
- :yes: Да
30
- :no: Нет
31
- :#{UNSET_KEY}: Неизвестно
32
- YAML
33
-
34
-
35
- # @note In you have ActiveAdmin installed, it will give you YAML example for ActiveAdmin as well, otherwise only for Formtastic
36
- #
37
- # @return [String] error message with YAML examples for the “unset” label translation lookup error
38
- #
39
- def self.missing_i18n_error_msg
40
- msg = []
41
- msg << "Add translations for the “unset” radio label"
42
- msg << ["For radiobutton labels in forms:", I18N_EXAMPLE_FORMTASTIC].join("\n")
43
- msg << "Note: “yes”, “no” and some other reserved words are converted into Boolean values in YAML, so you need to quote or symbolize them."
44
- msg << ["For ActiveAdmin status tags in index & view tables:", I18N_EXAMPLE_ACTIVEADMIN].join("\n") if !!defined?(ActiveAdmin)
45
- msg.join("\n\n")
46
- end
47
-
48
15
 
49
16
  # @see https://github.com/formtastic/formtastic/blob/35dc806964403cb2bb0a6074b951ceef906c8581/lib/formtastic/inputs/base/choices.rb#L59 Original Formtastic method
50
17
  #
@@ -89,8 +56,7 @@ class TristateRadioInput < Formtastic::Inputs::RadioInput
89
56
  # @see missing_i18n_error_msg
90
57
  #
91
58
  def label_text_for_unset
92
- options.fetch(:null, Formtastic::I18n.t(UNSET_KEY)).presence or \
93
- fail FormtasticTristateRadio::MissingTranslationError.new(self.class.missing_i18n_error_msg)
59
+ options.fetch(:null, Formtastic::I18n.t(UNSET_KEY)).presence or fail FormtasticTristateRadio::I18n::Error.new(locale, UNSET_KEY)
94
60
  end
95
61
 
96
62
 
@@ -16,21 +16,11 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.summary = "Have 3-state radiobuttons instead of a 2-state checkbox for your Boolean columns which can store NULL"
18
18
  spec.description = <<~HEREDOC
19
- #{spec.summary}.
20
-
21
- What the gem does?
22
-
19
+ #{spec.summary}. This gem:
23
20
  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
-
21
+ 2. Teaches Rails recognize `"null"` and `"nil"` param values as `nil`. See “[How it works](#how-it-works)” ☟ section for technical details on this.
22
+ 3. Encourages you to add translations for ActiveAdmin “status tag” so that `nil` be correctly translated as “Unset” instead of “False”.
27
23
  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
24
  HEREDOC
35
25
 
36
26
  spec.homepage = "https://github.com/sergeypedan/formtastic-tristate-radio"
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FormtasticTristateRadio
4
+ module I18n
5
+
6
+ EXAMPLE_ACTIVEADMIN = <<~YAML.chomp
7
+ ru:
8
+ active_admin:
9
+ status_tag:
10
+ :yes: Да
11
+ :no: Нет
12
+ :#{FormtasticTristateRadio.config.unset_key}: Неизвестно
13
+ YAML
14
+
15
+ EXAMPLE_FORMTASTIC = <<~YAML.chomp
16
+ ru:
17
+ formtastic:
18
+ :yes: Да
19
+ :no: Нет
20
+ :#{FormtasticTristateRadio.config.unset_key}: Неизвестно
21
+ YAML
22
+
23
+ class Error < ::I18n::MissingTranslationData
24
+ module Base
25
+
26
+ # @note In you have ActiveAdmin installed, it will give you YAML example for ActiveAdmin as well, otherwise only for Formtastic
27
+ #
28
+ # @return [String] error message with YAML examples for the “unset” label translation lookup error
29
+ #
30
+ # @see URL https://github.com/ruby-i18n/i18n/blob/master/lib/i18n/exceptions.rb#L63 Original I18n method
31
+ #
32
+ def message
33
+ msg = []
34
+ msg << "Add translations for the “unset” radio label"
35
+ msg << ["For radiobutton labels in forms:", EXAMPLE_FORMTASTIC].join("\n")
36
+ msg << "Note: “yes”, “no” and some other reserved words are converted into Boolean values in YAML, so you need to quote or symbolize them."
37
+ msg << ["For ActiveAdmin status tags in index & view tables:", EXAMPLE_ACTIVEADMIN].join("\n") if !!defined?(ActiveAdmin)
38
+ [super, msg.join("\n\n")].join("\n\n")
39
+ end
40
+ end
41
+
42
+ include Base
43
+ end
44
+
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FormtasticTristateRadio
4
- VERSION = '0.2.3'
4
+ VERSION = "0.2.4"
5
5
  end
@@ -1,9 +1,7 @@
1
1
  require_relative "formtastic_tristate_radio/version"
2
- require_relative "formtastic_tristate_radio/missing_translation_error"
3
2
  require_relative "formtastic_tristate_radio/configuration"
3
+ require_relative "formtastic_tristate_radio/i18n/error"
4
4
  require_relative "formtastic_tristate_radio/engine"
5
-
6
5
  require_relative "../app/models/active_record/base"
7
6
 
8
- module FormtasticTristateRadio
9
- end
7
+ module FormtasticTristateRadio; end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formtastic_tristate_radio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Pedan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2021-11-09 00:00:00.000000000 Z
@@ -85,21 +85,11 @@ dependencies:
85
85
  - !ruby/object:Gem::Version
86
86
  version: '1'
87
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
-
88
+ Have 3-state radiobuttons instead of a 2-state checkbox for your Boolean columns which can store NULL. This gem:
92
89
  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
-
90
+ 2. Teaches Rails recognize `"null"` and `"nil"` param values as `nil`. See “[How it works](#how-it-works)” ☟ section for technical details on this.
91
+ 3. Encourages you to add translations for ActiveAdmin “status tag” so that `nil` be correctly translated as “Unset” instead of “False”.
96
92
  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.
103
93
  email:
104
94
  - sergey.pedan@gmail.com
105
95
  executables: []
@@ -124,7 +114,7 @@ files:
124
114
  - lib/formtastic_tristate_radio.rb
125
115
  - lib/formtastic_tristate_radio/configuration.rb
126
116
  - lib/formtastic_tristate_radio/engine.rb
127
- - lib/formtastic_tristate_radio/missing_translation_error.rb
117
+ - lib/formtastic_tristate_radio/i18n/error.rb
128
118
  - lib/formtastic_tristate_radio/version.rb
129
119
  homepage: https://github.com/sergeypedan/formtastic-tristate-radio
130
120
  licenses:
@@ -134,7 +124,7 @@ metadata:
134
124
  documentation_uri: https://www.rubydoc.info/gems/formtastic_tristate_radio
135
125
  homepage_uri: https://github.com/sergeypedan/formtastic-tristate-radio
136
126
  source_code_uri: https://github.com/sergeypedan/formtastic-tristate-radio
137
- post_install_message:
127
+ post_install_message:
138
128
  rdoc_options:
139
129
  - "--charset=UTF-8"
140
130
  require_paths:
@@ -154,8 +144,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
144
  - !ruby/object:Gem::Version
155
145
  version: '0'
156
146
  requirements: []
157
- rubygems_version: 3.2.15
158
- signing_key:
147
+ rubyforge_project:
148
+ rubygems_version: 2.5.2.3
149
+ signing_key:
159
150
  specification_version: 4
160
151
  summary: Have 3-state radiobuttons instead of a 2-state checkbox for your Boolean
161
152
  columns which can store NULL
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module FormtasticTristateRadio
4
- class MissingTranslationError < I18n::MissingTranslationData
5
- end
6
- end