sample_core_api 0.0.9.pre.9 → 0.1.0

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: dccb4a18eab1fd181a10a8a6e406031d901967d7250edd915a40e3cadb9e06d9
4
- data.tar.gz: 82d0ba628a912397a3cd2eea67f4736b37a614634353f81ecab64aa7579f358a
3
+ metadata.gz: 965f58974d4462f9c951fd2b66542ac3492a971f724063a8b9b85b1fcb6189d5
4
+ data.tar.gz: 0ccebdb0da60cf420833ead29e63d1e8a959cd7b5ae2146bc56990bfa8c77f1d
5
5
  SHA512:
6
- metadata.gz: 58f1283caf64da0514271f05600be53e589a5f3c75eeb006ea6280afb696b9196491c30ec3af6ce05c332f3eaefe431fdee67db180795326fbbe95c1c446645a
7
- data.tar.gz: 31ddd062bd145e022db77b6be6ad3766a6ba2d5738a7c09c4f150dbfa4cf4f425f28064295585ae29bad73933fb51f813d0adea779eb0c5bab2e7f2af640e816
6
+ metadata.gz: 799cb6d38819cb020bc719e601495027bb4dcca96e44e22ff868b11c2d5bfc902bef135cf53430b38db80541c8eeb299f8a370dbe13a768c6c33adf33df680ff
7
+ data.tar.gz: 8694fe9fcaeeab7bb9653888837b993828f55996bf334dd0365d6143c601b9e7c488533406098270f0e3695204904a7436ba2803e8d20a759024e0b6b3a05543
@@ -4,11 +4,11 @@ module Validator
4
4
  def validate params={}
5
5
  lambda {|self_model, *args, &blk|
6
6
  puts "Validate"
7
- check_validate = self_model.check_validate(*args, &blk) # check validation and return true/false
8
- if check_validate
7
+ check_validate = self_model.check_validate(*args, &blk) # check validation and return [true]/[false, errors]
8
+ if check_validate[0]
9
9
  true
10
10
  else
11
- raise CommonError::InvalidData
11
+ check_validate[2].response_with_error(CommonError::InvalidData, check_validate[1])
12
12
  end
13
13
  }
14
14
  end
@@ -25,4 +25,9 @@ class RestApplication < Sinatra::Base
25
25
  status 422
26
26
  JSON RestApplication.error_response('InvalidData', @errors)
27
27
  end
28
+
29
+ def response_with_error(exception_class, errors=[])
30
+ @errors = errors if !errors.empty?
31
+ raise exception_class
32
+ end
28
33
  end
@@ -40,7 +40,7 @@ class RestService < RestApplication
40
40
  'The service is healthy!'
41
41
  end
42
42
  end
43
- # API route
43
+ # # API route
44
44
  # namespace RestConfiguration::CONFIG[:path] do
45
45
  # get '/seed_1' do
46
46
  # 'Seed 1 API'
@@ -52,13 +52,13 @@ class RestService < RestApplication
52
52
 
53
53
  # # Example for handling error
54
54
  # get '/health' do
55
- # @errors = [
55
+ # errors = [
56
56
  # {
57
57
  # field: 'error field',
58
58
  # code: 'error code',
59
59
  # message: 'error message'
60
60
  # }
61
61
  # ]
62
- # raise CommonError::InvalidData
62
+ # response_with_error(CommonError::InvalidData, errors)
63
63
  # end
64
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sample_core_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9.pre.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fusin Thang
@@ -268,9 +268,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
268
268
  version: 2.3.0
269
269
  required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  requirements:
271
- - - ">"
271
+ - - ">="
272
272
  - !ruby/object:Gem::Version
273
- version: 1.3.1
273
+ version: '0'
274
274
  requirements: []
275
275
  rubyforge_project:
276
276
  rubygems_version: 2.7.7