creatable 2.0.0 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9486fdf6f7b16f7f47017d42137d18fe6122d709
4
- data.tar.gz: 3e2a51254d9e8c10444c70e7910b80e90e6a20f8
3
+ metadata.gz: c3f68612a079b4a7fd1cde02086d26ee91f4006b
4
+ data.tar.gz: ccdf89aaac1f988e84f63183af4c43ed05cbc711
5
5
  SHA512:
6
- metadata.gz: c0ffc433467fea9f018fca7feb88b11a57872bf753d643b5539101df7a694130f95e33cccf32e09e96bddad3c2815c06b950560ec8ecbb4a0e7ce5c149428602
7
- data.tar.gz: 1b31eae388bcc13cb19848daf15d27bd3a1bee59f624d79b7380983c188525bef89937060b572ca5e6c21f11c04d9844a62a9e021529a787b0d30245dd1bbc02
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 [Hash] the current attributes
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: 'accesor', kind_of: nil)
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.merge!(name: name, type: type, kind_of: kind_of)
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] arg key/value pairs for existing attributes
49
+ # @param [Hash] args key/value pairs for existing attributes
46
50
  # @return [Object] Newly created object
47
- def create(arg = {})
51
+ def create(args = {})
48
52
  object = new
49
- key, value = arg.flatten
50
- attributes.each { |_l| object.instance_variable_set "@#{key}", value }
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
@@ -1,3 +1,3 @@
1
1
  module Creatable
2
- VERSION = '2.0.0'.freeze # VERSION
2
+ VERSION = '2.0.1'.freeze # VERSION
3
3
  end
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.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-08-27 00:00:00.000000000 Z
11
+ date: 2018-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump