comply 1.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +39 -5
- data/app/assets/javascripts/comply/base_validatable_form.js.coffee +1 -1
- data/app/controllers/comply/application_controller.rb +0 -1
- data/app/controllers/comply/validations_controller.rb +9 -9
- data/config/routes.rb +3 -1
- data/lib/comply.rb +0 -1
- data/lib/comply/version.rb +1 -1
- data/lib/comply/whitelist_constantize.rb +1 -1
- metadata +7 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2308727dd5cda38287f6a80667b39631fe41dc96b36b94c27d230bd5463ac892
|
4
|
+
data.tar.gz: 0a6a2baf3207d7722cd551dca5c0fae083b686ad0d7bcbc31d1d1d337504f94e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa67c3fbb64dbfe632d82ba0306a1c935b047bdf645d28a59e87bc23a0873716bba3a5b75f2319400aa2db6d32995930ccb17c8721b5c8c0ed1b489e952959e1
|
7
|
+
data.tar.gz: 105d1246d676ba240f5ec1bb0fae9a44a39d99bbd554618d0a747ba1b41c00dbc8f7398db0733402afc0a0021593c0034f255fdacc5cc10eeb0b97b173e26d30
|
data/README.md
CHANGED
@@ -13,11 +13,6 @@ Include Comply in your gemfile:
|
|
13
13
|
```ruby
|
14
14
|
gem 'comply'
|
15
15
|
```
|
16
|
-
If you are using Rails 3, you need to include `strong_parameters`
|
17
|
-
```ruby
|
18
|
-
gem 'comply'
|
19
|
-
gem 'strong_parameters'
|
20
|
-
```
|
21
16
|
Mount the engine in your `routes.rb`:
|
22
17
|
```ruby
|
23
18
|
mount Comply::Engine => '/comply'
|
@@ -68,6 +63,45 @@ Want success messages to add some personality to your forms? Add the message as
|
|
68
63
|
<%= f.text_field :title, data: { validate: true, validate_success: "Sweet title yo!" } %>
|
69
64
|
```
|
70
65
|
|
66
|
+
### Validation contexts
|
67
|
+
Supplementary reading on validation contexts:
|
68
|
+
- [ActiveRecord Validations :on](http://guides.rubyonrails.org/active_record_validations.html#on)
|
69
|
+
- [Also see api.rubyonrails.org](http://api.rubyonrails.org/classes/ActiveRecord/Validations.html#method-i-valid-3F)
|
70
|
+
- [Mastering Rails Validations: Contexts](http://blog.arkency.com/2014/04/mastering-rails-validations-contexts/)
|
71
|
+
|
72
|
+
By default, all validations run through Comply's `Comply::ValidationsController` will be in the `:comply` validation
|
73
|
+
context. This gives you the option to modify how your application runs its validations. The most common way to use
|
74
|
+
validation contexts, is when you want to skip a certain validation. Let's say we didn't want to check the uniqueness
|
75
|
+
of a particular attribute when asking Comply to validate a model. You would do this:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
class SomeModel < ActiveRecord::Base
|
79
|
+
validates :my_attribute, uniqueness: true, unless: -> { validation_context == :comply }
|
80
|
+
# or perhaps you *ONLY* want to run the validation when in the :comply context
|
81
|
+
validates :other_attribute, numericality: true, on: :comply
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
You now have the option to specify your own context if you inherit from `Comply::ValidationsController` if your
|
86
|
+
model has a specific business case for needing to run/not-run a set of validations for a given context.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
class SomeController < Comply::ValidationsController
|
90
|
+
# ... snip
|
91
|
+
protected
|
92
|
+
|
93
|
+
def validation_context
|
94
|
+
:my_new_context
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class SomeModel
|
99
|
+
validates :my_attribute, uniqueness: true, unless: -> { validation_context == :my_new_context }
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
That's it!
|
104
|
+
|
71
105
|
### Event triggers
|
72
106
|
You can change the jQuery event which triggers the input validation with the `data-validate-event` attribute.
|
73
107
|
```erb
|
@@ -14,7 +14,7 @@ class Comply.BaseValidatableForm
|
|
14
14
|
@validate inputs: @inputs, submit: true
|
15
15
|
|
16
16
|
validate: (options) ->
|
17
|
-
$.
|
17
|
+
$.post @validationRoute, @_params(), (response) =>
|
18
18
|
@_onValidate(response, options)
|
19
19
|
|
20
20
|
if @_allSuccess(response)
|
@@ -1,24 +1,24 @@
|
|
1
|
-
begin
|
2
|
-
require 'strong_parameters'
|
3
|
-
rescue LoadError
|
4
|
-
end
|
5
|
-
|
6
1
|
module Comply
|
7
2
|
class ValidationsController < Comply::ApplicationController
|
8
|
-
|
9
|
-
|
10
|
-
before_filter :require_model, :require_fields
|
3
|
+
before_action :require_model, :require_fields
|
11
4
|
|
12
5
|
if ActiveModel.const_defined?(:ForbiddenAttributesProtection)
|
13
6
|
include ActiveModel::ForbiddenAttributesProtection
|
14
7
|
end
|
15
8
|
|
16
9
|
def show
|
10
|
+
ActiveSupport::Deprecation.warn('GET support going away: use POST to access this endpoint') if request.request_method == 'GET'
|
17
11
|
@instance = validation_instance
|
18
|
-
@instance.valid?
|
12
|
+
@instance.valid?(validation_context)
|
19
13
|
render json: { error: @instance.errors }
|
20
14
|
end
|
21
15
|
|
16
|
+
protected
|
17
|
+
|
18
|
+
def validation_context
|
19
|
+
:comply
|
20
|
+
end
|
21
|
+
|
22
22
|
private
|
23
23
|
|
24
24
|
def validation_instance
|
data/config/routes.rb
CHANGED
data/lib/comply.rb
CHANGED
data/lib/comply/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comply
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@jacobaweiss"
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2020-05-20 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: coffee-rails
|
@@ -28,36 +28,8 @@ dependencies:
|
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '0'
|
31
|
-
- !ruby/object:Gem::Dependency
|
32
|
-
name: bartt-ssl_requirement
|
33
|
-
requirement: !ruby/object:Gem::Requirement
|
34
|
-
requirements:
|
35
|
-
- - "~>"
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 1.4.2
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
requirements:
|
42
|
-
- - "~>"
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: 1.4.2
|
45
31
|
- !ruby/object:Gem::Dependency
|
46
32
|
name: rails
|
47
|
-
requirement: !ruby/object:Gem::Requirement
|
48
|
-
requirements:
|
49
|
-
- - '='
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
version: 4.0.13
|
52
|
-
type: :runtime
|
53
|
-
prerelease: false
|
54
|
-
version_requirements: !ruby/object:Gem::Requirement
|
55
|
-
requirements:
|
56
|
-
- - '='
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version: 4.0.13
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
-
name: protected_attributes
|
61
33
|
requirement: !ruby/object:Gem::Requirement
|
62
34
|
requirements:
|
63
35
|
- - ">="
|
@@ -88,16 +60,16 @@ dependencies:
|
|
88
60
|
name: rspec-rails
|
89
61
|
requirement: !ruby/object:Gem::Requirement
|
90
62
|
requirements:
|
91
|
-
- - "
|
63
|
+
- - ">="
|
92
64
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
65
|
+
version: '0'
|
94
66
|
type: :development
|
95
67
|
prerelease: false
|
96
68
|
version_requirements: !ruby/object:Gem::Requirement
|
97
69
|
requirements:
|
98
|
-
- - "
|
70
|
+
- - ">="
|
99
71
|
- !ruby/object:Gem::Version
|
100
|
-
version:
|
72
|
+
version: '0'
|
101
73
|
- !ruby/object:Gem::Dependency
|
102
74
|
name: sqlite3
|
103
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,10 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
127
|
- !ruby/object:Gem::Version
|
156
128
|
version: '0'
|
157
129
|
requirements: []
|
158
|
-
|
159
|
-
rubygems_version: 2.2.3
|
130
|
+
rubygems_version: 3.1.2
|
160
131
|
signing_key:
|
161
132
|
specification_version: 4
|
162
133
|
summary: Inline validation of your ActiveRecord models via the AJAX internets
|
163
134
|
test_files: []
|
164
|
-
has_rdoc:
|