smart_init 3.1.0 → 3.1.1

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
  SHA256:
3
- metadata.gz: 7c160db7dd46c5dc77e00e49404e2354519b12ef5200265160586a57ae9fc711
4
- data.tar.gz: e378b890b6cc8c3c86301d227405ac80f14176b3d3a7e1b673578e4ba7cdcca4
3
+ metadata.gz: 34a07f2fa3876c9ca80bb60bf76e045aa0c96f408abb6f761c8b80a5d988806a
4
+ data.tar.gz: ca8b35191d340a1a43138e7698c8c0bd6f8f1d3d90787d252bf67d66e33e1f22
5
5
  SHA512:
6
- metadata.gz: 8d6ad48780eac79e681a956709af68dcda5f51c15796c74df575fe233df25f9f5c1817c2feea9a16b17f131d6228d0f7e3d3394676c4a73e891e0e823848d82d
7
- data.tar.gz: a47ab03b8918c0b34e7efec5200dc2f3831a47571ca888b642cd709db52ad13831ebd9af8beecb55cc29fa8f94a6024ab886c3589e4cb6bc4156a4645d231866
6
+ metadata.gz: 10780f72f2f6e43497fe4fbde549cfdd4cedf7db3c704bad8cc44f0c21f296d34e374bda479cd81835df1a44bac06708500ab4dcaa47ac3ec469ecc6341e66ce
7
+ data.tar.gz: 00c1fb99e8891cf6fb4081c42d03ff00b2f6e511350c630529d7255735b353156e9f50cdef5a9e6c2c3018e0032430685a317afbd0d3a33a5b11be0ee643509e
data/README.md CHANGED
@@ -50,7 +50,13 @@ object = ApiClient.new(network_provider: Faraday.new, api_token: 'secret_token')
50
50
  # <ApiClient:0x007fa16684ec20 @network_provider=Faraday<...>, @api_token="secret_token">
51
51
  ```
52
52
 
53
+ If you omit a required attribute an `ArgumentError` will be thrown:
53
54
 
55
+ ```ruby
56
+ object = ApiClient.new(network_provider: Faraday.new)
57
+
58
+ # ArgumentError (missing required attribute api_token)
59
+ ```
54
60
 
55
61
  You can also use `is_callable` method:
56
62
 
@@ -10,6 +10,10 @@ module SmartInit
10
10
  default_value_attrs = attributes.select { |attr| attr.is_a?(Hash) }.first || {}
11
11
 
12
12
  define_method :initialize do |*parameters|
13
+ unless parameters.first.is_a?(Hash)
14
+ raise ArgumentError, "invalid input, expected hash of attributes"
15
+ end
16
+
13
17
  required_attrs.each do |required_attr|
14
18
  unless parameters.first.has_key?(required_attr)
15
19
  raise ArgumentError, "missing required attribute #{required_attr}"
@@ -1,3 +1,3 @@
1
1
  module SmartInit
2
- VERSION = "3.1.0"
2
+ VERSION = "3.1.1"
3
3
  end
data/test/test_api.rb CHANGED
@@ -56,4 +56,10 @@ class HashApiTest < Test::Unit::TestCase
56
56
  TestService.call(attribute_1: "a", invalid_attribute: "b")
57
57
  end
58
58
  end
59
+
60
+ def test_invalid_input
61
+ assert_raise ArgumentError do
62
+ TestService.call("invalid_input here")
63
+ end
64
+ end
59
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_init
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb