diff --git a/lib/calligraphy/file_resource.rb b/lib/calligraphy/file_resource.rb index ada5ee5..add5a57 100644 --- a/lib/calligraphy/file_resource.rb +++ b/lib/calligraphy/file_resource.rb @@ -4,10 +4,10 @@ module Calligraphy class FileResource < Resource include Calligraphy::Utils - def initialize(resource: nil, req: nil, mount: nil) + def initialize(resource: nil, req: nil, mount: nil, root_dir: Dir.pwd) super - @root_dir = Dir.pwd + @root_dir = root_dir || Dir.pwd @src_path = join_paths @root_dir, @request_path if exists? diff --git a/lib/calligraphy/move.rb b/lib/calligraphy/move.rb index 74513df..d58043b 100644 --- a/lib/calligraphy/move.rb +++ b/lib/calligraphy/move.rb @@ -7,7 +7,7 @@ module Calligraphy if @resource.is_true? options[:overwrite] to_path = options[:destination].tap { |s| s.slice! @resource.mount_point } - to_resource = @resource.class.new resource: to_path, req: @request + to_resource = @resource.class.new resource: to_path, req: @request, root_dir: @resource.root_dir if to_resource.exists? to_resource.delete_collection diff --git a/lib/calligraphy/rails/web_dav_requests_controller.rb b/lib/calligraphy/rails/web_dav_requests_controller.rb index 9fa682d..9264d97 100644 --- a/lib/calligraphy/rails/web_dav_requests_controller.rb +++ b/lib/calligraphy/rails/web_dav_requests_controller.rb @@ -35,7 +35,8 @@ module Calligraphy::Rails end @resource_class = params[:resource_class] - @resource = @resource_class.new resource: resource_id, req: request + @resource_root_path = params[:resource_root_path] + @resource = @resource_class.new resource: resource_id, req: request, root_dir: @resource_root_path end def headers diff --git a/lib/calligraphy/resource.rb b/lib/calligraphy/resource.rb index 92d2f25..b5cce6d 100644 --- a/lib/calligraphy/resource.rb +++ b/lib/calligraphy/resource.rb @@ -1,9 +1,9 @@ module Calligraphy class Resource attr_accessor :contents, :updated_at - attr_reader :full_request_path, :mount_point, :request_body, :request_path + attr_reader :full_request_path, :mount_point, :request_body, :request_path, :root_dir - def initialize(resource: nil, req: nil, mount: nil) + def initialize(resource: nil, req: nil, mount: nil, root_dir: nil) @full_request_path = req&.original_url @mount_point = mount || req&.path&.tap { |s| s.slice! resource } @request_body = req&.body&.read || ''