Class: Temper::Base

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

Direct Known Subclasses

File, StringIO

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.

Raises:

  • (RuntimeException)


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/temper/base.rb', line 6

def initialize(options = {})
  raise RuntimeException, "No @storage set" unless @storage
  self.original_filename = options[:original_filename] || ::File.basename(path)
  self.content_type = options[:content_type] || infer_content_type || "text/plain"
  
  if block_given?
    begin
      yield self
    ensure
      close
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

:nodoc:



32
33
34
# File 'lib/temper/base.rb', line 32

def method_missing(method_name, *args, &block) #:nodoc:
  @storage.__send__(method_name, *args, &block)
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



4
5
6
# File 'lib/temper/base.rb', line 4

def content_type
  @content_type
end

#original_filenameObject

Returns the value of attribute original_filename.



3
4
5
# File 'lib/temper/base.rb', line 3

def original_filename
  @original_filename
end

Instance Method Details

#closeObject



20
21
22
# File 'lib/temper/base.rb', line 20

def close
  #noop
end

#fingerprintObject



24
25
26
# File 'lib/temper/base.rb', line 24

def fingerprint
  @fingerprint ||= Digest::MD5.hexdigest(self.read)
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/temper/base.rb', line 28

def respond_to?(*args)
  super or @storage.respond_to?(*args)
end