ar-s3-columns 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cbaf52e9ac8fdea731bbf550b27185955806509
4
- data.tar.gz: f263b3acc8c0a3a8b6eeef8f6fe653abb8295a83
3
+ metadata.gz: 282bdd2f9a64ab3ce8b5eb0d1da444561fa5a349
4
+ data.tar.gz: e3c3819dc1fb3e07e77771b0725e0bdedc213139
5
5
  SHA512:
6
- metadata.gz: fea92bf6329496d3ed002419fd006702c58287feeb2d4cb0a5a68813034d75b731caa5e6728ec88d568ac2fbdc76c7e91e71bf3ac19594a47871b7c59a103bf0
7
- data.tar.gz: 6e4aba64fdfe104f92a9ac9898e988a91b6f67aa1f5b055c278a280addcdaceb4ff03d733509bf71da301a9048a89b9d7618e7297335e8ee4ad98369d774db05
6
+ metadata.gz: 9f21b8cc024c18f83a05b1b7259d24f235faa018cb012f629dc51149fb4c86e11fc032013d0576ca0c074063d7a5238b94083bbadd0ac18cba0c8c67d01b1072
7
+ data.tar.gz: 366824645f80a8875cdb560dbfcfa5e5e5546bdfddf9b85cd6013fe473db118c1f5ec4e1aa42467d0ecfa6452afb399566b796cde409e8b2732ea4264ece25aa
@@ -29,18 +29,12 @@ module S3Columns
29
29
  def s3_column_#{column_name}
30
30
  if self.persisted? && key_path = read_attribute(:#{column_name})
31
31
  key = S3Columns.s3_connection.buckets["#{options[:s3_bucket]}"].objects[key_path]
32
-
33
- if key.exists?
32
+ # Retry in case it is not persisted in S3 yet
33
+ Retryable.retryable :on => [AWS::S3::Errors::NoSuchKey], :tries => 10, :sleep => 1 do
34
34
  @#{column_name} ||= Marshal.load(key.read)
35
- else
36
- # Retry in case it is not persisted in S3 yet
37
- Retryable.retryable :on => [AWS::S3::Errors::NoSuchKey], :tries => 10, :sleep => 1 do
38
- @#{column_name} ||= Marshal.load(key.read)
39
- end
40
35
  end
41
-
42
36
  else
43
- nil
37
+ @#{column_name}
44
38
  end
45
39
  end
46
40
  }
@@ -54,6 +48,7 @@ module S3Columns
54
48
  S3Columns.s3_connection.buckets["#{options[:s3_bucket]}"].objects[key_path].write(marshalled_value, write_options)
55
49
  # update column with new key
56
50
  write_attribute(:#{column_name}, key_path)
51
+ @#{column_name} = value
57
52
  end
58
53
  }
59
54
  end
@@ -1,3 +1,3 @@
1
1
  module S3Columns
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -45,6 +45,23 @@ describe "S3Columns" do
45
45
  test_object = ClassWithS3Columns.create(name: 'hey')
46
46
  assert_equal "hey", test_object.name
47
47
  end
48
+
49
+ it "memoizes value on write" do
50
+ SimpleUUID::UUID.any_instance.stubs(:to_guid).returns('unique')
51
+ test_object = ClassWithS3Columns.new
52
+ v = {hi: 'hello'}
53
+
54
+ @key_stub.expects(:write).with(Marshal.dump(v), {})
55
+ @objects_stub.expects(:[]).with("extra_data/unique").returns(@key_stub)
56
+ @buckets_stub.expects(:[]).with("test").returns(stub(objects: @objects_stub))
57
+ @s3_stub.expects(:buckets).returns(@buckets_stub)
58
+
59
+ test_object.s3_column_extra_data = v
60
+ assert_equal test_object.s3_column_extra_data, v
61
+
62
+ test_object = ClassWithS3Columns.new(extra_data: v)
63
+ assert_equal test_object.extra_data, v
64
+ end
48
65
 
49
66
  it "uploads marshalled value of columns to s3 and save s3 key to db" do
50
67
  SimpleUUID::UUID.any_instance.stubs(:to_guid).returns('unique')
@@ -60,11 +77,10 @@ describe "S3Columns" do
60
77
  assert_equal "extra_data/unique", test_object.read_attribute(:extra_data)
61
78
  end
62
79
 
63
- it "reads from S3 with key in db and if it exists" do
80
+ it "reads from S3 with key in db" do
64
81
  test_object = ClassWithS3Columns.create(name: "unique")
65
82
  test_object.send(:write_attribute, :extra_data, 'some/key')
66
83
 
67
- @key_stub.expects(:exists?).returns(true)
68
84
  @key_stub.expects(:read).returns(Marshal.dump("some data"))
69
85
  @objects_stub.expects(:[]).with("some/key").returns(@key_stub)
70
86
  @buckets_stub.expects(:[]).with("test").returns(stub(objects: @objects_stub))
@@ -72,18 +88,6 @@ describe "S3Columns" do
72
88
  assert_equal test_object.s3_column_extra_data, "some data"
73
89
  end
74
90
 
75
- it "retries S3 read, when S3 key in db, but does not exists (usually because S3 has not persisted object yet)" do
76
- test_object = ClassWithS3Columns.create(name: "unique")
77
- test_object.send(:write_attribute, :extra_data, 'some/key')
78
-
79
- Retryable.expects(:retryable)
80
- @key_stub.expects(:exists?).returns(false)
81
- @objects_stub.expects(:[]).with("some/key").returns(@key_stub)
82
- @buckets_stub.expects(:[]).with("test").returns(stub(objects: @objects_stub))
83
- @s3_stub.expects(:buckets).returns(@buckets_stub)
84
- test_object.s3_column_extra_data
85
- end
86
-
87
91
  it "returns nil and do not hit S3, if key is not in db" do
88
92
  @s3_stub.expects(:buckets).at_most(0)
89
93
  test_object = ClassWithS3Columns.create(name: "unique")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-s3-columns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-21 00:00:00.000000000 Z
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler