1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionservice/lib/action_service/protocol/registry.rb
David Heinemeier Hansson e7a2938029 Added Action Service to the repository
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@658 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2005-02-18 10:35:25 +00:00

55 lines
1.9 KiB
Ruby

module ActionService # :nodoc:
module Protocol # :nodoc:
HeaderAndBody = :header_and_body
BodyOnly = :body_only
module Registry # :nodoc:
def self.append_features(base) # :nodoc:
super
base.extend(ClassMethods)
base.send(:include, ActionService::Protocol::Registry::InstanceMethods)
end
module ClassMethods # :nodoc:
def register_protocol(type, klass) # :nodoc:
case type
when HeaderAndBody
write_inheritable_array("header_and_body_protocols", [klass])
when BodyOnly
write_inheritable_array("body_only_protocols", [klass])
else
raise(ProtocolError, "unknown protocol type #{type}")
end
end
end
module InstanceMethods # :nodoc:
private
def probe_request_protocol(action_pack_request)
(header_and_body_protocols + body_only_protocols).each do |protocol|
protocol_request = protocol.create_protocol_request(self.class, action_pack_request)
return protocol_request if protocol_request
end
raise(ProtocolError, "unsupported request message format")
end
def probe_protocol_client(api, protocol_name, endpoint_uri, options)
(header_and_body_protocols + body_only_protocols).each do |protocol|
protocol_client = protocol.create_protocol_client(api, protocol_name, endpoint_uri, options)
return protocol_client if protocol_client
end
raise(ProtocolError, "unsupported client protocol :#{protocol_name}")
end
def header_and_body_protocols
self.class.read_inheritable_attribute("header_and_body_protocols") || []
end
def body_only_protocols
self.class.read_inheritable_attribute("body_only_protocols") || []
end
end
end
end
end