creatable 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/creatable/class_methods.rb +15 -10
- data/lib/creatable/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: e6b42abcff609998d39ef809a52187796c820a88
|
4
|
+
data.tar.gz: fa805820fcee26be7b4febe18422cf47f33c0140
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f64fc80434e4a78a55b934b44d3d321c16315a3ddf5a8a592884d191a70592a271097f5b9e86e769d9fb4e98f58bc0bf7996c2fd9485f987189025fe50fd58bf
|
7
|
+
data.tar.gz: 8b77d760f5e4cad59d6f78ebecaccfc7883ce6bb6069447370d07d044544df7b0400d8981ec54a41a01017df788a6a1b65e61cf7042819ceb1e8f7f10cdf08e9
|
@@ -15,7 +15,7 @@ module Creatable
|
|
15
15
|
# @raise [ArgumentError] if name is not supplied
|
16
16
|
# @raise [ArgumentError] if the type is not accessor, reader, or writer
|
17
17
|
# @return [Void]
|
18
|
-
def attribute(name: nil, type: 'accessor', kind_of: nil)
|
18
|
+
def attribute(name: nil, type: 'accessor', kind_of: nil, &block)
|
19
19
|
raise ArgumentError, 'name is a required parameter' unless name
|
20
20
|
raise ArgumentError, "type must be of type: 'accessor', 'reader', or 'writer'" unless ['accessor', 'reader', 'writer'].include? type
|
21
21
|
|
@@ -30,11 +30,9 @@ module Creatable
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
if attributes.map { |e| e[:name] }.include? name
|
34
|
-
attributes.delete_if { |e| e[:name] == name }
|
35
|
-
end
|
33
|
+
attributes.delete_if { |e| e[:name] == name } if attributes.map { |e| e[:name] }.include? name
|
36
34
|
|
37
|
-
attributes.push(name: name, type: type, kind_of: kind_of)
|
35
|
+
attributes.push(name: name, type: type, kind_of: kind_of, block: block)
|
38
36
|
nil
|
39
37
|
end
|
40
38
|
|
@@ -43,13 +41,20 @@ module Creatable
|
|
43
41
|
# @return [Object] Newly created object
|
44
42
|
def create(args = {})
|
45
43
|
object = new
|
46
|
-
names = attributes.map { |e| e[:name].to_sym }
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
# names = attributes.map { |e| e[:name].to_sym }
|
45
|
+
|
46
|
+
attributes.each do |a|
|
47
|
+
value = args[a[:name].to_sym]
|
48
|
+
next unless value
|
50
49
|
|
51
|
-
|
50
|
+
if a[:block]
|
51
|
+
a[:block].call object
|
52
|
+
else
|
53
|
+
object.instance_variable_set "@#{a[:name]}".to_sym, value
|
54
|
+
end
|
55
|
+
end
|
52
56
|
|
57
|
+
yield object if block_given?
|
53
58
|
object
|
54
59
|
end
|
55
60
|
|
data/lib/creatable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: creatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Brodeur
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bump
|