Giter Club home page Giter Club logo

wrap's Introduction

NAME
  wrap

SYNOPSIS
  non-sucking :before and :after filters for any ruby class

DESCRIPTION
  yes yes, active_support does this.  but crapily.  with active_support you'll
  need to do this


    class Record
      include ActiveSupport::Callbacks
      define_callbacks :save

      def save
        run_callbacks :save do
          puts "- save"
        end
      end
    end

  but hey, if a subclass forgets to call 'super' or doesn't manually run
  'run_callbacks' the codez are *screwed*.  that sux.  why not this?


    class Record
      include Wrap

      wrap :save
    end


  yes, it's that simple.  you can now do

    class SubRecord < Record
      before :save do
        special_sauce
      end
      
      def save
        no_special_sauce
      end
    end

  did you get that?  the :before and :after hooks will be called no matter
  what the subclass does.  the method will be wrapped, period.  no special
  work required.  of course, if the sublcass messes with 'method_added' their
  will be hell to pay.  that's the price for simplicity.

  the callbacks are very close, but not identical to active_supports.  you can
  return 'false' to halt the chain, but you can also simply call 'halt!'.
  another neat trick is that :before callbacks will be called with the
  arguments to the wrapped method itself iff possible and :after callbacks
  will be called with the result of the wrapped method, iff possible.

  the test suite reads pretty damn clean.  have a go.

wrap's People

Contributors

ahoward avatar

Stargazers

Benjamin Fleischer avatar Ross Paffett avatar Joel Parker Henderson avatar Steven Lumos avatar Tyler Montgomery avatar  avatar Thomas Winkler avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

sferik

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.