aspector 0.13.1 → 0.14.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.
- checksums.yaml +7 -0
 - data/.gitignore +14 -0
 - data/.rubocop.yml +26 -0
 - data/.ruby-gemset +1 -0
 - data/.ruby-version +1 -0
 - data/.travis.yml +8 -11
 - data/Changelog.md +59 -0
 - data/Gemfile +9 -14
 - data/Gemfile.lock +84 -50
 - data/README.md +118 -0
 - data/Rakefile +6 -22
 - data/aspector.gemspec +15 -127
 - data/benchmarks/after_benchmark.rb +28 -0
 - data/benchmarks/around_advice_benchmark.rb +35 -0
 - data/benchmarks/around_benchmark.rb +32 -0
 - data/benchmarks/before_benchmark.rb +28 -0
 - data/benchmarks/benchmark_helper.rb +17 -0
 - data/benchmarks/combined_benchmark.rb +36 -0
 - data/benchmarks/method_invocation_benchmark.rb +30 -0
 - data/benchmarks/raw_benchmark.rb +39 -0
 - data/examples/activerecord_hooks.rb +10 -15
 - data/examples/around_example.rb +20 -31
 - data/examples/aspector_apply_example.rb +10 -17
 - data/examples/aspector_example.rb +7 -16
 - data/examples/cache_aspect.rb +20 -30
 - data/examples/design_by_contract.rb +20 -44
 - data/examples/exception_handler.rb +12 -20
 - data/examples/exception_handler2.rb +16 -24
 - data/examples/implicit_method_option_test.rb +8 -16
 - data/examples/interception_options_example.rb +71 -0
 - data/examples/logging_aspect.rb +16 -24
 - data/examples/process_aspector.rb +13 -0
 - data/examples/retry_aspect.rb +20 -20
 - data/lib/aspector.rb +17 -15
 - data/lib/aspector/advice.rb +44 -57
 - data/lib/aspector/advice_metadata.rb +10 -11
 - data/lib/aspector/aspect_instances.rb +2 -3
 - data/lib/aspector/base.rb +6 -368
 - data/lib/aspector/base_class_methods.rb +24 -55
 - data/lib/aspector/deferred_logic.rb +3 -4
 - data/lib/aspector/deferred_option.rb +5 -10
 - data/lib/aspector/interception.rb +356 -0
 - data/lib/aspector/logger.rb +18 -45
 - data/lib/aspector/logging.rb +10 -29
 - data/lib/aspector/method_matcher.rb +5 -6
 - data/lib/aspector/object_extension.rb +4 -12
 - data/lib/aspector/version.rb +3 -0
 - data/spec/examples_spec.rb +59 -0
 - data/spec/functionals/aspect_for_multiple_targets_spec.rb +54 -0
 - data/spec/functionals/aspect_interception_options_accessing_spec.rb +112 -0
 - data/spec/functionals/aspect_on_a_class_spec.rb +159 -0
 - data/spec/functionals/aspect_on_an_instance_spec.rb +66 -0
 - data/spec/functionals/aspector_spec.rb +138 -0
 - data/spec/functionals/aspects_combined_spec.rb +37 -0
 - data/spec/functionals/aspects_execution_order_spec.rb +61 -0
 - data/spec/functionals/aspects_on_private_methods_spec.rb +82 -0
 - data/spec/spec_helper.rb +20 -21
 - data/spec/support/class_builder.rb +44 -0
 - data/spec/units/advice_spec.rb +49 -0
 - data/spec/units/advices/after_spec.rb +328 -0
 - data/spec/units/advices/around_spec.rb +336 -0
 - data/spec/units/advices/before_filter_spec.rb +287 -0
 - data/spec/units/advices/before_spec.rb +237 -0
 - data/spec/units/advices/raw_spec.rb +67 -0
 - data/spec/units/base_class_methods_spec.rb +262 -0
 - data/spec/units/base_spec.rb +133 -0
 - data/spec/units/deferred_logic_spec.rb +35 -0
 - data/spec/units/logger_spec.rb +20 -0
 - data/spec/units/logging_spec.rb +85 -0
 - data/spec/units/method_matcher_spec.rb +95 -0
 - data/spec/units/object_extension_spec.rb +11 -0
 - data/spec/units/special_chars_spec.rb +128 -0
 - metadata +98 -246
 - data/.document +0 -5
 - data/.rvmrc +0 -8
 - data/README.rdoc +0 -80
 - data/VERSION +0 -1
 - data/performance-tests/after_test.rb +0 -25
 - data/performance-tests/around_advice_benchmark.rb +0 -66
 - data/performance-tests/around_test.rb +0 -27
 - data/performance-tests/before_test.rb +0 -25
 - data/performance-tests/combined_test.rb +0 -33
 - data/performance-tests/method_invocation_test.rb +0 -25
 - data/performance-tests/raw_test.rb +0 -37
 - data/performance-tests/test_helper.rb +0 -9
 - data/run_all_examples.sh +0 -12
 - data/spec/functional/advices_on_private_methods_spec.rb +0 -21
 - data/spec/functional/aspect_on_eigen_class_spec.rb +0 -72
 - data/spec/functional/aspect_on_object_spec.rb +0 -20
 - data/spec/functional/aspector_spec.rb +0 -140
 - data/spec/functional/aspects_combined_spec.rb +0 -48
 - data/spec/functional/execution_order_spec.rb +0 -42
 - data/spec/unit/advice_spec.rb +0 -4
 - data/spec/unit/after_spec.rb +0 -88
 - data/spec/unit/around_spec.rb +0 -76
 - data/spec/unit/base_class_methods_spec.rb +0 -28
 - data/spec/unit/base_spec.rb +0 -112
 - data/spec/unit/before_spec.rb +0 -125
 - data/spec/unit/deferred_logic_spec.rb +0 -23
 - data/spec/unit/method_matcher_spec.rb +0 -43
 - data/spec/unit/raw_spec.rb +0 -53
 - data/spec/unit/special_chars_spec.rb +0 -122
 
| 
         @@ -1,20 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            describe "Aspector for object" do
         
     | 
| 
       4 
     | 
    
         
            -
              it "should work" do
         
     | 
| 
       5 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                aspector(obj) do
         
     | 
| 
       10 
     | 
    
         
            -
                  before :test do value << "do_before" end
         
     | 
| 
       11 
     | 
    
         
            -
                end
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                obj.test
         
     | 
| 
       14 
     | 
    
         
            -
                obj.value.should == %w"do_before test"
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                obj2 = klass.new
         
     | 
| 
       17 
     | 
    
         
            -
                obj2.test
         
     | 
| 
       18 
     | 
    
         
            -
                obj2.value.should == %w"test"
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,140 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            describe "Aspector" do
         
     | 
| 
       4 
     | 
    
         
            -
              it "should work" do
         
     | 
| 
       5 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       8 
     | 
    
         
            -
                  before :test do value << "do_before" end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                  after  :test do |result|
         
     | 
| 
       11 
     | 
    
         
            -
                    value << "do_after"
         
     | 
| 
       12 
     | 
    
         
            -
                    result
         
     | 
| 
       13 
     | 
    
         
            -
                  end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  around :test do |proxy, &block|
         
     | 
| 
       16 
     | 
    
         
            -
                    value   <<  "do_around_before"
         
     | 
| 
       17 
     | 
    
         
            -
                    result  =   proxy.call &block
         
     | 
| 
       18 
     | 
    
         
            -
                    value   <<  "do_around_after"
         
     | 
| 
       19 
     | 
    
         
            -
                    result
         
     | 
| 
       20 
     | 
    
         
            -
                  end
         
     | 
| 
       21 
     | 
    
         
            -
                end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       24 
     | 
    
         
            -
                obj.test
         
     | 
| 
       25 
     | 
    
         
            -
                obj.value.should == %w"do_before do_around_before test do_around_after do_after"
         
     | 
| 
       26 
     | 
    
         
            -
              end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
              it "multiple aspects should work together" do
         
     | 
| 
       29 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       30 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       31 
     | 
    
         
            -
                  before(:test) { value << 'first_aspect' }
         
     | 
| 
       32 
     | 
    
         
            -
                end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       35 
     | 
    
         
            -
                  before(:test) { value << 'second_aspect' }
         
     | 
| 
       36 
     | 
    
         
            -
                end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       39 
     | 
    
         
            -
                obj.test
         
     | 
| 
       40 
     | 
    
         
            -
                obj.value.should == %w"second_aspect first_aspect test"
         
     | 
| 
       41 
     | 
    
         
            -
              end
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
              it "treating Aspect as regular class should work" do
         
     | 
| 
       44 
     | 
    
         
            -
                class TestAspect < Aspector::Base
         
     | 
| 
       45 
     | 
    
         
            -
                  before(:test) { value << 'before_test' }
         
     | 
| 
       46 
     | 
    
         
            -
                end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       49 
     | 
    
         
            -
                TestAspect.apply(klass)
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       52 
     | 
    
         
            -
                obj.test
         
     | 
| 
       53 
     | 
    
         
            -
                obj.value.should == %w"before_test test"
         
     | 
| 
       54 
     | 
    
         
            -
              end
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
              it "can be applied multiple times" do
         
     | 
| 
       57 
     | 
    
         
            -
                aspect = Aspector do
         
     | 
| 
       58 
     | 
    
         
            -
                  before(:test) { value << 'before_test' }
         
     | 
| 
       59 
     | 
    
         
            -
                end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       62 
     | 
    
         
            -
                aspect.apply(klass)
         
     | 
| 
       63 
     | 
    
         
            -
                aspect.apply(klass)
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       66 
     | 
    
         
            -
                obj.test
         
     | 
| 
       67 
     | 
    
         
            -
                obj.value.should == %w"before_test before_test test"
         
     | 
| 
       68 
     | 
    
         
            -
              end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
              it "if new_methods_only is true, do not apply to existing methods" do
         
     | 
| 
       71 
     | 
    
         
            -
                aspect = Aspector do
         
     | 
| 
       72 
     | 
    
         
            -
                  before(:test) { value << 'before_test' }
         
     | 
| 
       73 
     | 
    
         
            -
                end
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       76 
     | 
    
         
            -
                aspect.apply(klass, :new_methods_only => true)
         
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       79 
     | 
    
         
            -
                obj.test
         
     | 
| 
       80 
     | 
    
         
            -
                obj.value.should == %w"test"
         
     | 
| 
       81 
     | 
    
         
            -
              end
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
              it "if new_methods_only is true, do apply to new methods" do
         
     | 
| 
       84 
     | 
    
         
            -
                aspect = Aspector do
         
     | 
| 
       85 
     | 
    
         
            -
                  before(:test) { value << 'before_test' }
         
     | 
| 
       86 
     | 
    
         
            -
                end
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
                klass = Class.new do
         
     | 
| 
       89 
     | 
    
         
            -
                  def value
         
     | 
| 
       90 
     | 
    
         
            -
                    @value ||= []
         
     | 
| 
       91 
     | 
    
         
            -
                  end
         
     | 
| 
       92 
     | 
    
         
            -
                end
         
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
                aspect.apply(klass, :new_methods_only => true)
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
                klass.send :define_method, :test do
         
     | 
| 
       97 
     | 
    
         
            -
                  value << "test"
         
     | 
| 
       98 
     | 
    
         
            -
                end
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       101 
     | 
    
         
            -
                obj.test
         
     | 
| 
       102 
     | 
    
         
            -
                obj.value.should == %w"before_test test"
         
     | 
| 
       103 
     | 
    
         
            -
              end
         
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
              it "if old_methods_only is true, do apply to methods already defined" do
         
     | 
| 
       106 
     | 
    
         
            -
                aspect = Aspector do
         
     | 
| 
       107 
     | 
    
         
            -
                  before(:test) { value << 'before_test' }
         
     | 
| 
       108 
     | 
    
         
            -
                end
         
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       111 
     | 
    
         
            -
                aspect.apply(klass, :old_methods_only => true)
         
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       114 
     | 
    
         
            -
                obj.test
         
     | 
| 
       115 
     | 
    
         
            -
                obj.value.should == %w"before_test test"
         
     | 
| 
       116 
     | 
    
         
            -
              end
         
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
              it "if old_methods_only is true, do not apply to new methods" do
         
     | 
| 
       119 
     | 
    
         
            -
                aspect = Aspector do
         
     | 
| 
       120 
     | 
    
         
            -
                  before(:test) { value << 'before_test' }
         
     | 
| 
       121 
     | 
    
         
            -
                end
         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
                klass = Class.new do
         
     | 
| 
       124 
     | 
    
         
            -
                  def value
         
     | 
| 
       125 
     | 
    
         
            -
                    @value ||= []
         
     | 
| 
       126 
     | 
    
         
            -
                  end
         
     | 
| 
       127 
     | 
    
         
            -
                end
         
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
                aspect.apply(klass, :old_methods_only => true)
         
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
                klass.send :define_method, :test do
         
     | 
| 
       132 
     | 
    
         
            -
                  value << "test"
         
     | 
| 
       133 
     | 
    
         
            -
                end
         
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       136 
     | 
    
         
            -
                obj.test
         
     | 
| 
       137 
     | 
    
         
            -
                obj.value.should == %w"test"
         
     | 
| 
       138 
     | 
    
         
            -
              end
         
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,48 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            describe "Aspects combined" do
         
     | 
| 
       4 
     | 
    
         
            -
              it "should work" do
         
     | 
| 
       5 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       8 
     | 
    
         
            -
                  before :test do value << "do_before" end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                  after  :test do |result|
         
     | 
| 
       11 
     | 
    
         
            -
                    value << "do_after"
         
     | 
| 
       12 
     | 
    
         
            -
                    result
         
     | 
| 
       13 
     | 
    
         
            -
                  end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  around :test do |proxy, &block|
         
     | 
| 
       16 
     | 
    
         
            -
                    value   <<  "do_around_before"
         
     | 
| 
       17 
     | 
    
         
            -
                    result  =   proxy.call &block
         
     | 
| 
       18 
     | 
    
         
            -
                    value   <<  "do_around_after"
         
     | 
| 
       19 
     | 
    
         
            -
                    result
         
     | 
| 
       20 
     | 
    
         
            -
                  end
         
     | 
| 
       21 
     | 
    
         
            -
                end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       24 
     | 
    
         
            -
                  before :test do value << "do_before2" end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                  after  :test do |result|
         
     | 
| 
       27 
     | 
    
         
            -
                    value << "do_after2"
         
     | 
| 
       28 
     | 
    
         
            -
                    result
         
     | 
| 
       29 
     | 
    
         
            -
                  end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                  around :test do |proxy, &block|
         
     | 
| 
       32 
     | 
    
         
            -
                    value   <<  "do_around_before2"
         
     | 
| 
       33 
     | 
    
         
            -
                    result  =   proxy.call &block
         
     | 
| 
       34 
     | 
    
         
            -
                    value   <<  "do_around_after2"
         
     | 
| 
       35 
     | 
    
         
            -
                    result
         
     | 
| 
       36 
     | 
    
         
            -
                  end
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       40 
     | 
    
         
            -
                obj.test
         
     | 
| 
       41 
     | 
    
         
            -
                obj.value.should == %w"
         
     | 
| 
       42 
     | 
    
         
            -
                  do_before2 do_around_before2
         
     | 
| 
       43 
     | 
    
         
            -
                  do_before do_around_before
         
     | 
| 
       44 
     | 
    
         
            -
                  test
         
     | 
| 
       45 
     | 
    
         
            -
                  do_around_after do_after
         
     | 
| 
       46 
     | 
    
         
            -
                  do_around_after2 do_after2"
         
     | 
| 
       47 
     | 
    
         
            -
              end
         
     | 
| 
       48 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,42 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            describe "Aspect execution order" do
         
     | 
| 
       4 
     | 
    
         
            -
              it "should work" do
         
     | 
| 
       5 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       8 
     | 
    
         
            -
                  before :test do value << "do_before" end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                  after  :test do |result|
         
     | 
| 
       11 
     | 
    
         
            -
                    value << "do_after"
         
     | 
| 
       12 
     | 
    
         
            -
                    result
         
     | 
| 
       13 
     | 
    
         
            -
                  end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  around :test do |proxy, &block|
         
     | 
| 
       16 
     | 
    
         
            -
                    value   <<  "do_around_before"
         
     | 
| 
       17 
     | 
    
         
            -
                    result  =   proxy.call &block
         
     | 
| 
       18 
     | 
    
         
            -
                    value   <<  "do_around_after"
         
     | 
| 
       19 
     | 
    
         
            -
                    result
         
     | 
| 
       20 
     | 
    
         
            -
                  end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                  before :test do value << "do_before2" end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                  after  :test do |result|
         
     | 
| 
       25 
     | 
    
         
            -
                    value << "do_after2"
         
     | 
| 
       26 
     | 
    
         
            -
                    result
         
     | 
| 
       27 
     | 
    
         
            -
                  end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                  around :test do |proxy, &block|
         
     | 
| 
       30 
     | 
    
         
            -
                    value   <<  "do_around_before2"
         
     | 
| 
       31 
     | 
    
         
            -
                    result  =   proxy.call &block
         
     | 
| 
       32 
     | 
    
         
            -
                    value   <<  "do_around_after2"
         
     | 
| 
       33 
     | 
    
         
            -
                    result
         
     | 
| 
       34 
     | 
    
         
            -
                  end
         
     | 
| 
       35 
     | 
    
         
            -
                end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       38 
     | 
    
         
            -
                obj.test
         
     | 
| 
       39 
     | 
    
         
            -
                obj.value.should == %w"do_before do_before2 do_around_before do_around_before2 test
         
     | 
| 
       40 
     | 
    
         
            -
                                       do_around_after2 do_around_after do_after do_after2"
         
     | 
| 
       41 
     | 
    
         
            -
              end
         
     | 
| 
       42 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/unit/advice_spec.rb
    DELETED
    
    
    
        data/spec/unit/after_spec.rb
    DELETED
    
    | 
         @@ -1,88 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            describe "After advices" do
         
     | 
| 
       4 
     | 
    
         
            -
              it "should work" do
         
     | 
| 
       5 
     | 
    
         
            -
                klass = create_test_class do
         
     | 
| 
       6 
     | 
    
         
            -
                  def do_this result
         
     | 
| 
       7 
     | 
    
         
            -
                    value << "do_this"
         
     | 
| 
       8 
     | 
    
         
            -
                    result
         
     | 
| 
       9 
     | 
    
         
            -
                  end
         
     | 
| 
       10 
     | 
    
         
            -
                end
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       13 
     | 
    
         
            -
                  after :test, :do_this
         
     | 
| 
       14 
     | 
    
         
            -
                end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       17 
     | 
    
         
            -
                obj.test
         
     | 
| 
       18 
     | 
    
         
            -
                obj.value.should == %w"test do_this"
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
              it "method_arg" do
         
     | 
| 
       22 
     | 
    
         
            -
                klass = create_test_class do
         
     | 
| 
       23 
     | 
    
         
            -
                  def do_this method, result
         
     | 
| 
       24 
     | 
    
         
            -
                    value << "do_this(#{method})"
         
     | 
| 
       25 
     | 
    
         
            -
                    result
         
     | 
| 
       26 
     | 
    
         
            -
                  end
         
     | 
| 
       27 
     | 
    
         
            -
                end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       30 
     | 
    
         
            -
                  after :test, :do_this, :method_arg => true
         
     | 
| 
       31 
     | 
    
         
            -
                end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       34 
     | 
    
         
            -
                obj.test
         
     | 
| 
       35 
     | 
    
         
            -
                obj.value.should == %w"test do_this(test)"
         
     | 
| 
       36 
     | 
    
         
            -
              end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
              it "new result will be returned by default" do
         
     | 
| 
       39 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       42 
     | 
    
         
            -
                  after :test do |result|
         
     | 
| 
       43 
     | 
    
         
            -
                    value << "do_after"
         
     | 
| 
       44 
     | 
    
         
            -
                    'do_after'
         
     | 
| 
       45 
     | 
    
         
            -
                  end
         
     | 
| 
       46 
     | 
    
         
            -
                end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       49 
     | 
    
         
            -
                obj.test.should == 'do_after'
         
     | 
| 
       50 
     | 
    
         
            -
                obj.value.should == %w"test do_after"
         
     | 
| 
       51 
     | 
    
         
            -
              end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
              it "result_arg set to false" do
         
     | 
| 
       54 
     | 
    
         
            -
                klass = create_test_class do
         
     | 
| 
       55 
     | 
    
         
            -
                  def test
         
     | 
| 
       56 
     | 
    
         
            -
                    value << "test"
         
     | 
| 
       57 
     | 
    
         
            -
                    'test'
         
     | 
| 
       58 
     | 
    
         
            -
                  end
         
     | 
| 
       59 
     | 
    
         
            -
                end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       62 
     | 
    
         
            -
                  after :test, :result_arg => false do
         
     | 
| 
       63 
     | 
    
         
            -
                    value << "do_after"
         
     | 
| 
       64 
     | 
    
         
            -
                    'do_after'
         
     | 
| 
       65 
     | 
    
         
            -
                  end
         
     | 
| 
       66 
     | 
    
         
            -
                end
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       69 
     | 
    
         
            -
                obj.test.should == 'test'
         
     | 
| 
       70 
     | 
    
         
            -
                obj.value.should == %w"test do_after"
         
     | 
| 
       71 
     | 
    
         
            -
              end
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
              it "logic in block" do
         
     | 
| 
       74 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       77 
     | 
    
         
            -
                  after(:test) do |result|
         
     | 
| 
       78 
     | 
    
         
            -
                    value << 'do_block'
         
     | 
| 
       79 
     | 
    
         
            -
                    result
         
     | 
| 
       80 
     | 
    
         
            -
                  end
         
     | 
| 
       81 
     | 
    
         
            -
                end
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       84 
     | 
    
         
            -
                obj.test
         
     | 
| 
       85 
     | 
    
         
            -
                obj.value.should == %w"test do_block"
         
     | 
| 
       86 
     | 
    
         
            -
              end
         
     | 
| 
       87 
     | 
    
         
            -
            end
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
    
        data/spec/unit/around_spec.rb
    DELETED
    
    | 
         @@ -1,76 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            describe "Around advices" do
         
     | 
| 
       4 
     | 
    
         
            -
              it "should work" do
         
     | 
| 
       5 
     | 
    
         
            -
                klass = create_test_class do
         
     | 
| 
       6 
     | 
    
         
            -
                  def do_this proxy, &block
         
     | 
| 
       7 
     | 
    
         
            -
                    value << "before"
         
     | 
| 
       8 
     | 
    
         
            -
                    result = proxy.call &block
         
     | 
| 
       9 
     | 
    
         
            -
                    value << "after"
         
     | 
| 
       10 
     | 
    
         
            -
                    result
         
     | 
| 
       11 
     | 
    
         
            -
                  end
         
     | 
| 
       12 
     | 
    
         
            -
                end
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       15 
     | 
    
         
            -
                  around :test, :do_this
         
     | 
| 
       16 
     | 
    
         
            -
                end
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       19 
     | 
    
         
            -
                obj.test
         
     | 
| 
       20 
     | 
    
         
            -
                obj.value.should == %w"before test after"
         
     | 
| 
       21 
     | 
    
         
            -
              end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
              it "logic in String" do
         
     | 
| 
       24 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       27 
     | 
    
         
            -
                  around :test, <<-CODE
         
     | 
| 
       28 
     | 
    
         
            -
                    value << "before"
         
     | 
| 
       29 
     | 
    
         
            -
                    result = INVOKE_PROXY
         
     | 
| 
       30 
     | 
    
         
            -
                    value << "after"
         
     | 
| 
       31 
     | 
    
         
            -
                    result
         
     | 
| 
       32 
     | 
    
         
            -
                  CODE
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       36 
     | 
    
         
            -
                obj.test
         
     | 
| 
       37 
     | 
    
         
            -
                obj.value.should == %w"before test after"
         
     | 
| 
       38 
     | 
    
         
            -
              end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
              it "logic in block" do
         
     | 
| 
       41 
     | 
    
         
            -
                klass = create_test_class
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       44 
     | 
    
         
            -
                  around :test do |proxy, &block|
         
     | 
| 
       45 
     | 
    
         
            -
                    value << "before"
         
     | 
| 
       46 
     | 
    
         
            -
                    result = proxy.call &block
         
     | 
| 
       47 
     | 
    
         
            -
                    value << "after"
         
     | 
| 
       48 
     | 
    
         
            -
                    result
         
     | 
| 
       49 
     | 
    
         
            -
                  end
         
     | 
| 
       50 
     | 
    
         
            -
                end
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       53 
     | 
    
         
            -
                obj.test
         
     | 
| 
       54 
     | 
    
         
            -
                obj.value.should == %w"before test after"
         
     | 
| 
       55 
     | 
    
         
            -
              end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
              it "method_arg" do
         
     | 
| 
       58 
     | 
    
         
            -
                klass = create_test_class do
         
     | 
| 
       59 
     | 
    
         
            -
                  def do_this method, proxy, &block
         
     | 
| 
       60 
     | 
    
         
            -
                    value << "before(#{method})"
         
     | 
| 
       61 
     | 
    
         
            -
                    result = proxy.call &block
         
     | 
| 
       62 
     | 
    
         
            -
                    value << "after(#{method})"
         
     | 
| 
       63 
     | 
    
         
            -
                    result
         
     | 
| 
       64 
     | 
    
         
            -
                  end
         
     | 
| 
       65 
     | 
    
         
            -
                end
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
                aspector(klass) do
         
     | 
| 
       68 
     | 
    
         
            -
                  around :test, :do_this, :method_arg => true
         
     | 
| 
       69 
     | 
    
         
            -
                end
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
                obj = klass.new
         
     | 
| 
       72 
     | 
    
         
            -
                obj.test
         
     | 
| 
       73 
     | 
    
         
            -
                obj.value.should == %w"before(test) test after(test)"
         
     | 
| 
       74 
     | 
    
         
            -
              end
         
     | 
| 
       75 
     | 
    
         
            -
            end
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
         @@ -1,28 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            describe "Aspector::Base class methods" do
         
     | 
| 
       4 
     | 
    
         
            -
              it "before" do
         
     | 
| 
       5 
     | 
    
         
            -
                klass = Class.new(Aspector::Base) do
         
     | 
| 
       6 
     | 
    
         
            -
                  before :test, :do_before
         
     | 
| 
       7 
     | 
    
         
            -
                end
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                klass.send(:advices).size.should == 1
         
     | 
| 
       10 
     | 
    
         
            -
                advice = klass.send(:advices).first
         
     | 
| 
       11 
     | 
    
         
            -
                advice.before?.should be_true
         
     | 
| 
       12 
     | 
    
         
            -
                advice.options[:skip_if_false].should_not be_true
         
     | 
| 
       13 
     | 
    
         
            -
                advice.with_method.should == :do_before
         
     | 
| 
       14 
     | 
    
         
            -
              end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
              it "before_filter" do
         
     | 
| 
       17 
     | 
    
         
            -
                klass = Class.new(Aspector::Base) do
         
     | 
| 
       18 
     | 
    
         
            -
                  before_filter :test, :do_before
         
     | 
| 
       19 
     | 
    
         
            -
                end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                klass.send(:advices).size.should == 1
         
     | 
| 
       22 
     | 
    
         
            -
                advice = klass.send(:advices).first
         
     | 
| 
       23 
     | 
    
         
            -
                advice.before?.should be_true
         
     | 
| 
       24 
     | 
    
         
            -
                advice.options[:skip_if_false].should be_true
         
     | 
| 
       25 
     | 
    
         
            -
                advice.with_method.should == :do_before
         
     | 
| 
       26 
     | 
    
         
            -
              end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
            end
         
     |