ahoward-helene 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +274 -0
- data/helene.gemspec +26 -0
- data/lib/helene.rb +113 -0
- data/lib/helene/attempt.rb +46 -0
- data/lib/helene/aws.rb +50 -0
- data/lib/helene/config.rb +147 -0
- data/lib/helene/content_type.rb +15 -0
- data/lib/helene/content_type.yml +661 -0
- data/lib/helene/error.rb +12 -0
- data/lib/helene/logging.rb +55 -0
- data/lib/helene/objectpool.rb +220 -0
- data/lib/helene/rails.rb +21 -0
- data/lib/helene/rightscale/acf/right_acf_interface.rb +379 -0
- data/lib/helene/rightscale/awsbase/benchmark_fix.rb +39 -0
- data/lib/helene/rightscale/awsbase/right_awsbase.rb +803 -0
- data/lib/helene/rightscale/awsbase/support.rb +111 -0
- data/lib/helene/rightscale/ec2/right_ec2.rb +1737 -0
- data/lib/helene/rightscale/net_fix.rb +160 -0
- data/lib/helene/rightscale/right_aws.rb +71 -0
- data/lib/helene/rightscale/right_http_connection.rb +507 -0
- data/lib/helene/rightscale/s3/right_s3.rb +1094 -0
- data/lib/helene/rightscale/s3/right_s3_interface.rb +1180 -0
- data/lib/helene/rightscale/sdb/active_sdb.rb +930 -0
- data/lib/helene/rightscale/sdb/right_sdb_interface.rb +696 -0
- data/lib/helene/rightscale/sqs/right_sqs.rb +388 -0
- data/lib/helene/rightscale/sqs/right_sqs_gen2.rb +286 -0
- data/lib/helene/rightscale/sqs/right_sqs_gen2_interface.rb +444 -0
- data/lib/helene/rightscale/sqs/right_sqs_interface.rb +596 -0
- data/lib/helene/s3.rb +34 -0
- data/lib/helene/s3/bucket.rb +379 -0
- data/lib/helene/s3/grantee.rb +134 -0
- data/lib/helene/s3/key.rb +162 -0
- data/lib/helene/s3/owner.rb +16 -0
- data/lib/helene/sdb.rb +9 -0
- data/lib/helene/sdb/base.rb +1204 -0
- data/lib/helene/sdb/base/associations.rb +481 -0
- data/lib/helene/sdb/base/attributes.rb +90 -0
- data/lib/helene/sdb/base/connection.rb +20 -0
- data/lib/helene/sdb/base/error.rb +20 -0
- data/lib/helene/sdb/base/hooks.rb +82 -0
- data/lib/helene/sdb/base/literal.rb +52 -0
- data/lib/helene/sdb/base/logging.rb +23 -0
- data/lib/helene/sdb/base/transactions.rb +53 -0
- data/lib/helene/sdb/base/type.rb +137 -0
- data/lib/helene/sdb/base/types.rb +123 -0
- data/lib/helene/sdb/base/validations.rb +256 -0
- data/lib/helene/sdb/cast.rb +114 -0
- data/lib/helene/sdb/connection.rb +36 -0
- data/lib/helene/sdb/error.rb +5 -0
- data/lib/helene/sdb/interface.rb +412 -0
- data/lib/helene/sdb/sentinel.rb +15 -0
- data/lib/helene/sleepcycle.rb +29 -0
- data/lib/helene/superhash.rb +297 -0
- data/lib/helene/util.rb +132 -0
- data/test/auth.rb +31 -0
- data/test/helper.rb +98 -0
- data/test/integration/begin.rb +0 -0
- data/test/integration/ensure.rb +8 -0
- data/test/integration/s3/bucket.rb +106 -0
- data/test/integration/sdb/associations.rb +45 -0
- data/test/integration/sdb/creating.rb +13 -0
- data/test/integration/sdb/emptiness.rb +56 -0
- data/test/integration/sdb/hooks.rb +19 -0
- data/test/integration/sdb/limits.rb +27 -0
- data/test/integration/sdb/saving.rb +21 -0
- data/test/integration/sdb/selecting.rb +39 -0
- data/test/integration/sdb/types.rb +31 -0
- data/test/integration/sdb/validations.rb +60 -0
- data/test/integration/setup.rb +27 -0
- data/test/integration/teardown.rb +21 -0
- data/test/loader.rb +39 -0
- metadata +139 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
module Helene
|
2
|
+
module Sdb
|
3
|
+
class Base
|
4
|
+
class Attribute
|
5
|
+
attr_accessor 'base'
|
6
|
+
attr_accessor 'name'
|
7
|
+
attr_accessor 'type'
|
8
|
+
attr_accessor 'nilable'
|
9
|
+
attr_accessor 'default'
|
10
|
+
attr_accessor 'has_default'
|
11
|
+
alias_method 'has_default?', 'has_default'
|
12
|
+
|
13
|
+
def initialize(*args, &block)
|
14
|
+
options = args.extract_options!.to_options!
|
15
|
+
|
16
|
+
@base = args.shift || raise(ArgumentError, 'no base')
|
17
|
+
|
18
|
+
@name = args.shift || raise(ArgumentError, 'no name')
|
19
|
+
@name = @name.to_s
|
20
|
+
|
21
|
+
type = args.empty? ? (options[:type]||:string) : args.shift.to_s.to_sym
|
22
|
+
|
23
|
+
@type = Type.for(type) || raise(ArgumentError, {:type => type}.inspect)
|
24
|
+
|
25
|
+
not_nilable = [:nil, :null, :nilable, :nullable].any?{|k| options[k]==false}
|
26
|
+
@nilable = !not_nilable
|
27
|
+
|
28
|
+
@default = options[:default]
|
29
|
+
@has_default = options.has_key?(:default)
|
30
|
+
|
31
|
+
code = <<-__
|
32
|
+
def #{ name }()
|
33
|
+
attributes[#{ name.inspect }]
|
34
|
+
end
|
35
|
+
alias_method #{ name.inspect }+'?', #{ name.inspect }
|
36
|
+
def #{ name }=(value)
|
37
|
+
attributes[#{ name.inspect }]=value
|
38
|
+
end
|
39
|
+
if not #{ @nilable }
|
40
|
+
validates_presence_of #{ name.inspect }
|
41
|
+
end
|
42
|
+
__
|
43
|
+
|
44
|
+
@base.module_eval(code, __FILE__, __LINE__)
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize_record(record)
|
48
|
+
unless record.attributes.has_key?(name)
|
49
|
+
value =
|
50
|
+
if has_default?
|
51
|
+
default.respond_to?(:call) ? record.instance_eval(&default) : default
|
52
|
+
else
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
record.attributes[name] = value
|
56
|
+
end
|
57
|
+
|
58
|
+
if type.sti?
|
59
|
+
record.attributes[name] = record.class.name
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class << Base
|
65
|
+
def attributes_table
|
66
|
+
@attributes_table ||= (Base==self ? SuperHash.new() : SuperHash.new(superclass.attributes_table))
|
67
|
+
#@attributes_table ||= (Base==self ? Array.fields() : superclass.attributes_table.clone)
|
68
|
+
end
|
69
|
+
|
70
|
+
def attributes
|
71
|
+
attributes_table.values
|
72
|
+
end
|
73
|
+
|
74
|
+
def attribute(*args, &block)
|
75
|
+
attribute = Attribute.new(self, *args, &block)
|
76
|
+
attributes_table[attribute.name] = attribute
|
77
|
+
end
|
78
|
+
|
79
|
+
def attribute_for(name)
|
80
|
+
attributes_table[name.to_s]
|
81
|
+
end
|
82
|
+
|
83
|
+
def type_for(name)
|
84
|
+
name = name.to_s
|
85
|
+
attributes_table[name].type if attributes_table.has_key?(name)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Helene
|
2
|
+
module Sdb
|
3
|
+
class Base
|
4
|
+
class << Base
|
5
|
+
def connections(&block)
|
6
|
+
Sdb.connections(&block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def connection
|
10
|
+
Sdb.connection
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def connection
|
15
|
+
self.class.connection
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Helene
|
2
|
+
module Sdb
|
3
|
+
class Base
|
4
|
+
class Error < Helene::Error; end
|
5
|
+
class RecordNotFound < Error; end
|
6
|
+
class RecordInvalid < Error; end
|
7
|
+
class RecordNotSaved < Error; end
|
8
|
+
|
9
|
+
class << Base
|
10
|
+
def error!(message)
|
11
|
+
raise Error.new(message.to_s)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def error!(message)
|
16
|
+
self.class.error!(message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Helene
|
2
|
+
module Sdb
|
3
|
+
class Base
|
4
|
+
HOOKS = [
|
5
|
+
:before_initialize,
|
6
|
+
:after_initialize,
|
7
|
+
:before_load,
|
8
|
+
:after_load,
|
9
|
+
:before_create,
|
10
|
+
:after_create,
|
11
|
+
:before_update,
|
12
|
+
:after_update,
|
13
|
+
:before_validation,
|
14
|
+
:after_validation,
|
15
|
+
:before_save,
|
16
|
+
:after_save,
|
17
|
+
:before_destroy,
|
18
|
+
:after_destroy,
|
19
|
+
:before_delete,
|
20
|
+
:after_delete
|
21
|
+
] unless defined?(HOOKS)
|
22
|
+
|
23
|
+
class << Base
|
24
|
+
unless defined?(HOOK_METHOD_AFTER_ASSOCIATION_WARNING)
|
25
|
+
HOOK_METHOD_AFTER_ASSOCIATION_WARNING = <<-__
|
26
|
+
*IMPORTANT:* In order for inheritance to work for the callback
|
27
|
+
queues, you must specify the callbacks before specifying the
|
28
|
+
associations. Otherwise, you might trigger the loading of a child
|
29
|
+
before the parent has registered the callbacks and they won’t be
|
30
|
+
inherited.
|
31
|
+
__
|
32
|
+
end
|
33
|
+
|
34
|
+
# Some fancy code generation here in order to define the hook class methods...
|
35
|
+
unless defined?(HOOK_METHOD_STR)
|
36
|
+
HOOK_METHOD_STR = <<-__
|
37
|
+
def Base.%s(method = nil, &block)
|
38
|
+
unless block
|
39
|
+
(raise Error, 'No hook method specified') unless method
|
40
|
+
block = lambda {send method}
|
41
|
+
end
|
42
|
+
add_hook(%s, &block)
|
43
|
+
end
|
44
|
+
__
|
45
|
+
end
|
46
|
+
|
47
|
+
def def_hook_method(m) #:nodoc:
|
48
|
+
instance_eval(HOOK_METHOD_STR % [m.to_s, m.inspect])
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the hooks hash for the model class.
|
52
|
+
def hooks #:nodoc:
|
53
|
+
@hooks ||= Hash.new {|h, k| h[k] = []}
|
54
|
+
end
|
55
|
+
|
56
|
+
def hooks= hooks
|
57
|
+
@hooks = hooks
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_hook(hook, &block) #:nodoc:
|
61
|
+
chain = hooks[hook]
|
62
|
+
chain << block
|
63
|
+
define_method(hook) do
|
64
|
+
return false if super == false
|
65
|
+
chain.each {|h| break false if instance_eval(&h) == false}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Returns true if the model class or any of its ancestors have defined
|
70
|
+
# hooks for the given hook key. Notice that this method cannot detect
|
71
|
+
# hooks defined using overridden methods.
|
72
|
+
#def has_hooks?(key)
|
73
|
+
#has = hooks[key] && !hooks[key].empty?
|
74
|
+
#has || ((self != Base) && superclass.has_hooks?(key))
|
75
|
+
#end
|
76
|
+
end
|
77
|
+
|
78
|
+
HOOKS.each {|h| define_method(h) {}}
|
79
|
+
HOOKS.each {|h| def_hook_method(h)}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Helene
|
2
|
+
module Sdb
|
3
|
+
class Base
|
4
|
+
class Literal < ::String
|
5
|
+
def Literal.for(*args)
|
6
|
+
new(args.join).freeze
|
7
|
+
end
|
8
|
+
def literal?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
def literal
|
12
|
+
self
|
13
|
+
end
|
14
|
+
def inspect
|
15
|
+
"#{ self.class.name }(#{ string.inspect })"
|
16
|
+
end
|
17
|
+
def string
|
18
|
+
"#{ self }"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class << Base
|
23
|
+
def literal(*args)
|
24
|
+
Literal.for(*args)
|
25
|
+
end
|
26
|
+
def Literal(*args)
|
27
|
+
Literal.for(*args)
|
28
|
+
end
|
29
|
+
def literal?(*args)
|
30
|
+
args.all?{|arg| Literal === arg}
|
31
|
+
end
|
32
|
+
def Literal?(*args)
|
33
|
+
args.all?{|arg| Literal === arg}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def literal(*args)
|
39
|
+
Literal.for(*args)
|
40
|
+
end
|
41
|
+
def Literal(*args)
|
42
|
+
Literal.for(*args)
|
43
|
+
end
|
44
|
+
def literal?(*args)
|
45
|
+
args.all?{|arg| Literal === arg}
|
46
|
+
end
|
47
|
+
def Literal?(*args)
|
48
|
+
args.all?{|arg| Literal === arg}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Helene
|
2
|
+
module Sdb
|
3
|
+
class Base
|
4
|
+
class << Base
|
5
|
+
def logger
|
6
|
+
Helene.logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def log(*args, &block)
|
10
|
+
Helene.log(*args, &block)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def logger
|
15
|
+
Helene.logger
|
16
|
+
end
|
17
|
+
|
18
|
+
def log(*args, &block)
|
19
|
+
Helene.log(*args, &block)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Helene
|
2
|
+
module Sdb
|
3
|
+
class Base
|
4
|
+
module Transaction
|
5
|
+
attr_writer :id
|
6
|
+
attr_writer :time
|
7
|
+
|
8
|
+
def call(*args, &block)
|
9
|
+
return block.call() if id?
|
10
|
+
@id = generate_id
|
11
|
+
@time = Time.now.utc
|
12
|
+
begin
|
13
|
+
block.call()
|
14
|
+
ensure
|
15
|
+
@id = @time = nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def id?
|
20
|
+
defined?(@id) and @id
|
21
|
+
end
|
22
|
+
|
23
|
+
def id
|
24
|
+
id? ? @id : generate_id
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_id
|
28
|
+
UUID.timestamp_create().to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def time?
|
32
|
+
defined?(@time) and @time
|
33
|
+
end
|
34
|
+
|
35
|
+
def time
|
36
|
+
time? ? @time : Time.now.utc
|
37
|
+
end
|
38
|
+
|
39
|
+
extend self
|
40
|
+
end
|
41
|
+
|
42
|
+
class << Base
|
43
|
+
def transaction(&block)
|
44
|
+
Transaction.call(&block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def transaction(&block)
|
49
|
+
self.class.transaction.call(&block)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module Helene
|
2
|
+
module Sdb
|
3
|
+
class Base
|
4
|
+
class Type
|
5
|
+
unless defined?(INT_FMT)
|
6
|
+
INT_N_BYTES = [42].pack('i').size
|
7
|
+
INT_N_BITS = INT_N_BYTES * 8
|
8
|
+
INT_MAX = 2 ** (INT_N_BITS - 2) - 1
|
9
|
+
INT_MIN = -INT_MAX - 1
|
10
|
+
INT_OFF = INT_MAX / 2
|
11
|
+
INT_MAX_SIZE = INT_MAX.to_s.size
|
12
|
+
INT_MIN_SIZE = INT_MAX.to_s.size
|
13
|
+
INT_SIZE = [INT_MAX_SIZE, INT_MIN_SIZE].max
|
14
|
+
INT_FMT = "%0#{ INT_SIZE }d"
|
15
|
+
end
|
16
|
+
|
17
|
+
class << Type
|
18
|
+
def ruby_to_sdb(value)
|
19
|
+
value==nil ? Sentinel.Nil : value
|
20
|
+
end
|
21
|
+
|
22
|
+
def sdb_to_ruby(value)
|
23
|
+
value==Sentinel.Nil ? nil : value
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_condition(value)
|
27
|
+
value==nil ? Sentinel.Nil : value
|
28
|
+
end
|
29
|
+
|
30
|
+
def ruby_to_sdb_for(&block)
|
31
|
+
block ||= lambda{|value| value}
|
32
|
+
lambda{|value| value==nil ? Sentinel.Nil : block.call(value)}
|
33
|
+
end
|
34
|
+
|
35
|
+
def sdb_to_ruby_for(&block)
|
36
|
+
block ||= lambda{|value| value}
|
37
|
+
lambda{|value| value==Sentinel.Nil ? nil : block.call(value)}
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_condition_for(&block)
|
41
|
+
block ||= lambda{|value| value}
|
42
|
+
lambda{|value| value==nil ? Sentinel.Nil : block.call(value)}
|
43
|
+
end
|
44
|
+
|
45
|
+
def array_of_string value
|
46
|
+
[value].flatten.map{|val| val.to_s}
|
47
|
+
end
|
48
|
+
|
49
|
+
def format(&block)
|
50
|
+
define_method(:format, &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def list
|
54
|
+
@list ||= Array.fields
|
55
|
+
end
|
56
|
+
|
57
|
+
def for name
|
58
|
+
list[name.to_s.underscore]
|
59
|
+
end
|
60
|
+
|
61
|
+
def listify(*list)
|
62
|
+
[list].join(',').strip.split(%r/\s*,\s*/)
|
63
|
+
end
|
64
|
+
|
65
|
+
def name
|
66
|
+
@name ||= super
|
67
|
+
end
|
68
|
+
attr_writer :name
|
69
|
+
|
70
|
+
def type(name, *args, &block)
|
71
|
+
name = name.to_s.underscore
|
72
|
+
type = new(name, &block)
|
73
|
+
list[type.name] = type
|
74
|
+
|
75
|
+
["set_of_#{ name.singularize }", "set_of_#{ name.pluralize }"].uniq.each do |set_of_name|
|
76
|
+
set_of_type =
|
77
|
+
new(set_of_name) do
|
78
|
+
ruby_to_sdb do |values|
|
79
|
+
values = Array(values).flatten
|
80
|
+
values.each{|value| type.ruby_to_sdb(value)}
|
81
|
+
end
|
82
|
+
sdb_to_ruby do |values|
|
83
|
+
values = Array(values).flatten
|
84
|
+
values.each{|value| type.sdb_to_ruby(value)}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
list[set_of_type.name] = set_of_type
|
88
|
+
end
|
89
|
+
|
90
|
+
type
|
91
|
+
end
|
92
|
+
alias_method 'register_type', 'type'
|
93
|
+
end
|
94
|
+
|
95
|
+
# instance methods
|
96
|
+
#
|
97
|
+
attr_accessor :name
|
98
|
+
|
99
|
+
def initialize name, &block
|
100
|
+
@name = name
|
101
|
+
@ruby_to_sdb = Type.method(:ruby_to_sdb).to_proc
|
102
|
+
@sdb_to_ruby = Type.method(:sdb_to_ruby).to_proc
|
103
|
+
@to_condition = nil
|
104
|
+
instance_eval(&block)
|
105
|
+
end
|
106
|
+
|
107
|
+
def ruby_to_sdb(value=nil, &block)
|
108
|
+
if block
|
109
|
+
@ruby_to_sdb = Type.ruby_to_sdb_for(&block)
|
110
|
+
else
|
111
|
+
@ruby_to_sdb.call(value)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def sdb_to_ruby(value=nil, &block)
|
116
|
+
if block
|
117
|
+
@sdb_to_ruby = Type.sdb_to_ruby_for(&block)
|
118
|
+
else
|
119
|
+
@sdb_to_ruby.call(value)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_condition(value=nil, &block)
|
124
|
+
if block
|
125
|
+
@to_condition = Type.to_condition_for(&block)
|
126
|
+
else
|
127
|
+
(@to_condition || @ruby_to_sdb).call(value)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def sti?
|
132
|
+
name == 'sti'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|