ick 0.2.2 → 0.2.3
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/History.txt +4 -2
- data/Manifest.txt +1 -0
- data/lib/ick/advisor.rb +58 -11
- data/lib/ick/version.rb +1 -1
- data/test/test_advisor.rb +70 -0
- data/test/test_helper.rb +22 -0
- data/test/test_ick.rb +0 -21
- data/website/index.html +1 -1
- metadata +4 -2
    
        data/History.txt
    CHANGED
    
    | @@ -8,9 +8,11 @@ | |
| 8 8 | 
             
            * 3 minor enhancement:
         | 
| 9 9 | 
             
              * refactored Wrapped into Wrap with runtime options
         | 
| 10 10 | 
             
              * added ArrayWrapper and Tee classes
         | 
| 11 | 
            -
            * 4  | 
| 11 | 
            +
            * 4 tiny enhancement
         | 
| 12 12 | 
             
              * fixed manifest.txt
         | 
| 13 13 | 
             
              * TODO: build the manifest algorithmically!
         | 
| 14 | 
            -
            * 5  | 
| 14 | 
            +
            * 5 tiny enhancement
         | 
| 15 15 | 
             
              * #fork
         | 
| 16 | 
            +
            * 6 tiny enhancement
         | 
| 17 | 
            +
              * work in progress on Advisor
         | 
| 16 18 |  | 
    
        data/Manifest.txt
    CHANGED
    
    
    
        data/lib/ick/advisor.rb
    CHANGED
    
    | @@ -1,28 +1,28 @@ | |
| 1 1 | 
             
            module Ick
         | 
| 2 2 | 
             
              class Advisor < Wrapper
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
                  old_arounds = @@arounds
         | 
| 3 | 
            +
                
         | 
| 4 | 
            +
                def self.around *args, &proc # { |callback, receiver, sym, *args| ... }
         | 
| 5 | 
            +
                  target, conditions = self.extract_parameters(args)
         | 
| 6 | 
            +
                  old_arounds = self.around_chain 
         | 
| 8 7 | 
             
                  if target.kind_of?(Symbol)
         | 
| 9 8 | 
             
                    proc = lambda { |callback, receiver, sym, *args|
         | 
| 10 | 
            -
                      self.send(target, sym, *args, &proc)
         | 
| 9 | 
            +
                      self.send(target, callback, receiver, sym, *args, &proc)
         | 
| 11 10 | 
             
                    }
         | 
| 12 11 | 
             
                  elsif target.kind_of?(Class)
         | 
| 13 12 | 
             
                    proc = lambda { |callback, receiver, sym, *args|
         | 
| 14 13 | 
             
                      target.filter(receiver, sym, *args, &proc)
         | 
| 15 14 | 
             
                    }
         | 
| 16 15 | 
             
                  end
         | 
| 17 | 
            -
                   | 
| 16 | 
            +
                  self.around_chain = 
         | 
| 17 | 
            +
                    if conditions[:only]
         | 
| 18 18 | 
             
                      lambda { |callback, receiver, sym, *args|
         | 
| 19 19 | 
             
                        new_callback = lambda { old_arounds.call(callback, receiver, sym, *args) }
         | 
| 20 | 
            -
                        Array( | 
| 20 | 
            +
                        Array(conditions[:only]).include?(sym) ? proc.call(callback, receiver, sym, *args) : callback.call()
         | 
| 21 21 | 
             
                      }
         | 
| 22 | 
            -
                    elsif  | 
| 22 | 
            +
                    elsif conditions[:except]
         | 
| 23 23 | 
             
                      lambda { |callback, receiver, sym, *args|
         | 
| 24 24 | 
             
                        new_callback = lambda { old_arounds.call(callback, receiver, sym, *args) }
         | 
| 25 | 
            -
                        Array( | 
| 25 | 
            +
                        Array(conditions[:except]).include?(sym) ? new_callback.call() : proc.call(new_callback, receiver, sym, *args)
         | 
| 26 26 | 
             
                      }
         | 
| 27 27 | 
             
                    else
         | 
| 28 28 | 
             
                      lambda { |callback, receiver, sym, *args|
         | 
| @@ -31,13 +31,60 @@ module Ick | |
| 31 31 | 
             
                      }
         | 
| 32 32 | 
             
                    end
         | 
| 33 33 | 
             
                end
         | 
| 34 | 
            +
                
         | 
| 35 | 
            +
                def self.before *args, &proc # { |receiver, sym, *args| ... }
         | 
| 36 | 
            +
                  self.around *args, &(lambda { |callback, receiver, sym, *args|  
         | 
| 37 | 
            +
                    proc.call(receiver, sym, *args)
         | 
| 38 | 
            +
                    callback.call()
         | 
| 39 | 
            +
                  })
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
                
         | 
| 42 | 
            +
                def self.after *args, &proc # { |receiver, sym, *args| ... }
         | 
| 43 | 
            +
                  self.around *args, &(lambda { |callback, receiver, sym, *args|  
         | 
| 44 | 
            +
                    callback.call()
         | 
| 45 | 
            +
                    proc.call(receiver, sym, *args)
         | 
| 46 | 
            +
                  })
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
                
         | 
| 34 49 | 
             
                def __invoke__(sym, *args, &block)
         | 
| 35 | 
            -
                   | 
| 50 | 
            +
                  self.__class.around_chain.call(
         | 
| 36 51 | 
             
                    lambda { @value.__send__(sym, *args, &block) },
         | 
| 37 52 | 
             
                    @value,
         | 
| 38 53 | 
             
                    sym,
         | 
| 39 54 | 
             
                    *args
         | 
| 40 55 | 
             
                  )
         | 
| 41 56 | 
             
                end
         | 
| 57 | 
            +
                
         | 
| 58 | 
            +
                is_not_contagious
         | 
| 59 | 
            +
                
         | 
| 60 | 
            +
                private
         | 
| 61 | 
            +
                
         | 
| 62 | 
            +
                def self.around_chain
         | 
| 63 | 
            +
                  @around_chain || lambda { |callback, receiver, sym, *args|
         | 
| 64 | 
            +
                  callback.call()
         | 
| 65 | 
            +
                }
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
                
         | 
| 68 | 
            +
                def self.around_chain=(chain)
         | 
| 69 | 
            +
                  @around_chain = chain
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
                
         | 
| 72 | 
            +
                def self.extract_parameters arr
         | 
| 73 | 
            +
                  if arr.empty?
         | 
| 74 | 
            +
                    []
         | 
| 75 | 
            +
                  elsif arr.size == 2
         | 
| 76 | 
            +
                    arr
         | 
| 77 | 
            +
                  elsif arr.size > 2
         | 
| 78 | 
            +
                    [arr[0..-2], arr[-1]]
         | 
| 79 | 
            +
                  elsif arr.first.kind_of?(Class) or arr.first.kind_of?(Symbol)
         | 
| 80 | 
            +
                    [arr[0], {}]
         | 
| 81 | 
            +
                  elsif arr.first.respond_to?(:[])
         | 
| 82 | 
            +
                    [nil, arr.first]
         | 
| 83 | 
            +
                  else
         | 
| 84 | 
            +
                    raise "Argument problem with #{arr}"
         | 
| 85 | 
            +
                  end
         | 
| 86 | 
            +
                end
         | 
| 87 | 
            +
                
         | 
| 42 88 | 
             
              end
         | 
| 89 | 
            +
              
         | 
| 43 90 | 
             
            end
         | 
    
        data/lib/ick/version.rb
    CHANGED
    
    
| @@ -0,0 +1,70 @@ | |
| 1 | 
            +
            require File.dirname(__FILE__) + '/test_helper.rb'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class NoAdvice < Ick::Advisor
         | 
| 4 | 
            +
            end
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            class NameUpdator < Ick::Advisor
         | 
| 7 | 
            +
              around :only => :value= do |callback, receiver, sym, *args|
         | 
| 8 | 
            +
                callback.call()
         | 
| 9 | 
            +
                receiver.name = receiver.to_s
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            class NameUpdatorByMethod < Ick::Advisor
         | 
| 14 | 
            +
              around :update, :only => :value=
         | 
| 15 | 
            +
              
         | 
| 16 | 
            +
              def self.update(callback, receiver, sym, *args)
         | 
| 17 | 
            +
                callback.call()
         | 
| 18 | 
            +
                receiver.name = receiver.to_s
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            class DoublePlusOne < Ick::Advisor
         | 
| 23 | 
            +
              around :only => :value= do |callback, receiver, sym, *args|
         | 
| 24 | 
            +
                callback.call()
         | 
| 25 | 
            +
                receiver.name = receiver.to_s
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            class TestAdvisor < Test::Unit::TestCase
         | 
| 30 | 
            +
              
         | 
| 31 | 
            +
              def setup
         | 
| 32 | 
            +
                @box1 = Box.new(1)
         | 
| 33 | 
            +
                @box_one = Box.new(1)
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
              
         | 
| 36 | 
            +
              def test_no_advice
         | 
| 37 | 
            +
                nullo = NoAdvice.new(@box1)
         | 
| 38 | 
            +
                nullo.value = 2
         | 
| 39 | 
            +
                assert_equal(2, @box1.value)
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
              
         | 
| 42 | 
            +
              def test_simple_around_advice
         | 
| 43 | 
            +
                old_string = @box1.name
         | 
| 44 | 
            +
                @box1.value = 2
         | 
| 45 | 
            +
                assert_equal(2, @box1.value)
         | 
| 46 | 
            +
                assert_equal(old_string, @box1.name) # The name has not changed
         | 
| 47 | 
            +
                assert_not_equal(old_string, @box1.to_s) # but the string has
         | 
| 48 | 
            +
                updating = NameUpdator.new(@box_one)
         | 
| 49 | 
            +
                updating.value = 2
         | 
| 50 | 
            +
                assert_equal(updating.to_s, updating.name) # updated the name
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
              
         | 
| 53 | 
            +
              def test_simple_by_method
         | 
| 54 | 
            +
                updating = NameUpdatorByMethod.new(@box_one)
         | 
| 55 | 
            +
                updating.value = 2
         | 
| 56 | 
            +
                assert_equal(updating.to_s, updating.name) # updated the name
         | 
| 57 | 
            +
              end
         | 
| 58 | 
            +
              
         | 
| 59 | 
            +
              def test_simple_around_advice
         | 
| 60 | 
            +
                old_string = @box1.name
         | 
| 61 | 
            +
                @box1.value = 2
         | 
| 62 | 
            +
                assert_equal(2, @box1.value)
         | 
| 63 | 
            +
                assert_equal(old_string, @box1.name) # The name has not changed
         | 
| 64 | 
            +
                assert_not_equal(old_string, @box1.to_s) # but the string has
         | 
| 65 | 
            +
                updating = NameUpdator.new(@box_one)
         | 
| 66 | 
            +
                updating.value = 2
         | 
| 67 | 
            +
                assert_equal(updating.to_s, updating.name) # updated the name
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
              
         | 
| 70 | 
            +
            end
         | 
    
        data/test/test_helper.rb
    CHANGED
    
    | @@ -2,3 +2,25 @@ require 'test/unit' | |
| 2 2 | 
             
            require File.dirname(__FILE__) + '/../lib/ick'
         | 
| 3 3 |  | 
| 4 4 | 
             
            Ick.sugarize
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            class Box
         | 
| 7 | 
            +
              attr_accessor :value, :name
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              def initialize(_value)
         | 
| 10 | 
            +
                self.value = _value
         | 
| 11 | 
            +
                self.name = self.to_s
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              def == (other)
         | 
| 15 | 
            +
                other.respond_to?(:value) && self.value == other.value
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
              
         | 
| 18 | 
            +
              def to_s
         | 
| 19 | 
            +
                "Box(#{value})"
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
              
         | 
| 22 | 
            +
              def inspect
         | 
| 23 | 
            +
                "Box(#{value})"
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
              
         | 
| 26 | 
            +
            end
         | 
    
        data/test/test_ick.rb
    CHANGED
    
    | @@ -1,26 +1,5 @@ | |
| 1 1 | 
             
            require File.dirname(__FILE__) + '/test_helper.rb'
         | 
| 2 2 |  | 
| 3 | 
            -
            class Box
         | 
| 4 | 
            -
              attr_accessor :value
         | 
| 5 | 
            -
              
         | 
| 6 | 
            -
              def initialize(_value)
         | 
| 7 | 
            -
                self.value = _value
         | 
| 8 | 
            -
              end
         | 
| 9 | 
            -
              
         | 
| 10 | 
            -
              def == (other)
         | 
| 11 | 
            -
                other.respond_to?(:value) && self.value == other.value
         | 
| 12 | 
            -
              end
         | 
| 13 | 
            -
              
         | 
| 14 | 
            -
              def to_s
         | 
| 15 | 
            -
                "Box(#{value})"
         | 
| 16 | 
            -
              end
         | 
| 17 | 
            -
              
         | 
| 18 | 
            -
              def inspect
         | 
| 19 | 
            -
                "Box(#{value})"
         | 
| 20 | 
            -
              end
         | 
| 21 | 
            -
              
         | 
| 22 | 
            -
            end
         | 
| 23 | 
            -
             | 
| 24 3 | 
             
            class TestIck < Test::Unit::TestCase
         | 
| 25 4 |  | 
| 26 5 | 
             
              attr_accessor :value
         | 
    
        data/website/index.html
    CHANGED
    
    | @@ -33,7 +33,7 @@ | |
| 33 33 | 
             
                <h1>Invocation Construction Kit</h1>
         | 
| 34 34 | 
             
                <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/ick"; return false'>
         | 
| 35 35 | 
             
                  <p>Get Version</p>
         | 
| 36 | 
            -
                  <a href="http://rubyforge.org/projects/ick" class="numbers">0.2. | 
| 36 | 
            +
                  <a href="http://rubyforge.org/projects/ick" class="numbers">0.2.3</a>
         | 
| 37 37 | 
             
                </div>
         | 
| 38 38 | 
             
                <h1>→ ‘ick’</h1>
         | 
| 39 39 |  | 
    
        metadata
    CHANGED
    
    | @@ -3,8 +3,8 @@ rubygems_version: 0.9.0 | |
| 3 3 | 
             
            specification_version: 1
         | 
| 4 4 | 
             
            name: ick
         | 
| 5 5 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 6 | 
            -
              version: 0.2. | 
| 7 | 
            -
            date: 2008-03- | 
| 6 | 
            +
              version: 0.2.3
         | 
| 7 | 
            +
            date: 2008-03-10 00:00:00 -04:00
         | 
| 8 8 | 
             
            summary: Invocation Construction Kit
         | 
| 9 9 | 
             
            require_paths: 
         | 
| 10 10 | 
             
            - lib
         | 
| @@ -55,12 +55,14 @@ files: | |
| 55 55 | 
             
            - tasks/website.rake
         | 
| 56 56 | 
             
            - test/test_helper.rb
         | 
| 57 57 | 
             
            - test/test_ick.rb
         | 
| 58 | 
            +
            - test/test_advisor.rb
         | 
| 58 59 | 
             
            - website/index.html
         | 
| 59 60 | 
             
            - website/index.txt
         | 
| 60 61 | 
             
            - website/javascripts/rounded_corners_lite.inc.js
         | 
| 61 62 | 
             
            - website/stylesheets/screen.css
         | 
| 62 63 | 
             
            - website/template.rhtml
         | 
| 63 64 | 
             
            test_files: 
         | 
| 65 | 
            +
            - test/test_advisor.rb
         | 
| 64 66 | 
             
            - test/test_helper.rb
         | 
| 65 67 | 
             
            - test/test_ick.rb
         | 
| 66 68 | 
             
            rdoc_options: 
         |