hungryblank-dead_simple_db 0.0.1

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/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 1
3
+ :major: 0
4
+ :minor: 0
@@ -0,0 +1,8 @@
1
+ require 'aws_sdb'
2
+ require 'digest/md5'
3
+ Dir.glob(File.dirname(__FILE__) + '/dead_simple_db/**/*.rb').each do |lib|
4
+ require lib
5
+ end
6
+
7
+ module DeadSimpleDb
8
+ end
@@ -0,0 +1,35 @@
1
+ module DeadSimpleDb
2
+
3
+ class Attribute
4
+
5
+ attr_reader :name
6
+
7
+ def initialize(name, klass, opts={})
8
+ @name, @opts = name, opts
9
+ self.klass = klass
10
+ end
11
+
12
+ def set(value)
13
+ to_instantiate = @klass
14
+ value = value.first if value.is_a?(Array) && !to_instantiate.respond_to?(:multiple)
15
+ to_instantiate = SdbNull if SdbNull::NULL_VALUES.member?(value)
16
+ @value = to_instantiate.new(value, @opts)
17
+ end
18
+
19
+ def to_s
20
+ @value.to_s
21
+ end
22
+
23
+ def value
24
+ @value.casted
25
+ end
26
+
27
+ private
28
+
29
+ def klass=(klass)
30
+ @klass = instance_eval('Sdb' + klass.to_s)
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,17 @@
1
+ module DeadSimpleDb
2
+
3
+ class AttributeDefinition
4
+
5
+ attr_reader :name
6
+
7
+ def initialize(name, klass, opts={})
8
+ @name, @klass, @opts = name, klass, opts
9
+ end
10
+
11
+ def to_attr
12
+ Attribute.new(@name, @klass, @opts)
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,27 @@
1
+ module DeadSimpleDb
2
+
3
+ class SdbBoolean
4
+
5
+ def initialize(value, opts={})
6
+ @value_before_cast = value
7
+ end
8
+
9
+ def casted
10
+ @casted = if @value_before_cast || false
11
+ if @value_before_cast.respond_to?(:downcase)
12
+ @value_before_cast.downcase == 'false' ? false : true
13
+ else
14
+ true
15
+ end
16
+ else
17
+ false
18
+ end
19
+ end
20
+
21
+ def to_s
22
+ casted.to_s.upcase
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,31 @@
1
+ module DeadSimpleDb
2
+
3
+ class SdbDate
4
+
5
+ DEFAULT_OPTS = {:format => '%Y-%m-%d'}
6
+
7
+ def initialize(value, opts={})
8
+ @opts = DEFAULT_OPTS.merge(opts)
9
+ @value_before_cast = value
10
+ end
11
+
12
+ def casted
13
+ @casted = @value_before_cast if @value_before_cast.is_a?(Date)
14
+ @casted ||= begin
15
+ if @value_before_cast.respond_to?(:to_date)
16
+ @value_before_cast.to_date
17
+ elsif Date.respond_to?(:strptime)
18
+ Date.strptime(@value_before_cast, @opts[:format])
19
+ else
20
+ Date.new(*(@value_before_cast.split('-').map { |n| n.to_i }))
21
+ end
22
+ end
23
+ end
24
+
25
+ def to_s
26
+ @string ||= casted.strftime(@opts[:format])
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,28 @@
1
+ module DeadSimpleDb
2
+
3
+ class SdbFloat
4
+
5
+ include NegativeNumber
6
+
7
+ DEFAULT_OPTS = {:digits => 8, :decimals => 2}
8
+
9
+ def initialize(value, opts={})
10
+ @opts = DEFAULT_OPTS.merge(opts)
11
+ @value_before_cast = value
12
+ end
13
+
14
+ def casted
15
+ @casted ||= @value_before_cast.to_f
16
+ end
17
+
18
+ def to_s
19
+ @string ||= prepending_minus(casted.to_s) do |string|
20
+ integer, decimal = *string.split('.')
21
+ integer.rjust(@opts[:digits] - @opts[:decimals], '0') + '.' +
22
+ decimal[0..@opts[:decimals] - 1].ljust(@opts[:decimals], '0')
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,26 @@
1
+ module DeadSimpleDb
2
+
3
+ class SdbInteger
4
+
5
+ include NegativeNumber
6
+
7
+ DEFAULT_OPTS = {:digits => 6}
8
+
9
+ def initialize(value, opts={})
10
+ @opts = DEFAULT_OPTS.merge(opts)
11
+ @value_before_cast = value
12
+ end
13
+
14
+ def casted
15
+ @casted ||= @value_before_cast.to_i
16
+ end
17
+
18
+ def to_s
19
+ @string ||= prepending_minus(casted.to_s) do |string|
20
+ string.rjust(@opts[:digits], '0')
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,21 @@
1
+ module DeadSimpleDb
2
+
3
+ class SdbNull
4
+
5
+ NULL_VALUES = [nil, '', 'NULL']
6
+
7
+ def initialize(value, opts={})
8
+ raise "#{value} is not a null value" unless NULL_VALUES.member?(value)
9
+ end
10
+
11
+ def casted
12
+ nil
13
+ end
14
+
15
+ def to_s
16
+ 'NULL'
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,23 @@
1
+ module DeadSimpleDb
2
+
3
+ class SdbString
4
+
5
+ def initialize(value, opts={})
6
+ @value_before_cast = value
7
+ end
8
+
9
+ def casted
10
+ @casted = case @value_before_cast
11
+ when String : @value_before_cast
12
+ else
13
+ @value_before_cast.to_s
14
+ end
15
+ end
16
+
17
+ def to_s
18
+ casted
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,29 @@
1
+ module DeadSimpleDb
2
+
3
+ class SdbTime
4
+
5
+ DEFAULT_OPTS = {:format => '%Y-%m-%d %H:%M:%S'}
6
+
7
+ def initialize(value, opts={})
8
+ @opts = DEFAULT_OPTS.merge(opts)
9
+ @value_before_cast = value
10
+ end
11
+
12
+ def casted
13
+ @casted = @value_before_cast if @value_before_cast.is_a?(Time)
14
+ @casted ||= begin
15
+ if @value_before_cast.respond_to?(:to_time)
16
+ @value_before_cast.to_time
17
+ else
18
+ Time.local(*(@value_before_cast.split(/-|\s|:/).map { |n| n.to_i }))
19
+ end
20
+ end
21
+ end
22
+
23
+ def to_s
24
+ @string ||= casted.strftime(@opts[:format])
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,173 @@
1
+ require 'aws_sdb'
2
+ require 'digest/md5'
3
+
4
+ module DeadSimpleDb
5
+
6
+ class Base
7
+
8
+ attr_reader :attributes_hash
9
+
10
+ class << self
11
+
12
+ #Define the SimpleDb domain you want to use to store the current class
13
+ #
14
+ # class Employee < DeadSimpleDb::Base
15
+ #
16
+ # domain 'hr_application'
17
+ #
18
+ # end
19
+ #
20
+ #this will store all the instance of Employee class in the 'hr_application' domain
21
+ def domain(domain = nil)
22
+ return @domain unless domain
23
+ @domain = domain
24
+ end
25
+
26
+ #Refresh the current connection to SimpleDB
27
+ def reconnect!
28
+ @service = AwsSdb::Service.new
29
+ end
30
+
31
+ #The AwsSdb::Service currently used
32
+ def service
33
+ @service ||= AwsSdb::Service.new
34
+ end
35
+
36
+ #Create the SimpleDB domain used by the class
37
+ def setup
38
+ service.create_domain(@domain)
39
+ end
40
+
41
+ #Gets a specific record identified by serial
42
+ #
43
+ # Employee.get("78af7ab2ebb10e71e7a936564621bbf3")
44
+ #
45
+ def get(serial)
46
+ new(service.get_attributes(@domain, serial), :serial => serial)
47
+ end
48
+
49
+ #Lets you query the stored data
50
+ #
51
+ #to find the first employee who's name is Chuck
52
+ #
53
+ # Employee.find(:first, "['name' = 'Chuck']")
54
+ #
55
+ #to find all the employees who are designers
56
+ #
57
+ # Employee.find(:all, "['role' = 'designer']")
58
+ #
59
+ #please note the query syntax is SimpleDB custom syntax, refer to SimpleDB docs for details
60
+ #
61
+ def find(how_many, query, opts={})
62
+ results = find_ids(how_many, query, opts).map { |o| get(o) }
63
+ return results.first if how_many == :first
64
+ results
65
+ end
66
+
67
+ #The same as find but instead of returning the full object just returns
68
+ #the object ids satisfyng the query
69
+ #
70
+ def find_ids(how_many, query, opts={})
71
+ limit = case how_many
72
+ when :all : nil
73
+ when :first : 1
74
+ else
75
+ how_many
76
+ end
77
+ service.query(@domain, query, limit).first
78
+ end
79
+
80
+ def attr_definitions
81
+ @attr_definitions ||= []
82
+ end
83
+
84
+ private
85
+
86
+ def attr_sdb(name, klass, opts={})
87
+ define_method(name) do
88
+ attributes_hash[name.to_sym].value
89
+ end
90
+ define_method("#{name}=") do |value|
91
+ attributes_hash[name.to_sym].set(value)
92
+ end
93
+ attr_definitions << AttributeDefinition.new(name, klass, opts)
94
+ end
95
+
96
+ end
97
+
98
+ #Instantiates a new object passing an hash
99
+ #
100
+ # new_employee = Emloyee.new(:name => 'Arturo', :surname => 'Bandini')
101
+ #
102
+ #please note that this does't stores the object on SimpleDB
103
+ #it's the save method that performs the actual network operation of storing the data
104
+ def initialize(attributes_hash={}, opts={})
105
+ read_attributes(attributes_hash)
106
+ @serial = opts[:serial]
107
+ end
108
+
109
+ #Updates the attribute of the object using the hash passed as parameter
110
+ def update_attributes(attributes_hash, opts={})
111
+ read_attributes(attributes_hash)
112
+ end
113
+
114
+ def attributes_hash
115
+ @attributes_hash ||= attributes.inject({}) do |hash, attribute|
116
+ hash[attribute.name] = attribute
117
+ hash
118
+ end
119
+ end
120
+
121
+ def attributes_hash_for_call
122
+ attributes_hash.merge({:class_name => self.class.to_s})
123
+ end
124
+
125
+ #Saves the current record on SimpleDB
126
+ def save
127
+ service.put_attributes(domain, serial, attributes_hash_for_call)
128
+ serial
129
+ end
130
+
131
+ #Deletes the current record from SimpleDB
132
+ def destroy
133
+ service.delete_attributes(domain, serial)
134
+ end
135
+
136
+ #The unique identifier for the current record
137
+ def serial
138
+ @serial ||= begin
139
+ serial = serial_string
140
+ serial << Time.now.to_f.to_s
141
+ Digest::MD5.hexdigest(serial)
142
+ end
143
+ end
144
+
145
+ private
146
+
147
+ def service
148
+ self.class.service
149
+ end
150
+
151
+ def domain
152
+ self.class.domain
153
+ end
154
+
155
+ def serial_string
156
+ labels = attributes_hash.map { |k, v| k.to_s + v.to_s }.join('')
157
+ end
158
+
159
+ def read_attributes(hash)
160
+ attribute_names = attributes.map { |a| a.name }
161
+ attribute_names.map! { |an| an.to_s } if hash.keys.first.is_a?(String)
162
+ attributes.each_with_index do |attribute, index|
163
+ attribute.set(hash[attribute_names[index]])
164
+ end
165
+ end
166
+
167
+ def attributes
168
+ @attributes ||= self.class.attr_definitions.map { |d| d.to_attr }
169
+ end
170
+
171
+ end
172
+
173
+ end
@@ -0,0 +1,17 @@
1
+ module DeadSimpleDb
2
+
3
+ module NegativeNumber
4
+
5
+ def negative?
6
+ casted < 0
7
+ end
8
+
9
+ def prepending_minus(string)
10
+ raise "needs a block" unless block_given?
11
+ string.sub!('-', '') if negative?
12
+ string = yield(string)
13
+ negative? ? '-' + string : string
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class AttributeTest < Test::Unit::TestCase
4
+
5
+ include DeadSimpleDb
6
+
7
+ should "set the name" do
8
+ attribute = Attribute.new(:number, 'Integer')
9
+ assert_equal :number, attribute.name
10
+ end
11
+
12
+ should "should instantiate the correct class" do
13
+ SdbInteger.expects(:new).with('10', :decimals => 10)
14
+ attribute = Attribute.new(:number, 'Integer', :decimals => 10)
15
+ attribute.set('10')
16
+ end
17
+
18
+ should "should instantiate a null when a null value is passed" do
19
+ null_value = SdbNull::NULL_VALUES.first
20
+ SdbNull.expects(:new).with(null_value, :decimals => 10)
21
+ attribute = Attribute.new(:number, 'Integer', :decimals => 10)
22
+ attribute.set(null_value)
23
+ end
24
+
25
+ should "should call to_s on its value" do
26
+ integer_mock = Mocha::Mock.new
27
+ SdbInteger.expects(:new).with('10', :decimals => 10).returns(integer_mock)
28
+ attribute = Attribute.new(:number, 'Integer', :decimals => 10)
29
+ attribute.set('10')
30
+ integer_mock.expects(:to_s)
31
+ attribute.to_s
32
+ end
33
+
34
+ should "should cast to return value" do
35
+ integer_mock = Mocha::Mock.new
36
+ SdbInteger.expects(:new).with('10', :decimals => 10).returns(integer_mock)
37
+ attribute = Attribute.new(:number, 'Integer', :decimals => 10)
38
+ attribute.set('10')
39
+ integer_mock.expects(:casted)
40
+ attribute.value
41
+ end
42
+
43
+ end
@@ -0,0 +1,85 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ Dir.glob(File.dirname(__FILE__) + '/dummies/*.rb').each do |file|
3
+ require file
4
+ end
5
+
6
+ class DeadSimpleDbTest < Test::Unit::TestCase
7
+
8
+ include DeadSimpleDb
9
+
10
+ def setup
11
+ @service = Mocha::Mock.new
12
+ @arturo = Employee.new(:name => 'Arturo', :surname => 'Bandini')
13
+ AwsSdb::Service.stubs(:new).returns(@service)
14
+ Employee.reconnect!
15
+ end
16
+
17
+ should "create the domain with setup" do
18
+ @service.expects(:list_domains).returns([])
19
+ @service.expects(:create_domain).with('test_domain')
20
+ Employee.setup
21
+ end
22
+
23
+ should "put attributes on save" do
24
+ @arturo.expects(:serial).returns('serial_1').times(2)
25
+ put_hash = @arturo.attributes_hash_for_call
26
+ @service.expects(:put_attributes).with('test_domain', 'serial_1', put_hash).returns(nil)
27
+ @arturo.save
28
+ end
29
+
30
+
31
+ should "delete attributes on destroy" do
32
+ @arturo.expects(:serial).returns('serial_1')
33
+ @service.expects(:delete_attributes).with('test_domain', 'serial_1').returns(nil)
34
+ @arturo.destroy
35
+ end
36
+
37
+ should "add class name to call hash" do
38
+ assert_equal 'Employee', @arturo.attributes_hash_for_call[:class_name]
39
+ end
40
+
41
+ should "have a serial based on timestamp" do
42
+ Time.stubs(:now).returns(Time.utc(2000,"jan",1,20,15,1))
43
+ @arturo.expects(:serial_string).returns('nameArturosurnameBandini')
44
+ assert_equal Digest::MD5.hexdigest('nameArturosurnameBandini946757701.0'), @arturo.serial
45
+ end
46
+
47
+ should "get attributes when getting a specific record" do
48
+ @service.expects(:get_attributes).with('test_domain', 'serial_1').returns({:name => 'Arturo', :surname => 'Bandini'})
49
+ fetched_employee = Employee.get('serial_1')
50
+ assert Employee = fetched_employee.class
51
+ assert_equal 'serial_1', fetched_employee.serial
52
+ end
53
+
54
+ should "issue a query when finding ids" do
55
+ @service.expects(:query).with('test_domain', "['name' = 'Arturo']", nil).returns(['e34979d4dc7b5b949fa67916acb63743'])
56
+ Employee.find_ids(:all, "['name' = 'Arturo']")
57
+ end
58
+
59
+ should "fetch ids and after get attributes when finding" do
60
+ Employee.expects(:find_ids).with(:all, "['name' = 'Arturo']", {}).returns(['e34979d4dc7b5b949fa67916acb63743'])
61
+ Employee.expects(:get).with("e34979d4dc7b5b949fa67916acb63743")
62
+ Employee.find(:all, "['name' = 'Arturo']")
63
+ end
64
+
65
+ should "instantiate an attribute definition when sdb_attr is called" do
66
+ AttributeDefinition.expects(:new).with(:number, 'Integer', :decimals => 10).returns('w')
67
+ attr_def_ary = Mocha::Mock.new
68
+ Employee.expects(:attr_definitions).returns(attr_def_ary)
69
+ attr_def_ary.expects('<<').with('w')
70
+ Employee.send(:attr_sdb, :number, 'Integer', :decimals => 10)
71
+ end
72
+
73
+ should "read attributes from hash with symbols or strings" do
74
+ attribute = @arturo.send(:attributes).find { |a| a.name == :name }
75
+ attribute.expects(:set).with('Arturo')
76
+ @arturo.update_attributes(:name => 'Arturo')
77
+ attribute.expects(:set).with('Arturo string')
78
+ @arturo.update_attributes('name' => 'Arturo string')
79
+ end
80
+
81
+ should "build methods to access attributes" do
82
+ assert_equal 'Arturo', @arturo.name
83
+ end
84
+
85
+ end
@@ -0,0 +1,12 @@
1
+ class Employee < DeadSimpleDb::Base
2
+
3
+ domain 'test_domain'
4
+
5
+ attr_sdb :name, 'String'
6
+ attr_sdb :surname, 'String'
7
+ attr_sdb :number, 'Integer', :digits => 10
8
+ attr_sdb :rating, 'Float', :digits => 10, :decimals => 4
9
+ attr_sdb :joined, 'Date'
10
+ attr_sdb :last_login, 'Time'
11
+
12
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SdbBooleanTest < Test::Unit::TestCase
4
+
5
+ include DeadSimpleDb
6
+
7
+ should "cast correctly a true/false string" do
8
+ boolean = SdbBoolean.new('true')
9
+ assert_equal true, boolean.casted
10
+ boolean = SdbBoolean.new('false')
11
+ assert_equal false, boolean.casted
12
+ end
13
+
14
+ should "be identical if provided a boolean" do
15
+ boolean = SdbBoolean.new(true)
16
+ assert_equal true, boolean.casted
17
+ boolean = SdbBoolean.new(false)
18
+ assert_equal false, boolean.casted
19
+ end
20
+
21
+ should "be a string when converted to string" do
22
+ boolean = SdbBoolean.new('yeah')
23
+ assert_equal 'TRUE', boolean.to_s
24
+ boolean = SdbBoolean.new('false')
25
+ assert_equal 'FALSE', boolean.to_s
26
+ end
27
+
28
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SdbDateTest < Test::Unit::TestCase
4
+
5
+ include DeadSimpleDb
6
+
7
+ should "cast a string to date" do
8
+ date = SdbDate.new('2008-10-31')
9
+ assert_equal Date.new(2008, 10, 31), date.casted
10
+ end
11
+
12
+ should "be identical if provided a date" do
13
+ date = SdbDate.new(Date.new(2008, 10, 31))
14
+ assert_equal Date.new(2008, 10, 31), date.casted
15
+ end
16
+
17
+ should "be formatted if printed as string" do
18
+ date = SdbDate.new(Date.new(2008, 10, 31))
19
+ assert_equal '2008-10-31', date.to_s
20
+ end
21
+
22
+ end
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SdbFloatTest < Test::Unit::TestCase
4
+
5
+ include DeadSimpleDb
6
+
7
+ should "cast a string to float" do
8
+ float = SdbFloat.new('10')
9
+ assert_equal 10.0, float.casted
10
+ end
11
+
12
+ should "be identical if provided a float" do
13
+ float = SdbFloat.new(10.0)
14
+ assert_equal 10.0, float.casted
15
+ end
16
+
17
+ should "be casted if provided an integer" do
18
+ float = SdbFloat.new(10)
19
+ assert_equal 10.0, float.casted
20
+ end
21
+
22
+ should "be padded if printed as string" do
23
+ float = SdbFloat.new(100.1, :digits => 6)
24
+ assert_equal '0100.10', float.to_s
25
+ end
26
+
27
+ should "be trimmed if string is too long" do
28
+ float = SdbFloat.new(100.11231312312, :digits => 6)
29
+ assert_equal '0100.11', float.to_s
30
+ end
31
+
32
+ should "handle negative string" do
33
+ float = SdbFloat.new('-100.1', :digits => 6)
34
+ assert_equal '-0100.10', float.to_s
35
+ end
36
+
37
+ should "handle negative float" do
38
+ float = SdbFloat.new('-100.5', :digits => 6)
39
+ assert_equal '-0100.50', float.to_s
40
+ end
41
+
42
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SdbIntegerTest < Test::Unit::TestCase
4
+
5
+ include DeadSimpleDb
6
+
7
+ should "cast a string to integer" do
8
+ integer = SdbInteger.new('10')
9
+ assert_equal 10, integer.casted
10
+ end
11
+
12
+ should "be identical if provided an integer" do
13
+ integer = SdbInteger.new(10)
14
+ assert_equal 10, integer.casted
15
+ end
16
+
17
+ should "be casted if provided a float" do
18
+ integer = SdbInteger.new(10.99)
19
+ assert_equal 10, integer.casted
20
+ end
21
+
22
+ should "be padded if printed as string" do
23
+ integer = SdbInteger.new(10, :digits => 6)
24
+ assert_equal '000010', integer.to_s
25
+ end
26
+
27
+ should "be padded and have minus if printed as string" do
28
+ integer = SdbInteger.new(-10, :digits => 6)
29
+ assert_equal '-000010', integer.to_s
30
+ end
31
+
32
+ should "handle minus if provided negative string" do
33
+ integer = SdbInteger.new('-15', :digits => 6)
34
+ assert_equal '-000015', integer.to_s
35
+ end
36
+
37
+ end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SdbNullTest < Test::Unit::TestCase
4
+
5
+ include DeadSimpleDb
6
+
7
+ should "cast a string to nil" do
8
+ null = SdbNull.new('')
9
+ assert_equal nil, null.casted
10
+ end
11
+
12
+ should "be identical if provided a nil" do
13
+ null = SdbNull.new(nil)
14
+ assert_equal nil, null.casted
15
+ end
16
+
17
+ should "be a NULL when converted to string" do
18
+ null = SdbNull.new('')
19
+ assert_equal 'NULL', null.to_s
20
+ end
21
+
22
+ should "raise an exception if provided a non null string" do
23
+ assert_raise(RuntimeError) { SdbNull.new('4') }
24
+ end
25
+
26
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SdbStringTest < Test::Unit::TestCase
4
+
5
+ include DeadSimpleDb
6
+
7
+ should "cast a integer to string" do
8
+ string = SdbString.new(10)
9
+ assert_equal '10', string.casted
10
+ end
11
+
12
+ should "be identical if provided a string" do
13
+ string = SdbString.new('foo')
14
+ assert_equal 'foo', string.casted
15
+ end
16
+
17
+ should "be a string when converted to string" do
18
+ string = SdbString.new(1.1)
19
+ assert_equal '1.1', string.to_s
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SdbTimeTest < Test::Unit::TestCase
4
+
5
+ include DeadSimpleDb
6
+
7
+ should "cast a string to time" do
8
+ time = SdbTime.new('2008-10-31 23:35:41')
9
+ assert_equal Time.local(2008, 10, 31, 23, 35, 41), time.casted
10
+ end
11
+
12
+ should "be identical if provided a time" do
13
+ time = SdbTime.new(Time.local(2008, 10, 31, 23, 35, 41))
14
+ assert_equal Time.local(2008, 10, 31, 23, 35, 41), time.casted
15
+ end
16
+
17
+ should "be formatted if printed as string" do
18
+ time = SdbTime.new(Time.local(2008, 10, 31, 23, 35, 41))
19
+ assert_equal '2008-10-31 23:35:41', time.to_s
20
+ end
21
+
22
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'dead_simple_db'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hungryblank-dead_simple_db
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paolo Negri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-26 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: aws-sdb
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: TODO
25
+ email: hungryblank@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - VERSION.yml
34
+ - lib/dead_simple_db.rb
35
+ - lib/dead_simple_db
36
+ - lib/dead_simple_db/negative_number.rb
37
+ - lib/dead_simple_db/dead_simple_db.rb
38
+ - lib/dead_simple_db/datatypes
39
+ - lib/dead_simple_db/datatypes/sdb_time.rb
40
+ - lib/dead_simple_db/datatypes/sdb_integer.rb
41
+ - lib/dead_simple_db/datatypes/sdb_float.rb
42
+ - lib/dead_simple_db/datatypes/sdb_null.rb
43
+ - lib/dead_simple_db/datatypes/sdb_string.rb
44
+ - lib/dead_simple_db/datatypes/sdb_date.rb
45
+ - lib/dead_simple_db/datatypes/sdb_boolean.rb
46
+ - lib/dead_simple_db/attribute.rb
47
+ - lib/dead_simple_db/attribute_definition.rb
48
+ - test/dead_simple_db_test.rb
49
+ - test/sdb_float_test.rb
50
+ - test/sdb_date_test.rb
51
+ - test/dummies
52
+ - test/dummies/employee.rb
53
+ - test/sdb_integer_test.rb
54
+ - test/sdb_string_test.rb
55
+ - test/attribute_test.rb
56
+ - test/sdb_time_test.rb
57
+ - test/sdb_boolean_test.rb
58
+ - test/test_helper.rb
59
+ - test/sdb_null_test.rb
60
+ has_rdoc: true
61
+ homepage: http://github.com/hungryblank/dead_simple_db
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --inline-source
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.2.0
84
+ signing_key:
85
+ specification_version: 2
86
+ summary: Object oriented library to store data in Amazon SimpleDB AWS
87
+ test_files: []
88
+