simply_stored 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -186,6 +186,9 @@ Both the CouchDB backend and the SimpleDB backend have support for S3 attachment
|
|
186
186
|
log.save
|
187
187
|
# => true
|
188
188
|
|
189
|
+
log.data_size
|
190
|
+
# => 11238132
|
191
|
+
|
189
192
|
This will create an item on S3 in the specified bucket. The item will use the ID of the log object as the key and the body will be the data attribute. This way you can store big files outside of CouchDB or SimpleDB.
|
190
193
|
|
191
194
|
|
@@ -2,7 +2,7 @@ module SimplyStored
|
|
2
2
|
module Couch
|
3
3
|
module HasMany
|
4
4
|
def has_many(name, options = {})
|
5
|
-
|
5
|
+
properties << SimplyStored::Couch::HasMany::Property.new(self, name, options)
|
6
6
|
end
|
7
7
|
|
8
8
|
def define_has_many_getter(name)
|
@@ -2,7 +2,7 @@ module SimplyStored
|
|
2
2
|
module Couch
|
3
3
|
module HasOne
|
4
4
|
def has_one(name, options = {})
|
5
|
-
|
5
|
+
properties << SimplyStored::Couch::HasOne::Property.new(self, name, options)
|
6
6
|
end
|
7
7
|
|
8
8
|
def define_has_one_setter(name)
|
@@ -21,6 +21,7 @@ module SimplyStored
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def save(validate = true)
|
24
|
+
update_attachment_sizes
|
24
25
|
if ret = super(validate)
|
25
26
|
save_attachments
|
26
27
|
end
|
@@ -28,6 +29,7 @@ module SimplyStored
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def save!(*args)
|
32
|
+
update_attachment_sizes
|
31
33
|
super
|
32
34
|
save_attachments
|
33
35
|
end
|
@@ -64,6 +66,17 @@ module SimplyStored
|
|
64
66
|
end
|
65
67
|
end
|
66
68
|
end
|
69
|
+
|
70
|
+
def update_attachment_sizes
|
71
|
+
if @_s3_attachments
|
72
|
+
@_s3_attachments.each do |name, attachment|
|
73
|
+
if attachment[:dirty]
|
74
|
+
value = attachment[:value].is_a?(String) ? attachment[:value] : attachment[:value].to_json
|
75
|
+
send("#{name}_size=", (value.size rescue nil))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
67
80
|
|
68
81
|
def s3_attachment_key(name)
|
69
82
|
"#{self.class.name.tableize}/#{name}/#{id}"
|
@@ -76,11 +89,20 @@ module SimplyStored
|
|
76
89
|
require 's3/right_s3'
|
77
90
|
require 's3/right_s3_interface'
|
78
91
|
|
92
|
+
name = name.to_sym
|
93
|
+
|
79
94
|
self.class.instance_eval do
|
80
95
|
attr_accessor :_s3_options
|
81
96
|
end
|
82
97
|
|
83
|
-
|
98
|
+
self.class_eval do
|
99
|
+
if respond_to?(:property)
|
100
|
+
property "#{name}_size"
|
101
|
+
else
|
102
|
+
simpledb_integer "#{name}_size"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
84
106
|
raise ArgumentError, "No bucket name specified for attachment #{name}" if options[:bucket].blank?
|
85
107
|
options = {
|
86
108
|
:permissions => 'private',
|
@@ -10,7 +10,7 @@ class CouchTest < Test::Unit::TestCase
|
|
10
10
|
|
11
11
|
context "design documents" do
|
12
12
|
should "delete all" do
|
13
|
-
db = "http://
|
13
|
+
db = "http://127.0.0.1:5984/#{CouchPotato::Config.database_name}"
|
14
14
|
assert_equal 0, SimplyStored::Couch.delete_all_design_documents(db)
|
15
15
|
user = User.create
|
16
16
|
Post.create(:user => user)
|
@@ -148,7 +148,8 @@ class CouchTest < Test::Unit::TestCase
|
|
148
148
|
end
|
149
149
|
|
150
150
|
should "allow to order the results" do
|
151
|
-
|
151
|
+
assert_not_equal User.find(:all).map(&:id), User.find(:all, :order => :desc).map(&:id)
|
152
|
+
assert_equal User.find(:all).map(&:id).reverse, User.find(:all, :order => :desc).map(&:id)
|
152
153
|
end
|
153
154
|
end
|
154
155
|
|
@@ -1429,6 +1430,33 @@ class CouchTest < Test::Unit::TestCase
|
|
1429
1430
|
@bucket.expects(:put).with(anything, '["one log entry","and another one"]', {}, anything)
|
1430
1431
|
@log_item.save
|
1431
1432
|
end
|
1433
|
+
|
1434
|
+
context "when noting the size of the attachment" do
|
1435
|
+
should "store on upload" do
|
1436
|
+
@log_item.log_data = 'abc'
|
1437
|
+
@bucket.expects(:put)
|
1438
|
+
assert @log_item.save
|
1439
|
+
assert_equal 3, @log_item.log_data_size
|
1440
|
+
end
|
1441
|
+
|
1442
|
+
should "update the size if the attachment gets updated" do
|
1443
|
+
@log_item.log_data = 'abc'
|
1444
|
+
@bucket.stubs(:put)
|
1445
|
+
assert @log_item.save
|
1446
|
+
assert_equal 3, @log_item.log_data_size
|
1447
|
+
|
1448
|
+
@log_item.log_data = 'example'
|
1449
|
+
assert @log_item.save
|
1450
|
+
assert_equal 7, @log_item.log_data_size
|
1451
|
+
end
|
1452
|
+
|
1453
|
+
should "store the size of json attachments" do
|
1454
|
+
@log_item.log_data = ['abc']
|
1455
|
+
@bucket.stubs(:put)
|
1456
|
+
assert @log_item.save
|
1457
|
+
assert_equal ['abc'].to_json.size, @log_item.log_data_size
|
1458
|
+
end
|
1459
|
+
end
|
1432
1460
|
end
|
1433
1461
|
|
1434
1462
|
context "when fetching the data" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simply_stored
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathias Meyer, Jonathan Weiss
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-27 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|