lib/tori/file.rb in tori-0.2.0 vs lib/tori/file.rb in tori-0.3.0

- old
+ new

@@ -1,10 +1,15 @@ module Tori class File def initialize(model, from: nil, &block) @model = model - @from = from + if from.respond_to?(:read) and from.respond_to?(:rewind) + from.rewind + @from = from.read + else + @from = from + end @filename_callback = block end def name if @filename_callback @@ -14,16 +19,14 @@ end end alias to_s name def from? - !@from.nil? && @from.respond_to?(:path) + !@from.nil? end def write(opts = nil) - path = @from.path - path = Pathname.new(path) if path.kind_of?(String) - Tori.config.backend.write name, path, opts + Tori.config.backend.write name, @from, opts end def delete Tori.config.backend.delete name if exist? end