application_form 0.5.0 → 0.5.4

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: ef96372acd66b16420e3a1c63699eaf37f10b92cba2d834c3139bbdc056a8b46
4
+ data.tar.gz: ed40f7353a74c021381e579361a49c9c88f29f22df9f18a3bfd80d43ab132c76
5
5
  SHA512:
6
- metadata.gz: 5c729d4c8aedca0ecfcfc8282573d8ba2fbae16ac63bde9c829c81426c9ce2c58e4963ba80ecb2640a5213dd9f16760084d6f8bb9b30c93ce4ce2509ba78a285
7
- data.tar.gz: 7544e013f81ea4e137d9b2e2a2949f541a9636cf2dd6a873253b6f89b28a87619d0b2174e9f8344964194761a81c228d36fd201d5294228fb7f5e8ef03148d0d
6
+ metadata.gz: 05220ee71ee33781a8ddeb624aa639e2afddd57035924b1270549218948509a9d9493a79d052dd6f2b320fe33df8d26750be2f6c7e8320ed0a457105ef89c18b
7
+ data.tar.gz: d805e59a90b554cb232ff55ed33700d402bb116d88140eaacd5319e42491dc15196f2df3ddd47ef11e7a011d092ac415ff69c9f9c9c1032212e781b076c589a8
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
 
@@ -10,12 +10,12 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = 'Painless forms for ActiveRecord'
12
12
  spec.description = 'Lightweight inheritance based forms solution'
13
- spec.homepage = 'https://github.com/rbbr_io/application_form'
13
+ spec.homepage = 'https://github.com/rbbr-io/application_form'
14
14
  spec.license = 'MIT'
15
15
  spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
16
 
17
17
  spec.metadata['homepage_uri'] = spec.homepage
18
- spec.metadata['source_code_uri'] = 'https://github.com/rbbr_io/application_form.git'
18
+ spec.metadata['source_code_uri'] = 'https://github.com/rbbr-io/application_form.git'
19
19
  # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
@@ -35,11 +35,12 @@ 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}"
42
- form.add_error_key(field, key)
41
+ entity_name = self.class.superclass.to_s.tableize.split('/').last.singularize
42
+ full_key = "#{entity_name}.errors.#{key}"
43
+ form.add_error_key(field, full_key)
43
44
  end
44
45
  end
45
46
  end
@@ -76,8 +77,8 @@ module ApplicationForm
76
77
  errors.details[:base].first[:error].to_s
77
78
  end
78
79
 
79
- def assign_attrs(attrs)
80
- assign_attributes(attrs)
80
+ def assign_attrs(attributes)
81
+ assign_attributes(attributes)
81
82
  self
82
83
  end
83
84
  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.4'
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Mokevnin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-08-14 00:00:00.000000000 Z
12
+ date: 2021-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -77,12 +77,12 @@ files:
77
77
  - lib/generators/application_form/USAGE
78
78
  - lib/generators/application_form/form_generator.rb
79
79
  - lib/generators/application_form/templates/form.rb
80
- homepage: https://github.com/rbbr_io/application_form
80
+ homepage: https://github.com/rbbr-io/application_form
81
81
  licenses:
82
82
  - MIT
83
83
  metadata:
84
- homepage_uri: https://github.com/rbbr_io/application_form
85
- source_code_uri: https://github.com/rbbr_io/application_form.git
84
+ homepage_uri: https://github.com/rbbr-io/application_form
85
+ source_code_uri: https://github.com/rbbr-io/application_form.git
86
86
  post_install_message:
87
87
  rdoc_options: []
88
88
  require_paths: