Module: BetterStorage

Extended by:
ActiveSupport::Autoload
Defined in:
lib/better_storage.rb,
lib/better_storage/railtie.rb,
lib/better_storage/version.rb,
lib/better_storage/patches/blob.rb,
lib/better_storage/configuration.rb,
lib/better_storage/variant_metadata.rb,
lib/better_storage/patches/attachment.rb,
lib/better_storage/patches/variant_record.rb,
lib/better_storage/patches/s3_service_proxy.rb,
lib/better_storage/patches/variant_with_record.rb

Defined Under Namespace

Modules: Patches, VariantMetadata Classes: Configuration, Railtie

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.configObject



30
31
32
# File 'lib/better_storage.rb', line 30

def config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



25
26
27
28
# File 'lib/better_storage.rb', line 25

def configure
  yield config
  config
end

.generate_blob_key(token) ⇒ Object



42
43
44
# File 'lib/better_storage.rb', line 42

def generate_blob_key(token)
  [prefix, token].compact_blank.join("/")
end

.prefixObject



34
35
36
37
38
39
40
# File 'lib/better_storage.rb', line 34

def prefix
  parts = []
  parts << config.namespace if config.namespace
  parts << "dev" if Rails.env.development?
  parts << Date.today.strftime(config.prefix_date_format) if config.prefix_date_format
  parts.join("/")
end

.protected_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/better_storage.rb', line 46

def protected_key?(key)
  dev_prefix = [config.namespace, "dev"].compact.join("/")
  !key.start_with?(dev_prefix)
end

.public_url(key) ⇒ Object



51
52
53
54
55
56
# File 'lib/better_storage.rb', line 51

def public_url(key)
  uri = URI.parse(config.s3_endpoint)
  uri.path += "/" unless uri.path.end_with?("/")
  uri.path += key
  uri.to_s
end