clavatar 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/clavatar.rb +26 -11
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fbb3f61f81e4c9cc49182ca5ac6f2b6680cf005
|
4
|
+
data.tar.gz: 7c1c21fc5bd31874c002a8a8303b567b304e2fba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4354d16304659fff8bff453692ea09f08393191aa465bdbeb3e0bb0f0f2238ca9766f5861d74596b42a349a423d63860b6017aaebf942c1fbcd9c0ced0def301
|
7
|
+
data.tar.gz: 9cf359755e58ec5c95273501396b8076a912cd68d18966452b34efe1cbb980723b46f43b03be7f8f20ac3281bfa6487fa623f590457ad1947efb2e716a6d0a47
|
data/lib/clavatar.rb
CHANGED
@@ -11,26 +11,41 @@ module Clavatar
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
key_args = {}
|
15
|
+
args = []
|
15
16
|
construct_params = example.method(:initialize).parameters
|
16
17
|
construct_params.each do |param|
|
17
|
-
arg_required = param
|
18
|
-
arg_name = param.last
|
18
|
+
arg_required, arg_name = param
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
case arg_required
|
21
|
+
when :req
|
22
|
+
args << arg_name
|
23
|
+
when :opt
|
24
|
+
args << arg_name if hash.key? arg_name
|
25
|
+
when :keyreq
|
26
|
+
raise "parameter #{arg_name} is mandatory but missing in #{hash}" unless hash.key? arg_name
|
27
|
+
key_args[arg_name] = hash[arg_name]
|
28
|
+
when :keyrest
|
29
|
+
key_args.merge! hash
|
30
|
+
break
|
25
31
|
end
|
32
|
+
end
|
26
33
|
|
27
|
-
|
34
|
+
args.map! { |val| hash[val] }
|
35
|
+
if args.empty? and key_args.empty?
|
36
|
+
instance = klass.send(:new)
|
37
|
+
elsif args.empty?
|
38
|
+
instance = klass.send(:new, key_args)
|
39
|
+
elsif key_args.empty?
|
40
|
+
instance = klass.send(:new, *args)
|
41
|
+
else
|
42
|
+
instance = klass.send(:new, *args, **key_args)
|
28
43
|
end
|
29
44
|
|
30
|
-
instance = klass.new args
|
31
45
|
accessible_attr.each do |attr|
|
32
46
|
instance.send("#{attr}=", hash[attr])
|
33
47
|
end
|
34
|
-
|
48
|
+
|
49
|
+
instance
|
35
50
|
end
|
36
51
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clavatar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Han
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Apply a hash into a Ruby class and return an instance of it.
|
14
14
|
email: hex0cter@gmail.com
|