class_kit 0.2.3 → 0.2.4
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/attribute_helper.rb +11 -2
- data/lib/class_kit/class_methods.rb +7 -5
- data/lib/class_kit/version.rb +1 -1
- 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: dc76efa8bece6ce97ebdd183cf8dfbb714eab01e
|
4
|
+
data.tar.gz: ecd76a46a52174f00a5063efe331270a3351a799
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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.
|
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
|
6
|
-
|
5
|
+
unless instance_variable_defined?(:@class_kit_attributes)
|
6
|
+
instance_variable_set(:@class_kit_attributes, {})
|
7
7
|
end
|
8
8
|
|
9
|
-
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.
|
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.
|
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
|
data/lib/class_kit/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|