application_form 0.5.0 → 0.5.1

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: d4e7f93eb4164ad8f2c1d57bc2b4ddb6fa0a2f2ccfcd198c8426d2835c7403dd
4
- data.tar.gz: b8c36375600c846355f758a76350719aa46eef33c2c1d0acdd1c7d33d03a3015
3
+ metadata.gz: fb0692a0002ec9525e01b40a0a4ffddf2c8da9fd625259642965e06a2b135c0a
4
+ data.tar.gz: e110d5eaa1c9a5b06c6cc49042858d3706a8fcde8652921f2f60da8594dd4ab8
5
5
  SHA512:
6
- metadata.gz: 5c729d4c8aedca0ecfcfc8282573d8ba2fbae16ac63bde9c829c81426c9ce2c58e4963ba80ecb2640a5213dd9f16760084d6f8bb9b30c93ce4ce2509ba78a285
7
- data.tar.gz: 7544e013f81ea4e137d9b2e2a2949f541a9636cf2dd6a873253b6f89b28a87619d0b2174e9f8344964194761a81c228d36fd201d5294228fb7f5e8ef03148d0d
6
+ metadata.gz: 69d6e90cfe3c4bc58ccc4eab4ab5d435f0ecdb33ae0fe429d2942d3bc27d76e3a8f4110ddb3ff3f0c3cd732a97fa79db628d105feaa7ff8ec0193b10fd8ccda9
7
+ data.tar.gz: f090c870dfa53da190725d84cf75b2e9ec0299808ebb4f437a11de19f5a736d949fc352880ba70bd92b7f1e108a6e0bef35560c5bd861784761f6ebd8bea7228
data/README.md CHANGED
@@ -66,7 +66,14 @@ class UserSignUpForm < User
66
66
  end
67
67
  ```
68
68
 
69
- In some cases it is necessary to use ActiveRecord object directly without form. For such cases conveniently to use method `become()` (built-in ActiveRecord):
69
+ ```
70
+ form = UserSignUpForm.new(user_params)
71
+ form.valid?
72
+ ```
73
+
74
+ ### Usage with `becomes`
75
+
76
+ In some cases it is necessary to use ActiveRecord object directly without form. For such cases conveniently to use method `becomes()` (built-in ActiveRecord):
70
77
 
71
78
  ```ruby
72
79
  user = User.find(params[:id])
@@ -93,19 +100,19 @@ form = ReservationCreateForm.new(prepared_params)
93
100
  if form.checks_passed?
94
101
  # ...
95
102
  else
96
- render_error!(form.first_failed_check) # form.first_failed_check returns "max_number_of_reservations_reached"
103
+ render_error!(form.first_failed_check) # form.first_failed_check returns "reservation.error.max_number_of_reservations_reached"
97
104
  end
98
105
  ```
99
106
 
100
- You can also attach check to a specific field:
107
+ You can also assign check to a specific field:
101
108
 
102
- ```
109
+ ```ruby
103
110
  check :end_at_must_be_greater_then_start_at, ->(form) { form.end_at > form.start_at }, :end_at
104
111
  ```
105
112
 
106
113
  In this case it will work as a regular validation.
107
114
 
108
- ### `assign_atrs`
115
+ ### `assign_attrs`
109
116
 
110
117
  It works as regular `assign_attributes` but it also returns the object, so that you can chain it:
111
118
 
@@ -35,10 +35,11 @@ module ApplicationForm
35
35
  @_permitted_args || (superclass.respond_to?(:_permitted_args) && superclass._permitted_args) || []
36
36
  end
37
37
 
38
- def check(name, block, field = :base)
38
+ def check(key, block, field = :base)
39
39
  validate do |form|
40
40
  if !block.call(form)
41
- key = "#{self.class.table_name.singularize}.errors.#{name}"
41
+ entity_name = self.class.superclass.to_s.tableize.split('/').last.singularize
42
+ key = "#{entity_name}.errors.#{key}"
42
43
  form.add_error_key(field, key)
43
44
  end
44
45
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApplicationForm
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: application_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Mokevnin