seteable 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gems +1 -0
- data/lib/seteable.rb +7 -2
- data/makefile +9 -0
- data/seteable.gemspec +1 -1
- data/test/all.rb +49 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 012a9e874801eb6d88544969f8d64e71e19872d3
|
4
|
+
data.tar.gz: 240c9999adab94402f282c3cc4e30d71370b6d26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 469a3e2ca1967edcbe92011bc5d3f94e2a3ab1e6c445f10c50316665e48afbd920de6e8b5aa0c3981c9a77ff6e25fad5adcd14ee15053d69c8e7438d6ded053e
|
7
|
+
data.tar.gz: 891dab9df2edc34f98e5d1747edf6e5327e632d1813855efe1b31141a4be6eaa8e6e359fd4fdc80f22fc0a8fa560cdfe559c5efc21fc671ba05605ac12a9be4c
|
data/.gems
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
cutest:1.2.2
|
data/lib/seteable.rb
CHANGED
@@ -3,8 +3,12 @@ module Seteable
|
|
3
3
|
base.extend(ClassMethods)
|
4
4
|
end
|
5
5
|
|
6
|
-
def self.deepclone(
|
7
|
-
|
6
|
+
def self.deepclone(hash)
|
7
|
+
default_proc, hash.default_proc = hash.default_proc, nil
|
8
|
+
|
9
|
+
return Marshal.load(Marshal.dump(hash))
|
10
|
+
ensure
|
11
|
+
hash.default_proc = default_proc
|
8
12
|
end
|
9
13
|
|
10
14
|
def settings
|
@@ -14,6 +18,7 @@ module Seteable
|
|
14
18
|
module ClassMethods
|
15
19
|
def inherited(subclass)
|
16
20
|
subclass.settings.replace(Seteable.deepclone(settings))
|
21
|
+
subclass.settings.default_proc = proc { |h, k| h[k] = settings[k] }
|
17
22
|
end
|
18
23
|
|
19
24
|
def settings
|
data/makefile
ADDED
data/seteable.gemspec
CHANGED
data/test/all.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative "../lib/seteable"
|
2
|
+
|
3
|
+
test "settings" do
|
4
|
+
class Base
|
5
|
+
include Seteable
|
6
|
+
end
|
7
|
+
|
8
|
+
Base.settings[:foo] = "foo"
|
9
|
+
|
10
|
+
assert_equal "foo", Base.settings[:foo]
|
11
|
+
assert_equal "foo", Base.new.settings[:foo]
|
12
|
+
end
|
13
|
+
|
14
|
+
test "inheritance" do
|
15
|
+
class Parent
|
16
|
+
include Seteable
|
17
|
+
end
|
18
|
+
|
19
|
+
Parent.settings[:foo] = "foo"
|
20
|
+
|
21
|
+
class Child < Parent
|
22
|
+
end
|
23
|
+
|
24
|
+
assert_equal "foo", Child.settings[:foo]
|
25
|
+
end
|
26
|
+
|
27
|
+
test "look up parent if setting not exists" do
|
28
|
+
class Foo
|
29
|
+
include Seteable
|
30
|
+
end
|
31
|
+
|
32
|
+
class Bar < Foo
|
33
|
+
end
|
34
|
+
|
35
|
+
class Baz < Bar
|
36
|
+
end
|
37
|
+
|
38
|
+
Foo.settings[:foo] = "foo"
|
39
|
+
Bar.settings[:bar] = "bar"
|
40
|
+
|
41
|
+
assert_equal "foo", Bar.settings[:foo]
|
42
|
+
assert_equal "foo", Baz.settings[:foo]
|
43
|
+
assert_equal "bar", Baz.settings[:bar]
|
44
|
+
|
45
|
+
Bar.settings[:foo] = "bar"
|
46
|
+
|
47
|
+
assert_equal "bar", Bar.settings[:foo]
|
48
|
+
assert_equal "foo", Baz.settings[:foo]
|
49
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seteable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Rodríguez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Define settings for your library
|
14
14
|
email:
|
@@ -17,10 +17,13 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- ".gems"
|
20
21
|
- LICENSE
|
21
22
|
- README.md
|
22
23
|
- lib/seteable.rb
|
24
|
+
- makefile
|
23
25
|
- seteable.gemspec
|
26
|
+
- test/all.rb
|
24
27
|
homepage: https://github.com/harmoni/seteable
|
25
28
|
licenses:
|
26
29
|
- MIT
|