class_kit 0.2.3 → 0.2.4

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: e6175988d95d1b402e572de4e37188609b472faf
4
- data.tar.gz: cb3d17f32c2d552fd0a75f82d6aa07c6767a4b03
3
+ metadata.gz: dc76efa8bece6ce97ebdd183cf8dfbb714eab01e
4
+ data.tar.gz: ecd76a46a52174f00a5063efe331270a3351a799
5
5
  SHA512:
6
- metadata.gz: 63fba237db2c0dfdd7ee309696beb40d4715ce14b79ec3cac04eb8452ca779f759edbc689f3f297a2a13c874270218652b13a96b6d6aa798aab8f49c576ecb8b
7
- data.tar.gz: e187ffdfdf9acc30fd4eec3ce2a983899c8ddc495e3eed2ec797e8fd0a040de4c53c3750acb9ded8906782fd655569b11adf5439c7c33c45a569fd435363fcde
6
+ metadata.gz: a64b6be2224ce8daa5ffafd09b3a896ce19186d05045c43874ea1d4fa4f3530953b180750c7bf52d795b32ce81e87cfb1182ad01520d3884f0d97cbffe235549
7
+ data.tar.gz: b9f06655edf946da687ebac8febd2f10f693e30e80134d01b1f141e2d04db67feaf300febca1958acd3bb39c3a115211e1f5564e8fb89abeed0ff26540d7f405
@@ -6,7 +6,16 @@ module ClassKit
6
6
  #
7
7
  # @return [Hash]
8
8
  def get_attributes(klass)
9
- klass.class_variable_get(:@@class_kit_attributes).values.freeze
9
+ attributes = []
10
+ klass.ancestors.map do |k|
11
+ hash = k.instance_variable_get(:@class_kit_attributes)
12
+ if hash != nil
13
+ hash.values.each do |a|
14
+ attributes.push(a)
15
+ end
16
+ end
17
+ end
18
+ attributes.compact
10
19
  end
11
20
 
12
21
  # Get attribute for a given class and name
@@ -18,7 +27,7 @@ module ClassKit
18
27
  #
19
28
  # @return [Hash] that describes the attribute
20
29
  def get_attribute(klass:, name:)
21
- klass.class_variable_get(:@@class_kit_attributes)[name] ||
30
+ get_attributes(klass).detect { |a| a[:name] == name } ||
22
31
  raise(ClassKit::Exceptions::AttributeNotFoundError, "Attribute: #{name}, could not be found.")
23
32
  end
24
33
 
@@ -2,18 +2,20 @@ module ClassKit
2
2
  def attr_accessor_type(name, type: nil, collection_type: nil, allow_nil: true, default: nil, auto_init: false,
3
3
  meta: {})
4
4
 
5
- unless class_variable_defined?(:@@class_kit_attributes)
6
- class_variable_set(:@@class_kit_attributes, {})
5
+ unless instance_variable_defined?(:@class_kit_attributes)
6
+ instance_variable_set(:@class_kit_attributes, {})
7
7
  end
8
8
 
9
- attributes = class_variable_get(:@@class_kit_attributes)
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
+ puts self
14
+ puts self.ancestors
13
15
 
14
16
  class_eval do
15
17
  define_method name do
16
- cka = self.class.class_variable_get(:@@class_kit_attributes)[name]
18
+ cka = self.class.instance_variable_get(:@class_kit_attributes)[name]
17
19
 
18
20
  current_value = instance_variable_get(:"@#{name}")
19
21
 
@@ -32,7 +34,7 @@ module ClassKit
32
34
  class_eval do
33
35
  define_method "#{name}=" do |value|
34
36
  #get the attribute meta data
35
- cka = self.class.class_variable_get(:@@class_kit_attributes)[name]
37
+ cka = self.class.instance_variable_get(:@class_kit_attributes)[name]
36
38
 
37
39
  #verify if the attribute is allowed to be set to nil
38
40
  if value.nil? && cka[:allow_nil] == false
@@ -1,3 +1,3 @@
1
1
  module ClassKit
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
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.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaughanbrittonsage
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler