smart_init 3.1.1 → 3.2.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 +4 -4
- data/README.md +2 -2
- data/lib/smart_init/main.rb +4 -2
- data/lib/smart_init/version.rb +1 -1
- data/test/{test_v1_api.rb → test_args_api.rb} +1 -1
- data/test/{test_api.rb → test_hash_api.rb} +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81cc9ffbde7cec66828bcbb93ed817974a36c124b24ed41b375c15153c7cbb87
|
4
|
+
data.tar.gz: 1c008ff8b237652378db6108e0c9e545b7b34663001a56f592955537f2bf826a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96a55247900e09af2ac195a5819467756cd9bccb302215399d7cc4e8d8d09d01cdb338c04a8e6e45a907b9ad7ca63c209d1696e5f1e7acddf9fa2fe86eefe120
|
7
|
+
data.tar.gz: a2c82c78dc036fce298794963999d5327dab6b98d23f6eb778b79dd532dac2a5003065af0fd7fa44c4f188a52dd83ee15bbea6096d3f6c4ce4051ada60c08326
|
data/README.md
CHANGED
@@ -93,13 +93,13 @@ Adder.call(num_a: 2, num_b: 3) => 5
|
|
93
93
|
|
94
94
|
```
|
95
95
|
|
96
|
-
## Legacy API
|
96
|
+
## Legacy Arguments API
|
97
97
|
|
98
98
|
Alternatively you can a legacy API without hash arguments and default values:
|
99
99
|
|
100
100
|
```ruby
|
101
101
|
class Calculator < SmartInit::Base
|
102
|
-
|
102
|
+
initialize_with_args :data
|
103
103
|
is_callable
|
104
104
|
|
105
105
|
def call
|
data/lib/smart_init/main.rb
CHANGED
@@ -5,7 +5,7 @@ module SmartInit
|
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
8
|
+
def initialize_with_hash *attributes
|
9
9
|
required_attrs = attributes.select { |attr| attr.is_a?(Symbol) }
|
10
10
|
default_value_attrs = attributes.select { |attr| attr.is_a?(Hash) }.first || {}
|
11
11
|
|
@@ -33,7 +33,9 @@ module SmartInit
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
alias initialize_with initialize_with_hash
|
37
|
+
|
38
|
+
def initialize_with_args *attributes
|
37
39
|
define_method :initialize do |*parameters|
|
38
40
|
if attributes.count != parameters.count
|
39
41
|
raise ArgumentError, "wrong number of arguments (given #{parameters.count}, expected #{attributes.count})"
|
data/lib/smart_init/version.rb
CHANGED
File without changes
|
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.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
@@ -55,8 +55,8 @@ files:
|
|
55
55
|
- lib/smart_init/main.rb
|
56
56
|
- lib/smart_init/version.rb
|
57
57
|
- smart_init.gemspec
|
58
|
-
- test/
|
59
|
-
- test/
|
58
|
+
- test/test_args_api.rb
|
59
|
+
- test/test_hash_api.rb
|
60
60
|
homepage: http://github.com/pawurb/smart_init
|
61
61
|
licenses:
|
62
62
|
- MIT
|