contextuality 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -14
- data/README.md +29 -5
- data/lib/contextuality.rb +8 -0
- data/lib/contextuality/context.rb +1 -1
- data/lib/contextuality/version.rb +1 -1
- data/spec/contextuality_spec.rb +30 -0
- metadata +2 -2
data/Gemfile
CHANGED
@@ -1,22 +1,14 @@
|
|
1
|
-
def darwin_only(require_as)
|
2
|
-
RUBY_PLATFORM.include?('darwin') && require_as
|
3
|
-
end
|
4
|
-
|
5
|
-
def linux_only(require_as)
|
6
|
-
RUBY_PLATFORM.include?('linux') && require_as
|
7
|
-
end
|
8
|
-
|
9
1
|
source 'https://rubygems.org'
|
10
2
|
|
11
3
|
# Specify your gem's dependencies in cms_engine.gemspec
|
12
4
|
gemspec
|
13
5
|
|
14
6
|
gem 'rspec'
|
15
|
-
gem 'guard'
|
16
|
-
gem 'guard-rspec'
|
17
7
|
|
18
8
|
group :test do
|
19
|
-
gem '
|
20
|
-
gem '
|
21
|
-
gem '
|
22
|
-
|
9
|
+
gem 'guard'
|
10
|
+
gem 'guard-rspec'
|
11
|
+
gem 'rb-inotify', :require => false
|
12
|
+
gem 'rb-fsevent', :require => false
|
13
|
+
gem 'rb-fchange', :require => false
|
14
|
+
end
|
data/README.md
CHANGED
@@ -71,21 +71,45 @@ end #=> "Hello"
|
|
71
71
|
You can include `Contextuality` in Object and get access to context everywhere,
|
72
72
|
or just include in classes on-demand.
|
73
73
|
|
74
|
+
# Also `Contextuality` singleton can be used everywhere
|
75
|
+
|
76
|
+
```
|
77
|
+
contextualize(foo: 'Hello') do
|
78
|
+
Contextuality.foo #=> "Hello"
|
79
|
+
end #=> "Hello"
|
80
|
+
```
|
81
|
+
|
82
|
+
# You can setup default values for any key
|
83
|
+
|
84
|
+
```
|
85
|
+
Contextuality.defaults[:foo] = 'Hello'
|
86
|
+
|
87
|
+
contextualize(foo: 'Goodbye') do
|
88
|
+
Foo.foo #=> "Goodbye"
|
89
|
+
end #=> "Goodbye"
|
90
|
+
|
91
|
+
contextualize do
|
92
|
+
Foo.foo #=> "Hello"
|
93
|
+
end #=> "Hello"
|
94
|
+
```
|
95
|
+
|
74
96
|
### More complex example
|
75
97
|
|
76
98
|
```
|
99
|
+
|
100
|
+
# config/initializers/contextuality.rb
|
101
|
+
Contextuality.defaults[:host] = 'default'
|
102
|
+
|
103
|
+
# app/models/article.rb
|
77
104
|
class Article < ActiveRecord::Base
|
78
105
|
include Contextuality
|
79
106
|
|
80
107
|
def self.for_current_host
|
81
|
-
|
82
|
-
where(host: contextuality.host)
|
83
|
-
else
|
84
|
-
for_default_host # or just .all
|
85
|
-
end
|
108
|
+
where(host: contextuality.host)
|
86
109
|
end
|
87
110
|
end
|
88
111
|
|
112
|
+
# app/controllers/article_controller.rb
|
89
113
|
class ArticlesController < ActionController::Base
|
90
114
|
around_filter :setup_host
|
91
115
|
|
data/lib/contextuality.rb
CHANGED
@@ -9,6 +9,14 @@ module Contextuality
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
def self.method_missing method, *args, &block
|
13
|
+
::Thread.current.contextuality[method]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.defaults
|
17
|
+
::Thread.main[:contextuality_defaults] ||= {}
|
18
|
+
end
|
19
|
+
|
12
20
|
module ContextualityMethods
|
13
21
|
def contextuality
|
14
22
|
::Thread.current.contextuality
|
data/spec/contextuality_spec.rb
CHANGED
@@ -25,12 +25,24 @@ describe Contextuality do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
specify do
|
29
|
+
contextualize do
|
30
|
+
Contextuality.hello.should be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
28
34
|
specify do
|
29
35
|
contextualize(:hello => 'world') do
|
30
36
|
subject.hello.should == 'world'
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
40
|
+
specify do
|
41
|
+
contextualize(:hello => 'world') do
|
42
|
+
Contextuality.hello.should == 'world'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
34
46
|
specify do
|
35
47
|
contextualize(:hello => 'world') do
|
36
48
|
contextualize(:hello => 'hell') do
|
@@ -77,4 +89,22 @@ describe Contextuality do
|
|
77
89
|
end
|
78
90
|
end
|
79
91
|
end
|
92
|
+
|
93
|
+
context 'defaults' do
|
94
|
+
before { Contextuality.defaults[:foo] = 'Bar' }
|
95
|
+
|
96
|
+
specify { Contextuality.foo.should == 'Bar' }
|
97
|
+
|
98
|
+
specify do
|
99
|
+
contextualize do
|
100
|
+
Contextuality.foo.should == 'Bar'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
specify do
|
105
|
+
contextualize(foo: 'Hello') do
|
106
|
+
Contextuality.foo.should == 'Hello'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
80
110
|
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.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Contextual global variables
|
15
15
|
email:
|