Permalink
Browse files

ThreadOptions: support nested with_options

  • Loading branch information...
1 parent 1f0f285 commit e2727881a0687545ea6a9a6670bf8d7075dd7a01 @minad minad committed Sep 21, 2012
Showing with 11 additions and 8 deletions.
  1. +11 −8 lib/temple/mixins/options.rb
@@ -28,7 +28,7 @@ def define_options(*opts)
default_options.add_valid_keys(opts)
end
- def deprecated_options(*opts)
+ def define_deprecated_options(*opts)
if opts.last.respond_to?(:keys)
hash = opts.pop
default_options.add_deprecated_keys(hash.keys)
@@ -43,20 +43,23 @@ def disable_option_validator!
end
module ThreadOptions
- def thread_options_key
- @thread_options_key ||= "#{self.name}-thread-options".to_sym
- end
-
- def with_options(opts)
- Thread.current[thread_options_key] = opts
+ def with_options(options)
+ old_options = thread_options
+ Thread.current[thread_options_key] = ImmutableHash.new(options, thread_options)
yield
ensure
- Thread.current[thread_options_key] = nil
+ Thread.current[thread_options_key] = old_options
end
def thread_options
Thread.current[thread_options_key]
end
+
+ protected
+
+ def thread_options_key
+ @thread_options_key ||= "#{self.name}-thread-options".to_sym
+ end
end
# @api public

0 comments on commit e272788

Please sign in to comment.