methodmissing-scrooge 1.0.4 → 2.0.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/README.textile +139 -449
- data/Rakefile +20 -19
- data/VERSION.yml +2 -2
- data/lib/attributes_proxy.rb +121 -0
- data/lib/scrooge.rb +206 -47
- data/rails/init.rb +1 -10
- data/test/helper.rb +88 -0
- data/test/models/mysql_user.rb +4 -0
- data/test/scrooge_test.rb +75 -0
- data/test/setup.rb +3 -0
- metadata +11 -76
- data/assets/config/scrooge.yml.template +0 -27
- data/lib/scrooge/core/string.rb +0 -29
- data/lib/scrooge/core/symbol.rb +0 -21
- data/lib/scrooge/core/thread.rb +0 -26
- data/lib/scrooge/framework/base.rb +0 -315
- data/lib/scrooge/framework/rails.rb +0 -132
- data/lib/scrooge/middleware/tracker.rb +0 -46
- data/lib/scrooge/orm/active_record.rb +0 -159
- data/lib/scrooge/orm/base.rb +0 -102
- data/lib/scrooge/profile.rb +0 -223
- data/lib/scrooge/storage/base.rb +0 -46
- data/lib/scrooge/storage/memory.rb +0 -25
- data/lib/scrooge/strategy/base.rb +0 -74
- data/lib/scrooge/strategy/controller.rb +0 -31
- data/lib/scrooge/strategy/scope.rb +0 -15
- data/lib/scrooge/strategy/stage.rb +0 -77
- data/lib/scrooge/strategy/track.rb +0 -19
- data/lib/scrooge/strategy/track_then_scope.rb +0 -41
- data/lib/scrooge/tracker/app.rb +0 -161
- data/lib/scrooge/tracker/base.rb +0 -66
- data/lib/scrooge/tracker/model.rb +0 -150
- data/lib/scrooge/tracker/resource.rb +0 -181
- data/spec/fixtures/config/scrooge/scopes/1234567891/scope.yml +0 -2
- data/spec/fixtures/config/scrooge.yml +0 -20
- data/spec/helpers/framework/rails/cache.rb +0 -25
- data/spec/spec_helper.rb +0 -55
- data/spec/units/scrooge/core/string_spec.rb +0 -21
- data/spec/units/scrooge/core/symbol_spec.rb +0 -13
- data/spec/units/scrooge/core/thread_spec.rb +0 -15
- data/spec/units/scrooge/framework/base_spec.rb +0 -160
- data/spec/units/scrooge/framework/rails_spec.rb +0 -40
- data/spec/units/scrooge/orm/base_spec.rb +0 -61
- data/spec/units/scrooge/profile_spec.rb +0 -79
- data/spec/units/scrooge/storage/base_spec.rb +0 -35
- data/spec/units/scrooge/storage/memory_spec.rb +0 -20
- data/spec/units/scrooge/strategy/base_spec.rb +0 -62
- data/spec/units/scrooge/strategy/controller_spec.rb +0 -26
- data/spec/units/scrooge/strategy/scope_spec.rb +0 -18
- data/spec/units/scrooge/strategy/stage_spec.rb +0 -35
- data/spec/units/scrooge/strategy/track_spec.rb +0 -19
- data/spec/units/scrooge/strategy/track_then_scope_spec.rb +0 -22
- data/spec/units/scrooge/tracker/app_spec.rb +0 -68
- data/spec/units/scrooge/tracker/base_spec.rb +0 -29
- data/spec/units/scrooge/tracker/model_spec.rb +0 -79
- data/spec/units/scrooge/tracker/resource_spec.rb +0 -115
- data/spec/units/scrooge_spec.rb +0 -13
- data/tasks/scrooge.rake +0 -43
metadata
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: methodmissing-scrooge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Lourens Naud\xC3\xA9"
|
8
|
+
- Stephen Sykes
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date: 2009-03-
|
13
|
+
date: 2009-03-12 00:00:00 -07:00
|
13
14
|
default_executable:
|
14
15
|
dependencies: []
|
15
16
|
|
16
|
-
description:
|
17
|
-
email: lourens@methodmissing.com
|
17
|
+
description: An ActiveRecord attribute tracker to ensure production Ruby applications only fetch the database content needed to minimize wire traffic and reduce conversion overheads to native Ruby types.
|
18
|
+
email: lourens@methodmissing.com or sds@switchstep.com
|
18
19
|
executables: []
|
19
20
|
|
20
21
|
extensions: []
|
@@ -26,80 +27,14 @@ files:
|
|
26
27
|
- README
|
27
28
|
- README.textile
|
28
29
|
- VERSION.yml
|
29
|
-
- lib/
|
30
|
-
- lib/scrooge/core
|
31
|
-
- lib/scrooge/core/string.rb
|
32
|
-
- lib/scrooge/core/symbol.rb
|
33
|
-
- lib/scrooge/core/thread.rb
|
34
|
-
- lib/scrooge/framework
|
35
|
-
- lib/scrooge/framework/base.rb
|
36
|
-
- lib/scrooge/framework/rails.rb
|
37
|
-
- lib/scrooge/middleware
|
38
|
-
- lib/scrooge/middleware/tracker.rb
|
39
|
-
- lib/scrooge/orm
|
40
|
-
- lib/scrooge/orm/active_record.rb
|
41
|
-
- lib/scrooge/orm/base.rb
|
42
|
-
- lib/scrooge/profile.rb
|
43
|
-
- lib/scrooge/storage
|
44
|
-
- lib/scrooge/storage/base.rb
|
45
|
-
- lib/scrooge/storage/memory.rb
|
46
|
-
- lib/scrooge/strategy
|
47
|
-
- lib/scrooge/strategy/base.rb
|
48
|
-
- lib/scrooge/strategy/controller.rb
|
49
|
-
- lib/scrooge/strategy/scope.rb
|
50
|
-
- lib/scrooge/strategy/stage.rb
|
51
|
-
- lib/scrooge/strategy/track.rb
|
52
|
-
- lib/scrooge/strategy/track_then_scope.rb
|
53
|
-
- lib/scrooge/tracker
|
54
|
-
- lib/scrooge/tracker/app.rb
|
55
|
-
- lib/scrooge/tracker/base.rb
|
56
|
-
- lib/scrooge/tracker/model.rb
|
57
|
-
- lib/scrooge/tracker/resource.rb
|
30
|
+
- lib/attributes_proxy.rb
|
58
31
|
- lib/scrooge.rb
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
62
|
-
-
|
63
|
-
-
|
64
|
-
- spec/fixtures/config/scrooge/scopes/1234567891/scope.yml
|
65
|
-
- spec/fixtures/config/scrooge.yml
|
66
|
-
- spec/helpers
|
67
|
-
- spec/helpers/framework
|
68
|
-
- spec/helpers/framework/rails
|
69
|
-
- spec/helpers/framework/rails/cache.rb
|
70
|
-
- spec/spec_helper.rb
|
71
|
-
- spec/units
|
72
|
-
- spec/units/scrooge
|
73
|
-
- spec/units/scrooge/core
|
74
|
-
- spec/units/scrooge/core/string_spec.rb
|
75
|
-
- spec/units/scrooge/core/symbol_spec.rb
|
76
|
-
- spec/units/scrooge/core/thread_spec.rb
|
77
|
-
- spec/units/scrooge/framework
|
78
|
-
- spec/units/scrooge/framework/base_spec.rb
|
79
|
-
- spec/units/scrooge/framework/rails_spec.rb
|
80
|
-
- spec/units/scrooge/orm
|
81
|
-
- spec/units/scrooge/orm/base_spec.rb
|
82
|
-
- spec/units/scrooge/profile_spec.rb
|
83
|
-
- spec/units/scrooge/storage
|
84
|
-
- spec/units/scrooge/storage/base_spec.rb
|
85
|
-
- spec/units/scrooge/storage/memory_spec.rb
|
86
|
-
- spec/units/scrooge/strategy
|
87
|
-
- spec/units/scrooge/strategy/base_spec.rb
|
88
|
-
- spec/units/scrooge/strategy/controller_spec.rb
|
89
|
-
- spec/units/scrooge/strategy/scope_spec.rb
|
90
|
-
- spec/units/scrooge/strategy/stage_spec.rb
|
91
|
-
- spec/units/scrooge/strategy/track_spec.rb
|
92
|
-
- spec/units/scrooge/strategy/track_then_scope_spec.rb
|
93
|
-
- spec/units/scrooge/tracker
|
94
|
-
- spec/units/scrooge/tracker/app_spec.rb
|
95
|
-
- spec/units/scrooge/tracker/base_spec.rb
|
96
|
-
- spec/units/scrooge/tracker/model_spec.rb
|
97
|
-
- spec/units/scrooge/tracker/resource_spec.rb
|
98
|
-
- spec/units/scrooge_spec.rb
|
32
|
+
- test/helper.rb
|
33
|
+
- test/models
|
34
|
+
- test/models/mysql_user.rb
|
35
|
+
- test/scrooge_test.rb
|
36
|
+
- test/setup.rb
|
99
37
|
- rails/init.rb
|
100
|
-
- assets/config
|
101
|
-
- assets/config/scrooge.yml.template
|
102
|
-
- tasks/scrooge.rake
|
103
38
|
has_rdoc: true
|
104
39
|
homepage: http://github.com/methodmissing/scrooge
|
105
40
|
post_install_message:
|
@@ -1,27 +0,0 @@
|
|
1
|
-
production:
|
2
|
-
orm: :active_record
|
3
|
-
strategy: :track_then_scope
|
4
|
-
warmup: 600 # warmup / track for 10 minutes
|
5
|
-
scope:
|
6
|
-
verbose: false
|
7
|
-
on_missing_attribute: :reload # or :raise
|
8
|
-
logged_in_session: :user_id # session key that represents the logged in user
|
9
|
-
enabled: true
|
10
|
-
development:
|
11
|
-
orm: :active_record
|
12
|
-
strategy: :track
|
13
|
-
warmup: 600 # warmup / track for 10 minutes
|
14
|
-
scope:
|
15
|
-
verbose: true
|
16
|
-
on_missing_attribute: :reload # or :raise
|
17
|
-
logged_in_session: :user_id # session key that represents the logged in user
|
18
|
-
enabled: true
|
19
|
-
test:
|
20
|
-
orm: :active_record
|
21
|
-
strategy: :track
|
22
|
-
warmup: 600 # warmup / track for 10 minutes
|
23
|
-
scope:
|
24
|
-
verbose: true
|
25
|
-
on_missing_attribute: :reload # or :raise
|
26
|
-
logged_in_session: :user_id # session key that represents the logged in user
|
27
|
-
enabled: true
|
data/lib/scrooge/core/string.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module Scrooge
|
2
|
-
module Core
|
3
|
-
module String
|
4
|
-
|
5
|
-
# Framework agnostic String <=> Constant helpers.
|
6
|
-
# Perhaps not the cleanest abstraction, but also not good practice to piggy
|
7
|
-
# back on or use a naming convention that may clash with and uproot the API
|
8
|
-
# any given framework ships with.
|
9
|
-
|
10
|
-
def to_const
|
11
|
-
self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_const!( instantiate = true )
|
15
|
-
begin
|
16
|
-
const = Object.module_eval(to_const, __FILE__, __LINE__)
|
17
|
-
instantiate ? const.new : const
|
18
|
-
rescue => exception
|
19
|
-
exception.to_s.match( /uninitialized constant/ ) ? self : raise
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class String
|
28
|
-
include Scrooge::Core::String
|
29
|
-
end
|
data/lib/scrooge/core/symbol.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Scrooge
|
2
|
-
module Core
|
3
|
-
module Symbol
|
4
|
-
|
5
|
-
# See Scrooge::Core::String
|
6
|
-
|
7
|
-
def to_const
|
8
|
-
to_s.to_const
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_const!
|
12
|
-
to_s.to_const!
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class Symbol
|
20
|
-
include Scrooge::Core::Symbol
|
21
|
-
end
|
data/lib/scrooge/core/thread.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Scrooge
|
2
|
-
module Core
|
3
|
-
module Thread
|
4
|
-
|
5
|
-
# Scrooge Resource tracker scoped to the current Thread for threadsafety in
|
6
|
-
# multi-threaded environments.
|
7
|
-
|
8
|
-
def scrooge_resource
|
9
|
-
current[:scrooge_resource] ||= Scrooge::Tracker::Resource.new
|
10
|
-
end
|
11
|
-
|
12
|
-
def scrooge_resource=( resource )
|
13
|
-
current[:scrooge_resource] = resource
|
14
|
-
end
|
15
|
-
|
16
|
-
def reset_scrooge_resource!
|
17
|
-
current[:scrooge_resource] = nil
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class Thread
|
25
|
-
extend Scrooge::Core::Thread
|
26
|
-
end
|
@@ -1,315 +0,0 @@
|
|
1
|
-
module Scrooge
|
2
|
-
module Framework
|
3
|
-
|
4
|
-
# Scrooge is framework agnostic and attempts to abstract the following :
|
5
|
-
#
|
6
|
-
# * current environment
|
7
|
-
# * app root dir
|
8
|
-
# * app tmp dir
|
9
|
-
# * app config dir
|
10
|
-
# * logging
|
11
|
-
# * resource endpoints
|
12
|
-
# * caching
|
13
|
-
# * injecting Rack MiddleWare
|
14
|
-
#
|
15
|
-
# Framework Signatures
|
16
|
-
#
|
17
|
-
# Scrooge will attempt to determine the current active framework it's deployed with
|
18
|
-
# through various framework specific hooks.
|
19
|
-
#
|
20
|
-
# module Scrooge
|
21
|
-
# module Framework
|
22
|
-
# module YetAnother < Base
|
23
|
-
# ...
|
24
|
-
# signature do
|
25
|
-
# Object.const_defined?( "UnlikeAnyOther" )
|
26
|
-
# end
|
27
|
-
# ...
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
|
32
|
-
autoload :Rails, 'scrooge/framework/rails'
|
33
|
-
|
34
|
-
class Base < Scrooge::Base
|
35
|
-
|
36
|
-
GUARD = Mutex.new
|
37
|
-
|
38
|
-
SCOPE_REGEX = /\d{10}/.freeze
|
39
|
-
|
40
|
-
CONFIGURATION_FILE = 'scrooge.yml'.freeze
|
41
|
-
|
42
|
-
SCOPE_FILE = 'scope.yml'.freeze
|
43
|
-
|
44
|
-
class NotImplemented < StandardError
|
45
|
-
end
|
46
|
-
|
47
|
-
class NoSupportedFrameworks < StandardError
|
48
|
-
end
|
49
|
-
|
50
|
-
class InvalidScopeSignature < StandardError
|
51
|
-
end
|
52
|
-
|
53
|
-
# Per framework signature lookup.
|
54
|
-
#
|
55
|
-
@@signatures = Hash.new( [] )
|
56
|
-
@@signatures[self.name] = []
|
57
|
-
|
58
|
-
# Support none by default.
|
59
|
-
#
|
60
|
-
@@frameworks = []
|
61
|
-
|
62
|
-
class << self
|
63
|
-
|
64
|
-
# Registers a framework signature.
|
65
|
-
#
|
66
|
-
def signature( &block )
|
67
|
-
@@signatures[self.name] << block
|
68
|
-
end
|
69
|
-
|
70
|
-
# All signatures for the current klass.
|
71
|
-
#
|
72
|
-
def signatures
|
73
|
-
@@signatures[self.name]
|
74
|
-
end
|
75
|
-
|
76
|
-
# All supported frameworks.
|
77
|
-
#
|
78
|
-
def frameworks
|
79
|
-
@@frameworks
|
80
|
-
end
|
81
|
-
|
82
|
-
# Infer the framework Scrooge attaches to in a first yield manner.
|
83
|
-
# A match of all defined signatures is required.
|
84
|
-
#
|
85
|
-
def which_framework?
|
86
|
-
iterate_frameworks() || raise( NoSupportedFrameworks )
|
87
|
-
end
|
88
|
-
|
89
|
-
# Yield an instance of the current framework.
|
90
|
-
#
|
91
|
-
def instantiate
|
92
|
-
which_framework?().new
|
93
|
-
end
|
94
|
-
|
95
|
-
private
|
96
|
-
|
97
|
-
def inherited( subclass ) #:nodoc:
|
98
|
-
@@frameworks << subclass
|
99
|
-
end
|
100
|
-
|
101
|
-
def iterate_frameworks #:nodoc:
|
102
|
-
frameworks.detect do |framework|
|
103
|
-
framework.signatures.all?{|sig| sig.call }
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
# The framework environment eg. test, development etc.
|
110
|
-
#
|
111
|
-
def environment
|
112
|
-
raise NotImplemented
|
113
|
-
end
|
114
|
-
|
115
|
-
# Application root directory
|
116
|
-
#
|
117
|
-
def root
|
118
|
-
raise NotImplemented
|
119
|
-
end
|
120
|
-
|
121
|
-
# Application temp. directory
|
122
|
-
#
|
123
|
-
def tmp
|
124
|
-
raise NotImplemented
|
125
|
-
end
|
126
|
-
|
127
|
-
# Application configuration directory
|
128
|
-
#
|
129
|
-
def config
|
130
|
-
raise NotImplemented
|
131
|
-
end
|
132
|
-
|
133
|
-
# Application logger instance.
|
134
|
-
# API compat with stdlib Logger assumed.
|
135
|
-
#
|
136
|
-
def logger
|
137
|
-
raise NotImplemented
|
138
|
-
end
|
139
|
-
|
140
|
-
# Supplement the current Resource tracker with additional environment context.
|
141
|
-
#
|
142
|
-
def resource( env, request = nil )
|
143
|
-
raise NotImplemented
|
144
|
-
end
|
145
|
-
|
146
|
-
# Write to the framework cache.
|
147
|
-
#
|
148
|
-
def write_cache( key, value )
|
149
|
-
raise NotImplemented
|
150
|
-
end
|
151
|
-
|
152
|
-
# Read from the framework cache.
|
153
|
-
#
|
154
|
-
def read_cache( key )
|
155
|
-
raise NotImplemented
|
156
|
-
end
|
157
|
-
|
158
|
-
# Access to the framework's Rack middleware stack.
|
159
|
-
#
|
160
|
-
def middleware
|
161
|
-
raise NotImplemented
|
162
|
-
end
|
163
|
-
|
164
|
-
# Inject scoping middleware.
|
165
|
-
#
|
166
|
-
def install_scope_middleware( tracker )
|
167
|
-
raise NotImplemented
|
168
|
-
end
|
169
|
-
|
170
|
-
# Inject tracking middleware.
|
171
|
-
#
|
172
|
-
def install_tracking_middleware
|
173
|
-
raise NotImplemented
|
174
|
-
end
|
175
|
-
|
176
|
-
# Remove tracking middleware
|
177
|
-
#
|
178
|
-
def uninstall_tracking_middleware
|
179
|
-
raise NotImplemented
|
180
|
-
end
|
181
|
-
|
182
|
-
# Register a code block to run when the host framework is fully initialized.
|
183
|
-
#
|
184
|
-
def initialized( &block )
|
185
|
-
raise NotImplemented
|
186
|
-
end
|
187
|
-
|
188
|
-
# Yields a controller constant from a given Resource Tracker
|
189
|
-
#
|
190
|
-
def controller( resource )
|
191
|
-
raise NotImplemented
|
192
|
-
end
|
193
|
-
|
194
|
-
# Retrieve all previously persisted scopes tracked with Scrooge.
|
195
|
-
#
|
196
|
-
def scopes
|
197
|
-
ensure_scopes_path do
|
198
|
-
Dir.entries( scopes_path ).grep( SCOPE_REGEX )
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
# Determine if there's any previously persisted scopes.
|
203
|
-
#
|
204
|
-
def scopes?
|
205
|
-
!scopes().empty?
|
206
|
-
end
|
207
|
-
|
208
|
-
# Return the scopes storage path for the current framework.
|
209
|
-
#
|
210
|
-
def scopes_path
|
211
|
-
@scopes_path ||= File.join( config, 'scrooge', 'scopes' )
|
212
|
-
end
|
213
|
-
|
214
|
-
# Return the scopes storage path for a given scope and optional filename.
|
215
|
-
#
|
216
|
-
def scope_path( scope, filename = nil )
|
217
|
-
path = File.join( scopes_path, scope.to_s )
|
218
|
-
filename ? File.join( path, filename ) : path
|
219
|
-
end
|
220
|
-
|
221
|
-
# Log a message to the logger.
|
222
|
-
#
|
223
|
-
def log( message, flush = false )
|
224
|
-
logger.info "[Scrooge] #{message}"
|
225
|
-
flush_logger! if flush
|
226
|
-
end
|
227
|
-
|
228
|
-
# Persist the current tracker as scope or restore a previously persisted scope
|
229
|
-
# from a given signature.
|
230
|
-
#
|
231
|
-
def scope!( scope = nil )
|
232
|
-
scope ? from_scope!( scope ) : to_scope!()
|
233
|
-
end
|
234
|
-
|
235
|
-
# Do we have a valid scope signature ?
|
236
|
-
#
|
237
|
-
def scope?( scope )
|
238
|
-
scopes.include?( scope.to_s )
|
239
|
-
end
|
240
|
-
|
241
|
-
# Restore a previously persisted scope to the current tracker from a given
|
242
|
-
# signature.Raises Scrooge::Framework::InvalidScopeSignature if the signature
|
243
|
-
# could not be found.
|
244
|
-
#
|
245
|
-
def from_scope!( scope )
|
246
|
-
GUARD.synchronize do
|
247
|
-
if scope?( scope )
|
248
|
-
restore_scope!( scope )
|
249
|
-
else
|
250
|
-
raise InvalidScopeSignature
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
# Dump the current tracker to the filesystem.
|
256
|
-
#
|
257
|
-
def to_scope!
|
258
|
-
GUARD.synchronize do
|
259
|
-
scope = Time.now.to_i
|
260
|
-
dump_scope!( scope )
|
261
|
-
scope.to_s
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
# Full path the scrooge configuration file.
|
266
|
-
#
|
267
|
-
def configuration_file
|
268
|
-
@configuration_file ||= File.join( config, CONFIGURATION_FILE )
|
269
|
-
end
|
270
|
-
|
271
|
-
private
|
272
|
-
|
273
|
-
def flush_logger! #:nodoc:
|
274
|
-
logger.flush if logger.respond_to?(:flush)
|
275
|
-
end
|
276
|
-
|
277
|
-
def restore_scope!( scope ) #:nodoc:
|
278
|
-
tracker = Scrooge::Tracker::App.new
|
279
|
-
tracker.marshal_load( scope_from_yaml( scope ) )
|
280
|
-
tracker
|
281
|
-
end
|
282
|
-
|
283
|
-
def dump_scope!( scope ) #:nodoc:
|
284
|
-
ensure_scope_path( scope ) do
|
285
|
-
File.open( scope_path( scope, SCOPE_FILE ), 'w' ) do |io|
|
286
|
-
scope_to_yaml( io )
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
def scope_from_yaml( scope ) #:nodoc:
|
292
|
-
YAML.load( IO.read( scope_path( scope.to_s, SCOPE_FILE ) ) )
|
293
|
-
end
|
294
|
-
|
295
|
-
def scope_to_yaml( io ) #:nodoc:
|
296
|
-
YAML.dump( Scrooge::Base.profile.tracker.marshal_dump, io )
|
297
|
-
end
|
298
|
-
|
299
|
-
def ensure_scope_path( scope ) #:nodoc:
|
300
|
-
makedir_unless_exist( scope_path( scope ) )
|
301
|
-
yield if block_given?
|
302
|
-
end
|
303
|
-
|
304
|
-
def ensure_scopes_path #:nodoc:
|
305
|
-
makedir_unless_exist( scopes_path )
|
306
|
-
yield if block_given?
|
307
|
-
end
|
308
|
-
|
309
|
-
def makedir_unless_exist( path ) #:nodoc:
|
310
|
-
FileUtils.makedirs( path ) unless File.exist?( path )
|
311
|
-
end
|
312
|
-
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
module Scrooge
|
2
|
-
module Framework
|
3
|
-
class Rails < Base
|
4
|
-
|
5
|
-
# Look for RAILS_ROOT and Rails.
|
6
|
-
|
7
|
-
signature do
|
8
|
-
defined?(RAILS_ROOT)
|
9
|
-
end
|
10
|
-
|
11
|
-
signature do
|
12
|
-
Object.const_defined?( "Rails" )
|
13
|
-
end
|
14
|
-
|
15
|
-
def environment
|
16
|
-
::RAILS_ENV
|
17
|
-
end
|
18
|
-
|
19
|
-
def root
|
20
|
-
::Rails.root
|
21
|
-
end
|
22
|
-
|
23
|
-
def tmp
|
24
|
-
@tmp ||= File.join( ::Rails.root, 'tmp' )
|
25
|
-
end
|
26
|
-
|
27
|
-
def config
|
28
|
-
@config ||= File.join( ::Rails.root, 'config' )
|
29
|
-
end
|
30
|
-
|
31
|
-
def logger
|
32
|
-
::Rails.logger
|
33
|
-
end
|
34
|
-
|
35
|
-
def resource( env, request = nil )
|
36
|
-
GUARD.synchronize do
|
37
|
-
# TODO: Wonky practice to piggy back on this current Edge / 2.3 hack
|
38
|
-
request = request || env['action_controller.rescue.request']
|
39
|
-
supplement_current_resource!( request )
|
40
|
-
Thread.scrooge_resource = Scrooge::Base.profile.tracker.resource_for( Thread.scrooge_resource )
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def read_cache( key )
|
45
|
-
::Rails.cache.read( key )
|
46
|
-
end
|
47
|
-
|
48
|
-
def write_cache( key, value )
|
49
|
-
::Rails.cache.write( key, value )
|
50
|
-
end
|
51
|
-
|
52
|
-
def middleware
|
53
|
-
::Rails.configuration.middleware
|
54
|
-
end
|
55
|
-
|
56
|
-
# Push the Tracking middleware into the first slot.
|
57
|
-
#
|
58
|
-
def install_tracking_middleware
|
59
|
-
GUARD.synchronize do
|
60
|
-
with_or_without_prepatation( :scrooge_install_tracking_middleware ) do
|
61
|
-
ApplicationController.prepend_around_filter Scrooge::Middleware::Tracker
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Remove all tracking filters
|
67
|
-
#
|
68
|
-
def uninstall_tracking_middleware
|
69
|
-
GUARD.synchronize do
|
70
|
-
# Handle dev. mode
|
71
|
-
ActionController::Dispatcher.prepare_dispatch_callback_chain.delete( :scrooge_install_tracking_middleware )
|
72
|
-
ApplicationController.skip_filter Scrooge::Middleware::Tracker
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Install per Resource scoping middleware.
|
77
|
-
#
|
78
|
-
def install_scope_middleware( tracker )
|
79
|
-
GUARD.synchronize do
|
80
|
-
with_or_without_prepatation( :scrooge_install_scope_middleware ) do
|
81
|
-
tracker.resources.each do |resource|
|
82
|
-
install_scope_middleware_for_resource!( resource )
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def initialized( &block )
|
89
|
-
begin
|
90
|
-
::Rails.configuration.after_initialize( &block )
|
91
|
-
rescue NameError
|
92
|
-
# No config initialized - plugin installation etc.
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def controller( resource )
|
97
|
-
"#{resource.controller}_controller".classify.constantize
|
98
|
-
end
|
99
|
-
|
100
|
-
private
|
101
|
-
|
102
|
-
def with_or_without_prepatation( callback_signature, &block ) #:nodoc:
|
103
|
-
if development?
|
104
|
-
ActionController::Dispatcher.to_prepare( callback_signature ) do
|
105
|
-
block.call
|
106
|
-
end
|
107
|
-
else
|
108
|
-
block.call
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def development? #:nodoc:
|
113
|
-
environment == 'development'
|
114
|
-
end
|
115
|
-
|
116
|
-
def install_scope_middleware_for_resource!( resource ) #:nodoc:
|
117
|
-
resource.middleware.each do |resource_middleware|
|
118
|
-
controller( resource ).prepend_around_filter resource_middleware, :only => resource.action
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def supplement_current_resource!( request ) #:nodoc:
|
123
|
-
Thread.scrooge_resource.controller = request.path_parameters['controller']
|
124
|
-
Thread.scrooge_resource.action = request.path_parameters['action']
|
125
|
-
Thread.scrooge_resource.method = request.method
|
126
|
-
Thread.scrooge_resource.format = request.format.to_s
|
127
|
-
Thread.scrooge_resource.is_public = request.session[Scrooge::Base.profile.logged_in_session].nil?
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Scrooge
|
2
|
-
module Middleware
|
3
|
-
class Tracker < Scrooge::Base
|
4
|
-
|
5
|
-
class << self
|
6
|
-
|
7
|
-
# Around Filter compatible implementation for Rails as Dispatcher is
|
8
|
-
# the root Rack application and as such don't provide access to the Rails
|
9
|
-
# Routing internals from other middleware.
|
10
|
-
#
|
11
|
-
def filter( controller )
|
12
|
-
Scrooge::Base.profile.tracker.track( Thread.scrooge_resource ) do
|
13
|
-
begin
|
14
|
-
Scrooge::Base.profile.framework.resource( {}, controller.request )
|
15
|
-
yield
|
16
|
-
ensure
|
17
|
-
Thread.reset_scrooge_resource!
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def initialize(app, options = {})
|
25
|
-
@app = app
|
26
|
-
end
|
27
|
-
|
28
|
-
# Assign a default Resource Tracker instance to Thread.current[:scrooge_resource]
|
29
|
-
# and supplement it with request specific details ( format, action && controller )
|
30
|
-
# after yielding to the app.Flush Thread.current[:scrooge_resource] on completion.
|
31
|
-
#
|
32
|
-
def call(env)
|
33
|
-
Scrooge::Base.profile.tracker.track( Thread.scrooge_resource ) do
|
34
|
-
begin
|
35
|
-
result = @app.call(env)
|
36
|
-
Scrooge::Base.profile.framework.resource( env )
|
37
|
-
result
|
38
|
-
ensure
|
39
|
-
Thread.reset_scrooge_resource!
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|