class_kit 0.2.7 → 0.3.0
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 +4 -4
- data/lib/class_kit/class_methods.rb +9 -8
- 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: b20c309d94b643964bf86c44e068340b2d755c63
|
4
|
+
data.tar.gz: 060545a9535b6b92473588488180854b49b0cb65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bff14c110017f3241f4eba01ab2bfdaf41fa8a0ac837f3998ee9558465fffa161739adc8a0e9dfd1d7e44bafe07e74853773726e6f2291abf7d33ddf55615d3
|
7
|
+
data.tar.gz: 67ea2b16891d7ccc3d628b941a7a199922b963882f11bf2edb592cfd1c5ac7ccb0141403ea56e37b602eb33c176a002edd4e55d057705e5a33183a6c238b3d08
|
@@ -9,16 +9,17 @@ module ClassKit
|
|
9
9
|
attributes = instance_variable_get(:@class_kit_attributes)
|
10
10
|
|
11
11
|
attributes[name] = { name: name, type: type, collection_type: collection_type, allow_nil: allow_nil,
|
12
|
-
|
12
|
+
default: default, auto_init: auto_init, meta: meta }
|
13
13
|
|
14
14
|
class_eval do
|
15
15
|
define_method name do
|
16
|
-
|
16
|
+
|
17
|
+
cka = ClassKit::AttributeHelper.instance.get_attribute(klass: self.class, name: name)
|
17
18
|
|
18
19
|
current_value = instance_variable_get(:"@#{name}")
|
19
20
|
|
20
21
|
if current_value.nil?
|
21
|
-
if cka[:default]
|
22
|
+
if !cka[:default].nil?
|
22
23
|
current_value = instance_variable_set(:"@#{name}", cka[:default])
|
23
24
|
elsif cka[:auto_init]
|
24
25
|
current_value = instance_variable_set(:"@#{name}", cka[:type].new)
|
@@ -31,20 +32,20 @@ module ClassKit
|
|
31
32
|
|
32
33
|
class_eval do
|
33
34
|
define_method "#{name}=" do |value|
|
34
|
-
#get the attribute meta data
|
35
|
+
# get the attribute meta data
|
35
36
|
cka = ClassKit::AttributeHelper.instance.get_attribute(klass: self.class, name: name)
|
36
37
|
|
37
|
-
#verify if the attribute is allowed to be set to nil
|
38
|
+
# verify if the attribute is allowed to be set to nil
|
38
39
|
if value.nil? && cka[:allow_nil] == false
|
39
|
-
raise ClassKit::Exceptions::InvalidAttributeValueError
|
40
|
+
raise ClassKit::Exceptions::InvalidAttributeValueError, "Attribute: #{name}, must not be nil."
|
40
41
|
end
|
41
42
|
|
42
|
-
#check if the value being set is not of the specified type and should attempt to parse the value
|
43
|
+
# check if the value being set is not of the specified type and should attempt to parse the value
|
43
44
|
if !cka[:type].nil? && !value.nil? && (cka[:type] == :bool || !value.is_a?(cka[:type]))
|
44
45
|
begin
|
45
46
|
value = ClassKit::ValueHelper.instance.parse(type: cka[:type], value: value)
|
46
47
|
rescue => e
|
47
|
-
raise ClassKit::Exceptions::InvalidAttributeValueError
|
48
|
+
raise ClassKit::Exceptions::InvalidAttributeValueError, "Attribute: #{name}, must be of type: #{cka[:type]}. Error: #{e}"
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: class_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sage One
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|