hyperactiveform 0.4.0 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +9 -0
- data/context7.json +4 -0
- data/docs/FormGenerator.html +11 -7
- data/docs/HyperActiveForm/Base.html +215 -115
- data/docs/HyperActiveForm/CancelFormSubmit.html +10 -7
- data/docs/HyperActiveForm/FormDidNotSubmitError.html +10 -7
- data/docs/HyperActiveForm/Generators/InstallGenerator.html +11 -7
- data/docs/HyperActiveForm/Generators.html +10 -7
- data/docs/HyperActiveForm.html +12 -9
- data/docs/Hyperactiveform_.html +146 -0
- data/docs/Rspec/Generators/FormGenerator.html +11 -7
- data/docs/Rspec/Generators.html +10 -7
- data/docs/Rspec.html +10 -7
- data/docs/TestUnit/Generators/FormGenerator.html +11 -7
- data/docs/TestUnit/Generators.html +10 -7
- data/docs/TestUnit.html +10 -7
- data/docs/_index.html +20 -13
- data/docs/class_list.html +6 -6
- data/docs/css/common.css +1 -1
- data/docs/css/full_list.css +201 -53
- data/docs/css/style.css +988 -402
- data/docs/file.README.html +29 -78
- data/docs/file_list.html +5 -5
- data/docs/frames.html +1 -1
- data/docs/index.html +29 -78
- data/docs/js/app.js +800 -343
- data/docs/js/full_list.js +332 -240
- data/docs/method_list.html +5 -5
- data/docs/top-level-namespace.html +9 -7
- data/gemfiles/{Gemfile.rails-8.x → Gemfile.rails-8.0.x} +1 -1
- data/gemfiles/Gemfile.rails-8.1.x +5 -0
- data/lib/hyper_active_form/base.rb +22 -6
- data/lib/hyper_active_form/version.rb +1 -1
- metadata +7 -7
|
@@ -50,12 +50,24 @@ 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
|
-
|
|
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)
|
|
67
|
+
public_send(:"#{attribute}=", params&.dig(attribute))
|
|
68
|
+
elsif overwrite_missing
|
|
69
|
+
public_send(:"#{attribute}=", default_value)
|
|
70
|
+
end
|
|
59
71
|
end
|
|
60
72
|
@assigned_attribute_names = params.slice(*attribute_names).keys
|
|
61
73
|
end
|
|
@@ -65,10 +77,12 @@ module HyperActiveForm
|
|
|
65
77
|
# running validations and calling the `perform` method if the form is valid
|
|
66
78
|
#
|
|
67
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
|
|
68
82
|
# @return [Boolean] true if the form is valid and the `perform` method returned something truthy
|
|
69
|
-
def submit(params)
|
|
83
|
+
def submit(params = nil, **options)
|
|
70
84
|
run_callbacks :submit do
|
|
71
|
-
assign_form_attributes(params)
|
|
85
|
+
assign_form_attributes(params, **options)
|
|
72
86
|
!!(valid? && perform)
|
|
73
87
|
end
|
|
74
88
|
rescue HyperActiveForm::CancelFormSubmit
|
|
@@ -78,9 +92,11 @@ module HyperActiveForm
|
|
|
78
92
|
# Same as `submit` but raises a `FormDidNotSubmitError` if the form is not valid
|
|
79
93
|
#
|
|
80
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
|
|
81
97
|
# @return [Boolean] true if the form is valid and the `perform` method returned something truthy
|
|
82
|
-
def submit!(params)
|
|
83
|
-
submit(params) || raise(HyperActiveForm::FormDidNotSubmitError)
|
|
98
|
+
def submit!(params = nil, **options)
|
|
99
|
+
submit(params, **options) || raise(HyperActiveForm::FormDidNotSubmitError)
|
|
84
100
|
end
|
|
85
101
|
|
|
86
102
|
# Adds the errors from a model to the form
|
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
|
+
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:
|
|
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:
|
|
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: []
|