lib/tori/backend/filesystem.rb in tori-0.7.2 vs lib/tori/backend/filesystem.rb in tori-0.8.0
- old
+ new
@@ -1,5 +1,7 @@
+require 'ruby2_keywords'
+
module Tori
module Backend
class FileSystem
ResourceError = Class.new(StandardError)
@@ -43,22 +45,34 @@
def exist?(filename)
::File.exist? path(filename)
end
alias exists? exist?
- def read(filename, *args)
- if args.last.kind_of?(Hash)
- opt = args.pop
- else
- opt = {}
+ if RUBY_VERSION < '2.7'
+ ruby2_keywords def read(filename, *args)
+ if args.last.kind_of?(Hash)
+ opt = args.pop
+ else
+ opt = {}
+ end
+ open(filename, {mode: 'rb'}.merge(opt)) do |f|
+ f.read(*args)
+ end
end
- open(filename, {mode: 'rb'}.merge(opt)) do |f|
- f.read(*args)
+
+ ruby2_keywords def open(filename, *rest, &block)
+ ::File.open(path(filename), *rest, &block)
end
- end
+ else
+ def read(filename, len=nil, **args)
+ open(filename, **{mode: 'rb'}.merge(args)) do |f|
+ f.read(len)
+ end
+ end
- def open(filename, *rest, &block)
- ::File.open(path(filename), *rest, &block)
+ def open(filename, **rest, &block)
+ ::File.open(path(filename), **rest, &block)
+ end
end
def copy_to(filename, tori_file, **opts)
FileUtils.mkdir_p tori_file.path.dirname