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: 9441b691eb7b09b49b1d6ee931433b553f04b32d
4
- data.tar.gz: f4e91f6a4781dd12199fb678da95c4420ec1fd58
3
+ metadata.gz: 6663d86802f24bf946de879228947b71ccb67a7c
4
+ data.tar.gz: e96e83b1a7908ff59a1db6904105ff9fa6094a70
5
5
  SHA512:
6
- metadata.gz: a0e223edb7f846da2d893c2ff64e7383e20a981ff83fa06f2ae4ee28a86b41b00fb0346b668c974fc4657ab2706189346931e2e049eb1975e6211d29e1b02372
7
- data.tar.gz: e390806aaa2d295fe60544ba02a56287884f33915d77fe1e89f2daa685997f1b24a226b57273e0c2259146dcf9b4c000eebb02b4ceae28e32f6db929f03d308d
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
@@ -0,0 +1,11 @@
1
+ module Grape
2
+ module Validations
3
+ class ParamsScope
4
+
5
+ def requires_or_optional(*attrs, &block)
6
+ optional(*attrs, &block)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module NestedResources
3
- VERSION = '0.1.1'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  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.1.1
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-01 00:00:00.000000000 Z
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: []