rails_current 1.1.0 → 1.2.0
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.
- data/lib/rails_current.rb +22 -26
- data/rails_current.gemspec +1 -1
- data/test/rails_current_test.rb +86 -5
- metadata +2 -2
data/lib/rails_current.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'map'
|
2
2
|
|
3
3
|
module Current
|
4
|
-
def Current.version
|
4
|
+
def Current.version
|
5
|
+
'1.2.0'
|
6
|
+
end
|
5
7
|
|
6
8
|
def Current.data
|
7
9
|
Thread.current[:current] ||= Map.new
|
@@ -51,8 +53,8 @@ module Current
|
|
51
53
|
data[name] = value
|
52
54
|
end
|
53
55
|
|
54
|
-
define_method(name + '?') do |
|
55
|
-
|
56
|
+
define_method(name + '?') do |*args|
|
57
|
+
send(name)
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
@@ -106,29 +108,15 @@ module Current
|
|
106
108
|
end
|
107
109
|
end
|
108
110
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
super
|
117
|
-
end
|
111
|
+
def method_missing(method, *args, &block)
|
112
|
+
case method.to_s
|
113
|
+
when /^current_(.*)$/
|
114
|
+
msg = $1
|
115
|
+
Current.send(msg, *args, &block)
|
116
|
+
else
|
117
|
+
super
|
118
118
|
end
|
119
119
|
end
|
120
|
-
|
121
|
-
def Current.included(other)
|
122
|
-
super
|
123
|
-
ensure
|
124
|
-
other.send(:module_eval, &Code)
|
125
|
-
end
|
126
|
-
|
127
|
-
def Current.extend_object(object)
|
128
|
-
super
|
129
|
-
ensure
|
130
|
-
object.send(:instance_eval, &Code)
|
131
|
-
end
|
132
120
|
end
|
133
121
|
|
134
122
|
def Current(*args, &block)
|
@@ -147,7 +135,7 @@ if defined?(Rails)
|
|
147
135
|
Current.clear
|
148
136
|
Current.controller = controller
|
149
137
|
end
|
150
|
-
end
|
138
|
+
end if defined?(::ActionController::Base)
|
151
139
|
end
|
152
140
|
end
|
153
141
|
|
@@ -157,8 +145,16 @@ if defined?(Rails)
|
|
157
145
|
Current.install_before_filter!
|
158
146
|
end
|
159
147
|
end
|
148
|
+
else
|
149
|
+
Current.install_before_filter!
|
160
150
|
end
|
161
151
|
|
162
152
|
end
|
163
153
|
|
164
|
-
Rails_current = Current
|
154
|
+
::Rails_current = ::Current
|
155
|
+
|
156
|
+
BEGIN {
|
157
|
+
Object.send(:remove_const, :Current) if defined?(::Current)
|
158
|
+
Object.send(:remove_const, :Rails_current) if defined?(::Rails_current)
|
159
|
+
}
|
160
|
+
|
data/rails_current.gemspec
CHANGED
data/test/rails_current_test.rb
CHANGED
@@ -112,19 +112,100 @@ Testing Current do
|
|
112
112
|
assert{ Current.attributes =~ {:foo => :bar, :bar => :foo} }
|
113
113
|
end
|
114
114
|
|
115
|
+
##
|
116
|
+
#
|
117
|
+
test 'that assigning to Current dynamically adds accessor methods' do
|
118
|
+
assert{ Current.foo = 42 }
|
119
|
+
assert{ Current.foo == 42 }
|
120
|
+
|
121
|
+
assert{ Current.bar = 'forty-two' }
|
122
|
+
assert{ Current.bar == 'forty-two' }
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
#
|
127
|
+
test 'that query methods on Current werky' do
|
128
|
+
assert{ Current.foo?.nil? }
|
129
|
+
assert{ Current.foo = 42 }
|
130
|
+
assert{ Current.foo? == 42 }
|
131
|
+
end
|
132
|
+
|
133
|
+
##
|
134
|
+
#
|
135
|
+
test 'that loading Current into a rails app creates Current.user and Current.controller' do
|
136
|
+
mock_rails! do
|
137
|
+
assert{ Current.attributes =~ {:user => nil, :controller => nil} }
|
138
|
+
end
|
139
|
+
|
140
|
+
mock_rails_engine! do
|
141
|
+
assert{ Current.attributes =~ {:user => nil, :controller => nil} }
|
142
|
+
assert{ $before_initialize_called }
|
143
|
+
assert{ $before_filter_called }
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
115
147
|
##
|
116
148
|
#
|
117
149
|
teardown do
|
118
150
|
assert{ Current.reset }
|
119
151
|
end
|
120
152
|
|
153
|
+
|
154
|
+
private
|
155
|
+
def mock_rails!
|
156
|
+
Object.module_eval <<-__
|
157
|
+
module Rails
|
158
|
+
end
|
159
|
+
__
|
160
|
+
$load.call()
|
161
|
+
yield
|
162
|
+
Object.send(:remove_const, :Rails)
|
163
|
+
end
|
164
|
+
|
165
|
+
def mock_rails_engine!
|
166
|
+
Object.module_eval <<-__
|
167
|
+
module Rails
|
168
|
+
class Engine
|
169
|
+
def Engine.config
|
170
|
+
Config
|
171
|
+
end
|
172
|
+
|
173
|
+
class Config
|
174
|
+
def Config.before_initialize(*args, &block)
|
175
|
+
block.call
|
176
|
+
ensure
|
177
|
+
$before_initialize_called = true
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
module ActionController
|
184
|
+
class Base
|
185
|
+
def Base.before_filter(*args, &block)
|
186
|
+
block.call()
|
187
|
+
ensure
|
188
|
+
$before_filter_called = true
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
__
|
193
|
+
$load.call()
|
194
|
+
yield
|
195
|
+
Object.send(:remove_const, :Rails)
|
196
|
+
end
|
121
197
|
end
|
122
198
|
|
123
199
|
|
124
200
|
BEGIN {
|
125
|
-
this = File.expand_path(__FILE__)
|
126
|
-
root = File.dirname(File.dirname(this))
|
127
|
-
|
128
|
-
|
129
|
-
|
201
|
+
$this = File.expand_path(__FILE__)
|
202
|
+
$root = File.dirname(File.dirname($this))
|
203
|
+
|
204
|
+
(
|
205
|
+
$load =
|
206
|
+
proc do
|
207
|
+
Kernel.load(File.join($root, 'lib/rails_current.rb'))
|
208
|
+
Kernel.load(File.join($root, 'test/testing.rb'))
|
209
|
+
end
|
210
|
+
).call()
|
130
211
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_current
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
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-01-
|
12
|
+
date: 2012-01-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'description: rails_current kicks the ass'
|
15
15
|
email: ara.t.howard@gmail.com
|