creatable 2.0.0 → 2.0.1
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 -9
- 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: c3f68612a079b4a7fd1cde02086d26ee91f4006b
|
4
|
+
data.tar.gz: ccdf89aaac1f988e84f63183af4c43ed05cbc711
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a651ef82b80b066b7c390f6fa1b68fb4563fab374f6b256116f0f2f93242cb2aa8ef4208960258199bf9f19e727eb76e18a77f62db474aafda45bd9d67fe86a7
|
7
|
+
data.tar.gz: 10b25e036b87828ed0f5833953607c8716a1113e72eb6c9f041a62e98bb4daebe0a5002f8ea9dec2b4e41a54a660a4f2343688b95431cefca9ceb76fbf5e6902
|
@@ -2,10 +2,9 @@ module Creatable
|
|
2
2
|
# Class methods that get mixed in.
|
3
3
|
module ClassMethods
|
4
4
|
# Returns the list of attributes attatched to this object
|
5
|
-
# @return [
|
5
|
+
# @return [Array] the current attributes
|
6
6
|
def attributes
|
7
|
-
@attributes ||=
|
8
|
-
@attributes
|
7
|
+
@attributes ||= []
|
9
8
|
end
|
10
9
|
|
11
10
|
# Replacement for attr_* Will build the same getter/setter methods.
|
@@ -16,7 +15,7 @@ module Creatable
|
|
16
15
|
# @raise [ArgumentError] if name is not supplied
|
17
16
|
# @raise [ArgumentError] if the type is not accessor, reader, or writer
|
18
17
|
# @return [Void]
|
19
|
-
def attribute(name: nil, type: '
|
18
|
+
def attribute(name: nil, type: 'accessor', kind_of: nil)
|
20
19
|
raise ArgumentError, 'name is a required parameter' unless name
|
21
20
|
raise ArgumentError, "type must be of type: 'accessor', 'reader', or 'writer'" unless ['accessor', 'reader', 'writer'].include? type
|
22
21
|
|
@@ -37,17 +36,24 @@ module Creatable
|
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
|
-
attributes.
|
39
|
+
if attributes.map { |e| e[:name] }.include? name
|
40
|
+
attributes.delete_if { |e| e[:name] == name }
|
41
|
+
attributes.push(name: name, type: type, kind_of: kind_of)
|
42
|
+
else
|
43
|
+
attributes.push(name: name, type: type, kind_of: kind_of)
|
44
|
+
end
|
41
45
|
nil
|
42
46
|
end
|
43
47
|
|
44
48
|
# Create a new instance of a given object. Allows you to pass in any attribute.
|
45
|
-
# @param [Hash]
|
49
|
+
# @param [Hash] args key/value pairs for existing attributes
|
46
50
|
# @return [Object] Newly created object
|
47
|
-
def create(
|
51
|
+
def create(args = {})
|
48
52
|
object = new
|
49
|
-
|
50
|
-
|
53
|
+
names = attributes.map { |e| e[:name].to_sym }
|
54
|
+
args.each do |k, v|
|
55
|
+
object.instance_variable_set "@#{k}".to_sym, v if names.include? k
|
56
|
+
end
|
51
57
|
object
|
52
58
|
end
|
53
59
|
end
|
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.0.
|
4
|
+
version: 2.0.1
|
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-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bump
|