Method: ChupaText::VirtualContent#initialize

Defined in:
lib/chupa-text/virtual-content.rb

#initialize(input, original_path = nil) ⇒ VirtualContent

Returns a new instance of VirtualContent.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/chupa-text/virtual-content.rb', line 26

def initialize(input, original_path=nil)
  if original_path.is_a?(String)
    if original_path.empty?
      original_path = nil
    else
      original_path = Pathname.new(original_path)
    end
  end
  @original_path = original_path
  body = input.read(INLINE_MAX_SIZE + 1) || ""
  if body.bytesize <= INLINE_MAX_SIZE
    @body = body
    @size = @body.bytesize
    @file = nil
    @path = nil
  else
    @body = nil
    setup_file do |file|
      file.write(body)
      @size = body.bytesize
      @size += IO.copy_stream(input, file)
    end
  end
end