contextuality 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -83,8 +83,10 @@ end #=> "Hello"
83
83
 
84
84
  ```
85
85
  Contextuality.defaults[:foo] = 'Hello'
86
+ Contextuality.defaults[:bar] = ->{ 'Hello' }
86
87
 
87
88
  contextualize(foo: 'Goodbye') do
89
+ Contextuality.bar #=> 'Hello'
88
90
  Foo.foo #=> "Goodbye"
89
91
  end #=> "Goodbye"
90
92
 
@@ -1,4 +1,5 @@
1
1
  require "contextuality/version"
2
+ require "contextuality/defaults"
2
3
  require "contextuality/context"
3
4
 
4
5
  module Contextuality
@@ -14,7 +15,7 @@ module Contextuality
14
15
  end
15
16
 
16
17
  def self.defaults
17
- ::Thread.main[:contextuality_defaults] ||= {}
18
+ ::Thread.main[:contextuality_defaults] ||= Contextuality::Defaults.new
18
19
  end
19
20
 
20
21
  module ContextualityMethods
@@ -0,0 +1,12 @@
1
+ module Contextuality
2
+ class Defaults < Hash
3
+ def [] key
4
+ value = super key.to_sym
5
+ value.respond_to?(:call) ? value.call : value
6
+ end
7
+
8
+ def []= key, value
9
+ super key.to_sym, value
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Contextuality
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -107,4 +107,22 @@ describe Contextuality do
107
107
  end
108
108
  end
109
109
  end
110
+
111
+ context 'defaults lambda' do
112
+ before { Contextuality.defaults[:bar] = ->{ 'Foo' } }
113
+
114
+ specify { Contextuality.bar.should == 'Foo' }
115
+
116
+ specify do
117
+ contextualize do
118
+ Contextuality.bar.should == 'Foo'
119
+ end
120
+ end
121
+
122
+ specify do
123
+ contextualize(bar: 'Hello') do
124
+ Contextuality.bar.should == 'Hello'
125
+ end
126
+ end
127
+ end
110
128
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contextuality
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -29,6 +29,7 @@ files:
29
29
  - contextuality.gemspec
30
30
  - lib/contextuality.rb
31
31
  - lib/contextuality/context.rb
32
+ - lib/contextuality/defaults.rb
32
33
  - lib/contextuality/version.rb
33
34
  - spec/contextuality/context_spec.rb
34
35
  - spec/contextuality_spec.rb