light-services 0.2.0 → 0.3.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: 5db84437c5190b2655be8840e05543d0e9c5cc27
4
- data.tar.gz: 77bf318293be0f35ebb87062fc3f625a2f0e7a25
3
+ metadata.gz: 6dc81950e4f4b54c022aaf5541706b2571f65f5a
4
+ data.tar.gz: 114558b414ac617bf67aeb62ab24ed5e846b89b0
5
5
  SHA512:
6
- metadata.gz: 7eb78b4a6126f9347047615a1f904237f9b0a62529a19eed29c585cdbc91ae1727f0079efc87b590df845d2577aa298b3b747c3f7f84a4d469b24f097cca6457
7
- data.tar.gz: 017de716dc089d5031334fddc933ed030fdf33f0ec2f5cbdfc093d96a72937dbf16f10f66d595a9c12339a623842bc9504a8cdb566c0ee41b17a89e983cd7947
6
+ metadata.gz: 8447dc3a9f85f4fdf24d1ab6bc7f789a9caab8ffd81d9883de94e5f8c16b198a9b55a7837408383cb7b3610c409bf0067ffe5e0e4da33bcd8d5db40fff0d4a28
7
+ data.tar.gz: 7ef1779434b7836916605df9d05c09f613f79cf6d1cfd11d1ee2975a47ee64a8ec830be67ea09f1020130206ccdd413cccd6148019ad5118e988465fdad282b6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- light-services (0.1.0)
4
+ light-services (0.2.0)
5
5
  rails (> 4.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- light-services (0.1.0)
4
+ light-services (0.2.0)
5
5
  rails (> 4.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- light-services (0.1.0)
4
+ light-services (0.2.0)
5
5
  rails (> 4.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- light-services (0.1.0)
4
+ light-services (0.2.0)
5
5
  rails (> 4.0)
6
6
 
7
7
  GEM
@@ -28,6 +28,7 @@ module Light
28
28
  # Skip or raise exception if parameter not exist
29
29
  unless args.key?(options[:name])
30
30
  next unless options[:required]
31
+ next if options[:allow_nil]
31
32
  raise Light::Services::ParamRequired, "Parameter \"#{options[:name]}\" is required"
32
33
  end
33
34
 
@@ -35,7 +36,10 @@ module Light
35
36
  value = args[options[:name]]
36
37
 
37
38
  # Check type of parameter
38
- if options[:type] && !value.is_a?(options[:type])
39
+ wrong_type = options[:type] && !options[:type].include?(value.class)
40
+ not_allow_nil = !options[:allow_nil] || (options[:allow_nil] && !value.nil?)
41
+
42
+ if wrong_type && not_allow_nil
39
43
  raise Light::Services::ParamType, "Type of \"#{options[:name]}\" must be \"#{options[:type]}\""
40
44
  end
41
45
 
@@ -76,10 +80,11 @@ module Light
76
80
  def param(name, options = {})
77
81
  self.parameters ||= []
78
82
  self.parameters << {
79
- name: name,
80
- required: options.fetch(:required, true),
81
- public: options.fetch(:private, false),
82
- type: options[:type] || nil
83
+ name: name,
84
+ required: options.fetch(:required, true),
85
+ public: options.fetch(:private, false),
86
+ type: [*options[:type]].compact,
87
+ allow_nil: options.fetch(:allow_nil, false)
83
88
  }
84
89
  end
85
90
 
@@ -1,5 +1,5 @@
1
1
  module Light
2
2
  module Services
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: light-services
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Emelianenko