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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec4904f269918a1df2b7f383c89039666d1741d7
4
- data.tar.gz: f719d5fa0a2714e2adabadb7a432c5e1bf2bb077
3
+ metadata.gz: 012a9e874801eb6d88544969f8d64e71e19872d3
4
+ data.tar.gz: 240c9999adab94402f282c3cc4e30d71370b6d26
5
5
  SHA512:
6
- metadata.gz: f5236d5fe2713b83c8d337aa1d2c5a2df8115cbb23154f4a8e3d225b9e74f44ec9525eb5ecfccf38817a791f9b2657f81ef8e2c2006336274fa38efcaa39c81d
7
- data.tar.gz: 76e43dda54e6d43b228b1f6c2c992935b7b4f42cef958f7669097f76bfe01f392e8e3ed91a418b64b44acd5b6ed64c20ee51986046757cf8ac431a63cc4488f6
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(obj)
7
- return Marshal.load(Marshal.dump(obj))
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
@@ -0,0 +1,9 @@
1
+ default: test
2
+
3
+ install:
4
+ @cat .gems | xargs gem install
5
+
6
+ test:
7
+ @cutest ./test/all.rb
8
+
9
+ .PHONY: test
data/seteable.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "seteable"
3
- s.version = "1.0.0"
3
+ s.version = "1.1.0"
4
4
  s.summary = "Define settings for your library"
5
5
  s.description = s.summary
6
6
  s.authors = ["Francesco Rodríguez"]
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.0.0
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-09-15 00:00:00.000000000 Z
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