creatable 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3c021202eacf13d5497b46a64aebeda336811be
4
- data.tar.gz: 05634edfbc85041a7edbd1293d11f959d61c154b
3
+ metadata.gz: dea71b1c10a1d84dba409e63e548bf0ae7506281
4
+ data.tar.gz: 0c8c4e8fd956cc31098e489d17597fb057fd1011
5
5
  SHA512:
6
- metadata.gz: b2038da9e88f5c7521a5a8faa5a67d97687f17b5a170374a8ca29da04a42e05c845e3d91da49f9ba4e5eecfa2dbbe9ecc86e5fc32b39ca53d04a823b7fa2e3fe
7
- data.tar.gz: d98af0936df2416738194bab876339457a2f416b03f975f09e3d6184d5261e16311052dc070e96ee31601cabc33a21bb9dbe078f08a73e11b5e4130b5ca3bd7e
6
+ metadata.gz: 2f5c993adc099683ca06ad07d1f9e312e766973beb0ab2629c2429464e5b1df8571cdeb49bf8df078b50258852a61a6e3c78654bed3c4c0927014925fe614164
7
+ data.tar.gz: d3859c46f62b4bd23b00d9a74cc57b0b57bd2b5e495edb816474b1e28b049329b083c0d15bebc80f32b6b596875a012e501fb52b83665e55d3f2ea91e971e5cb
data/README.md CHANGED
@@ -66,6 +66,10 @@ end
66
66
  # creating a new object from parameters
67
67
  A.create i.to_parameters
68
68
  ```
69
+ ## Usage notes
70
+
71
+ - key can be in several formats: 'key', :key, and ':key' will all be accepted.
72
+ - if you supply a `block` of code, it will be executed right before `.create` returns.
69
73
 
70
74
  ## Development
71
75
 
@@ -42,19 +42,22 @@ module Creatable
42
42
  def create(args = {})
43
43
  object = new
44
44
 
45
+ fixed_args = {}
46
+ args.each { |k, v| fixed_args.store(fix_key(k), v) }
47
+
45
48
  attributes.each do |a|
46
- next unless args.keys.include? a[:name].to_sym
49
+ next unless fixed_args.key? a[:name].to_sym
47
50
 
48
- value = args[a[:name].to_sym]
51
+ value = fixed_args[a[:name].to_sym]
49
52
 
50
53
  if a[:block]
51
54
  a[:block].call object, value
52
55
  else
53
- object.instance_variable_set "@#{a[:name]}".to_sym, value
56
+ object.instance_variable_set "@#{a[:name].to_sym}", value
54
57
  end
55
58
  end
56
59
 
57
- yield object, args if block_given?
60
+ yield object, fixed_args if block_given?
58
61
  object
59
62
  end
60
63
 
@@ -75,5 +78,10 @@ module Creatable
75
78
  instance_variable_set "@#{name}", value
76
79
  end
77
80
  end
81
+
82
+ def fix_key(key)
83
+ key = key[1..-1] if key.is_a?(String) && key.start_with?(":")
84
+ key.to_sym
85
+ end
78
86
  end
79
87
  end
@@ -1,3 +1,3 @@
1
1
  module Creatable
2
- VERSION = '2.3.0'.freeze # VERSION
2
+ VERSION = '2.3.1'.freeze # VERSION
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: creatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Brodeur