├── .gitignore ├── doc └── rdoc │ ├── images │ ├── bug.png │ ├── date.png │ ├── find.png │ ├── ruby.png │ ├── zoom.png │ ├── brick.png │ ├── package.png │ ├── plugin.png │ ├── wrench.png │ ├── tag_green.png │ ├── brick_link.png │ ├── bullet_black.png │ ├── macFFBgHack.png │ ├── page_green.png │ ├── wrench_orange.png │ ├── loadingAnimation.gif │ ├── page_white_text.png │ ├── page_white_width.png │ ├── bullet_toggle_minus.png │ └── bullet_toggle_plus.png │ ├── created.rid │ ├── lib │ ├── ruby_events_rb.html │ └── ruby_events │ │ ├── object_patch_rb.html │ │ └── core_rb.html │ ├── index.html │ ├── js │ ├── quicksearch.js │ ├── darkfish.js │ ├── thickbox-compressed.js │ └── jquery.js │ ├── RubyEvents.html │ ├── Object.html │ ├── rdoc.css │ └── RubyEvents │ └── Events.html ├── pkg ├── ruby_events-0.0.1.gem ├── ruby_events-0.0.2.gem ├── ruby_events-0.0.3.gem ├── ruby_events-0.0.4.gem ├── ruby_events-0.0.5.gem ├── ruby_events-0.0.6.gem ├── ruby_events-0.0.7.gem ├── ruby_events-0.0.8.gem ├── ruby_events-1.0.0.gem ├── ruby_events-1.0.1.gem ├── ruby_events-1.1.0.gem ├── ruby_events-1.1.0.beta.gem └── ruby_events-1.1.0.beta2.gem ├── lib ├── ruby_events.rb └── ruby_events │ ├── object_patch.rb │ └── core.rb ├── Rakefile ├── ruby_events.gemspec ├── CHANGELOG ├── README.markdown └── spec └── ruby_events_spec.rb /.gitignore: -------------------------------------------------------------------------------- 1 | nbproject -------------------------------------------------------------------------------- /doc/rdoc/images/bug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/bug.png -------------------------------------------------------------------------------- /doc/rdoc/images/date.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/date.png -------------------------------------------------------------------------------- /doc/rdoc/images/find.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/find.png -------------------------------------------------------------------------------- /doc/rdoc/images/ruby.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/ruby.png -------------------------------------------------------------------------------- /doc/rdoc/images/zoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/zoom.png -------------------------------------------------------------------------------- /doc/rdoc/images/brick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/brick.png -------------------------------------------------------------------------------- /doc/rdoc/images/package.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/package.png -------------------------------------------------------------------------------- /doc/rdoc/images/plugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/plugin.png -------------------------------------------------------------------------------- /doc/rdoc/images/wrench.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/wrench.png -------------------------------------------------------------------------------- /pkg/ruby_events-0.0.1.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-0.0.1.gem -------------------------------------------------------------------------------- /pkg/ruby_events-0.0.2.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-0.0.2.gem -------------------------------------------------------------------------------- /pkg/ruby_events-0.0.3.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-0.0.3.gem -------------------------------------------------------------------------------- /pkg/ruby_events-0.0.4.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-0.0.4.gem -------------------------------------------------------------------------------- /pkg/ruby_events-0.0.5.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-0.0.5.gem -------------------------------------------------------------------------------- /pkg/ruby_events-0.0.6.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-0.0.6.gem -------------------------------------------------------------------------------- /pkg/ruby_events-0.0.7.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-0.0.7.gem -------------------------------------------------------------------------------- /pkg/ruby_events-0.0.8.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-0.0.8.gem -------------------------------------------------------------------------------- /pkg/ruby_events-1.0.0.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-1.0.0.gem -------------------------------------------------------------------------------- /pkg/ruby_events-1.0.1.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-1.0.1.gem -------------------------------------------------------------------------------- /pkg/ruby_events-1.1.0.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-1.1.0.gem -------------------------------------------------------------------------------- /doc/rdoc/images/tag_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/tag_green.png -------------------------------------------------------------------------------- /doc/rdoc/images/brick_link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/brick_link.png -------------------------------------------------------------------------------- /doc/rdoc/images/bullet_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/bullet_black.png -------------------------------------------------------------------------------- /doc/rdoc/images/macFFBgHack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/macFFBgHack.png -------------------------------------------------------------------------------- /doc/rdoc/images/page_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/page_green.png -------------------------------------------------------------------------------- /pkg/ruby_events-1.1.0.beta.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-1.1.0.beta.gem -------------------------------------------------------------------------------- /pkg/ruby_events-1.1.0.beta2.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/pkg/ruby_events-1.1.0.beta2.gem -------------------------------------------------------------------------------- /doc/rdoc/images/wrench_orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/wrench_orange.png -------------------------------------------------------------------------------- /doc/rdoc/images/loadingAnimation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/loadingAnimation.gif -------------------------------------------------------------------------------- /doc/rdoc/images/page_white_text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/page_white_text.png -------------------------------------------------------------------------------- /doc/rdoc/images/page_white_width.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/page_white_width.png -------------------------------------------------------------------------------- /doc/rdoc/images/bullet_toggle_minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/bullet_toggle_minus.png -------------------------------------------------------------------------------- /doc/rdoc/images/bullet_toggle_plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathankleyn/ruby_events/HEAD/doc/rdoc/images/bullet_toggle_plus.png -------------------------------------------------------------------------------- /lib/ruby_events.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "ruby_events/core") 2 | require File.join(File.dirname(__FILE__), "ruby_events/object_patch") 3 | -------------------------------------------------------------------------------- /doc/rdoc/created.rid: -------------------------------------------------------------------------------- 1 | Fri, 17 Jun 2011 23:47:39 +0100 2 | lib/ruby_events.rb Fri, 17 Jun 2011 23:07:23 +0100 3 | lib/ruby_events/core.rb Fri, 17 Jun 2011 23:35:59 +0100 4 | README.markdown Fri, 17 Jun 2011 23:40:05 +0100 5 | lib/ruby_events/object_patch.rb Fri, 17 Jun 2011 20:53:32 +0100 6 | -------------------------------------------------------------------------------- /lib/ruby_events/object_patch.rb: -------------------------------------------------------------------------------- 1 | # Extending the Object class with the events accessor. 2 | class Object 3 | attr_writer :events 4 | 5 | # Attribute reader for the events accessor. Returns a new instance of the 6 | # events class if not defined, or the already defined class otherwise. 7 | def events 8 | @events ||= RubyEvents::Events.new(self) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'rake' 3 | require 'rake/clean' 4 | require 'rdoc/task' 5 | require 'rspec/core/rake_task' 6 | 7 | RDoc::Task.new do |rdoc| 8 | files =['README.markdown', 'lib/**/*.rb'] 9 | rdoc.rdoc_files.add(files) 10 | rdoc.main = "README.markdown" # page to start on 11 | rdoc.title = "ruby_events Docs" 12 | rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder 13 | rdoc.options << '--line-numbers' 14 | end 15 | 16 | RSpec::Core::RakeTask.new(:spec) 17 | -------------------------------------------------------------------------------- /ruby_events.gemspec: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), 'lib/ruby_events') 2 | 3 | GEM_SPEC = Gem::Specification.new do |spec| 4 | spec.name = 'ruby_events' 5 | spec.version = RubyEvents::Events.version 6 | spec.extra_rdoc_files = ['README.markdown'] 7 | spec.summary = 'A really simple event implementation that hooks into the Object class by default, or can be used to extend modules and classes. Now all your objects can join in the fun of firing events!' 8 | spec.description = spec.summary + ' See http://github.com/nathankleyn/ruby_events for more information.' 9 | spec.author = 'Nathan Kleyn' 10 | spec.email = 'nathan@unfinitydesign.com' 11 | spec.homepage = 'http://github.com/nathankleyn/ruby_events' 12 | spec.files = %w(README.markdown Rakefile) + Dir.glob("{bin,lib,spec}/**/*") 13 | spec.require_path = "lib" 14 | spec.bindir = "bin" 15 | 16 | spec.add_development_dependency("rspec", "~>2.13.0") 17 | end 18 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## v 1.1.1 - ? 4 | 5 | * Fixed depedency for RSpec to be the right version. 6 | * Migrated tests to RSpec 7 | * Lots of significant updates to README. 8 | * Regenerated docs, will be moving these to the GitHub wiki with the next 9 | release. 10 | 11 | ## v 1.1.0 - 17th June, 2011 12 | 13 | * :fire_on_method now takes an array of Symbols to attach to, so you can define 14 | handlers for multiple methods, including their aliases. 15 | * Refactored into a split Module - this allows you to require ruby_events/core 16 | to get the library without extending Object by default. 17 | * Added proper .gemspec, and cleaned up Rakefile of all bogus tasks. 18 | * Added proper dependencies to the .gemspec. 19 | * Adding MIT license for those who were asking about license restrictions. 20 | 21 | *** 22 | 23 | ## v 1.0.2 - 6th September, 2011 24 | 25 | * Updating docs. 26 | 27 | *** 28 | 29 | ## v 1.0.1 - 6th September, 2011 30 | 31 | * Fix for Enumerable detection that was causing exceptions for some people. 32 | 33 | *** 34 | 35 | ## v 1.0.0 - 6th September, 2011 36 | 37 | * Added proper spec tests in place of the original crappy tests that didn't 38 | really help with anything. 39 | * Cleanup of Rakefile to get rid of warnings and errors. 40 | * Adding comments and regerating docs. 41 | -------------------------------------------------------------------------------- /doc/rdoc/lib/ruby_events_rb.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 |
7 | 8 | 9 |Extending the Object class with the events 48 | accessor.
49 | 50 |The RubyEvents module contains the core 48 | logic used by the events firing class. All Object’s are extended by 49 | default with an events accessor that is set to an instance of the RubyEvents::Events class. By 51 | calling the methods on this accessor, you can set up and listen to events 52 | or callbacks as fired by this class.
53 | 54 |This is the API documentation for 'ruby_events Docs'.
26 | 27 | 28 | 29 | 30 | 31 |Generated with the Darkfish 66 | Rdoc Generator 2.
67 |The RubyEvents module contains the core logic 108 | used by the events firing class. All Object’s are extended by default 109 | with an events accessor that is set to an instance of the RubyEvents::Events class. By calling the 111 | methods on this accessor, you can set up and listen to events or callbacks 112 | as fired by this class.
113 | 114 |Generated with the Darkfish 136 | Rdoc Generator 2.
137 |Extending the Object class with the events 116 | accessor.
117 | 118 |Attribute reader for the events accessor. Returns a new instance of the 174 | events class if not defined, or the already defined class otherwise.
175 | 176 | 177 | 178 |180 | # File lib/ruby_events/object_patch.rb, line 7 181 | def events 182 | @events ||= RubyEvents::Events.new(self) 183 | end184 |
Generated with the Darkfish 204 | Rdoc Generator 2.
205 |The Events class. Contains all the methods and 128 | functionality that drives the actual processes of adding, listening, 129 | calling and receiving events.
130 | 131 |Initialize the events class by instantiating the class methods we’ll be 163 | using.
164 | 165 | 166 | 167 |169 | # File lib/ruby_events/core.rb, line 17 170 | def initialize(parent) 171 | @parent, @events = parent, {} 172 | end173 |
The current version of RubyEvents.
197 | 198 | 199 | 200 |202 | # File lib/ruby_events/core.rb, line 11 203 | def self.version 204 | '1.1.0' 205 | end206 |
Fire all registered listeners to the passed event, passing them the 236 | arguments as provided.
237 | 238 | 239 | 240 |242 | # File lib/ruby_events/core.rb, line 37 243 | def fire(event_type, *arguments) 244 | @events[event_type].each do |event| 245 | event.call(*arguments) 246 | end if event_is_defined(event_type) 247 | end248 |
Set an event to fire when passed method is called. This is useful for 272 | adding callbacks or events to built-in methods.
273 | 274 | 275 | 276 |278 | # File lib/ruby_events/core.rb, line 45 279 | def fire_on_method(method, event_type, &block) 280 | if method.is_a? Array 281 | method.map { |sym| fire_on_method(sym, event_type, &block) } 282 | return 283 | end 284 | 285 | # We alias @parent to parent here, because class_eval can't see outside 286 | # this scope otherwise. 287 | parent, old_method = @parent, ('ruby_events_' + method.to_s + '_event_old').to_sym 288 | if parent && parent.respond_to?(method) 289 | parent.class.class_eval do 290 | # If the parent is already responding to the alias method, it means 291 | # the fire_on_method event was already triggered. Remove the other 292 | # event and continue if this happens. 293 | if parent.respond_to?(old_method, true) 294 | remove_method method 295 | alias_method method, old_method 296 | remove_method old_method 297 | end 298 | 299 | alias_method old_method, method 300 | private old_method 301 | 302 | # Make sure the self.send is at the end, or we won't return what we 303 | # are supposed to. 304 | define_method method do |*args| 305 | events.fire(event_type, *args) 306 | block.call(*args) if block # Calling the block we've been passed 307 | __send__(old_method, *args) 308 | end 309 | end 310 | else 311 | raise 'The given object does not respond to method you are trying to intercept calls to.' 312 | end 313 | end314 |
Add a listener to the passed event type. You can pass a Proc, an array of 338 | Proc’s, or a block.
339 | 340 | 341 | 342 |344 | # File lib/ruby_events/core.rb, line 23 345 | def listen(event_type, procs = nil, &block) 346 | @events[event_type] = [] unless event_is_defined(event_type) 347 | procs_collected = [] 348 | if procs.respond_to?(:each) && procs.respond_to?(:to_a) 349 | procs_collected += procs.to_a 350 | elsif procs 351 | procs_collected << procs 352 | end 353 | procs_collected << block if block 354 | @events[event_type] += procs_collected 355 | end356 |
Remove a method from the listening queue.
380 | 381 | 382 | 383 |385 | # File lib/ruby_events/core.rb, line 82 386 | def remove(event_type, event) 387 | @events[event_type].delete_if {|stored_event| stored_event == event} if event_is_defined(event_type) 388 | end389 |
Remove a fire on method alias event.
413 | 414 | 415 | 416 |418 | # File lib/ruby_events/core.rb, line 87 419 | def remove_fire_on_method(method) 420 | parent, old_method = @parent, ('ruby_events_' + method.to_s + '_event_old').to_sym 421 | parent.class.class_eval do 422 | if parent.respond_to?(old_method, true) 423 | remove_method method 424 | alias_method method, old_method 425 | public method 426 | else 427 | raise 'The fire on method trigger you were trying to remove does not exist.' 428 | end 429 | end 430 | end431 |
Generated with the Darkfish 451 | Rdoc Generator 2.
452 |