formtastic_tristate_radio 0.2.1 → 0.2.2

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
2
  SHA256:
3
- metadata.gz: 86bedb2f66a40f6a3ed5279b74fe1ecdc3ad78cf0c288183580986c162ace2ec
4
- data.tar.gz: 7616b0e734f3760402146faabc3826b65e19662b18656aa21b182302d8268cdd
3
+ metadata.gz: 654200d81e8ba934c905356fa626b6089419edc8a81021bed298793c283c6c7b
4
+ data.tar.gz: 5d3230415c94b4d2d054a25f1a4bbd339554f77bddd878798e9c5c4686ab140f
5
5
  SHA512:
6
- metadata.gz: f43eb8544a29be624ac73048e86e4369653e4311347a5f07b49cfbe1cc70c6adf66827e5f9cf2a6530ff84a0e1fc6b2d5154f9d08a11849b07e4781fa28ad2ef
7
- data.tar.gz: 6e60adba7f1d57f623f60a7cd4a448e5c443f0eb27721da49fc1767c509d16e19842a8b220ec301dfdbb188a051e2d1c1e4d8420efbbcf810f65a4dd07229704
6
+ metadata.gz: 9d88136b057f6cc2c17e890c73851c20e29dea4b107671d28f2936beac64da1b7dda13fa9ff07dee076ec512bfd698b3669b38ce28f534bbdeeb0e925c84802b
7
+ data.tar.gz: dc1a06b004aca154a1b728d4bcb14c798bc1eb998fff614c675128c5a36c2a9f860abdd17ee90763c98d59da23e34acef57236e8ef56e443ae96d423625c9e66
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.2] - 2021-11-05
4
+
5
+ - Make the gem configurable
6
+ - Pull the key used for “unset” choice value into configuration
7
+
3
8
  ## [0.2.1] - 2021-11-04
4
9
 
5
10
  - Updates docs URL in gemspec
data/README.md CHANGED
@@ -94,7 +94,22 @@ Notice that the key ActiveAdmin uses is “unset”, not “null”.
94
94
 
95
95
  ## Configuration
96
96
 
97
- Nothing is configurable yet. I think of making configurable which values are regognized as `nil`.
97
+ It’s difficult to come up with a reasonable use case for that, but you can configure what will be used as inputs value:
98
+
99
+ ```ruby
100
+ # config/initializers/formtastic.rb
101
+ FormtasticTristateRadio.configure do |config|
102
+ config.unset_key = "__unset" # default is :null
103
+ end
104
+ ```
105
+
106
+ which will result in:
107
+
108
+ ```html
109
+ <input name="am_i_awake" type="radio" value="__unset"> <label>Unset</label>
110
+ ```
111
+
112
+ Mind that for that 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).
98
113
 
99
114
 
100
115
  ## Documentation
@@ -178,10 +193,10 @@ ActiveModel::Type::Boolean.new.cast(:nil) #=> nil
178
193
 
179
194
  ## Roadmap
180
195
 
196
+ - [x] Make the gem configurable
197
+ - [x] Pull the key used for “unset” choice value into configuration
181
198
  - [ ] Load translations from gem
182
199
  - [ ] Add translations into most popular languages
183
- - [ ] Make the gem configurable
184
- - [ ] Pull the key used for “unset” choice value into configuration
185
200
  - [ ] Rgister `:tristate_radio` for Boolean columns with `null`
186
201
  - [ ] Decouple `ActiveModel::Type::Boolean` thing from Formtastic things, maybe into a separate gem
187
202
  - [ ] Decouple from Rails
@@ -6,12 +6,13 @@ require "formtastic"
6
6
  class TristateRadioInput < Formtastic::Inputs::RadioInput
7
7
 
8
8
  # No equals `:null`.
9
+ # Should equal one of `ActiveModel::Type::Boolean::NULL_VALUES`
9
10
  #
10
11
  # Mind ActiveAdmin [status resolving logic](https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/views/components/status_tag.rb#L51):
11
12
  # in status tag builder the value is lowercased before casting into Boolean, and the keyword for nil is `"unset"`.
12
13
  # So if we have lowercase `"unset"`, translations from `ru.formtastic.unset` will be overriden by `ru.active_admin.status_tag.unset`.
13
14
  #
14
- UNSET_KEY = ActiveModel::Type::Boolean::NULL_VALUES.reject(&:blank?).first
15
+ UNSET_KEY = FormtasticTristateRadio.config.unset_key
15
16
 
16
17
  I18N_EXAMPLE_ACTIVEADMIN = <<~YAML.chomp
17
18
  ru:
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FormtasticTristateRadio
4
+
5
+ class << self
6
+ attr_writer :config
7
+ end
8
+
9
+ def self.config
10
+ @config ||= Configuration.new
11
+ end
12
+
13
+ def self.configure
14
+ yield(config)
15
+ end
16
+
17
+ class Configuration
18
+ attr_accessor :unset_key
19
+
20
+ def initialize
21
+ @unset_key = :null
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FormtasticTristateRadio
4
+ class MissingTranslationError < StandardError
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FormtasticTristateRadio
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
  end
@@ -1,9 +1,9 @@
1
1
  require_relative "formtastic_tristate_radio/version"
2
+ require_relative "formtastic_tristate_radio/missing_translation_error"
3
+ require_relative "formtastic_tristate_radio/configuration"
2
4
  require_relative "formtastic_tristate_radio/engine"
5
+
3
6
  require_relative "../app/models/active_record/base"
4
7
 
5
8
  module FormtasticTristateRadio
6
-
7
- class MissingTranslationError < StandardError; end
8
-
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formtastic_tristate_radio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Pedan
@@ -50,6 +50,20 @@ dependencies:
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '7'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '3'
53
67
  - !ruby/object:Gem::Dependency
54
68
  name: yard
55
69
  requirement: !ruby/object:Gem::Requirement
@@ -93,7 +107,9 @@ files:
93
107
  - config/locales/formtastic.ru.yml
94
108
  - config/routes.rb
95
109
  - lib/formtastic_tristate_radio.rb
110
+ - lib/formtastic_tristate_radio/configuration.rb
96
111
  - lib/formtastic_tristate_radio/engine.rb
112
+ - lib/formtastic_tristate_radio/missing_translation_error.rb
97
113
  - lib/formtastic_tristate_radio/version.rb
98
114
  - lib/tasks/formtastic_tristate_radio_tasks.rake
99
115
  homepage: https://github.com/sergeypedan/formtastic-tristate-radio