Browse files

Make Format a class, so we can store instance variables etc

  • Loading branch information...
1 parent 1776896 commit de0e33d53c5e31b832b6464c241795bda6be4c9f @maccman committed Apr 20, 2010
View
1 .gitignore
@@ -1 +1,2 @@
pkg
+*.gem
View
2 lib/nestful/connection.rb
@@ -25,7 +25,7 @@ def requests
# The +site+ parameter is required and will set the +site+
# attribute to the URI for the remote resource service.
- def initialize(site, format = ActiveResource::Formats::XmlFormat)
+ def initialize(site, format = Formats::XmlFormat.new)
raise ArgumentError, 'Missing site URI' unless site
@user = @password = nil
@uri_parser = URI.const_defined?(:Parser) ? URI::Parser.new : URI
View
14 lib/nestful/formats.rb
@@ -1,5 +1,19 @@
module Nestful
module Formats
+ class Format
+ def extension
+ end
+
+ def mime_type
+ end
+
+ def encode(*args)
+ end
+
+ def decode(*args)
+ end
+ end
+
autoload :BlankFormat, 'nestful/formats/blank_format'
autoload :MultipartFormat, 'nestful/formats/multipart_format'
autoload :FormFormat, 'nestful/formats/form_format'
View
10 lib/nestful/formats/blank_format.rb
@@ -1,14 +1,6 @@
module Nestful
module Formats
- module BlankFormat
- extend self
-
- def extension
- end
-
- def mime_type
- end
-
+ class BlankFormat < Format
def encode(params, options = nil)
raise "Choose an encoding format, such as :form"
end
View
7 lib/nestful/formats/form_format.rb
@@ -1,11 +1,6 @@
module Nestful
module Formats
- module FormFormat
- extend self
-
- def extension
- end
-
+ class FormFormat < Format
def mime_type
"application/x-www-form-urlencoded"
end
View
4 lib/nestful/formats/json_format.rb
@@ -3,9 +3,7 @@
module Nestful
module Formats
- module JsonFormat
- extend self
-
+ class JsonFormat < Format
def extension
"json"
end
View
6 lib/nestful/formats/multipart_format.rb
@@ -2,13 +2,9 @@
module Nestful
module Formats
- module MultipartFormat
- extend self
+ class MultipartFormat < Format
EOL = "\r\n"
- def extension
- end
-
def mime_type
%Q{multipart/form-data; boundary=#{boundary}}
end
View
4 lib/nestful/formats/xml_format.rb
@@ -2,9 +2,7 @@
module Nestful
module Formats
- module XmlFormat
- extend self
-
+ class XmlFormat < Format
def extension
"xml"
end
View
2 lib/nestful/request.rb
@@ -28,7 +28,7 @@ def initialize(url, options = {})
def format=(mime_or_format)
@format = mime_or_format.is_a?(Symbol) ?
- Formats[mime_or_format] : mime_or_format
+ Formats[mime_or_format].new : mime_or_format
end
def connection

0 comments on commit de0e33d

Please sign in to comment.