class_kit 0.2.7 → 0.3.0

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: fe1a16b05bdf0a91dd502c6d515510ccf445b614
4
- data.tar.gz: b0fee353af3fd8919136e0f37b9408b2ecabb736
3
+ metadata.gz: b20c309d94b643964bf86c44e068340b2d755c63
4
+ data.tar.gz: 060545a9535b6b92473588488180854b49b0cb65
5
5
  SHA512:
6
- metadata.gz: f6ccbe25890a6b58f1838ee558ddfe93f8a5bb9c3aa8a387a25294518d8fbbdc5e44fe7bb25858d249fedac739a51cf7008e52b876c5cff3c8c2e671791f7f04
7
- data.tar.gz: a6dcd8ae3560b67709da763c8e71f74af6672aa2ae0d1b72890d32a147104b3ee1093d57ac40a58bce59b2326871547ede72e3abd6bbe4d951b6241d0195b882
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
- default: default, auto_init: auto_init, meta: meta }
12
+ default: default, auto_init: auto_init, meta: meta }
13
13
 
14
14
  class_eval do
15
15
  define_method name do
16
- cka = self.class.instance_variable_get(:@class_kit_attributes)[name]
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] != nil
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.new("Attribute: #{name}, must not be nil.")
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.new("Attribute: #{name}, must be of type: #{cka[:type]}. Error: #{e}")
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.2.7
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-04-04 00:00:00.000000000 Z
11
+ date: 2017-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler