Permalink
Browse files

Changes to the event object

  • Loading branch information...
1 parent 65eb764 commit c3fece723c04f7bed83dbe9a0adc22070d6b8f99 @karmajunkie committed Jan 17, 2012
Showing with 25 additions and 8 deletions.
  1. +12 −8 lib/replay/event.rb
  2. +13 −0 test/unit/event_spec.rb
View
@@ -1,23 +1,27 @@
module Replay
class Event
- attr_accessor :event_type, :data
+ attr_accessor :event_type, :attributes
- def initialize(event_type, data = {})
- self.event_type = event_type
- self.data = data
+ def initialize(event_type, *data)
+ @event_type = event_type
+ if data.first.kind_of? Hash
+ @attributes = HashWithIndifferentAccess.new data.first.dup
+ else
+ @attributes = HashWithIndifferentAccess.new({data.first => data.last})
+ end
end
def method_missing(method, *args)
method_root = method.to_s.gsub(/=$/, "")
- if data && data.has_key?(method_root)
+ if @attributes && @attributes.has_key?(method_root)
if method.to_s[/=$/]
- self.data[method_root] = args.first
+ @attributes[method_root] = args.first
else
- self.data[method]
+ @attributes[method]
end
else
nil
end
end
end
-end
+end
View
@@ -0,0 +1,13 @@
+require './test/spec_helper'
+
+describe Replay::Event do
+ before do
+ @event = Replay::Event.new("shit_happened", :foo => :bar)
+ end
+
+ describe "method_missing" do
+ it "fakes the reader" do
+ @event.foo.must_equal :bar
+ end
+ end
+end

0 comments on commit c3fece7

Please sign in to comment.