hyperactiveform 0.4.1 → 0.5.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.
@@ -50,14 +50,22 @@ module HyperActiveForm
50
50
  # for example if you want to refresh the form with new data
51
51
  #
52
52
  # @param params [Hash] the params to assign the attributes from
53
- def assign_form_attributes(params)
53
+ # @param options [Hash] optional keyword arguments
54
+ # @option options [Boolean] :overwrite_missing whether to overwrite missing attributes with their default value or nil
55
+ def assign_form_attributes(params = nil, **options)
56
+ overwrite_missing = if params.nil?
57
+ params = options
58
+ else
59
+ options.fetch(:overwrite_missing, true)
60
+ end
61
+
54
62
  run_callbacks :assign_form_attributes do
55
63
  params = ActionController::Parameters.new(params) unless params.is_a?(ActionController::Parameters)
56
64
  attribute_names.each do |attribute|
57
65
  default_value = self.class._default_attributes[attribute]&.value_before_type_cast
58
66
  if params&.key?(attribute)
59
- public_send(:"#{attribute}=", params&.dig(attribute))
60
- else
67
+ public_send(:"#{attribute}=", params&.dig(attribute))
68
+ elsif overwrite_missing
61
69
  public_send(:"#{attribute}=", default_value)
62
70
  end
63
71
  end
@@ -69,10 +77,12 @@ module HyperActiveForm
69
77
  # running validations and calling the `perform` method if the form is valid
70
78
  #
71
79
  # @param params [Hash] the params to assign the attributes from
80
+ # @param options [Hash] optional keyword arguments
81
+ # @option options [Boolean] :overwrite_missing whether to overwrite missing attributes with their default value or nil
72
82
  # @return [Boolean] true if the form is valid and the `perform` method returned something truthy
73
- def submit(params)
83
+ def submit(params = nil, **options)
74
84
  run_callbacks :submit do
75
- assign_form_attributes(params)
85
+ assign_form_attributes(params, **options)
76
86
  !!(valid? && perform)
77
87
  end
78
88
  rescue HyperActiveForm::CancelFormSubmit
@@ -82,9 +92,11 @@ module HyperActiveForm
82
92
  # Same as `submit` but raises a `FormDidNotSubmitError` if the form is not valid
83
93
  #
84
94
  # @param params [Hash] the params to assign the attributes from
95
+ # @param options [Hash] optional keyword arguments
96
+ # @option options [Boolean] :overwrite_missing whether to overwrite missing attributes with their default value or nil
85
97
  # @return [Boolean] true if the form is valid and the `perform` method returned something truthy
86
- def submit!(params)
87
- submit(params) || raise(HyperActiveForm::FormDidNotSubmitError)
98
+ def submit!(params = nil, **options)
99
+ submit(params, **options) || raise(HyperActiveForm::FormDidNotSubmitError)
88
100
  end
89
101
 
90
102
  # Adds the errors from a model to the form
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HyperActiveForm
4
- VERSION = "0.4.1"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperactiveform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Siami
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-05-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
@@ -65,6 +64,7 @@ files:
65
64
  - LICENSE.txt
66
65
  - README.md
67
66
  - Rakefile
67
+ - context7.json
68
68
  - docs/FormGenerator.html
69
69
  - docs/HyperActiveForm.html
70
70
  - docs/HyperActiveForm/Base.html
@@ -72,6 +72,7 @@ files:
72
72
  - docs/HyperActiveForm/FormDidNotSubmitError.html
73
73
  - docs/HyperActiveForm/Generators.html
74
74
  - docs/HyperActiveForm/Generators/InstallGenerator.html
75
+ - docs/Hyperactiveform_.html
75
76
  - docs/Rspec.html
76
77
  - docs/Rspec/Generators.html
77
78
  - docs/Rspec/Generators/FormGenerator.html
@@ -95,7 +96,8 @@ files:
95
96
  - examples/basic.md
96
97
  - gemfiles/Gemfile.rails-7.1.x
97
98
  - gemfiles/Gemfile.rails-7.2.x
98
- - gemfiles/Gemfile.rails-8.x
99
+ - gemfiles/Gemfile.rails-8.0.x
100
+ - gemfiles/Gemfile.rails-8.1.x
99
101
  - lib/generators/form/form_generator.rb
100
102
  - lib/generators/form/templates/form.rb
101
103
  - lib/generators/hyper_active_form/install/install_generator.rb
@@ -115,7 +117,6 @@ metadata:
115
117
  homepage_uri: https://github.com/Intrepidd/hyperactiveform
116
118
  source_code_uri: https://github.com/Intrepidd/hyperactiveform
117
119
  changelog_uri: https://github.com/Intrepidd/hyperactiveform/blob/main/CHANGELOG.md
118
- post_install_message:
119
120
  rdoc_options: []
120
121
  require_paths:
121
122
  - lib
@@ -130,8 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  - !ruby/object:Gem::Version
131
132
  version: '0'
132
133
  requirements: []
133
- rubygems_version: 3.5.9
134
- signing_key:
134
+ rubygems_version: 4.0.19
135
135
  specification_version: 4
136
136
  summary: Simple form objects for Rails
137
137
  test_files: []