inherited_class_var 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/inherited_class_var/version.rb +1 -1
- data/lib/inherited_class_var.rb +13 -3
- 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: 5c5ef71f52f5e727e244a172a79678277c22d97f
|
4
|
+
data.tar.gz: 28ee4455746c407372eefa3017e5d3c8686250d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 312e9432006f123571e33cf44260c6e345d0d7585adec3d0b6bcf1eec6c0334d5228efe1973d805a05dede3c41ec214182271127bc9d35cb72049044179c7357
|
7
|
+
data.tar.gz: d0c85a0549b2f4d5df589bdcb49754ab857483333fe681e9f7d44d050132d9313fece11bee61fa751c58e94ddffdba135b8299d3cdb47cbde36d792ec060f92b
|
data/lib/inherited_class_var.rb
CHANGED
@@ -21,13 +21,16 @@ module InheritedClassVar
|
|
21
21
|
hidden_variable_name = hidden_variable_name(variable_name)
|
22
22
|
|
23
23
|
define_singleton_method variable_name do
|
24
|
-
inherited_class_var(hidden_variable_name, {}, :
|
24
|
+
inherited_class_var(hidden_variable_name, {}, :deep_merge)
|
25
|
+
end
|
26
|
+
|
27
|
+
define_singleton_method :"raw_#{variable_name}" do
|
28
|
+
class_var(hidden_variable_name, {})
|
25
29
|
end
|
26
30
|
|
27
31
|
define_singleton_method :"merge_#{variable_name}" do |merge_value|
|
28
|
-
value = instance_variable_get(hidden_variable_name) || instance_variable_set(hidden_variable_name, {})
|
29
32
|
deep_clear_class_cache(hidden_variable_name)
|
30
|
-
|
33
|
+
public_send(:"raw_#{variable_name}").deep_merge!(merge_value)
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
@@ -64,6 +67,13 @@ module InheritedClassVar
|
|
64
67
|
:"@_#{variable_name}"
|
65
68
|
end
|
66
69
|
|
70
|
+
# @param variable_name [Symbol] class variable name
|
71
|
+
# @param default_value [Object] default value of the class variable
|
72
|
+
# @return [Object] a class variable of the specific class without taking into account inheritance
|
73
|
+
def class_var(variable_name, default_value)
|
74
|
+
instance_variable_get(variable_name) || instance_variable_set(variable_name, default_value)
|
75
|
+
end
|
76
|
+
|
67
77
|
# @param variable_name [Symbol] class variable name (recommend :@_variable_name)
|
68
78
|
# @param default_value [Object] default value of the class variable
|
69
79
|
# @param merge_method [Symbol] method to merge values of the class variable
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inherited_class_var
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Chung
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-06-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|