inherited_class_var 0.2.1 → 0.2.2
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.rb +6 -5
- data/lib/inherited_class_var/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: a7e840571a249a64b262bfc9bf8527a8035f9af1
|
4
|
+
data.tar.gz: 1af56f855f62cd025389c36691459142a2b3ef78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2a1732a324a908fbe3b7dabed0a9a77dd27f75123158460e682d0d353bef9369bb2ba4f661eebc143330f9719110a3dd69f86bb19018c8389cbf46e29480ee0
|
7
|
+
data.tar.gz: ede1f603e5815b1f6da2c74fdd3cc3a7395b65600ff2f6b0586208d1fc732698058e76716365cf91ec525202be9081396be779f9e4e0bf8806668abb6feed2ce
|
data/lib/inherited_class_var.rb
CHANGED
@@ -21,7 +21,9 @@ 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, {}) do |hash, to_merge|
|
25
|
+
hash.deep_merge!(to_merge) {|key,left,right| left } # a reverse_deep_merge! implementation, this will keep the parent's key order
|
26
|
+
end
|
25
27
|
end
|
26
28
|
|
27
29
|
define_singleton_method :"raw_#{variable_name}" do
|
@@ -75,14 +77,13 @@ module InheritedClassVar
|
|
75
77
|
end
|
76
78
|
|
77
79
|
# @param variable_name [Symbol] class variable name (recommend :@_variable_name)
|
78
|
-
# @param default_value [Object] default value of the class variable
|
79
|
-
# @param merge_method [Symbol] method to merge values of the class variable
|
80
80
|
# @return [Object] a class variable merged across ancestors until inherited_class_module
|
81
|
-
def inherited_class_var(variable_name,
|
81
|
+
def inherited_class_var(variable_name, *reduce_args, &block)
|
82
82
|
class_cache(variable_name) do
|
83
83
|
inherited_ancestors.map { |ancestor| ancestor.instance_variable_get(variable_name) }
|
84
84
|
.compact
|
85
|
-
.
|
85
|
+
.reverse
|
86
|
+
.reduce(*reduce_args, &block)
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
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.2
|
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-06-
|
12
|
+
date: 2016-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|