saviour 0.4.3 → 0.4.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 319d2711e341ea64600303c886f98cba1d698946
4
- data.tar.gz: 2d48a9c86baa03ade58dd34b5932735080120b2c
3
+ metadata.gz: 74f1d7faa90b8712dbf65f86ce592db60c296ac3
4
+ data.tar.gz: 680a73e0bb124fc7de9ca66ea09e1ee486088731
5
5
  SHA512:
6
- metadata.gz: 0d49c6f41a7ab74b67e52b99e85e13c6c653c7fce639231835ba9ca1cbd6991213231558505ea9d42be51d0b173226a144d5657779ef36570e3960ad156b4ddb
7
- data.tar.gz: 4aad76005e7bb31d153a8e135816ac255cd2e812cd1af00360147c1122c1eba54f296d70f5cd363f139fa858f3fd3c2f6db61c27eff4826a5dfc23afe1833963
6
+ metadata.gz: a152333b01f299de797c04ab0d76a07401ebdf673cb2e2d93f02151b495b4d8d18bafbec884b9ddb53aaf12ae94bf409d0e1769ae60e0e06fa939be14486a2ea
7
+ data.tar.gz: eabe42debcdc6c8caf0e48f8fbb4645964bb848329198844607ef0b7b3cd93bd41855bfdf5ccb71aaaac717921c10b6c6203203ad203d3eb1c03236fced79860
data/README.md CHANGED
@@ -267,6 +267,30 @@ on a path that already exists. This behaviour in enabled by default, but you can
267
267
  argument when instantiating the storage: `overwrite_protection: false`. This feature requires an additional HEAD request
268
268
  to verify existence for every write.
269
269
 
270
+ NOTE: Be aware that S3 has a limit of 1024 bytes for the keys (paths) used. Be sure to truncate to that maximum length
271
+ if you're using an s3 storage, for example with a processor like this:
272
+
273
+ ```ruby
274
+ # http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html
275
+ # Max 1024 bytes for keys in S3
276
+ def truncate_at_max_key_size(contents, filename)
277
+ # Left 20 bytes of margin (up to 1024) to have some room for a name
278
+ if store_dir.bytesize > 1004
279
+ raise "The store_dir used is already bigger than 1004 bytes, must be reduced!"
280
+ end
281
+
282
+ key = "#{store_dir}#{filename}"
283
+ new_filename = if key > 1024
284
+ # note mb_chars is an active support's method
285
+ filename.mb_chars.limit(1024 - store_dir.bytesize).to_s
286
+ else
287
+ filename
288
+ end
289
+
290
+ [contents, new_filename]
291
+ end
292
+ ```
293
+
270
294
 
271
295
  ## Source abstraction
272
296
 
@@ -384,6 +408,8 @@ When using `process_with_file`, the last file instance you return from your last
384
408
  `process_with_file` will be automatically deleted by Saviour. Be aware of this if you return
385
409
  some File instance different than the one you received pointing to a file.
386
410
 
411
+ From inside a process you can also access the current store dir with `store_dir`.
412
+
387
413
  Finally, processors can be disabled entirely via a configuration parameter. Example:
388
414
 
389
415
  ```
@@ -20,7 +20,6 @@ module Saviour
20
20
  end
21
21
 
22
22
  def write(contents, filename)
23
- store_dir = Uploader::StoreDirExtractor.new(self).store_dir
24
23
  raise RuntimeError, "Please use `store_dir` before trying to write" unless store_dir
25
24
 
26
25
  if Config.processing_enabled
@@ -32,6 +31,10 @@ module Saviour
32
31
  path
33
32
  end
34
33
 
34
+ def store_dir
35
+ @store_dir ||= Uploader::StoreDirExtractor.new(self).store_dir
36
+ end
37
+
35
38
  class << self
36
39
  def store_dirs
37
40
  @store_dirs ||= []
@@ -19,6 +19,12 @@ module Saviour
19
19
  raise(RuntimeError, "The path you're trying to write already exists!") if @overwrite_protection && exists?(path)
20
20
 
21
21
  path = sanitize_leading_slash(path)
22
+
23
+ # http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html
24
+ if path.bytesize > 1024
25
+ raise(RuntimeError, "The key in S3 must be at max 1024 bytes, this key is too big: #{path}")
26
+ end
27
+
22
28
  directory.files.create({
23
29
  key: path,
24
30
  body: contents,
@@ -1,3 +1,3 @@
1
1
  module Saviour
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "access to model data from uploaders" do
3
+ describe "processor's API" do
4
4
  before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) }
5
5
 
6
6
  let(:uploader) {
@@ -22,7 +22,7 @@ describe "access to model data from uploaders" do
22
22
  klass
23
23
  }
24
24
 
25
- describe "file store" do
25
+ describe "can access to model and attached_as" do
26
26
  it do
27
27
  with_test_file("example.xml") do |example, name|
28
28
  a = klass.new
@@ -34,4 +34,25 @@ describe "access to model data from uploaders" do
34
34
  end
35
35
  end
36
36
  end
37
+
38
+ describe "can access store_dir" do
39
+ let(:uploader) {
40
+ Class.new(Saviour::BaseUploader) do
41
+ store_dir { "/store/dir/#{model.id}" }
42
+ process { |contents, name| ["FAKE: #{store_dir}", name] }
43
+ end
44
+ }
45
+
46
+ it do
47
+ with_test_file("example.xml") do |example, name|
48
+ a = klass.new
49
+ a.file = example
50
+ path = a.file.write
51
+
52
+ contents = Saviour::Config.storage.read(path)
53
+ expect(Saviour::Config.storage.exists?(path)).to be_truthy
54
+ expect(contents).to eq "FAKE: /store/dir/87"
55
+ end
56
+ end
57
+ end
37
58
  end
@@ -27,6 +27,11 @@ describe Saviour::S3Storage do
27
27
  end
28
28
  end
29
29
 
30
+ it "raises exception if key > 1024 bytes" do
31
+ key = "a" * 1025
32
+ expect { subject.write("contents", key) }.to raise_error.with_message(/The key in S3 must be at max 1024 bytes, this key is too big/)
33
+ end
34
+
30
35
  describe "overwritting" do
31
36
  context "without overwrite protection" do
32
37
  subject {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saviour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Campos
@@ -173,12 +173,12 @@ files:
173
173
  - lib/saviour/validator.rb
174
174
  - lib/saviour/version.rb
175
175
  - saviour.gemspec
176
- - spec/feature/access_to_model_and_mounted_as_spec.rb
177
176
  - spec/feature/allow_overriding_attached_as_method.rb
178
177
  - spec/feature/crud_workflows_spec.rb
179
178
  - spec/feature/dirty_spec.rb
180
179
  - spec/feature/follow_file_spec.rb
181
180
  - spec/feature/persisted_path_spec.rb
181
+ - spec/feature/processors_api.rb
182
182
  - spec/feature/reload_model_spec.rb
183
183
  - spec/feature/rewind_source_before_read.rb
184
184
  - spec/feature/uploader_declaration.rb