From 3316fd8d1e5a5a46b11b69bfaaaee4dc322768c2 Mon Sep 17 00:00:00 2001 From: Brandon Robins Date: Thu, 25 Jan 2018 22:58:26 -0600 Subject: [PATCH] Use `last` instead of `[-1]` --- lib/calligraphy/resource/file_resource.rb | 11 ++++++----- lib/calligraphy/resource/resource.rb | 2 +- lib/calligraphy/web_dav_request/copy.rb | 4 ++-- lib/calligraphy/web_dav_request/lock.rb | 3 ++- lib/calligraphy/web_dav_request/propfind.rb | 2 ++ lib/calligraphy/xml/utils.rb | 2 +- lib/calligraphy/xml/web_dav_elements.rb | 4 ++-- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/calligraphy/resource/file_resource.rb b/lib/calligraphy/resource/file_resource.rb index 1990afe..91321f9 100644 --- a/lib/calligraphy/resource/file_resource.rb +++ b/lib/calligraphy/resource/file_resource.rb @@ -222,7 +222,7 @@ module Calligraphy def refresh_lock if locked? @store.transaction do - @store[:lockdiscovery][-1][:timeout] = timeout_node + @store[:lockdiscovery].last[:timeout] = timeout_node end fetch_lock_info @@ -416,7 +416,8 @@ module Calligraphy end def lockscope - @lock_info[-1][:lockscope] + @lock_info + .last[:lockscope] .children .select { |x| x.is_a? Nokogiri::XML::Element } .last @@ -439,7 +440,7 @@ module Calligraphy def locking_ancestor?(ancestor_path, ancestors, headers = nil) ancestor_info = ancestor_lock_info headers - ancestor_store_path = "#{ancestor_path}/#{ancestors[-1]}.pstore" + ancestor_store_path = "#{ancestor_path}/#{ancestors.last}.pstore" ancestors.pop @@ -669,7 +670,7 @@ module Calligraphy end def refresh_ancestor_locks(ancestor_path, ancestors) - ancestor_store_path = "#{ancestor_path}/#{ancestors[-1]}.pstore" + ancestor_store_path = "#{ancestor_path}/#{ancestors.last}.pstore" ancestors.pop if File.exist? ancestor_store_path @@ -686,7 +687,7 @@ module Calligraphy ancestor_store = PStore.new ancestor_store_path ancestor_store.transaction do - ancestor_store[:lockdiscovery][-1][:timeout] = timeout_node + ancestor_store[:lockdiscovery].last[:timeout] = timeout_node ancestor_store[:lockdiscovery]&.map do |lock_info| lock_info.transform_values do |xml_fragment| parse_serialized_fragment xml_fragment diff --git a/lib/calligraphy/resource/resource.rb b/lib/calligraphy/resource/resource.rb index 8311975..de435d9 100644 --- a/lib/calligraphy/resource/resource.rb +++ b/lib/calligraphy/resource/resource.rb @@ -16,7 +16,7 @@ module Calligraphy @full_request_path = req&.original_url @mount_point = mount || req&.path&.tap { |s| s.slice! resource } @request_body = req&.body&.read || '' - @request_path = mount.nil? ? resource : resource.split(mount)[-1] + @request_path = mount.nil? ? resource : resource.split(mount).last @root_dir = root_dir end diff --git a/lib/calligraphy/web_dav_request/copy.rb b/lib/calligraphy/web_dav_request/copy.rb index 63a1a16..c8ca10f 100644 --- a/lib/calligraphy/web_dav_request/copy.rb +++ b/lib/calligraphy/web_dav_request/copy.rb @@ -32,11 +32,11 @@ module Calligraphy end def destination_header - @headers['Destination'].split(@headers['Host'])[-1] + @headers['Destination'].split(@headers['Host']).last end def remove_trailing_slash(input) - input[-1] == '/' ? input[0..-2] : input + input.last == '/' ? input[0..-2] : input end end end diff --git a/lib/calligraphy/web_dav_request/lock.rb b/lib/calligraphy/web_dav_request/lock.rb index 4c1a942..a12526d 100644 --- a/lib/calligraphy/web_dav_request/lock.rb +++ b/lib/calligraphy/web_dav_request/lock.rb @@ -69,7 +69,8 @@ module Calligraphy end def extract_lock_token(properties) - properties[-1] + properties + .last .select { |x| x.name == 'locktoken' }[0] .children .text diff --git a/lib/calligraphy/web_dav_request/propfind.rb b/lib/calligraphy/web_dav_request/propfind.rb index 8fd3e2a..9149b75 100644 --- a/lib/calligraphy/web_dav_request/propfind.rb +++ b/lib/calligraphy/web_dav_request/propfind.rb @@ -7,6 +7,8 @@ module Calligraphy # Executes the WebDAV request for a particular resource. def execute + # The `propfind` tag contains the properties to retrieve for a + # particular resource. xml = xml_for body: body, node: 'propfind' return :bad_request if xml == :bad_request diff --git a/lib/calligraphy/xml/utils.rb b/lib/calligraphy/xml/utils.rb index e0ca625..44a26d4 100644 --- a/lib/calligraphy/xml/utils.rb +++ b/lib/calligraphy/xml/utils.rb @@ -31,7 +31,7 @@ module Calligraphy xml_str = fragment.is_a?(Array) ? fragment.join : fragment xml = Nokogiri::XML.fragment(xml_str).children - fragment.is_a?(Array) ? xml : xml[-1] + fragment.is_a?(Array) ? xml : xml.last end # Iterates through each property in `properties` hash and deserializes diff --git a/lib/calligraphy/xml/web_dav_elements.rb b/lib/calligraphy/xml/web_dav_elements.rb index 9a115da..665f8b1 100644 --- a/lib/calligraphy/xml/web_dav_elements.rb +++ b/lib/calligraphy/xml/web_dav_elements.rb @@ -20,9 +20,9 @@ module Calligraphy def lock_response(activelock_properties) build :prop do |xml| xml.lockdiscovery do - activelock_properties.each do |properties| + activelock_properties.each do |property_set| xml.activelock do - iterate_and_drilldown xml, properties + iterate_and_drilldown xml, property_set end end end