lib/tori/file.rb in tori-0.4.0 vs lib/tori/file.rb in tori-0.4.1

- old
+ new

@@ -1,10 +1,10 @@ module Tori class File def initialize(model, title: nil, from: nil, &block) @model = model - @title = title + @title = title.kind_of?(String) ? title.to_sym : title if from.respond_to?(:read) and from.respond_to?(:rewind) from.rewind @from = from.read else @from = from @@ -12,21 +12,25 @@ @filename_callback = block end def name context = Context.new(@title) - if @filename_callback - context.define_singleton_method(:__bind__, @filename_callback) - context.__bind__(@model) + filename_callback = if @filename_callback + @filename_callback else - context.define_singleton_method(:__bind__, Tori.config.filename_callback) - context.__bind__(@model) + Tori.config.filename_callback end + context.define_singleton_method(:__filename_callback__, filename_callback) + context.__filename_callback__(@model) end alias to_s name def from? !@from.nil? + end + + def read + Tori.config.backend.read name end def write(opts = nil) Tori.config.backend.write name, @from, opts end