Permalink
Browse files

Added initialize method that takes a config so plugins that don't def…

…ine it won't break

Conflicts:

	lib/siriproxy/plugin.rb
  • Loading branch information...
1 parent 2285a4e commit 5ee281c3ff92c38f88e0713fb526ec019af1ff43 @chendo chendo committed Dec 8, 2011
Showing with 85 additions and 15 deletions.
  1. +19 −15 lib/siriproxy/plugin.rb
  2. +66 −0 lib/siriproxy/plugin.rb.orig
View
@@ -1,37 +1,41 @@
require 'cora'
class SiriProxy::Plugin < Cora::Plugin
+ def initialize(config)
+
+ end
+
def request_completed
self.manager.send_request_complete_to_iphone
end
-
+
#use send_object(object, target: :guzzoni) to send to guzzoni
def send_object(object, options={})
(object = object.to_hash) rescue nil #convert SiriObjects to a hash
options[:target] = options[:target] ||= :iphone
-
+
if(options[:target] == :iphone)
self.manager.guzzoni_conn.inject_object_to_output_stream(object)
- elsif(options[:target] == :guzzoni)
- self.manager.iphone_conn.inject_object_to_output_stream(object)
- end
+ elsif(options[:target] == :guzzoni)
+ self.manager.iphone_conn.inject_object_to_output_stream(object)
+ end
end
-
+
def last_ref_id
self.manager.iphone_conn.last_ref_id
end
-
+
#direction should be :from_iphone, or :from_guzzoni
def process_filters(object, direction)
return nil if object == nil
f = filters[object["class"]]
- if(f != nil && (f[:direction] == :both || f[:direction] == direction))
+ if(f != nil && (f[:direction] == :both || f[:direction] == direction))
object = instance_exec(object, &f[:block])
end
-
+
object
end
-
+
class << self
def filter(class_names, options={}, &block)
[class_names].flatten.each do |class_name|
@@ -41,14 +45,14 @@ def filter(class_names, options={}, &block)
}
end
end
-
+
def filters
@filters ||= {}
end
- end
-
+ end
+
def filters
self.class.filters
end
-
-end
+
+end
@@ -0,0 +1,66 @@
+require 'cora'
+
+class SiriProxy::Plugin < Cora::Plugin
+ def initialize(config)
+
+ end
+
+ def request_completed
+ self.manager.send_request_complete_to_iphone
+ end
+
+ #use send_object(object, target: :guzzoni) to send to guzzoni
+ def send_object(object, options={})
+ (object = object.to_hash) rescue nil #convert SiriObjects to a hash
+<<<<<<< HEAD
+ options[:target] = options[:target] ||= :iphone
+
+=======
+
+>>>>>>> fd2b325... Added initialize method that takes a config so plugins that don't define it won't break
+ if(options[:target] == :iphone)
+ self.manager.guzzoni_conn.inject_object_to_output_stream(object)
+ elsif(options[:target] == :guzzoni)
+ self.manager.iphone_conn.inject_object_to_output_stream(object)
+ end
+ end
+
+ def last_ref_id
+ self.manager.iphone_conn.last_ref_id
+ end
+<<<<<<< HEAD
+
+ #direction should be :from_iphone, or :from_guzzoni
+ def process_filters(object, direction)
+ return nil if object == nil
+ f = filters[object["class"]]
+ if(f != nil && (f[:direction] == :both || f[:direction] == direction))
+ object = instance_exec(object, &f[:block])
+ end
+
+ object
+ end
+
+ class << self
+ def filter(class_names, options={}, &block)
+ [class_names].flatten.each do |class_name|
+ filters[class_name] = {
+ direction: (options[:direction] ||= :both),
+ block: block
+ }
+ end
+ end
+
+ def filters
+ @filters ||= {}
+ end
+ end
+
+ def filters
+ self.class.filters
+ end
+
+end
+=======
+end
+>>>>>>> fd2b325... Added initialize method that takes a config so plugins that don't define it won't break

0 comments on commit 5ee281c

Please sign in to comment.