public
Rubygem
Description: A version of Vassily Bykov's Smalltalk Announcements framework
Homepage: http://www.bofh.org.uk/articles/tag/announcementsproject
Clone URL: git://github.com/pdcawley/announcements.git
Search Repo:
Click here to lend your support to: announcements and make a donation at www.pledgie.com !
name age message
folder .gitignore Sun Jun 29 07:13:38 -0700 2008 Added a .gitignore to ignore the generated docs [pdcawley]
folder History.txt Fri Jun 27 14:25:59 -0700 2008 RubyAnnouncements is evil and must be stopped [pdcawley]
folder License.txt Thu Jun 26 12:01:02 -0700 2008 Initial checkin from newgem [pdcawley]
folder Manifest.txt Sun Jun 29 00:03:25 -0700 2008 tidied up the manifest [pdcawley]
folder PostInstall.txt Sun Jun 29 02:41:15 -0700 2008 Added a detailed usage synopsis. First step on ... [pdcawley]
folder README.txt Sun Jun 29 02:43:52 -0700 2008 saem terms? [pdcawley]
folder Rakefile Thu Jun 26 12:01:02 -0700 2008 Initial checkin from newgem [pdcawley]
folder announcements.gemspec Sun Jun 29 02:40:30 -0700 2008 Added a github gemspec [pdcawley]
folder config/ Fri Jun 27 14:25:59 -0700 2008 RubyAnnouncements is evil and must be stopped [pdcawley]
folder lib/ Mon Jul 14 08:13:59 -0700 2008 Fixed a few typos - amazing what actually _usin... [pdcawley]
folder script/ Fri Jun 27 14:25:59 -0700 2008 RubyAnnouncements is evil and must be stopped [pdcawley]
folder setup.rb Thu Jun 26 12:01:02 -0700 2008 Initial checkin from newgem [pdcawley]
folder spec/ Sun Jun 29 07:13:38 -0700 2008 Rubifying the API a little [pdcawley]
folder tasks/ Thu Jun 26 12:01:02 -0700 2008 Initial checkin from newgem [pdcawley]
README.txt
= announcements

http://www.bofh.org.uk/articles/tag/announcementsproject

== DESCRIPTION:

A port of Vassily Bykov's Smalltalk Announcements framework. Think of it as
Observer/Observable on steroids.

== FEATURES/PROBLEMS:

=== Problems first

This is very much a first cut. Testing is sparse because this is mostly a direct port
from a Smalltalk package that's pretty much test free. The API also a pretty
much straight port of the Smalltalk and isn't what could be called idiomatic
Ruby just yet.

=== Features

* Announcements are objects and can carry all the information a subscriber will need.
* Small, uniform interface for subscription

== SYNOPSIS:

  class ObservableValue
    include Announcements
    class ChangeAnnouncement < Announcements::Anouncement
      attr_accessor :from, :to

      def initialize(from, to)
        @from, @to = from, to
      end

      def inspect
        self.class.to_s.gsub(/([a-z])(A-Z)/) { $1 + ' ' + $2}.downcase << 
          " from #{@from.inspect} to #{@to.inspect}"
      end
    end

    class ValueWillChange <  ChangeAnnouncement
      def veto!
        @vetoed = true
      end

      def vetoed?
        @vetoed
      end
    end

    class ValueChanging < ChangeAnnouncement; end
    class ValueChanged < ChangeAnnouncement; end

    def self.announcer
      @@announcer ||= Announcements::Announcer.new
    end

    def announce(*args)
      self.class.announcer.announce(*args)
    end

    def value=(new_value) 
      unless announce(ValueWillChange.new(@value, new_value)).vetoed?
        announce(ValueChanging.new(@value, new_value)
        change_complete = ValueChanged.new(@value, new_value)
        @value = new_value
        announce(change_complete)
    end
  end

  # Spy on all the changes

  ObservableValue.watch(ObservableValue::ChangeAnnouncement) do |notice, sender|
    puts "#{announcer.inspect} #{announcement.inspect}"
  end

  # Remember changes for undoing

  ObservableValue.watch(ObservableValue::ValueChanged) do |notice, sender|
    command_history << UndoableCommand.new(sender, notice.from, notice.to)
  end

== REQUIREMENTS:

* Rspec, but only if you want to run the tests
* Er...
* That's it

== INSTALL:

  sudo gem install announcements

== COPYRIGHT:

Copyright (c) 2008 Piers Cawley

This library is free software; you can redistribute it and/or modify it under
the same terms as Ruby itself.

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.