grape-nested_resources 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6663d86802f24bf946de879228947b71ccb67a7c
|
4
|
+
data.tar.gz: e96e83b1a7908ff59a1db6904105ff9fa6094a70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcab00ca5732c3d2ecdc13c9c2dc91faffc973174d185d3f0106828f79a4342e68bc0f28b6b39275311a26424289f29e55627d79310bbaf9c9b8e0aafbd0e9a8
|
7
|
+
data.tar.gz: b0eff6d5025405dea0c4df6ca6950e467c0d7a9bef5bedb98082eb75fce61938872ece7c236c445c35845093e8e5fdddc56f2e00c495c4cddf288722b00ad585
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_support/core_ext/object/blank'
|
2
|
+
|
3
|
+
module Grape
|
4
|
+
module Validations
|
5
|
+
class DependsOf < Grape::Validations::Base
|
6
|
+
|
7
|
+
def validate!(params)
|
8
|
+
attributes = Grape::Validations::AttributesIterator.new(self, @scope, params)
|
9
|
+
attributes.each do |resource_params, attr_name|
|
10
|
+
validate_param!(attr_name, resource_params) if resource_params.respond_to?(:key?)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def validate_param!(attr_name, params)
|
15
|
+
return if params.key?(attr_name) && params[attr_name].present?
|
16
|
+
|
17
|
+
unless params.key?(@option) && params[@option].present?
|
18
|
+
fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message_key: :presence
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -2,6 +2,9 @@ require 'grape'
|
|
2
2
|
require 'active_support/concern'
|
3
3
|
require 'active_support/core_ext/string/inflections'
|
4
4
|
|
5
|
+
require_relative 'nested_resources/validations/depends_of'
|
6
|
+
require_relative 'nested_resources/validations/params_scope'
|
7
|
+
|
5
8
|
module Grape
|
6
9
|
module NestedResources
|
7
10
|
extend ActiveSupport::Concern
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-nested_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikhail Grachev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,6 +82,8 @@ files:
|
|
82
82
|
- bin/setup
|
83
83
|
- grape-nested_resources.gemspec
|
84
84
|
- lib/grape/nested_resources.rb
|
85
|
+
- lib/grape/nested_resources/validations/depends_of.rb
|
86
|
+
- lib/grape/nested_resources/validations/params_scope.rb
|
85
87
|
- lib/grape/nested_resources/version.rb
|
86
88
|
homepage: ''
|
87
89
|
licenses: []
|