sauberia-aws-s3 0.6.2.1254423624

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/CHANGELOG +107 -0
  2. data/COPYING +19 -0
  3. data/INSTALL +55 -0
  4. data/README.erb +58 -0
  5. data/Rakefile +334 -0
  6. data/TODO +26 -0
  7. data/aws-s3.gemspec +42 -0
  8. data/bin/s3sh +6 -0
  9. data/bin/setup.rb +10 -0
  10. data/lib/aws/s3.rb +60 -0
  11. data/lib/aws/s3/acl.rb +636 -0
  12. data/lib/aws/s3/authentication.rb +222 -0
  13. data/lib/aws/s3/base.rb +270 -0
  14. data/lib/aws/s3/bittorrent.rb +58 -0
  15. data/lib/aws/s3/bucket.rb +372 -0
  16. data/lib/aws/s3/connection.rb +288 -0
  17. data/lib/aws/s3/error.rb +69 -0
  18. data/lib/aws/s3/exceptions.rb +133 -0
  19. data/lib/aws/s3/extensions.rb +342 -0
  20. data/lib/aws/s3/logging.rb +317 -0
  21. data/lib/aws/s3/object.rb +626 -0
  22. data/lib/aws/s3/owner.rb +46 -0
  23. data/lib/aws/s3/parsing.rb +99 -0
  24. data/lib/aws/s3/response.rb +180 -0
  25. data/lib/aws/s3/service.rb +51 -0
  26. data/lib/aws/s3/version.rb +12 -0
  27. data/site/index.erb +41 -0
  28. data/site/public/images/box-and-gem.gif +0 -0
  29. data/site/public/images/favicon.ico +0 -0
  30. data/site/public/ruby.css +18 -0
  31. data/site/public/screen.css +99 -0
  32. data/support/faster-xml-simple/COPYING +18 -0
  33. data/support/faster-xml-simple/README +8 -0
  34. data/support/faster-xml-simple/Rakefile +54 -0
  35. data/support/faster-xml-simple/lib/faster_xml_simple.rb +190 -0
  36. data/support/faster-xml-simple/test/fixtures/test-1.rails.yml +4 -0
  37. data/support/faster-xml-simple/test/fixtures/test-1.xml +3 -0
  38. data/support/faster-xml-simple/test/fixtures/test-1.yml +4 -0
  39. data/support/faster-xml-simple/test/fixtures/test-2.rails.yml +6 -0
  40. data/support/faster-xml-simple/test/fixtures/test-2.xml +3 -0
  41. data/support/faster-xml-simple/test/fixtures/test-2.yml +6 -0
  42. data/support/faster-xml-simple/test/fixtures/test-3.rails.yml +6 -0
  43. data/support/faster-xml-simple/test/fixtures/test-3.xml +5 -0
  44. data/support/faster-xml-simple/test/fixtures/test-3.yml +6 -0
  45. data/support/faster-xml-simple/test/fixtures/test-4.rails.yml +5 -0
  46. data/support/faster-xml-simple/test/fixtures/test-4.xml +7 -0
  47. data/support/faster-xml-simple/test/fixtures/test-4.yml +5 -0
  48. data/support/faster-xml-simple/test/fixtures/test-5.rails.yml +8 -0
  49. data/support/faster-xml-simple/test/fixtures/test-5.xml +7 -0
  50. data/support/faster-xml-simple/test/fixtures/test-5.yml +8 -0
  51. data/support/faster-xml-simple/test/fixtures/test-6.rails.yml +43 -0
  52. data/support/faster-xml-simple/test/fixtures/test-6.xml +29 -0
  53. data/support/faster-xml-simple/test/fixtures/test-6.yml +41 -0
  54. data/support/faster-xml-simple/test/fixtures/test-7.rails.yml +23 -0
  55. data/support/faster-xml-simple/test/fixtures/test-7.xml +22 -0
  56. data/support/faster-xml-simple/test/fixtures/test-7.yml +22 -0
  57. data/support/faster-xml-simple/test/fixtures/test-8.rails.yml +14 -0
  58. data/support/faster-xml-simple/test/fixtures/test-8.xml +8 -0
  59. data/support/faster-xml-simple/test/fixtures/test-8.yml +11 -0
  60. data/support/faster-xml-simple/test/regression_test.rb +47 -0
  61. data/support/faster-xml-simple/test/test_helper.rb +17 -0
  62. data/support/faster-xml-simple/test/xml_simple_comparison_test.rb +46 -0
  63. data/support/rdoc/code_info.rb +211 -0
  64. data/test/acl_test.rb +254 -0
  65. data/test/authentication_test.rb +118 -0
  66. data/test/base_test.rb +136 -0
  67. data/test/bucket_test.rb +74 -0
  68. data/test/connection_test.rb +216 -0
  69. data/test/error_test.rb +70 -0
  70. data/test/extensions_test.rb +340 -0
  71. data/test/fixtures.rb +89 -0
  72. data/test/fixtures/buckets.yml +133 -0
  73. data/test/fixtures/errors.yml +34 -0
  74. data/test/fixtures/headers.yml +3 -0
  75. data/test/fixtures/logging.yml +15 -0
  76. data/test/fixtures/loglines.yml +5 -0
  77. data/test/fixtures/logs.yml +7 -0
  78. data/test/fixtures/policies.yml +16 -0
  79. data/test/logging_test.rb +89 -0
  80. data/test/mocks/fake_response.rb +26 -0
  81. data/test/object_test.rb +205 -0
  82. data/test/parsing_test.rb +66 -0
  83. data/test/remote/acl_test.rb +116 -0
  84. data/test/remote/bittorrent_test.rb +45 -0
  85. data/test/remote/bucket_test.rb +146 -0
  86. data/test/remote/logging_test.rb +82 -0
  87. data/test/remote/object_test.rb +379 -0
  88. data/test/remote/test_file.data +0 -0
  89. data/test/remote/test_helper.rb +33 -0
  90. data/test/response_test.rb +68 -0
  91. data/test/service_test.rb +23 -0
  92. data/test/test_helper.rb +118 -0
  93. metadata +221 -0
@@ -0,0 +1,107 @@
1
+ head:
2
+
3
+ - Fix that S3Object.stream raises NoSuchKey exception when trying to stream an object that doesn't exist.
4
+
5
+ 0.6.2:
6
+
7
+ - Apparently need to use custom __method__ in Ruby versions right up to 1.8.7.
8
+
9
+ 0.6.1:
10
+
11
+ - Use custom __method__ in Ruby versions *prior* to 1.8.7 not *up to* 1.8.7.
12
+
13
+ - Rename Kernel#memoize to Kernel#expirable_memoize so that it doesn't conflict with memoize method in ActiveSupport which has an entirely different API and semantics. Reported by [Florian Dütsc (mail@florian-duetsch.de)].
14
+
15
+ 0.6.0:
16
+
17
+ - Full 1.9 compatibility (all tests passing against 1.9 & 1.8.6). Thanks to [David (dvdplm@gmail.com), Cyril David (cyx.ucron@gmail.com)]
18
+
19
+ 0.5.1:
20
+
21
+ - For now just redefine __method__ to take arguments so we don't break 1.8.7 use today
22
+
23
+ 0.5.0:
24
+
25
+ - Bug #17458 fixed. Normalize the :expires_in option to always be an integer even if the actual object passed in is a proxy to an integer, such as is the case with 2.hours from ActiveSupport which is actually an instance of ActiveSupport::Duration. Reported by [Steve Kickert steve@riverocktech.com]
26
+
27
+ - Bug #19158 fixed. Don't prepend leading slash onto bucket name when deleting a bucket with the :force => true option.
28
+
29
+ - Bug #17628 fixed. Don't ignore :use_ssl => false in url_for when the connection is established over ssl. Reported by [Tom Fixed (tkat11)]
30
+
31
+ - Bug #13052 fixed. Appease some proxies by always including a Content-Length with all requests. Reported by [James Murty (jmurty)]
32
+
33
+ - Bug #13756 fixed. Attributes that are false should not raise NoMethodError in Base#method_missing. Fixed by [Scott Patten]
34
+
35
+ - Bug #19189 fixed. No longer reference Date::ABBR_MONTHS constant which was removed in Ruby 1.8.6. Reported by [Khurram Virani (kvirani)]
36
+
37
+ - Bug #20487 fixed. If a request fails and is retried, only escape the request path the first time. Reported by [anonymous]
38
+
39
+ - Replace ad-hoc S3Object.copy method with newly support built in API call.
40
+
41
+ - Do not make connections persistent by default. This "feature" causes far more broken pipes than it is worth. Use with caution.
42
+
43
+ 0.4.0:
44
+
45
+ - Various adjustments to connection handling to try to mitigate exceptions raised from deep within Net::HTTP.
46
+
47
+ - Don't coerce numbers that start with a zero because the zero will be lost. If a bucket, for example, has a name like '0815', all operation it will fail. Closes ticket #10089 [reported anonymously]"
48
+
49
+ - Add ability to connect through a proxy using the :proxy option when establishing a connection. Suggested by [Simon Horne <simon@soulware.co.uk>]
50
+
51
+ - Add :authenticated option to url_for. When passing false, don't generate signature parameters for query string.
52
+
53
+ - Make url_for accept custom port settings. [Rich Olson]
54
+
55
+ 0.3.0:
56
+
57
+ - Ensure content type is eventually set to account for changes made to Net::HTTP in Ruby version 1.8.5. Reported by [David Hanson, Stephen Caudill, Tom Mornini <tmornini@engineyard.com>]
58
+
59
+ - Add :persistent option to connections which keeps a persistent connection rather than creating a new one per request, defaulting to true. Based on a patch by [Metalhead <metalhead@metalhead.ws>]
60
+
61
+ - If we are retrying a request after rescuing one of the retry exceptions, rewind the body if its an IO stream so it starts at the beginning. [Jamis Buck]
62
+
63
+ - Ensure that all paths being submitted to S3 are valid utf8. If they are not, we remove the extended characters. Ample help from [Jamis Buck]
64
+
65
+ - Wrap logs in Log objects which exposes each line as a Log::Line that has accessors by name for each field.
66
+
67
+ - Various performance optimizations for the extensions code. [Roman LE NEGRATE <roman2k@free.fr>]
68
+
69
+ - Make S3Object.copy more efficient by streaming in both directions in parallel.
70
+
71
+ - Open up Net:HTTPGenericRequest to make the chunk size 1 megabyte, up from 1 kilobyte.
72
+
73
+ - Add S3Object.exists?
74
+
75
+ 0.2.1:
76
+
77
+ - When the bucket name argument (for e.g. Bucket.objects) is being used as the option hash, reassign it to the options variable and set the bucket to nil so bucket inference + options works.
78
+
79
+ - Don't call CGI.escape on query string parameters in Hash#to_query_string since all paths get passed through URI.escape right before the request is made. Paths were getting double escaped. Bug spotted by [David Hanson]
80
+
81
+ - Make s3sh exec irb.bat if on Windows. Bug spotted by [N. Sathish Kumar <nsathishk@yahoo.com>]
82
+
83
+ - Avoid class_variable_(get|set) since it was only recently added to Ruby. Spotted by [N. Sathish Kumar <nsathishk@yahoo.com>]
84
+
85
+ - Raise NoSuchKey if S3Object.about requests a key that does not exist.
86
+
87
+ - If the response body is an empty string, don't try to parse it as xml.
88
+
89
+ - Don't reject every body type save for IO and String at the door when making a request. Suggested by [Alex MacCaw <maccman@gmail.com>]
90
+
91
+ - Allow dots in bucket names. [Jesse Newland]
92
+
93
+ 0.2.0:
94
+
95
+ - Infer content type for an object when calling S3Object.store without explicitly passing in the :content_type option.
96
+
97
+ 0.1.2:
98
+
99
+ - Scrap (overly) fancy generator based version of CoercibleString with a much simpler and clearer case statement. Continuations are really slow and the specific use of the generator was leaking memory. Bug spotted by [Remco van't Veer]
100
+
101
+ 0.1.1:
102
+
103
+ - Don't add the underscore method to String if it is already defined (like, for example, from ActiveSupport). Bug spotted by [Matt White <stockliasteroid@gmail.com>]
104
+
105
+ 0.1.0:
106
+
107
+ - Initial public release
data/COPYING ADDED
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright (c) 2006-2009 Marcel Molina Jr. <marcel@vernix.org>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in the
6
+ # Software without restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8
+ # Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18
+ # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/INSTALL ADDED
@@ -0,0 +1,55 @@
1
+ == Rubygems
2
+
3
+ The easiest way to install aws/s3 is with Rubygems:
4
+
5
+ % sudo gem i aws-s3 -ry
6
+
7
+ == Directly from svn
8
+
9
+ % svn co svn://rubyforge.org/var/svn/amazon/s3/trunk aws
10
+
11
+ == As a Rails plugin
12
+
13
+ If you want to use aws/s3 with a Rails application, you can export the repository
14
+ into your plugins directory and then check it in:
15
+
16
+ % cd my-rails-application/vendor/plugins
17
+ % svn export svn://rubyforge.org/var/svn/amazon/s3/trunk aws
18
+ % svn add aws
19
+
20
+ Or you could pull it down with an svn:externals:
21
+
22
+ % cd my-rails-application/vendor/plugins
23
+ % svn propedit svn:externals .
24
+
25
+ Then add the following line, save and exit:
26
+
27
+ aws svn://rubyforge.org/var/svn/amazon/s3/trunk
28
+
29
+ If you go the svn route, be sure that you have all the dependencies installed. The list of dependencies follow.
30
+
31
+ == Dependencies
32
+
33
+ AWS::S3 requires Ruby 1.8.4 or greater.
34
+
35
+ It also has the following dependencies:
36
+
37
+ sudo gem i xml-simple -ry
38
+ sudo gem i builder -ry
39
+ sudo gem i mime-types -ry
40
+
41
+ === XML parsing (xml-simple)
42
+
43
+ AWS::S3 depends on XmlSimple (http://xml-simple.rubyforge.org/). When installing aws/s3 with
44
+ Rubygems, this dependency will be taken care of for you. Otherwise, installation instructions are listed on the xml-simple
45
+ site.
46
+
47
+ If your system has the Ruby libxml bindings installed (http://libxml.rubyforge.org/) they will be used instead of REXML (which is what XmlSimple uses). For those concerned with speed and efficiency, it would behoove you to install libxml (instructions here: http://libxml.rubyforge.org/install.html) as it is considerably faster and less expensive than REXML.
48
+
49
+ === XML generation (builder)
50
+
51
+ AWS::S3 also depends on the Builder library (http://builder.rubyforge.org/ and http://rubyforge.org/projects/builder/). This will also automatically be installed for you when using Rubygems.
52
+
53
+ === Content type inference (mime-types)
54
+
55
+ AWS::S3 depends on the MIME::Types library (http://mime-types.rubyforge.org/) to infer the content type of an object that does not explicitly specify it. This library will automatically be installed for you when using Rubygems.
@@ -0,0 +1,58 @@
1
+ = AWS::S3
2
+
3
+ <%= docs_for['AWS::S3'] %>
4
+
5
+ == AWS::S3 Basics
6
+ === The service, buckets and objects
7
+
8
+ The three main concepts of S3 are the service, buckets and objects.
9
+
10
+ ==== The service
11
+
12
+ <%= docs_for['AWS::S3::Service'] %>
13
+
14
+ ==== Buckets
15
+
16
+ <%= docs_for['AWS::S3::Bucket'] %>
17
+
18
+ ==== Objects
19
+
20
+ <%= docs_for['AWS::S3::S3Object'] %>
21
+
22
+ ==== Streaming uploads
23
+
24
+ <%= docs_for['AWS::S3::S3Object::store'] %>
25
+
26
+ == Setting the current bucket
27
+ ==== Scoping operations to a specific bucket
28
+
29
+ <%= docs_for['AWS::S3::Base.set_current_bucket_to'] %>
30
+
31
+ == BitTorrent
32
+ ==== Another way to download large files
33
+
34
+ <%= docs_for['AWS::S3::BitTorrent'] %>
35
+
36
+ == Access control
37
+ ==== Using canned access control policies
38
+
39
+ <%= docs_for['AWS::S3::ACL'] %>
40
+
41
+ ==== Accessing private objects from a browser
42
+
43
+ <%= docs_for['AWS::S3::S3Object.url_for'] %>
44
+
45
+ == Logging
46
+ ==== Tracking requests made on a bucket
47
+
48
+ <%= docs_for['AWS::S3::Logging'] %>
49
+
50
+ == Errors
51
+ ==== When things go wrong
52
+
53
+ <%= docs_for['AWS::S3::Error'] %>
54
+
55
+ ==== Accessing the last request's response
56
+
57
+ <%= docs_for['AWS::S3::Service.response'] %>
58
+
@@ -0,0 +1,334 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+
8
+ require File.dirname(__FILE__) + '/lib/aws/s3'
9
+
10
+ def library_root
11
+ File.dirname(__FILE__)
12
+ end
13
+
14
+ task :default => :test
15
+
16
+ Rake::TestTask.new do |test|
17
+ test.pattern = 'test/*_test.rb'
18
+ test.verbose = true
19
+ end
20
+
21
+ namespace :doc do
22
+ Rake::RDocTask.new do |rdoc|
23
+ rdoc.rdoc_dir = 'doc'
24
+ rdoc.title = "AWS::S3 -- Support for Amazon S3's REST api"
25
+ rdoc.options << '--line-numbers' << '--inline-source'
26
+ rdoc.rdoc_files.include('README')
27
+ rdoc.rdoc_files.include('COPYING')
28
+ rdoc.rdoc_files.include('INSTALL')
29
+ rdoc.rdoc_files.include('lib/**/*.rb')
30
+ end
31
+
32
+ task :rdoc => 'doc:readme'
33
+
34
+ task :refresh => :rerdoc do
35
+ system 'open doc/index.html'
36
+ end
37
+
38
+ task :readme do
39
+ require 'support/rdoc/code_info'
40
+ RDoc::CodeInfo.parse('lib/**/*.rb')
41
+
42
+ strip_comments = lambda {|comment| comment.gsub(/^# ?/, '')}
43
+ docs_for = lambda do |location|
44
+ info = RDoc::CodeInfo.for(location)
45
+ raise RuntimeError, "Couldn't find documentation for `#{location}'" unless info
46
+ strip_comments[info.comment]
47
+ end
48
+
49
+ open('README', 'w') do |file|
50
+ file.write ERB.new(IO.read('README.erb')).result(binding)
51
+ end
52
+ end
53
+
54
+ task :deploy => :rerdoc do
55
+ sh %(scp -r doc marcel@rubyforge.org:/var/www/gforge-projects/amazon/)
56
+ end
57
+ end
58
+
59
+ namespace :dist do
60
+ spec = Gem::Specification.new do |s|
61
+ s.name = 'aws-s3'
62
+ s.version = Gem::Version.new(AWS::S3::Version)
63
+ s.summary = "Client library for Amazon's Simple Storage Service's REST API"
64
+ s.description = s.summary
65
+ s.email = 'marcel@vernix.org'
66
+ s.author = 'Marcel Molina Jr.'
67
+ s.has_rdoc = true
68
+ s.extra_rdoc_files = %w(README COPYING INSTALL)
69
+ s.homepage = 'http://amazon.rubyforge.org'
70
+ s.rubyforge_project = 'amazon'
71
+ s.files = FileList['Rakefile', 'lib/**/*.rb', 'bin/*', 'support/**/*.rb']
72
+ s.executables << 's3sh'
73
+ s.test_files = Dir['test/**/*']
74
+
75
+ s.add_dependency 'xml-simple'
76
+ s.add_dependency 'builder'
77
+ s.add_dependency 'mime-types'
78
+ s.rdoc_options = ['--title', "AWS::S3 -- Support for Amazon S3's REST api",
79
+ '--main', 'README',
80
+ '--line-numbers', '--inline-source']
81
+ end
82
+
83
+ # Regenerate README before packaging
84
+ task :package => 'doc:readme'
85
+ Rake::GemPackageTask.new(spec) do |pkg|
86
+ pkg.need_tar_gz = true
87
+ pkg.package_files.include('{lib,script,test,support}/**/*')
88
+ pkg.package_files.include('README')
89
+ pkg.package_files.include('COPYING')
90
+ pkg.package_files.include('INSTALL')
91
+ pkg.package_files.include('Rakefile')
92
+ end
93
+
94
+ desc 'Install with gems'
95
+ task :install => :repackage do
96
+ sh "sudo gem i pkg/#{spec.name}-#{spec.version}.gem"
97
+ end
98
+
99
+ desc 'Uninstall gem'
100
+ task :uninstall do
101
+ sh "sudo gem uninstall #{spec.name} -x"
102
+ end
103
+
104
+ desc 'Reinstall gem'
105
+ task :reinstall => [:uninstall, :install]
106
+
107
+ task :confirm_release do
108
+ print "Releasing version #{spec.version}. Are you sure you want to proceed? [Yn] "
109
+ abort if STDIN.getc == ?n
110
+ end
111
+
112
+ desc 'Tag release'
113
+ task :tag do
114
+ sh %(git tag -a '#{spec.version}-release' -m 'Tagging #{spec.version} release')
115
+ sh 'git push --tags'
116
+ end
117
+
118
+ desc 'Update changelog to include a release marker'
119
+ task :add_release_marker_to_changelog do
120
+ changelog = IO.read('CHANGELOG')
121
+ changelog.sub!(/^head:/, "#{spec.version}:")
122
+
123
+ open('CHANGELOG', 'w') do |file|
124
+ file.write "head:\n\n#{changelog}"
125
+ end
126
+ end
127
+
128
+ task :commit_changelog do
129
+ sh %(git commit CHANGELOG -m "Bump changelog version marker for release")
130
+ sh 'git push'
131
+ end
132
+
133
+ package_name = lambda {|specification| File.join('pkg', "#{specification.name}-#{specification.version}")}
134
+
135
+ desc 'Push a release to rubyforge'
136
+ task :release => [:confirm_release, :clean, :add_release_marker_to_changelog, :package, :commit_changelog, :tag] do
137
+ require 'rubyforge'
138
+ package = package_name[spec]
139
+
140
+ rubyforge = RubyForge.new.configure
141
+ rubyforge.login
142
+
143
+ user_config = rubyforge.userconfig
144
+ user_config['release_changes'] = YAML.load_file('CHANGELOG')[spec.version.to_s].join("\n")
145
+
146
+ version_already_released = lambda do
147
+ releases = rubyforge.autoconfig['release_ids']
148
+ releases.has_key?(spec.name) && releases[spec.name][spec.version.to_s]
149
+ end
150
+
151
+ abort("Release #{spec.version} already exists!") if version_already_released.call
152
+
153
+ begin
154
+ rubyforge.add_release(spec.rubyforge_project, spec.name, spec.version.to_s, "#{package}.tar.gz", "#{package}.gem")
155
+ puts "Version #{spec.version} released!"
156
+ rescue Exception => exception
157
+ puts 'Release failed!'
158
+ raise
159
+ end
160
+ end
161
+
162
+ desc 'Upload a beta gem'
163
+ task :push_beta_gem => [:clobber_package, :package] do
164
+ beta_gem = package_name[spec]
165
+ sh %(scp #{beta_gem}.gem marcel@rubyforge.org:/var/www/gforge-projects/amazon/beta)
166
+ end
167
+
168
+ task :spec do
169
+ puts spec.to_ruby
170
+ end
171
+ end
172
+
173
+ desc 'Check code to test ratio'
174
+ task :stats do
175
+ library_files = FileList["#{library_root}/lib/**/*.rb"]
176
+ test_files = FileList["#{library_root}/test/**/*_test.rb"]
177
+ count_code_lines = Proc.new do |lines|
178
+ lines.inject(0) do |code_lines, line|
179
+ next code_lines if [/^\s*$/, /^\s*#/].any? {|non_code_line| non_code_line === line}
180
+ code_lines + 1
181
+ end
182
+ end
183
+
184
+ count_code_lines_for_files = Proc.new do |files|
185
+ files.inject(0) {|code_lines, file| code_lines + count_code_lines[IO.read(file)]}
186
+ end
187
+
188
+ library_code_lines = count_code_lines_for_files[library_files]
189
+ test_code_lines = count_code_lines_for_files[test_files]
190
+ ratio = Proc.new { sprintf('%.2f', test_code_lines.to_f / library_code_lines)}
191
+
192
+ puts "Code LOC: #{library_code_lines} Test LOC: #{test_code_lines} Code to Test Ratio: 1:#{ratio.call}"
193
+ end
194
+
195
+ namespace :test do
196
+ find_file = lambda do |name|
197
+ file_name = lambda {|path| File.join(path, "#{name}.rb")}
198
+ root = $:.detect do |path|
199
+ File.exist?(file_name[path])
200
+ end
201
+ file_name[root] if root
202
+ end
203
+
204
+ TEST_LOADER = find_file['rake/rake_test_loader']
205
+ multiruby = lambda do |glob|
206
+ system 'multiruby', TEST_LOADER, *Dir.glob(glob)
207
+ end
208
+
209
+ desc 'Check test coverage'
210
+ task :coverage do
211
+ system("rcov -x Library -x support --sort coverage #{File.join(library_root, 'test/*_test.rb')}")
212
+ show_test_coverage_results
213
+ end
214
+
215
+ Rake::TestTask.new(:remote) do |test|
216
+ test.pattern = 'test/remote/*_test.rb'
217
+ test.verbose = true
218
+ end
219
+
220
+ Rake::TestTask.new(:all) do |test|
221
+ test.pattern = 'test/**/*_test.rb'
222
+ test.verbose = true
223
+ end
224
+
225
+ desc 'Check test coverage of full stack remote tests'
226
+ task :full_coverage do
227
+ system("rcov -x Library -x support --sort coverage #{File.join(library_root, 'test/remote/*_test.rb')} #{File.join(library_root, 'test/*_test.rb')}")
228
+ show_test_coverage_results
229
+ end
230
+
231
+ desc 'Run local tests against multiple versions of Ruby'
232
+ task :version_audit do
233
+ multiruby['test/*_test.rb']
234
+ end
235
+
236
+ namespace :version_audit do
237
+ desc 'Run remote tests against multiple versions of Ruby'
238
+ task :remote do
239
+ multiruby['test/remote/*_test.rb']
240
+ end
241
+
242
+ desc 'Run all tests against multiple versions of Ruby'
243
+ task :all do
244
+ multiruby['test/**/*_test.rb']
245
+ end
246
+ end
247
+
248
+ def show_test_coverage_results
249
+ system("open #{File.join(library_root, 'coverage/index.html')}") if PLATFORM['darwin']
250
+ end
251
+
252
+ desc 'Remove coverage products'
253
+ task :clobber_coverage do
254
+ rm_r 'coverage' rescue nil
255
+ end
256
+ end
257
+
258
+ namespace :todo do
259
+ class << TODOS = IO.read(File.join(library_root, 'TODO'))
260
+ def items
261
+ split("\n").grep(/^\[\s|X\]/)
262
+ end
263
+
264
+ def completed
265
+ find_items_matching(/^\[X\]/)
266
+ end
267
+
268
+ def uncompleted
269
+ find_items_matching(/^\[\s\]/)
270
+ end
271
+
272
+ def find_items_matching(regexp)
273
+ items.grep(regexp).instance_eval do
274
+ def display
275
+ puts map {|item| "* #{item.sub(/^\[[^\]]\]\s/, '')}"}
276
+ end
277
+ self
278
+ end
279
+ end
280
+ end
281
+
282
+ desc 'Completed todo items'
283
+ task :completed do
284
+ TODOS.completed.display
285
+ end
286
+
287
+ desc 'Incomplete todo items'
288
+ task :uncompleted do
289
+ TODOS.uncompleted.display
290
+ end
291
+ end if File.exists?(File.join(library_root, 'TODO'))
292
+
293
+ namespace :site do
294
+ require 'erb'
295
+ require 'rdoc/markup/simple_markup'
296
+ require 'rdoc/markup/simple_markup/to_html'
297
+
298
+ readme = lambda { IO.read('README')[/^== Getting started\n(.*)/m, 1] }
299
+
300
+ readme_to_html = lambda do
301
+ handler = SM::ToHtml.new
302
+ handler.instance_eval do
303
+ require 'syntax'
304
+ require 'syntax/convertors/html'
305
+ def accept_verbatim(am, fragment)
306
+ syntax = Syntax::Convertors::HTML.for_syntax('ruby')
307
+ @res << %(<div class="ruby">#{syntax.convert(fragment.txt, true)}</div>)
308
+ end
309
+ end
310
+ SM::SimpleMarkup.new.convert(readme.call, handler)
311
+ end
312
+
313
+ desc 'Regenerate the public website page'
314
+ task :build => 'doc:readme' do
315
+ open('site/public/index.html', 'w') do |file|
316
+ erb_data = {}
317
+ erb_data[:readme] = readme_to_html.call
318
+ file.write ERB.new(IO.read('site/index.erb')).result(binding)
319
+ end
320
+ end
321
+
322
+ task :refresh => :build do
323
+ system 'open site/public/index.html'
324
+ end
325
+
326
+ desc 'Update the live website'
327
+ task :deploy => :build do
328
+ site_files = FileList['site/public/*']
329
+ site_files.delete_if {|file| File.directory?(file)}
330
+ sh %(scp #{site_files.join ' '} marcel@rubyforge.org:/var/www/gforge-projects/amazon/)
331
+ end
332
+ end
333
+
334
+ task :clean => ['dist:clobber_package', 'doc:clobber_rdoc', 'test:clobber_coverage']