smart_init 3.0.0 → 3.1.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
  SHA256:
3
- metadata.gz: 8dee28a188d21cf07e256ca0fd7ef9be6200e7397226b4b4e26b7f995b94acf5
4
- data.tar.gz: fef3f5bad20e6cf3df03dd27a69df4aa429d304098b1acc60426a00c0a8eafd0
3
+ metadata.gz: 7c160db7dd46c5dc77e00e49404e2354519b12ef5200265160586a57ae9fc711
4
+ data.tar.gz: e378b890b6cc8c3c86301d227405ac80f14176b3d3a7e1b673578e4ba7cdcca4
5
5
  SHA512:
6
- metadata.gz: d47fbddd944636439c176a32d5d62871669d5c9ffb505f7b6180e28bc52ac7f91bb9e7699c14378e89b811671ef3626f888ea84916e17ccde3daff96538e1255
7
- data.tar.gz: 32751fb0cda8bc3713f57da5368ae8dde9dbf90ab7b95a1671b61eec17ed69de249d58fa116e4127260291bdeb34c62e962a690a9ee2970929bf1a7733376332
6
+ metadata.gz: 8d6ad48780eac79e681a956709af68dcda5f51c15796c74df575fe233df25f9f5c1817c2feea9a16b17f131d6228d0f7e3d3394676c4a73e891e0e823848d82d
7
+ data.tar.gz: a47ab03b8918c0b34e7efec5200dc2f3831a47571ca888b642cd709db52ad13831ebd9af8beecb55cc29fa8f94a6024ab886c3589e4cb6bc4156a4645d231866
data/README.md CHANGED
@@ -50,6 +50,8 @@ 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
+
54
+
53
55
  You can also use `is_callable` method:
54
56
 
55
57
  ```ruby
@@ -10,8 +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
- if required_attrs.count > parameters.first.count
14
- raise ArgumentError, "wrong number of arguments (given #{parameters.count}, expected at least #{required_attrs.count})"
13
+ required_attrs.each do |required_attr|
14
+ unless parameters.first.has_key?(required_attr)
15
+ raise ArgumentError, "missing required attribute #{required_attr}"
16
+ end
15
17
  end
16
18
 
17
19
  (required_attrs + default_value_attrs.keys).each do |attribute|
@@ -23,7 +25,7 @@ module SmartInit
23
25
  instance_eval do
24
26
  private
25
27
 
26
- attr_reader *(required_attrs + default_value_attrs.keys)
28
+ attr_reader(*(required_attrs + default_value_attrs.keys).compact)
27
29
  end
28
30
  end
29
31
 
@@ -43,10 +45,9 @@ module SmartInit
43
45
  instance_eval do
44
46
  private
45
47
 
46
- attr_reader *attributes
48
+ attr_reader(*attributes)
47
49
  end
48
50
  end
49
-
50
51
  end
51
52
 
52
53
  class SmartInit::Base
@@ -1,3 +1,3 @@
1
1
  module SmartInit
2
- VERSION = "3.0.0"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require "test/unit"
2
2
  require_relative '../lib/smart_init/main'
3
3
 
4
- class TestKeywords
4
+ class TestService
5
5
  extend SmartInit
6
6
  initialize_with :attribute_1, :attribute_2
7
7
  is_callable
@@ -11,7 +11,7 @@ class TestKeywords
11
11
  end
12
12
  end
13
13
 
14
- class TestKeywordsDefaults
14
+ class TestServiceDefaults
15
15
  extend SmartInit
16
16
  initialize_with :attribute_1, attribute_2: "default_value_2", attribute_3: "default_value_3"
17
17
  is_callable
@@ -21,7 +21,7 @@ class TestKeywordsDefaults
21
21
  end
22
22
  end
23
23
 
24
- class TestKeywordsIntegerDefaults
24
+ class TestHashIntegerDefaults
25
25
  extend SmartInit
26
26
  initialize_with :attribute_1, attribute_2: 2
27
27
  is_callable
@@ -31,29 +31,29 @@ class TestKeywordsIntegerDefaults
31
31
  end
32
32
  end
33
33
 
34
- class KeywordsApiTest < Test::Unit::TestCase
34
+ class HashApiTest < Test::Unit::TestCase
35
35
  def test_keywords
36
- assert_equal TestKeywords.call(attribute_1: "a", attribute_2: "b"), ["a", "b"]
36
+ assert_equal TestService.call(attribute_1: "a", attribute_2: "b"), ["a", "b"]
37
37
 
38
38
  assert_raise ArgumentError do
39
- TestKeywords.new(
39
+ TestService.new(
40
40
  attribute_1: "a"
41
41
  )
42
42
  end
43
43
  end
44
44
 
45
45
  def test_keywords_defaults
46
- assert_equal TestKeywordsDefaults.call(attribute_1: "a"), ["a", "default_value_2", "default_value_3"]
47
- assert_equal TestKeywordsDefaults.call(attribute_1: "a", attribute_2: "b"), ["a", "b", "default_value_3"]
46
+ assert_equal TestServiceDefaults.call(attribute_1: "a"), ["a", "default_value_2", "default_value_3"]
47
+ assert_equal TestServiceDefaults.call(attribute_1: "a", attribute_2: "b"), ["a", "b", "default_value_3"]
48
48
  end
49
49
 
50
50
  def test_integer_defaults
51
- assert_equal TestKeywordsIntegerDefaults.call(attribute_1: 1), [1, 2]
51
+ assert_equal TestHashIntegerDefaults.call(attribute_1: 1), [1, 2]
52
52
  end
53
53
 
54
- private
55
-
56
- def test_object
57
- @_test_object ||= TestClass.new("attr_1_value", "attr_2_value")
54
+ def test_missing_attributes
55
+ assert_raise ArgumentError do
56
+ TestService.call(attribute_1: "a", invalid_attribute: "b")
57
+ end
58
58
  end
59
59
  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.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
@@ -55,7 +55,7 @@ files:
55
55
  - lib/smart_init/main.rb
56
56
  - lib/smart_init/version.rb
57
57
  - smart_init.gemspec
58
- - test/test_keywords_api.rb
58
+ - test/test_api.rb
59
59
  - test/test_v1_api.rb
60
60
  homepage: http://github.com/pawurb/smart_init
61
61
  licenses: