Sha256: bd32539272a3727d451e9b5309f1b183709a8d3ac5100b4893045f09b02d661c

Contents?: true

Size: 874 Bytes

Versions: 1

Compression:

Stored size: 874 Bytes

Contents

module Tori
  class File
    def initialize(model, from: nil)
      @model = model
      @from = from
    end

    def name
      Tori.config.filename_callback.call(@model)
    end
    alias to_s name

    def copy?
      !@model.nil? && !@from.nil? && @from.respond_to?(:path) && 0 < name.length
    rescue NameError => e
      false
    end

    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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tori-0.0.4 lib/tori/file.rb