smart_init 3.3.0 → 3.4.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: 6348b5da71d03671ec74c8a43d2400e84076b4510fae3cb61f1db3da92752ba9
4
- data.tar.gz: 95879658e1ff5b439206ad61c8472659d4331e058e1841d83bef56eaea3eb254
3
+ metadata.gz: '0892f8aa5ed6cba8c888e4a44e67ab3b7fd95fae4648c227593d3ce517fa07f4'
4
+ data.tar.gz: 927c461dfc531d9b21d365609b2f86be35a14102fde2bba092f672d8d55a9d16
5
5
  SHA512:
6
- metadata.gz: 3239515e6cfee5cfc1a1be8b12d6b4799ede9e8ca020f4d7c8ee38d8ab6f2e61d80c9d1f86563c5302779f47d232dda0cd44db8a5164439522dfbd33abc450b2
7
- data.tar.gz: 60abdec0ed7227d03bdc6d1c93d955202ea64ce31a6ade006a0b0c9a3f25c547bda222d0c8a349242789be5e8d1b70609f9a29ea11855cbb8b3981dce1d57d6c
6
+ metadata.gz: 3de078331f718dc999244841c6e3b2e0321af77e43352fde4593c2b08f45e680f98685480fe7455192d9b2d44e804f610ef3ddd588b810700750d116a3c9b1b6
7
+ data.tar.gz: 6523291cb5c8b9a9af044b82ff85c6b2d3c0814a25d506ed2c1d8502b355ba15e33211cd0ebfc45bc859848b7e571a8e83668d5f4d30194970f2c3e452170836
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  rvm:
2
2
  - 2.4.4
3
3
  - 2.5.3
4
- - 2.6.0
4
+ - 2.6.5
5
5
  notifications:
6
6
  email: false
7
7
 
data/README.md CHANGED
@@ -15,7 +15,7 @@ end
15
15
 
16
16
  Gem provides a simple DSL for getting rid of it. It offers an alternative to using `Struct.new` which does not check for number of parameters provided in initializer, exposes getters and instantiates unecessary class instances.
17
17
 
18
- **Smart Init** offers a unified api for stateless service objects, accepting values in initializer and exposing one public class method `call` which instantiates new objects and accepts arguments passed to initializer.
18
+ **Smart Init** offers a unified API convention for stateless service objects, accepting values in initializer and exposing one public class method `call` which instantiates new objects and accepts arguments passed to initializer.
19
19
 
20
20
  Check out [this blog post](https://pawelurbanek.com/2018/02/12/ruby-on-rails-service-objects-and-testing-in-isolation/) for my reasoning behind this approach to service object pattern.
21
21
 
@@ -64,6 +64,15 @@ object = ApiClient.new(network_provider: Faraday.new)
64
64
  # ArgumentError (missing required attribute api_token)
65
65
  ```
66
66
 
67
+ Contrary to using Struct, reader methods are not publicly exposed:
68
+
69
+ ```ruby
70
+ object = ApiClient.new(network_provider: Faraday.new, api_token: 'secret_token')
71
+ object.api_token
72
+
73
+ # NoMethodError (private method `api_token' called for #<ApiClient:0x00007fe911876a48>)
74
+ ```
75
+
67
76
  You can also use `is_callable` method:
68
77
 
69
78
  ```ruby
@@ -114,9 +123,9 @@ Adder.call(num_a: 2, num_b: 3) => 5
114
123
 
115
124
  ```
116
125
 
117
- ## Legacy Arguments API
126
+ ## Arguments API
118
127
 
119
- Alternatively you can a legacy API without hash arguments and default values:
128
+ Alternatively you can use an API without hash arguments and default values:
120
129
 
121
130
  ```ruby
122
131
  class Calculator < SmartInit::Base
@@ -16,6 +16,7 @@ module SmartInit
16
16
  default_value_attrs = attributes.select { |attr| attr.is_a?(Hash) }.first || {}
17
17
 
18
18
  define_method :initialize do |*parameters|
19
+ parameters = [{}] if parameters == []
19
20
  unless parameters.first.is_a?(Hash)
20
21
  raise ArgumentError, "invalid input, expected hash of attributes"
21
22
  end
@@ -1,3 +1,3 @@
1
1
  module SmartInit
2
- VERSION = "3.3.0"
2
+ VERSION = "3.4.0"
3
3
  end
@@ -21,6 +21,16 @@ class TestServiceDefaults
21
21
  end
22
22
  end
23
23
 
24
+ class TestServiceAllDefaults
25
+ extend SmartInit
26
+ initialize_with attribute_1: "default_value_1", attribute_2: "default_value_2", attribute_3: "default_value_3"
27
+ is_callable
28
+
29
+ def call
30
+ [attribute_1, attribute_2, attribute_3]
31
+ end
32
+ end
33
+
24
34
  class TestHashIntegerDefaults
25
35
  extend SmartInit
26
36
  initialize_with :attribute_1, attribute_2: 2
@@ -62,4 +72,8 @@ class HashApiTest < Test::Unit::TestCase
62
72
  TestService.call("invalid_input here")
63
73
  end
64
74
  end
75
+
76
+ def test_all_defaults
77
+ assert_equal TestServiceAllDefaults.call, ["default_value_1", "default_value_2", "default_value_3"]
78
+ end
65
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_init
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-02 00:00:00.000000000 Z
11
+ date: 2019-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubygems_version: 3.0.0
79
+ rubygems_version: 3.0.3
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: Remove Ruby initializer boilerplate code