puppet-module 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.markdown +91 -0
- data/LICENSE +17 -0
- data/README.markdown +221 -0
- data/Rakefile +87 -0
- data/VERSION +1 -0
- data/bin/puppet-module +7 -0
- data/lib/puppet/module/tool.rb +124 -0
- data/lib/puppet/module/tool/applications.rb +18 -0
- data/lib/puppet/module/tool/applications/application.rb +83 -0
- data/lib/puppet/module/tool/applications/builder.rb +88 -0
- data/lib/puppet/module/tool/applications/checksummer.rb +38 -0
- data/lib/puppet/module/tool/applications/cleaner.rb +14 -0
- data/lib/puppet/module/tool/applications/freezer.rb +20 -0
- data/lib/puppet/module/tool/applications/generator.rb +117 -0
- data/lib/puppet/module/tool/applications/installer.rb +83 -0
- data/lib/puppet/module/tool/applications/registrar.rb +34 -0
- data/lib/puppet/module/tool/applications/releaser.rb +48 -0
- data/lib/puppet/module/tool/applications/searcher.rb +34 -0
- data/lib/puppet/module/tool/applications/unpacker.rb +69 -0
- data/lib/puppet/module/tool/applications/unreleaser.rb +42 -0
- data/lib/puppet/module/tool/cache.rb +56 -0
- data/lib/puppet/module/tool/checksums.rb +52 -0
- data/lib/puppet/module/tool/cli.rb +127 -0
- data/lib/puppet/module/tool/contents_description.rb +84 -0
- data/lib/puppet/module/tool/dependency.rb +26 -0
- data/lib/puppet/module/tool/metadata.rb +80 -0
- data/lib/puppet/module/tool/modulefile.rb +47 -0
- data/lib/puppet/module/tool/repository.rb +74 -0
- data/lib/puppet/module/tool/skeleton.rb +39 -0
- data/lib/puppet/module/tool/utils.rb +9 -0
- data/lib/puppet/module/tool/utils/interrogation.rb +39 -0
- data/lib/puppet/module/tool/utils/settings.rb +36 -0
- data/lib/puppet/module/tool/utils/uri.rb +16 -0
- data/spec/fixtures/releases/jamtur01-apache/Modulefile +2 -0
- data/spec/fixtures/releases/jamtur01-apache/files/httpd +24 -0
- data/spec/fixtures/releases/jamtur01-apache/files/test.vhost +18 -0
- data/spec/fixtures/releases/jamtur01-apache/lib/puppet/provider/a2mod/debian.rb +21 -0
- data/spec/fixtures/releases/jamtur01-apache/lib/puppet/type/a2mod.rb +12 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/dev.pp +5 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/init.pp +34 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/params.pp +17 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/php.pp +5 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/ssl.pp +15 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/vhost.pp +15 -0
- data/spec/fixtures/releases/jamtur01-apache/metadata.json +1 -0
- data/spec/fixtures/releases/jamtur01-apache/templates/vhost-default.conf.erb +20 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/apache.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/dev.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/init.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/php.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/ssl.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/vhost.pp +2 -0
- data/spec/integration/cli_spec.rb +373 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/output_support.rb +19 -0
- data/spec/support/stub_http_support.rb +14 -0
- data/spec/support/testdir_support.rb +26 -0
- data/spec/unit/application_spec.rb +25 -0
- data/spec/unit/repository_spec.rb +51 -0
- data/templates/generator/Modulefile.erb +5 -0
- data/templates/generator/README.erb +3 -0
- data/templates/generator/files/README.markdown +22 -0
- data/templates/generator/lib/puppet/facter/README.markdown +22 -0
- data/templates/generator/lib/puppet/parser/functions/README.markdown +17 -0
- data/templates/generator/lib/puppet/provider/README.markdown +14 -0
- data/templates/generator/lib/puppet/type/README.markdown +14 -0
- data/templates/generator/manifests/README.markdown +28 -0
- data/templates/generator/manifests/init.pp.erb +17 -0
- data/templates/generator/metadata.json +12 -0
- data/templates/generator/spec/README.markdown +7 -0
- data/templates/generator/spec/spec.opts +6 -0
- data/templates/generator/spec/spec_helper.rb +18 -0
- data/templates/generator/spec/unit/puppet/provider/README.markdown +4 -0
- data/templates/generator/spec/unit/puppet/type/README.markdown +4 -0
- data/templates/generator/templates/README.markdown +23 -0
- data/templates/generator/tests/init.pp.erb +1 -0
- data/vendor/facets-2.8.2-partial/lib/facets/kernel/returning.rb +23 -0
- data/vendor/facets-2.8.2-partial/lib/facets/kernel/tap.rb +39 -0
- data/vendor/multipart-post-1.0/Manifest.txt +9 -0
- data/vendor/multipart-post-1.0/README.txt +61 -0
- data/vendor/multipart-post-1.0/Rakefile +21 -0
- data/vendor/multipart-post-1.0/lib/composite_io.rb +89 -0
- data/vendor/multipart-post-1.0/lib/multipartable.rb +13 -0
- data/vendor/multipart-post-1.0/lib/net/http/post/multipart.rb +27 -0
- data/vendor/multipart-post-1.0/lib/parts.rb +66 -0
- data/vendor/multipart-post-1.0/test/net/http/post/test_multipart.rb +55 -0
- data/vendor/multipart-post-1.0/test/test_composite_io.rb +50 -0
- data/vendor/thor-852190ae/CHANGELOG.rdoc +89 -0
- data/vendor/thor-852190ae/LICENSE +20 -0
- data/vendor/thor-852190ae/README.rdoc +297 -0
- data/vendor/thor-852190ae/REVISION +1 -0
- data/vendor/thor-852190ae/Thorfile +69 -0
- data/vendor/thor-852190ae/bin/rake2thor +86 -0
- data/vendor/thor-852190ae/bin/thor +6 -0
- data/vendor/thor-852190ae/lib/thor.rb +244 -0
- data/vendor/thor-852190ae/lib/thor/actions.rb +275 -0
- data/vendor/thor-852190ae/lib/thor/actions/create_file.rb +103 -0
- data/vendor/thor-852190ae/lib/thor/actions/directory.rb +91 -0
- data/vendor/thor-852190ae/lib/thor/actions/empty_directory.rb +134 -0
- data/vendor/thor-852190ae/lib/thor/actions/file_manipulation.rb +223 -0
- data/vendor/thor-852190ae/lib/thor/actions/inject_into_file.rb +104 -0
- data/vendor/thor-852190ae/lib/thor/base.rb +540 -0
- data/vendor/thor-852190ae/lib/thor/core_ext/file_binary_read.rb +9 -0
- data/vendor/thor-852190ae/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
- data/vendor/thor-852190ae/lib/thor/core_ext/ordered_hash.rb +100 -0
- data/vendor/thor-852190ae/lib/thor/error.rb +30 -0
- data/vendor/thor-852190ae/lib/thor/group.rb +271 -0
- data/vendor/thor-852190ae/lib/thor/invocation.rb +180 -0
- data/vendor/thor-852190ae/lib/thor/parser.rb +4 -0
- data/vendor/thor-852190ae/lib/thor/parser/argument.rb +67 -0
- data/vendor/thor-852190ae/lib/thor/parser/arguments.rb +150 -0
- data/vendor/thor-852190ae/lib/thor/parser/option.rb +128 -0
- data/vendor/thor-852190ae/lib/thor/parser/options.rb +169 -0
- data/vendor/thor-852190ae/lib/thor/rake_compat.rb +66 -0
- data/vendor/thor-852190ae/lib/thor/runner.rb +314 -0
- data/vendor/thor-852190ae/lib/thor/shell.rb +83 -0
- data/vendor/thor-852190ae/lib/thor/shell/basic.rb +239 -0
- data/vendor/thor-852190ae/lib/thor/shell/color.rb +108 -0
- data/vendor/thor-852190ae/lib/thor/task.rb +102 -0
- data/vendor/thor-852190ae/lib/thor/util.rb +230 -0
- data/vendor/thor-852190ae/lib/thor/version.rb +3 -0
- data/vendor/thor-852190ae/spec/actions/create_file_spec.rb +170 -0
- data/vendor/thor-852190ae/spec/actions/directory_spec.rb +131 -0
- data/vendor/thor-852190ae/spec/actions/empty_directory_spec.rb +91 -0
- data/vendor/thor-852190ae/spec/actions/file_manipulation_spec.rb +271 -0
- data/vendor/thor-852190ae/spec/actions/inject_into_file_spec.rb +135 -0
- data/vendor/thor-852190ae/spec/actions_spec.rb +292 -0
- data/vendor/thor-852190ae/spec/base_spec.rb +263 -0
- data/vendor/thor-852190ae/spec/core_ext/hash_with_indifferent_access_spec.rb +43 -0
- data/vendor/thor-852190ae/spec/core_ext/ordered_hash_spec.rb +115 -0
- data/vendor/thor-852190ae/spec/fixtures/application.rb +2 -0
- data/vendor/thor-852190ae/spec/fixtures/bundle/execute.rb +6 -0
- data/vendor/thor-852190ae/spec/fixtures/bundle/main.thor +1 -0
- data/vendor/thor-852190ae/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/vendor/thor-852190ae/spec/fixtures/doc/README +3 -0
- data/vendor/thor-852190ae/spec/fixtures/doc/config.rb +1 -0
- data/vendor/thor-852190ae/spec/fixtures/group.thor +83 -0
- data/vendor/thor-852190ae/spec/fixtures/invoke.thor +112 -0
- data/vendor/thor-852190ae/spec/fixtures/script.thor +140 -0
- data/vendor/thor-852190ae/spec/fixtures/task.thor +10 -0
- data/vendor/thor-852190ae/spec/group_spec.rb +171 -0
- data/vendor/thor-852190ae/spec/invocation_spec.rb +107 -0
- data/vendor/thor-852190ae/spec/parser/argument_spec.rb +47 -0
- data/vendor/thor-852190ae/spec/parser/arguments_spec.rb +64 -0
- data/vendor/thor-852190ae/spec/parser/option_spec.rb +202 -0
- data/vendor/thor-852190ae/spec/parser/options_spec.rb +292 -0
- data/vendor/thor-852190ae/spec/rake_compat_spec.rb +68 -0
- data/vendor/thor-852190ae/spec/runner_spec.rb +202 -0
- data/vendor/thor-852190ae/spec/shell/basic_spec.rb +205 -0
- data/vendor/thor-852190ae/spec/shell/color_spec.rb +41 -0
- data/vendor/thor-852190ae/spec/shell_spec.rb +34 -0
- data/vendor/thor-852190ae/spec/spec.opts +1 -0
- data/vendor/thor-852190ae/spec/spec_helper.rb +54 -0
- data/vendor/thor-852190ae/spec/task_spec.rb +69 -0
- data/vendor/thor-852190ae/spec/thor_spec.rb +237 -0
- data/vendor/thor-852190ae/spec/util_spec.rb +167 -0
- data/vendor/thor-852190ae/thor.gemspec +120 -0
- metadata +229 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
= multipart-post
|
|
2
|
+
|
|
3
|
+
* http://github.com/nicksieger/multipart-post
|
|
4
|
+
|
|
5
|
+
== DESCRIPTION:
|
|
6
|
+
|
|
7
|
+
Adds a multipart form post capability to Net::HTTP.
|
|
8
|
+
|
|
9
|
+
== FEATURES/PROBLEMS:
|
|
10
|
+
|
|
11
|
+
* Appears to actually work. A good feature to have.
|
|
12
|
+
* Encapsulates posting of file/binary parts and name/value parameter parts, similar to
|
|
13
|
+
most browsers' file upload forms.
|
|
14
|
+
* Provides an UploadIO helper module to prepare IO objects for inclusion in the params
|
|
15
|
+
hash of the multipart post object.
|
|
16
|
+
|
|
17
|
+
== SYNOPSIS:
|
|
18
|
+
|
|
19
|
+
require 'net/http/post/multipart'
|
|
20
|
+
|
|
21
|
+
url = URI.parse('http://www.example.com/upload')
|
|
22
|
+
File.open("./image.jpg") do |jpg|
|
|
23
|
+
req = Net::HTTP::Post::Multipart.new url.path,
|
|
24
|
+
"file" => UploadIO.new(jpg, "image/jpeg", "image.jpg")
|
|
25
|
+
res = Net::HTTP.start(url.host, url.port) do |http|
|
|
26
|
+
http.request(req)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
== REQUIREMENTS:
|
|
31
|
+
|
|
32
|
+
None
|
|
33
|
+
|
|
34
|
+
== INSTALL:
|
|
35
|
+
|
|
36
|
+
gem install multipart-post
|
|
37
|
+
|
|
38
|
+
== LICENSE:
|
|
39
|
+
|
|
40
|
+
(The MIT License)
|
|
41
|
+
|
|
42
|
+
Copyright (c) 2007-2009 Nick Sieger <nick@nicksieger.com>
|
|
43
|
+
|
|
44
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
45
|
+
a copy of this software and associated documentation files (the
|
|
46
|
+
'Software'), to deal in the Software without restriction, including
|
|
47
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
48
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
49
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
50
|
+
the following conditions:
|
|
51
|
+
|
|
52
|
+
The above copyright notice and this permission notice shall be
|
|
53
|
+
included in all copies or substantial portions of the Software.
|
|
54
|
+
|
|
55
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
56
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
57
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
58
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
59
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
60
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
61
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'hoe'
|
|
4
|
+
|
|
5
|
+
require 'lib/multipart_post'
|
|
6
|
+
|
|
7
|
+
hoe = Hoe.new("multipart-post", MultipartPost::VERSION) do |p|
|
|
8
|
+
p.rubyforge_name = "caldersphere"
|
|
9
|
+
p.author = "Nick Sieger"
|
|
10
|
+
p.url = "http://github.com/nicksieger/multipart-post"
|
|
11
|
+
p.email = "nick@nicksieger.com"
|
|
12
|
+
p.description = "Use with Net::HTTP to do multipart form posts. IO values that have #content_type, #original_filename, and #local_path will be posted as a binary file."
|
|
13
|
+
p.summary = "Creates a multipart form post accessory for Net::HTTP."
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
task :gemspec do
|
|
17
|
+
File.open("#{hoe.name}.gemspec", "w") {|f| f << hoe.spec.to_ruby }
|
|
18
|
+
end
|
|
19
|
+
rescue LoadError
|
|
20
|
+
puts "You really need Hoe installed to be able to package this gem"
|
|
21
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# (c) Copyright 2007-2008 Nick Sieger.
|
|
3
|
+
# See the file README.txt included with the distribution for
|
|
4
|
+
# software license details.
|
|
5
|
+
#++
|
|
6
|
+
|
|
7
|
+
# Concatenate together multiple IO objects into a single, composite IO object
|
|
8
|
+
# for purposes of reading as a single stream.
|
|
9
|
+
#
|
|
10
|
+
# Usage:
|
|
11
|
+
#
|
|
12
|
+
# crio = CompositeReadIO.new(StringIO.new('one'), StringIO.new('two'), StringIO.new('three'))
|
|
13
|
+
# puts crio.read # => "onetwothree"
|
|
14
|
+
#
|
|
15
|
+
class CompositeReadIO
|
|
16
|
+
# Create a new composite-read IO from the arguments, all of which should
|
|
17
|
+
# respond to #read in a manner consistent with IO.
|
|
18
|
+
def initialize(*ios)
|
|
19
|
+
@ios = ios.flatten
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Read from the IO object, overlapping across underlying streams as necessary.
|
|
23
|
+
def read(amount = nil, buf = nil)
|
|
24
|
+
buffer = buf || ''
|
|
25
|
+
done = if amount; nil; else ''; end
|
|
26
|
+
partial_amount = amount
|
|
27
|
+
|
|
28
|
+
loop do
|
|
29
|
+
result = done
|
|
30
|
+
|
|
31
|
+
while !@ios.empty? && (result = @ios.first.read(partial_amount)) == done
|
|
32
|
+
@ios.shift
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
buffer << result if result
|
|
36
|
+
partial_amount -= result.length if partial_amount && result != done
|
|
37
|
+
|
|
38
|
+
break if partial_amount && partial_amount <= 0
|
|
39
|
+
break if result == done
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
if buffer.length > 0
|
|
43
|
+
buffer
|
|
44
|
+
else
|
|
45
|
+
done
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Convenience methods for dealing with files and IO that are to be uploaded.
|
|
51
|
+
module UploadIO
|
|
52
|
+
# Create an upload IO suitable for including in the params hash of a
|
|
53
|
+
# Net::HTTP::Post::Multipart.
|
|
54
|
+
#
|
|
55
|
+
# Can take two forms. The first accepts a filename and content type, and
|
|
56
|
+
# opens the file for reading (to be closed by finalizer). The second accepts
|
|
57
|
+
# an already-open IO, but also requires a third argument, the filename from
|
|
58
|
+
# which it was opened.
|
|
59
|
+
#
|
|
60
|
+
# UploadIO.new("file.txt", "text/plain")
|
|
61
|
+
# UploadIO.new(file_io, "text/plain", "file.txt")
|
|
62
|
+
def self.new(filename_or_io, content_type, filename = nil)
|
|
63
|
+
io = filename_or_io
|
|
64
|
+
unless io.respond_to? :read
|
|
65
|
+
io = File.open(filename_or_io)
|
|
66
|
+
filename = filename_or_io
|
|
67
|
+
end
|
|
68
|
+
convert!(io, content_type, File.basename(filename), filename)
|
|
69
|
+
io
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Enhance an existing IO for including in the params hash of a
|
|
73
|
+
# Net::HTTP::Post::Multipart by adding #content_type, #original_filename,
|
|
74
|
+
# and #local_path methods to the object's singleton class.
|
|
75
|
+
def self.convert!(io, content_type, original_filename, local_path)
|
|
76
|
+
io.instance_eval(<<-EOS, __FILE__, __LINE__)
|
|
77
|
+
def content_type
|
|
78
|
+
"#{content_type}"
|
|
79
|
+
end
|
|
80
|
+
def original_filename
|
|
81
|
+
"#{original_filename}"
|
|
82
|
+
end
|
|
83
|
+
def local_path
|
|
84
|
+
"#{local_path}"
|
|
85
|
+
end
|
|
86
|
+
EOS
|
|
87
|
+
io
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'parts'
|
|
2
|
+
module Multipartable
|
|
3
|
+
DEFAULT_BOUNDARY = "-----------RubyMultipartPost"
|
|
4
|
+
def initialize(path, params, headers={}, boundary = DEFAULT_BOUNDARY)
|
|
5
|
+
super(path, headers)
|
|
6
|
+
parts = params.map {|k,v| Parts::Part.new(boundary, k, v)}
|
|
7
|
+
parts << Parts::EpiloguePart.new(boundary)
|
|
8
|
+
ios = parts.map{|p| p.to_io }
|
|
9
|
+
self.set_content_type("multipart/form-data", { "boundary" => boundary })
|
|
10
|
+
self.content_length = parts.inject(0) {|sum,i| sum + i.length }
|
|
11
|
+
self.body_stream = CompositeReadIO.new(*ios)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# (c) Copyright 2007-2008 Nick Sieger.
|
|
3
|
+
# See the file README.txt included with the distribution for
|
|
4
|
+
# software license details.
|
|
5
|
+
#++
|
|
6
|
+
|
|
7
|
+
require 'net/http'
|
|
8
|
+
require 'stringio'
|
|
9
|
+
require 'cgi'
|
|
10
|
+
require 'composite_io'
|
|
11
|
+
require 'multipartable'
|
|
12
|
+
require 'parts'
|
|
13
|
+
|
|
14
|
+
module Net #:nodoc:
|
|
15
|
+
class HTTP #:nodoc:
|
|
16
|
+
class Put
|
|
17
|
+
class Multipart < Put
|
|
18
|
+
include Multipartable
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
class Post #:nodoc:
|
|
22
|
+
class Multipart < Post
|
|
23
|
+
include Multipartable
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module Parts
|
|
2
|
+
module Part #:nodoc:
|
|
3
|
+
def self.new(boundary, name, value)
|
|
4
|
+
if value.respond_to? :content_type
|
|
5
|
+
FilePart.new(boundary, name, value)
|
|
6
|
+
else
|
|
7
|
+
ParamPart.new(boundary, name, value)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def length
|
|
12
|
+
@part.length
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_io
|
|
16
|
+
@io
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class ParamPart
|
|
21
|
+
include Part
|
|
22
|
+
def initialize(boundary, name, value)
|
|
23
|
+
@part = build_part(boundary, name, value)
|
|
24
|
+
@io = StringIO.new(@part)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def build_part(boundary, name, value)
|
|
28
|
+
part = ''
|
|
29
|
+
part << "--#{boundary}\r\n"
|
|
30
|
+
part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\r\n"
|
|
31
|
+
part << "\r\n"
|
|
32
|
+
part << "#{value}\r\n"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Represents a part to be filled from file IO.
|
|
37
|
+
class FilePart
|
|
38
|
+
include Part
|
|
39
|
+
attr_reader :length
|
|
40
|
+
def initialize(boundary, name, io)
|
|
41
|
+
file_length = io.respond_to?(:length) ? io.length : File.size(io.local_path)
|
|
42
|
+
@head = build_head(boundary, name, io.original_filename, io.content_type, file_length)
|
|
43
|
+
@length = @head.length + file_length
|
|
44
|
+
@io = CompositeReadIO.new(StringIO.new(@head), io, StringIO.new("\r\n"))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def build_head(boundary, name, filename, type, content_len)
|
|
48
|
+
part = ''
|
|
49
|
+
part << "--#{boundary}\r\n"
|
|
50
|
+
part << "Content-Disposition: form-data; name=\"#{name.to_s}\"; filename=\"#{filename}\"\r\n"
|
|
51
|
+
part << "Content-Length: #{content_len}\r\n"
|
|
52
|
+
part << "Content-Type: #{type}\r\n"
|
|
53
|
+
part << "Content-Transfer-Encoding: binary\r\n"
|
|
54
|
+
part << "\r\n"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Represents the epilogue or closing boundary.
|
|
59
|
+
class EpiloguePart
|
|
60
|
+
include Part
|
|
61
|
+
def initialize(boundary)
|
|
62
|
+
@part = "--#{boundary}--\r\n"
|
|
63
|
+
@io = StringIO.new(@part)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# (c) Copyright 2007-2008 Nick Sieger.
|
|
3
|
+
# See the file README.txt included with the distribution for
|
|
4
|
+
# software license details.
|
|
5
|
+
#++
|
|
6
|
+
|
|
7
|
+
require 'net/http/post/multipart'
|
|
8
|
+
|
|
9
|
+
class Net::HTTP::Post::MultiPartTest < Test::Unit::TestCase
|
|
10
|
+
TEMP_FILE = "temp.txt"
|
|
11
|
+
|
|
12
|
+
HTTPPost = Struct.new("HTTPPost", :content_length, :body_stream, :content_type)
|
|
13
|
+
HTTPPost.module_eval do
|
|
14
|
+
def set_content_type(type, params = {})
|
|
15
|
+
self.content_type = type + params.map{|k,v|"; #{k}=#{v}"}.join('')
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def teardown
|
|
20
|
+
File.delete(TEMP_FILE) rescue nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_form_multipart_body
|
|
24
|
+
File.open(TEMP_FILE, "w") {|f| f << "1234567890"}
|
|
25
|
+
@io = File.open(TEMP_FILE)
|
|
26
|
+
UploadIO.convert! @io, "text/plain", TEMP_FILE, TEMP_FILE
|
|
27
|
+
assert_results Net::HTTP::Post::Multipart.new("/foo/bar", :foo => 'bar', :file => @io)
|
|
28
|
+
end
|
|
29
|
+
def test_form_multipart_body_put
|
|
30
|
+
File.open(TEMP_FILE, "w") {|f| f << "1234567890"}
|
|
31
|
+
@io = File.open(TEMP_FILE)
|
|
32
|
+
UploadIO.convert! @io, "text/plain", TEMP_FILE, TEMP_FILE
|
|
33
|
+
assert_results Net::HTTP::Put::Multipart.new("/foo/bar", :foo => 'bar', :file => @io)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_form_multipart_body_with_stringio
|
|
37
|
+
@io = StringIO.new("1234567890")
|
|
38
|
+
UploadIO.convert! @io, "text/plain", TEMP_FILE, TEMP_FILE
|
|
39
|
+
assert_results Net::HTTP::Post::Multipart.new("/foo/bar", :foo => 'bar', :file => @io)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def assert_results(post)
|
|
43
|
+
assert post.content_length && post.content_length > 0
|
|
44
|
+
assert post.body_stream
|
|
45
|
+
assert_equal "multipart/form-data; boundary=#{Multipartable::DEFAULT_BOUNDARY}", post['content-type']
|
|
46
|
+
body = post.body_stream.read
|
|
47
|
+
boundary_regex = Regexp.quote Multipartable::DEFAULT_BOUNDARY
|
|
48
|
+
assert body =~ /1234567890/
|
|
49
|
+
# ensure there is at least one boundary
|
|
50
|
+
assert body =~ /^--#{boundary_regex}\r\n/
|
|
51
|
+
# ensure there is an epilogue
|
|
52
|
+
assert body =~ /^--#{boundary_regex}--\r\n/
|
|
53
|
+
assert body =~ /text\/plain/
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'composite_io'
|
|
2
|
+
require 'stringio'
|
|
3
|
+
require 'test/unit'
|
|
4
|
+
|
|
5
|
+
class CompositeReadIOTest < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
@io = CompositeReadIO.new(CompositeReadIO.new(StringIO.new('the '), StringIO.new('quick ')),
|
|
8
|
+
StringIO.new('brown '), StringIO.new('fox'))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_full_read_from_several_ios
|
|
12
|
+
assert_equal 'the quick brown fox', @io.read
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_partial_read
|
|
16
|
+
assert_equal 'the quick', @io.read(9)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_partial_read_to_boundary
|
|
20
|
+
assert_equal 'the quick ', @io.read(10)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_read_with_size_larger_than_available
|
|
24
|
+
assert_equal 'the quick brown fox', @io.read(32)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_read_into_buffer
|
|
28
|
+
buf = ''
|
|
29
|
+
@io.read(nil, buf)
|
|
30
|
+
assert_equal 'the quick brown fox', buf
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_multiple_reads
|
|
34
|
+
assert_equal 'the ', @io.read(4)
|
|
35
|
+
assert_equal 'quic', @io.read(4)
|
|
36
|
+
assert_equal 'k br', @io.read(4)
|
|
37
|
+
assert_equal 'own ', @io.read(4)
|
|
38
|
+
assert_equal 'fox', @io.read(4)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_read_after_end
|
|
42
|
+
@io.read
|
|
43
|
+
assert_equal "", @io.read
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_read_after_end_with_amount
|
|
47
|
+
@io.read(32)
|
|
48
|
+
assert_equal nil, @io.read(32)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
== 0.13, released 2010-02-03
|
|
2
|
+
|
|
3
|
+
* Several bug fixes
|
|
4
|
+
* Decoupled Thor::Group and Thor, so it's easier to vendor
|
|
5
|
+
* Added check_unknown_options! in case you want error messages to be raised in valid switches.
|
|
6
|
+
* run(command) should return the results of command
|
|
7
|
+
|
|
8
|
+
== 0.12, released 2010-01-02
|
|
9
|
+
|
|
10
|
+
* Methods generated by attr_* are automatically not marked as tasks
|
|
11
|
+
* inject_into_file does not add the same content twice, unless :force is set
|
|
12
|
+
* Removed rr in favor to rspec mock framework
|
|
13
|
+
* Improved output for thor -T
|
|
14
|
+
* [#7] Do not force white color on status
|
|
15
|
+
* [#8] Yield a block with the filename on directory
|
|
16
|
+
|
|
17
|
+
== 0.11, released 2009-07-01
|
|
18
|
+
|
|
19
|
+
* Added a rake compatibility layer. It allows you to use spec and rdoc tasks on
|
|
20
|
+
Thor classes.
|
|
21
|
+
|
|
22
|
+
* BACKWARDS INCOMPATIBLE: aliases are not generated automatically anymore
|
|
23
|
+
since it wrong behavior to the invocation system.
|
|
24
|
+
|
|
25
|
+
* thor help now show information about any class/task. All those calls are
|
|
26
|
+
possible:
|
|
27
|
+
|
|
28
|
+
thor help describe
|
|
29
|
+
thor help describe:amazing
|
|
30
|
+
|
|
31
|
+
Or even with default namespaces:
|
|
32
|
+
|
|
33
|
+
thor help :spec
|
|
34
|
+
|
|
35
|
+
* Thor::Runner now invokes the default task if none is supplied:
|
|
36
|
+
|
|
37
|
+
thor describe # invokes the default task, usually help
|
|
38
|
+
|
|
39
|
+
* Thor::Runner now works with mappings:
|
|
40
|
+
|
|
41
|
+
thor describe -h
|
|
42
|
+
|
|
43
|
+
* Added some documentation and code refactoring.
|
|
44
|
+
|
|
45
|
+
== 0.9.8, released 2008-10-20
|
|
46
|
+
|
|
47
|
+
* Fixed some tiny issues that were introduced lately.
|
|
48
|
+
|
|
49
|
+
== 0.9.7, released 2008-10-13
|
|
50
|
+
|
|
51
|
+
* Setting global method options on the initialize method works as expected:
|
|
52
|
+
All other tasks will accept these global options in addition to their own.
|
|
53
|
+
* Added 'group' notion to Thor task sets (class Thor); by default all tasks
|
|
54
|
+
are in the 'standard' group. Running 'thor -T' will only show the standard
|
|
55
|
+
tasks - adding --all will show all tasks. You can also filter on a specific
|
|
56
|
+
group using the --group option: thor -T --group advanced
|
|
57
|
+
|
|
58
|
+
== 0.9.6, released 2008-09-13
|
|
59
|
+
|
|
60
|
+
* Generic improvements
|
|
61
|
+
|
|
62
|
+
== 0.9.5, released 2008-08-27
|
|
63
|
+
|
|
64
|
+
* Improve Windows compatibility
|
|
65
|
+
* Update (incorrect) README and task.thor sample file
|
|
66
|
+
* Options hash is now frozen (once returned)
|
|
67
|
+
* Allow magic predicates on options object. For instance: `options.force?`
|
|
68
|
+
* Add support for :numeric type
|
|
69
|
+
* BACKWARDS INCOMPATIBLE: Refactor Thor::Options. You cannot access shorthand forms in options hash anymore (for instance, options[:f])
|
|
70
|
+
* Allow specifying optional args with default values: method_options(:user => "mislav")
|
|
71
|
+
* Don't write options for nil or false values. This allows, for example, turning color off when running specs.
|
|
72
|
+
* Exit with the status of the spec command to help CI stuff out some.
|
|
73
|
+
|
|
74
|
+
== 0.9.4, released 2008-08-13
|
|
75
|
+
|
|
76
|
+
* Try to add Windows compatibility.
|
|
77
|
+
* BACKWARDS INCOMPATIBLE: options hash is now accessed as a property in your class and is not passed as last argument anymore
|
|
78
|
+
* Allow options at the beginning of the argument list as well as the end.
|
|
79
|
+
* Make options available with symbol keys in addition to string keys.
|
|
80
|
+
* Allow true to be passed to Thor#method_options to denote a boolean option.
|
|
81
|
+
* If loading a thor file fails, don't give up, just print a warning and keep going.
|
|
82
|
+
* Make sure that we re-raise errors if they happened further down the pipe than we care about.
|
|
83
|
+
* Only delete the old file on updating when the installation of the new one is a success
|
|
84
|
+
* Make it Ruby 1.8.5 compatible.
|
|
85
|
+
* Don't raise an error if a boolean switch is defined multiple times.
|
|
86
|
+
* Thor::Options now doesn't parse through things that look like options but aren't.
|
|
87
|
+
* Add URI detection to install task, and make sure we don't append ".thor" to URIs
|
|
88
|
+
* Add rake2thor to the gem binfiles.
|
|
89
|
+
* Make sure local Thorfiles override system-wide ones.
|