Class: StandardStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/standard_storage.rb,
lib/standard_storage/version.rb

Direct Known Subclasses

B2, Filesystem, S3

Defined Under Namespace

Classes: B2, Filesystem, S3

Constant Summary collapse

VERSION =
'1.0.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configs = {}) ⇒ StandardStorage

Returns a new instance of StandardStorage.



7
8
9
10
11
12
13
14
# File 'lib/standard_storage.rb', line 7

def initialize(configs={})
  @partition = configs.has_key?(:partition) || configs.has_key?(:partition_depth)
  @partition_depth = if configs[:partition].is_a?(Integer)
    configs[:partition]
  else
    configs[:partition_depth] || 3
  end
end

Instance Attribute Details

#partition_depthObject (readonly)

Returns the value of attribute partition_depth.



5
6
7
# File 'lib/standard_storage.rb', line 5

def partition_depth
  @partition_depth
end

Instance Method Details

#copy_to_tempfile(key) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/standard_storage.rb', line 16

def copy_to_tempfile(key)
  tmpfile = Tempfile.new([File.basename(key), File.extname(key)], binmode: true)
  cp(key, tmpfile.path)
  if block_given?
    begin
      yield(tmpfile)
    ensure
      tmpfile.close!
    end
  else
    tmpfile
  end
end