formatic 0.1.10 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 687ee85ecfa183d400cf541d63658c3b28cb0f05e90025f02b3fbf8546f152f2
4
- data.tar.gz: f5c8b8a96e972e101cc1c1c97fb800ed928e6371ba91425f6d22088da9232bbf
3
+ metadata.gz: b769e11f1dd433a6e012b56c44e9d53656e7695a5be8993f155f24dbac724972
4
+ data.tar.gz: f754250dfe1154a554bb436e6f60bf9033fcf0fdfce32fb1688d51a206795936
5
5
  SHA512:
6
- metadata.gz: fb155b07034cdd4a969073a5dd5c4178865c5d921c5be29c91d310cf1c1383d5d77cf10dad5f01909b8d6e875531b820a45b58eccbc222dcf124c3d4f62b673b
7
- data.tar.gz: 2a5740a62b035fc4662c3d50dba2a23d29a76a5e38678aa6aff2c2179d41a0a340131d5357e58fa5ef2da83da333ec1e9a2f9b39b1033de4bc8c1bd23beab87d
6
+ metadata.gz: 0e390afe0bd8c0a5ca4336049a4eb9ab90ea0655e1a1e4ef161ca63598276b27db22a8e89e8df741327c6a2af352abeb00667193000b2b57a2202a0aaab2986d
7
+ data.tar.gz: 10cf8c0c85ce7178117c014ab2523a933d47e2b84b97a09b63d0918e3a36d60b399755798ab659f489f0fa0197b5b1f2d27ca5a70bbc13e659017fc7d28536a7
data/README.md CHANGED
@@ -13,16 +13,22 @@ Opinionated ViewComponents for building forms.
13
13
 
14
14
  Install the gem and add to the application's Gemfile by executing:
15
15
 
16
- $ bundle add formatic
16
+ bundle add formatic
17
17
 
18
18
  If bundler is not being used to manage dependencies, install the gem by executing:
19
19
 
20
- $ gem install formatic
20
+ gem install formatic
21
21
 
22
22
  ## Development
23
23
 
24
24
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/ci` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
25
 
26
+ ## Testing
27
+
28
+ Run one test individually with:
29
+
30
+ bundle exec ruby -I test test/lib/wrappers/test_required.rb
31
+
26
32
  ## Contributing
27
33
 
28
34
  Bug reports and pull requests are welcome on GitHub at https://github.com/halo/formatic.
@@ -31,6 +31,10 @@ module Formatic
31
31
  end
32
32
  end
33
33
 
34
+ # When this is set, we always submit `1` as the day.
35
+ #
36
+ # We could also assume the currently set day, but that could lead to switching months on submit:
37
+ # If 2016-12-31 is set and the form changes to 2016-11, it becomes 2016-11-31 (i.e. 2016-12-01).
34
38
  option :discard_day, optional: true
35
39
 
36
40
  erb_template(::Formatic::Templates::Date.call)
@@ -70,10 +74,6 @@ module Formatic
70
74
  "#{f.object.model_name.param_key}[#{attribute_name}(1i)]"
71
75
  end
72
76
 
73
- def day_value
74
- f.object.public_send(attribute_name)&.day
75
- end
76
-
77
77
  def day_input_id
78
78
  "#{f.object.model_name.param_key}_#{attribute_name}_3i"
79
79
  end
@@ -20,7 +20,7 @@ module Formatic
20
20
 
21
21
  <div class="c-formatic-date__inputs">
22
22
  <% if discard_day %>
23
- <%= hidden_field_tag day_attribute_name, (day_value || 1) %>
23
+ <%= hidden_field_tag day_attribute_name, 1 %>
24
24
  <% else %>
25
25
  <%= select_tag day_attribute_name,
26
26
  options_for_day,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Formatic
4
- VERSION = '0.1.10'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -17,13 +17,22 @@ module Formatic
17
17
  return false if manual_required == false
18
18
  return false if validators.empty?
19
19
 
20
- validators.any? { _1.kind == :presence }
20
+ validators.any? { applicable?(_1) }
21
21
  end
22
22
 
23
+ private
24
+
23
25
  # All applicable validatiors of this attribute.
24
26
  def validators
25
27
  @validators ||= ::Formatic::Wrappers::Validators.call(object:, attribute_name:)
26
28
  end
29
+
30
+ def applicable?(validator)
31
+ validator.options.keys.exclude?(:if) &&
32
+ validator.options.keys.exclude?(:unless) &&
33
+ validator.options.keys.exclude?(:on) &&
34
+ validator.kind == :presence
35
+ end
27
36
  end
28
37
  end
29
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - halo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-21 00:00:00.000000000 Z
11
+ date: 2025-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview