lib/tori/file.rb in tori-0.0.3 vs lib/tori/file.rb in tori-0.0.4
- old
+ new
@@ -1,28 +1,39 @@
module Tori
class File
- attr_accessor :from
-
- def initialize(model, from = nil)
+ def initialize(model, from: nil)
@model = model
@from = from
end
- def to_s
+ def name
Tori.config.filename_callback.call(@model)
end
+ alias to_s name
- def exist?
- Tori.config.backend.exist?(to_s)
- end
-
def copy?
- !@model.nil? && !@from.nil? && @from.respond_to?(:path) && 0 < to_s.length
+ !@model.nil? && !@from.nil? && @from.respond_to?(:path) && 0 < name.length
rescue NameError => e
false
end
- def read
- Tori.config.backend.read(to_s)
+ def copy
+ Tori.config.backend.copy @from.path, name if copy?
+ end
+
+ def delete
+ Tori.config.backend.delete name if exist?
+ end
+
+ def respond_to_missing?(sym, include_private)
+ Tori.config.backend.respond_to?(sym, include_private)
+ end
+
+ def method_missing(sym)
+ if respond_to_missing?(sym, false)
+ Tori.config.backend.__send__ sym, name
+ else
+ fail NameError, "undefined local variable or method `#{sym}' for #{Tori.config.backend.inspect}"
+ end
end
end
end