Browse files

fix for missing configuration in instance

  • Loading branch information...
1 parent 8ec1c03 commit dc7284424d60539f855a9e740563817dc12341fe @ssoroka ssoroka committed Aug 10, 2012
Showing with 11 additions and 8 deletions.
  1. +1 −1 lib/wolverine.rb
  2. +6 −4 lib/wolverine/path_component.rb
  3. +4 −3 lib/wolverine/script.rb
View
2 lib/wolverine.rb
@@ -73,7 +73,7 @@ def self.root_directory
end
def root_directory
- @root_directory ||= PathComponent.new(config.script_path, redis)
+ @root_directory ||= PathComponent.new(config.script_path, {:config => config, :redis => redis})
end
end
View
10 lib/wolverine/path_component.rb
@@ -15,9 +15,11 @@ class MissingTemplate < StandardError ; end
# @param path [Pathname] full path to the current file or directory
# @param redis [Redis]
- def initialize path, redis = nil
+ def initialize path, options = {}
@path = path
- @redis = redis || Wolverine.redis
+ @options = options
+ @redis = options[:redis] || Wolverine.redis
+ @config = options[:config] || Wolverine.config
end
# @param sym [Symbol] the file or directory to look up and execute
@@ -51,12 +53,12 @@ def file?(path)
end
def define_directory_method path, sym
- dir = PathComponent.new(path, @redis)
+ dir = PathComponent.new(path, @options)
define_metaclass_method(sym) { dir }
end
def define_script_method path, sym, *args
- script = Wolverine::Script.new(path)
+ script = Wolverine::Script.new(path, @options)
define_metaclass_method(sym) { |*args|
script.call(@redis, *args)
}
View
7 lib/wolverine/script.rb
@@ -11,10 +11,11 @@ class Script
# Loads the script file from disk and calculates its +SHA1+ sum.
#
# @param file [Pathname] the full path to the indicated file
- def initialize file
+ def initialize file, options = {}
@file = Pathname.new(file)
@content = load_lua file
@digest = Digest::SHA1.hexdigest @content
+ @config = options[:config] || Wolverine.config
end
# Passes the script and supplied arguments to redis for evaulation.
@@ -59,12 +60,12 @@ def run_eval redis, *args
def instrument eval_type
ret = nil
runtime = Benchmark.realtime { ret = yield }
- Wolverine.config.instrumentation.call relative_path.to_s, runtime, eval_type
+ @config.instrumentation.call relative_path.to_s, runtime, eval_type
ret
end
def relative_path
- path = @file.relative_path_from(Wolverine.config.script_path)
+ path = @file.relative_path_from(@config.script_path)
end
def load_lua file

0 comments on commit dc72844

Please sign in to comment.