Class: InlineUploader

Inherits:
Object
  • Object
show all
Defined in:
lib/inline_uploader.rb

Defined Under Namespace

Modules: Helpers Classes: Attacher, EndPoint

Constant Summary collapse

TAG_PREFIX =

32 is the length of an md5 hex digest

'inline_upload_'.freeze
TAG_REGEXP =
/\A#{TAG_PREFIX}[a-z0-9]{32,32}\Z/i.freeze
TAG_LENGTH =
TAG_PREFIX.length + 32
DEFAULT_ENDPOINT =
'/inline_upload'
DEFAULT_UPLOAD_FLAG =
'has_inline_uploads'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ InlineUploader

Returns a new instance of InlineUploader.



35
36
37
38
39
40
41
42
# File 'lib/inline_uploader.rb', line 35

def initialize(options)
  @upload_dir = options[:tmp_dir]     || File.join(Dir.tmpdir, "inline_uploader_#{Process.pid}#{Time.now.to_i}")
  @flag_param = options[:upload_flag] || DEFAULT_UPLOAD_FLAG
  @endpoint   = options[:endpoint]    || DEFAULT_ENDPOINT
  @logger     = options[:logger]      || Logger.new($stderr)

  FileUtils.mkdir_p(upload_dir)
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



33
34
35
# File 'lib/inline_uploader.rb', line 33

def endpoint
  @endpoint
end

#flag_paramObject (readonly)

Returns the value of attribute flag_param.



33
34
35
# File 'lib/inline_uploader.rb', line 33

def flag_param
  @flag_param
end

#loggerObject (readonly)

Returns the value of attribute logger.



33
34
35
# File 'lib/inline_uploader.rb', line 33

def logger
  @logger
end

#upload_dirObject (readonly)

Returns the value of attribute upload_dir.



33
34
35
# File 'lib/inline_uploader.rb', line 33

def upload_dir
  @upload_dir
end

Class Method Details

.new(inner_app, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/inline_uploader.rb', line 17

def self.new(inner_app, options = {})
  uploader = allocate
  uploader.send :initialize, options

  Rack::Builder.app do
    map uploader.endpoint do
      run InlineUploader::EndPoint.new(uploader)
    end

    map '/' do
      use InlineUploader::Attacher, uploader
      run inner_app
    end
  end
end