class_config 0.0.1 → 0.0.2
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/README.md +5 -0
- data/lib/class_config.rb +17 -5
- data/spec/class_config_spec.rb +26 -0
- 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: 76024a4446d2d1178a4ed613a5cdf75126b0f86f
|
4
|
+
data.tar.gz: 1c60e7a58bfb216ecadceefdda66f5438ac4ad20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3affdd141f4565aae0a2b8e4a430aea7be63698523caf2275e300d0ddee9eb5f24ed6d229be07996fd71d32f8b9bf1d9bef085a883642d0425d968b651b008bd
|
7
|
+
data.tar.gz: f7712879fdd1b3ddb244ba23ae1abeb8acea3aab1389d6e03925397f428b2ac79171ad792fbe8d8a97111fbd27f86ba87300937d67628aea0772fba4c7892448
|
data/README.md
CHANGED
@@ -20,9 +20,14 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
class MyClass
|
22
22
|
extend ClassConfig
|
23
|
+
|
23
24
|
attr_config :with_default, 'default value'
|
24
25
|
attr_config :without_default
|
25
26
|
attr_config :setting
|
27
|
+
|
28
|
+
after_config do |config|
|
29
|
+
# Do something
|
30
|
+
end
|
26
31
|
end
|
27
32
|
|
28
33
|
MyClass.configure do |config|
|
data/lib/class_config.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module ClassConfig
|
2
2
|
|
3
|
-
VERSION = '0.0.
|
4
|
-
|
5
|
-
alias_method :configure, :tap
|
3
|
+
VERSION = '0.0.2'
|
6
4
|
|
7
5
|
def attr_config(name, default_value=nil)
|
8
6
|
configuration_defaults[name.to_sym] = default_value
|
@@ -16,6 +14,15 @@ module ClassConfig
|
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
17
|
+
def configure(&block)
|
18
|
+
tap &block
|
19
|
+
@after_config_callback.call self if @after_config_callback
|
20
|
+
end
|
21
|
+
|
22
|
+
def after_config(&block)
|
23
|
+
@after_config_callback = block
|
24
|
+
end
|
25
|
+
|
19
26
|
def configuration
|
20
27
|
configuration_defaults.merge configuration_values
|
21
28
|
end
|
@@ -24,6 +31,12 @@ module ClassConfig
|
|
24
31
|
configuration_values.clear
|
25
32
|
end
|
26
33
|
|
34
|
+
def inherited(subclass)
|
35
|
+
%w(configuration_defaults configuration_values after_config_callback).each do |var|
|
36
|
+
subclass.instance_variable_set "@#{var}", instance_variable_get("@#{var}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
27
40
|
private
|
28
41
|
|
29
42
|
def configuration_defaults
|
@@ -34,5 +47,4 @@ module ClassConfig
|
|
34
47
|
@configuration_values ||= {}
|
35
48
|
end
|
36
49
|
|
37
|
-
|
38
|
-
end
|
50
|
+
end
|
data/spec/class_config_spec.rb
CHANGED
@@ -55,4 +55,30 @@ describe ClassConfig do
|
|
55
55
|
Configurable.setting.must_equal :config_block
|
56
56
|
end
|
57
57
|
|
58
|
+
it 'After configure callback' do
|
59
|
+
class ConfigCallback
|
60
|
+
extend ClassConfig
|
61
|
+
attr_config :key1
|
62
|
+
attr_config :key2
|
63
|
+
|
64
|
+
after_config do |config|
|
65
|
+
config.key2 = config.key1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
ConfigCallback.key2.must_be_nil
|
70
|
+
|
71
|
+
ConfigCallback.configure do |config|
|
72
|
+
config.key1 = :value
|
73
|
+
end
|
74
|
+
|
75
|
+
ConfigCallback.key2.must_equal :value
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'Inherits configuration' do
|
79
|
+
Child = Class.new(Configurable)
|
80
|
+
|
81
|
+
Child.with_default.must_equal 'default value'
|
82
|
+
end
|
83
|
+
|
58
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: class_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|