Permalink
Browse files

Use options[:name] inside aspect body to access deferred_option, migh…

…t be confusing
  • Loading branch information...
1 parent db1b125 commit c5afb3f876f1a7130261d24803da4a606a7d786b @gcao committed Dec 9, 2011
View
@@ -34,7 +34,7 @@ def self.cache key, ttl
require 'aspector'
class CacheAspect < Aspector::Base
- around deferred_option(:method), :context_arg => true do |context, &block|
+ around options[:method], :context_arg => true do |context, &block|
SimpleCache.cache 'test', context.options[:ttl] do
block.call
end
View
@@ -7,7 +7,7 @@ class Base
def initialize target, options = {}
@target = target
- @options = options.merge(self.class.options)
+ @options = options.merge(self.class.default_options)
@context = get_context # Context is where advices will be applied (i.e. where methods are modified)
end
@@ -7,8 +7,8 @@ def advices
@advices ||= []
end
- def options
- @options ||= {}
+ def default_options
+ @default_options ||= {}
end
def deferred_logics
@@ -24,10 +24,10 @@ def apply target, options = {}
end
def default options
- if @options
- @options.merge! options
+ if @default_options
+ @default_options.merge! options
else
- @options = options
+ @default_options = options
end
end
@@ -53,8 +53,8 @@ def target code = nil, &block
logic
end
- def deferred_option key
- DeferredOption.new(key)
+ def options
+ DeferredOption.new
end
private
@@ -3,8 +3,9 @@ class DeferredOption
attr_reader :key
- def initialize key
+ def [] key
@key = key
+ self
end
end
@@ -6,7 +6,7 @@
default :test => 'value'
end
- aspect.options[:test].should == 'value'
+ aspect.default_options[:test].should == 'value'
end
it "deferred_option" do
@@ -21,7 +21,7 @@ def test
end
aspect = Aspector do
- before deferred_option(:methods) do
+ before options[:methods] do
value << "do_this"
end
end

0 comments on commit c5afb3f

Please sign in to comment.