class Triboelectric::Uploader
Public Class Methods
new(options = {})
click to toggle source
# File lib/triboelectric/uploader.rb, line 5 def initialize(options = {}) @bucket = options[:bucket] @root = options[:root] @urls = options[:urls] end
upload(*args)
click to toggle source
# File lib/triboelectric/uploader.rb, line 11 def self.upload(*args) new(*args).upload end
Public Instance Methods
files()
click to toggle source
# File lib/triboelectric/uploader.rb, line 28 def files urls = @urls if @urls.is_a?(Array) urls = @urls.values if @urls.is_a?(Hash) urls.map do |url| if @root url = File.join(@root, url) else url = url.sub(/^\//, "") end if File.file? url url else Dir[File.join(url, "**/*")].select { |f| File.file? f } end end.flatten end
upload()
click to toggle source
# File lib/triboelectric/uploader.rb, line 15 def upload return unless @bucket return if %w(development test).include? ENV["RACK_ENV"] files.each do |file| next if @bucket.object(file).exists? @bucket.put_object( key: file, body: File.open(file, "r"), content_type: Rack::Mime.mime_type(File.extname(file), "text/plain"), ) end end