ahoward-helene 0.0.3

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.
Files changed (72) hide show
  1. data/Rakefile +274 -0
  2. data/helene.gemspec +26 -0
  3. data/lib/helene.rb +113 -0
  4. data/lib/helene/attempt.rb +46 -0
  5. data/lib/helene/aws.rb +50 -0
  6. data/lib/helene/config.rb +147 -0
  7. data/lib/helene/content_type.rb +15 -0
  8. data/lib/helene/content_type.yml +661 -0
  9. data/lib/helene/error.rb +12 -0
  10. data/lib/helene/logging.rb +55 -0
  11. data/lib/helene/objectpool.rb +220 -0
  12. data/lib/helene/rails.rb +21 -0
  13. data/lib/helene/rightscale/acf/right_acf_interface.rb +379 -0
  14. data/lib/helene/rightscale/awsbase/benchmark_fix.rb +39 -0
  15. data/lib/helene/rightscale/awsbase/right_awsbase.rb +803 -0
  16. data/lib/helene/rightscale/awsbase/support.rb +111 -0
  17. data/lib/helene/rightscale/ec2/right_ec2.rb +1737 -0
  18. data/lib/helene/rightscale/net_fix.rb +160 -0
  19. data/lib/helene/rightscale/right_aws.rb +71 -0
  20. data/lib/helene/rightscale/right_http_connection.rb +507 -0
  21. data/lib/helene/rightscale/s3/right_s3.rb +1094 -0
  22. data/lib/helene/rightscale/s3/right_s3_interface.rb +1180 -0
  23. data/lib/helene/rightscale/sdb/active_sdb.rb +930 -0
  24. data/lib/helene/rightscale/sdb/right_sdb_interface.rb +696 -0
  25. data/lib/helene/rightscale/sqs/right_sqs.rb +388 -0
  26. data/lib/helene/rightscale/sqs/right_sqs_gen2.rb +286 -0
  27. data/lib/helene/rightscale/sqs/right_sqs_gen2_interface.rb +444 -0
  28. data/lib/helene/rightscale/sqs/right_sqs_interface.rb +596 -0
  29. data/lib/helene/s3.rb +34 -0
  30. data/lib/helene/s3/bucket.rb +379 -0
  31. data/lib/helene/s3/grantee.rb +134 -0
  32. data/lib/helene/s3/key.rb +162 -0
  33. data/lib/helene/s3/owner.rb +16 -0
  34. data/lib/helene/sdb.rb +9 -0
  35. data/lib/helene/sdb/base.rb +1204 -0
  36. data/lib/helene/sdb/base/associations.rb +481 -0
  37. data/lib/helene/sdb/base/attributes.rb +90 -0
  38. data/lib/helene/sdb/base/connection.rb +20 -0
  39. data/lib/helene/sdb/base/error.rb +20 -0
  40. data/lib/helene/sdb/base/hooks.rb +82 -0
  41. data/lib/helene/sdb/base/literal.rb +52 -0
  42. data/lib/helene/sdb/base/logging.rb +23 -0
  43. data/lib/helene/sdb/base/transactions.rb +53 -0
  44. data/lib/helene/sdb/base/type.rb +137 -0
  45. data/lib/helene/sdb/base/types.rb +123 -0
  46. data/lib/helene/sdb/base/validations.rb +256 -0
  47. data/lib/helene/sdb/cast.rb +114 -0
  48. data/lib/helene/sdb/connection.rb +36 -0
  49. data/lib/helene/sdb/error.rb +5 -0
  50. data/lib/helene/sdb/interface.rb +412 -0
  51. data/lib/helene/sdb/sentinel.rb +15 -0
  52. data/lib/helene/sleepcycle.rb +29 -0
  53. data/lib/helene/superhash.rb +297 -0
  54. data/lib/helene/util.rb +132 -0
  55. data/test/auth.rb +31 -0
  56. data/test/helper.rb +98 -0
  57. data/test/integration/begin.rb +0 -0
  58. data/test/integration/ensure.rb +8 -0
  59. data/test/integration/s3/bucket.rb +106 -0
  60. data/test/integration/sdb/associations.rb +45 -0
  61. data/test/integration/sdb/creating.rb +13 -0
  62. data/test/integration/sdb/emptiness.rb +56 -0
  63. data/test/integration/sdb/hooks.rb +19 -0
  64. data/test/integration/sdb/limits.rb +27 -0
  65. data/test/integration/sdb/saving.rb +21 -0
  66. data/test/integration/sdb/selecting.rb +39 -0
  67. data/test/integration/sdb/types.rb +31 -0
  68. data/test/integration/sdb/validations.rb +60 -0
  69. data/test/integration/setup.rb +27 -0
  70. data/test/integration/teardown.rb +21 -0
  71. data/test/loader.rb +39 -0
  72. metadata +139 -0
@@ -0,0 +1,274 @@
1
+ This.rubyforge_project = 'codeforpeople'
2
+ This.author = "Ara T. Howard"
3
+ This.email = "ara.t.howard@gmail.com"
4
+ This.homepage = "http://github.com/ahoward/#{ This.lib }/tree/master"
5
+
6
+
7
+ task :default do
8
+ puts(Rake::Task.tasks.map{|task| task.name} - ['default'])
9
+ end
10
+
11
+ task :gemspec do
12
+ ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
13
+ ignore_directories = 'pkg'
14
+ ignore_files = 'test/log'
15
+
16
+ shiteless =
17
+ lambda do |list|
18
+ list.delete_if do |entry|
19
+ next unless test(?e, entry)
20
+ extension = File.basename(entry).split(%r/[.]/).last
21
+ ignore_extensions.any?{|ext| ext === extension}
22
+ end
23
+ list.delete_if do |entry|
24
+ next unless test(?d, entry)
25
+ dirname = File.expand_path(entry)
26
+ ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
27
+ end
28
+ list.delete_if do |entry|
29
+ next unless test(?f, entry)
30
+ filename = File.expand_path(entry)
31
+ ignore_files.any?{|file| File.expand_path(file) == filename}
32
+ end
33
+ end
34
+
35
+ lib = This.lib
36
+ version = This.version
37
+ files = shiteless[Dir::glob("**/**")]
38
+ executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
39
+ has_rdoc = true #File.exist?('doc')
40
+ test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
41
+
42
+ extensions = This.extensions
43
+ if extensions.nil?
44
+ %w( Makefile configure extconf.rb ).each do |ext|
45
+ extensions << ext if File.exists?(ext)
46
+ end
47
+ end
48
+ extensions = [extensions].flatten.compact
49
+
50
+ template =
51
+ if test(?e, 'gemspec.erb')
52
+ Template{ IO.read('gemspec.erb') }
53
+ else
54
+ Template {
55
+ <<-__
56
+ ## #{ lib }.gemspec
57
+ #
58
+
59
+ Gem::Specification::new do |spec|
60
+ spec.name = #{ lib.inspect }
61
+ spec.version = #{ version.inspect }
62
+ spec.platform = Gem::Platform::RUBY
63
+ spec.summary = #{ lib.inspect }
64
+
65
+ spec.files = #{ files.inspect }
66
+ spec.executables = #{ executables.inspect }
67
+
68
+ spec.require_path = "lib"
69
+
70
+ spec.has_rdoc = #{ has_rdoc.inspect }
71
+ spec.test_files = #{ test_files.inspect }
72
+ #spec.add_dependency 'lib', '>= version'
73
+ #spec.add_dependency 'fattr'
74
+
75
+ spec.extensions.push(*#{ extensions.inspect })
76
+
77
+ spec.rubyforge_project = #{ This.rubyforge_project.inspect }
78
+ spec.author = #{ This.author.inspect }
79
+ spec.email = #{ This.email.inspect }
80
+ spec.homepage = #{ This.homepage.inspect }
81
+ end
82
+ __
83
+ }
84
+ end
85
+
86
+ open("#{ lib }.gemspec", "w"){|fd| fd.puts template}
87
+ This.gemspec = "#{ lib }.gemspec"
88
+ end
89
+
90
+ task :gem => [:clean, :gemspec] do
91
+ Fu.mkdir_p This.pkgdir
92
+ before = Dir['*.gem']
93
+ cmd = "gem build #{ This.gemspec }"
94
+ `#{ cmd }`
95
+ after = Dir['*.gem']
96
+ gem = ((after - before).first || after.first) or abort('no gem!')
97
+ Fu.mv gem, This.pkgdir
98
+ This.gem = File.basename(gem)
99
+ end
100
+
101
+ task :readme do
102
+ samples = ''
103
+ prompt = '~ > '
104
+ lib = This.lib
105
+ version = This.version
106
+
107
+ Dir['sample*/*'].sort.each do |sample|
108
+ samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
109
+
110
+ cmd = "cat #{ sample }"
111
+ samples << Util.indent(prompt + cmd, 2) << "\n\n"
112
+ samples << Util.indent(`#{ cmd }`, 4) << "\n"
113
+
114
+ cmd = "ruby #{ sample }"
115
+ samples << Util.indent(prompt + cmd, 2) << "\n\n"
116
+
117
+ cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -Ilib #{ sample })'"
118
+ samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
119
+ end
120
+
121
+ template =
122
+ if test(?e, 'readme.erb')
123
+ Template{ IO.read('readme.erb') }
124
+ else
125
+ Template {
126
+ <<-__
127
+ NAME
128
+ #{ lib }
129
+
130
+ DESCRIPTION
131
+
132
+ INSTALL
133
+ gem install #{ lib }
134
+
135
+ SAMPLES
136
+ #{ samples }
137
+ __
138
+ }
139
+ end
140
+
141
+ open("README", "w"){|fd| fd.puts template}
142
+ end
143
+
144
+ task :clean do
145
+ Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
146
+ end
147
+
148
+ task :release => [:clean, :gemspec, :gem] do
149
+ gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
150
+ raise "which one? : #{ gems.inspect }" if gems.size > 1
151
+ raise "no gems?" if gems.size < 1
152
+ cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.pkgdir }/#{ This.gem }"
153
+ puts cmd
154
+ system cmd
155
+ end
156
+
157
+ namespace 'test' do
158
+ def test_files(prefix=nil, &block)
159
+ files = [ENV['FILES'], ENV['FILE']].flatten.compact
160
+ if files.empty?
161
+ files = Dir.glob("#{ prefix }/**/*.rb")
162
+ else
163
+ files.map!{|file| Dir.glob(file)}.flatten.compact
164
+ end
165
+ files = files.join(' ').strip.split(%r/\s+/)
166
+ files.delete_if{|file| file =~ /(begin|ensure|setup|teardown).rb$/}
167
+ files.delete_if{|file| !test(?s, file) or !test(?f, file)}
168
+ files.delete_if{|file| !file[%r/#{ prefix }/]}
169
+ block ? files.each{|file| block.call(file)} : files
170
+ end
171
+
172
+ desc 'run all tests'
173
+ task 'all' => %w[ unit integration ] do
174
+ end
175
+
176
+ desc 'run unit tests'
177
+ task 'unit' do
178
+ test_files('test/unit/') do |file|
179
+ test_loader file
180
+ end
181
+ end
182
+
183
+ desc 'run integration tests'
184
+ task 'integration' do
185
+ test_files('test/integration/') do |file|
186
+ test_loader file, :require_auth => true
187
+ end
188
+ end
189
+
190
+ namespace 'integration' do
191
+ task 'setup' do
192
+ test_loader 'test/integration/setup.rb', :require_auth => true
193
+ end
194
+ task 'teardown' do
195
+ test_loader 'test/integration/teardown.rb', :require_auth => true
196
+ end
197
+ end
198
+ end
199
+ task('test' => 'test:all'){}
200
+
201
+
202
+ BEGIN {
203
+ $VERBOSE = nil
204
+
205
+ require 'ostruct'
206
+ require 'erb'
207
+ require 'fileutils'
208
+
209
+ Fu = FileUtils
210
+
211
+ This = OpenStruct.new
212
+
213
+ This.file = File.expand_path(__FILE__)
214
+ This.dir = File.dirname(This.file)
215
+ This.pkgdir = File.join(This.dir, 'pkg')
216
+
217
+ lib = ENV['LIB']
218
+ unless lib
219
+ lib = File.basename(Dir.pwd)
220
+ end
221
+ This.lib = lib
222
+
223
+ version = ENV['VERSION']
224
+ unless version
225
+ name = lib.capitalize
226
+ require "./lib/#{ lib }"
227
+ version = eval(name).send(:version)
228
+ end
229
+ This.version = version
230
+
231
+ abort('no lib') unless This.lib
232
+ abort('no version') unless This.version
233
+
234
+ module Util
235
+ def indent(s, n = 2)
236
+ s = unindent(s)
237
+ ws = ' ' * n
238
+ s.gsub(%r/^/, ws)
239
+ end
240
+
241
+ def unindent(s)
242
+ indent = nil
243
+ s.each do |line|
244
+ next if line =~ %r/^\s*$/
245
+ indent = line[%r/^\s*/] and break
246
+ end
247
+ indent ? s.gsub(%r/^#{ indent }/, "") : s
248
+ end
249
+ extend self
250
+ end
251
+
252
+ class Template
253
+ def initialize(&block)
254
+ @block = block
255
+ @template = block.call.to_s
256
+ end
257
+ def expand(b=nil)
258
+ ERB.new(Util.unindent(@template)).result(b||@block)
259
+ end
260
+ alias_method 'to_s', 'expand'
261
+ end
262
+ def Template(*args, &block) Template.new(*args, &block) end
263
+
264
+ Dir.chdir(This.dir)
265
+
266
+ def test_loader basename, options = {}
267
+ tests = ENV['TESTS']||ENV['TEST']
268
+ tests = " -- -n #{ tests.inspect }" if tests
269
+ auth = '-r test/auth.rb ' if options[:require_auth]
270
+ command = "ruby -r test/loader.rb #{ auth }#{ basename }#{ tests }"
271
+ STDERR.print "\n==== TEST ====\n #{ command }\n\n==============\n"
272
+ system command or abort("#{ command } # FAILED WITH #{ $?.inspect }")
273
+ end
274
+ }
@@ -0,0 +1,26 @@
1
+ ## helene.gemspec
2
+ #
3
+
4
+ Gem::Specification::new do |spec|
5
+ spec.name = "helene"
6
+ spec.version = "0.0.3"
7
+ spec.platform = Gem::Platform::RUBY
8
+ spec.summary = "helene"
9
+
10
+ spec.files = ["helene.gemspec", "lib", "lib/helene", "lib/helene/attempt.rb", "lib/helene/aws.rb", "lib/helene/config.rb", "lib/helene/content_type.rb", "lib/helene/content_type.yml", "lib/helene/error.rb", "lib/helene/logging.rb", "lib/helene/objectpool.rb", "lib/helene/rails.rb", "lib/helene/rightscale", "lib/helene/rightscale/acf", "lib/helene/rightscale/acf/right_acf_interface.rb", "lib/helene/rightscale/awsbase", "lib/helene/rightscale/awsbase/benchmark_fix.rb", "lib/helene/rightscale/awsbase/right_awsbase.rb", "lib/helene/rightscale/awsbase/support.rb", "lib/helene/rightscale/ec2", "lib/helene/rightscale/ec2/right_ec2.rb", "lib/helene/rightscale/net_fix.rb", "lib/helene/rightscale/right_aws.rb", "lib/helene/rightscale/right_http_connection.rb", "lib/helene/rightscale/s3", "lib/helene/rightscale/s3/right_s3.rb", "lib/helene/rightscale/s3/right_s3_interface.rb", "lib/helene/rightscale/sdb", "lib/helene/rightscale/sdb/active_sdb.rb", "lib/helene/rightscale/sdb/right_sdb_interface.rb", "lib/helene/rightscale/sqs", "lib/helene/rightscale/sqs/right_sqs.rb", "lib/helene/rightscale/sqs/right_sqs_gen2.rb", "lib/helene/rightscale/sqs/right_sqs_gen2_interface.rb", "lib/helene/rightscale/sqs/right_sqs_interface.rb", "lib/helene/s3", "lib/helene/s3/bucket.rb", "lib/helene/s3/grantee.rb", "lib/helene/s3/key.rb", "lib/helene/s3/owner.rb", "lib/helene/s3.rb", "lib/helene/sdb", "lib/helene/sdb/base", "lib/helene/sdb/base/associations.rb", "lib/helene/sdb/base/attributes.rb", "lib/helene/sdb/base/connection.rb", "lib/helene/sdb/base/error.rb", "lib/helene/sdb/base/hooks.rb", "lib/helene/sdb/base/literal.rb", "lib/helene/sdb/base/logging.rb", "lib/helene/sdb/base/transactions.rb", "lib/helene/sdb/base/type.rb", "lib/helene/sdb/base/types.rb", "lib/helene/sdb/base/validations.rb", "lib/helene/sdb/base.rb", "lib/helene/sdb/cast.rb", "lib/helene/sdb/connection.rb", "lib/helene/sdb/error.rb", "lib/helene/sdb/interface.rb", "lib/helene/sdb/sentinel.rb", "lib/helene/sdb.rb", "lib/helene/sleepcycle.rb", "lib/helene/superhash.rb", "lib/helene/util.rb", "lib/helene.rb", "Rakefile", "test", "test/auth.rb", "test/helper.rb", "test/integration", "test/integration/begin.rb", "test/integration/ensure.rb", "test/integration/s3", "test/integration/s3/bucket.rb", "test/integration/sdb", "test/integration/sdb/associations.rb", "test/integration/sdb/creating.rb", "test/integration/sdb/emptiness.rb", "test/integration/sdb/hooks.rb", "test/integration/sdb/limits.rb", "test/integration/sdb/saving.rb", "test/integration/sdb/selecting.rb", "test/integration/sdb/types.rb", "test/integration/sdb/validations.rb", "test/integration/setup.rb", "test/integration/teardown.rb", "test/loader.rb"]
11
+ spec.executables = []
12
+
13
+ spec.require_path = "lib"
14
+
15
+ spec.has_rdoc = true
16
+ spec.test_files = nil
17
+ #spec.add_dependency 'lib', '>= version'
18
+ #spec.add_dependency 'fattr'
19
+
20
+ spec.extensions.push(*[])
21
+
22
+ spec.rubyforge_project = "codeforpeople"
23
+ spec.author = "Ara T. Howard"
24
+ spec.email = "ara.t.howard@gmail.com"
25
+ spec.homepage = "http://github.com/ahoward/helene/tree/master"
26
+ end
@@ -0,0 +1,113 @@
1
+ module Helene
2
+ # version
3
+ #
4
+ Helene::VERSION = '0.0.3' unless defined?(Helene::VERSION)
5
+ def Helene.version() Helene::VERSION end
6
+
7
+ # ruby built-ins
8
+ #
9
+ require 'ostruct'
10
+ require 'logger'
11
+ require 'pathname'
12
+
13
+ # rubygems
14
+ #
15
+ begin
16
+ require 'rubygems'
17
+ rescue LoadError
18
+ nil
19
+ end
20
+
21
+ # gems
22
+ #
23
+ require 'active_support' unless defined?(ActiveSupport)
24
+ require 'uuidtools'
25
+ gem 'arrayfields', '~> 4.7'
26
+ require 'arrayfields'
27
+ gem 'threadify', '~> 1.1'
28
+ require 'threadify'
29
+
30
+ # helene load support
31
+ #
32
+ def Helene.lib
33
+ @lib = Pathname.new(__FILE__).realpath.to_s
34
+ end
35
+
36
+ def Helene.libdir(*args)
37
+ @libdir ||= File.dirname(lib)
38
+ if args.empty?
39
+ @libdir
40
+ else
41
+ File.join(@libdir, *args.flatten.compact.map{|arg| arg.to_s})
42
+ end
43
+ end
44
+
45
+ def Helene.reload!
46
+ Kernel.load lib
47
+ end
48
+
49
+ def Helene.load_path(&block)
50
+ $LOAD_PATH.unshift(Helene.libdir)
51
+ $LOAD_PATH.unshift(Helene.libdir('helene'))
52
+ begin
53
+ block.call
54
+ ensure
55
+ $LOAD_PATH.shift
56
+ $LOAD_PATH.shift
57
+ end
58
+ end
59
+
60
+ def Helene.rightscale_load_path(&block)
61
+ $LOAD_PATH.unshift(Helene.libdir('helene', 'rightscale'))
62
+ begin
63
+ block.call
64
+ ensure
65
+ $LOAD_PATH.shift
66
+ end
67
+ end
68
+
69
+ def Helene.rails?
70
+ defined?(Rails)
71
+ end
72
+
73
+ def Helene.rails_root(*args)
74
+ if rails?
75
+ File.join(RAILS_ROOT, *args.flatten.map{|arg| arg.to_s})
76
+ end
77
+ end
78
+
79
+ def Helene.uuid
80
+ UUID.timestamp_create().to_s
81
+ end
82
+
83
+ # helene
84
+ #
85
+ Helene.load_path do
86
+ Helene.rightscale_load_path do
87
+ load 'right_http_connection.rb'
88
+ load 'right_aws.rb'
89
+ end
90
+ load 'error.rb'
91
+ load 'util.rb'
92
+ load 'sleepcycle.rb'
93
+ load 'superhash.rb'
94
+ load 'objectpool.rb'
95
+ load 'attempt.rb'
96
+ load 'content_type.rb'
97
+ load 'logging.rb'
98
+ load 'config.rb'
99
+ load 'aws.rb'
100
+ load 'sdb.rb'
101
+ load 's3.rb'
102
+ load 'rails.rb' if defined?(Rails)
103
+ end
104
+
105
+ # mega-hacks
106
+ #
107
+ ca_file =
108
+ ENV['CA_FILE'] ||
109
+ ENV['AMAZON_CA_FILE'] ||
110
+ (defined?(AMAZON_CA_FILE) and AMAZON_CA_FILE) ||
111
+ (defined?(CA_FILE) and CA_FILE)
112
+ Rightscale::HttpConnection.params[:ca_file] = ca_file if ca_file
113
+ end
@@ -0,0 +1,46 @@
1
+ module Helene
2
+ module Attempt
3
+ class TooMany < StandardError; end
4
+
5
+ def attempt(*args, &block)
6
+ options = args.extract_options!.to_options!
7
+
8
+ retries = Integer(args.shift || options[:retries] || 42)
9
+ label = String(args.shift || options[:label] || caller.first(1))
10
+ exceptions = [options[:rescue] || StandardError].flatten
11
+ result = nil
12
+ attempts = 0
13
+ sleepcycle = options[:sleepcycle] || options[:backoff] || SleepCycle.new
14
+ Thread.current[:attempt_label] = label
15
+
16
+ loop do
17
+ caught =
18
+ begin
19
+ catch(label) do
20
+ result = yield(attempts += 1)
21
+ end
22
+ rescue *exceptions => e
23
+ #STDERR.puts Util.emsg(e)
24
+ raise if options[:rescue]==false
25
+ sleep(sleepcycle.next)
26
+ :try_again
27
+ end
28
+
29
+ break unless caught == :try_again
30
+ raise TooMany, "#{ retries } (#{ label })" if attempts >= retries
31
+ end
32
+
33
+ result
34
+ end
35
+
36
+ def try_again! label = Thread.current[:attempt_label]
37
+ throw label, :try_again
38
+ end
39
+
40
+ def give_up! label = Thread.current[:attempt_label]
41
+ throw label, :give_up
42
+ end
43
+
44
+ extend self
45
+ end
46
+ end