forked from plamoni/SiriProxy
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
85 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |