Sha256: 938d176a7c8b5053e21550fcd01ffa5a8e5bf6250018e126c7b779b123263a38
Contents?: true
Size: 1.46 KB
Versions: 4
Compression:
Stored size: 1.46 KB
Contents
require_relative 'uploader/store_dir_extractor' require_relative 'uploader/processors_runner' module Saviour class BaseUploader def initialize(opts = {}) @data = opts.fetch(:data, {}) end def method_missing(name, *args, &block) if @data.key?(name) @data[name] else super end end def respond_to_missing?(name, *) @data.key?(name) || super end def write(contents, filename) store_dir = Uploader::StoreDirExtractor.new(self).store_dir raise RuntimeError, "Please use `store_dir` before trying to write" unless store_dir if Config.processing_enabled contents, filename = Uploader::ProcessorsRunner.new(self).run!(contents, filename) end path = ::File.join(store_dir, filename) Config.storage.write(contents, path) path end class << self def store_dirs @store_dirs ||= [] end def processors @processors ||= [] end def process(name = nil, opts = {}, type = :memory, &block) if block_given? processors.push(method_or_block: name || block, type: type) else processors.push(method_or_block: name || block, type: type, opts: opts) end end def process_with_file(name = nil, opts = {}, &block) process(name, opts, :file, &block) end def store_dir(name = nil, &block) store_dirs.push(name || block) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
saviour-0.4.3 | lib/saviour/base_uploader.rb |
saviour-0.4.2 | lib/saviour/base_uploader.rb |
saviour-0.4.1 | lib/saviour/base_uploader.rb |
saviour-0.4.0 | lib/saviour/base_uploader.rb |