From 9ee8d1c52860a8133c3a34bf5f861e084dcb08fb Mon Sep 17 00:00:00 2001 From: Brandon Robins Date: Sat, 30 Dec 2017 22:06:28 -0600 Subject: [PATCH] Enable Style/DocumentationMethod cop --- .rubocop.yml | 2 + Gemfile | 2 + Rakefile | 63 +++++++++++-------- calligraphy.gemspec | 4 +- lib/calligraphy/resource/resource.rb | 1 + lib/calligraphy/utils.rb | 13 +++- .../web_dav_request/web_dav_request.rb | 1 + .../calligraphy/install_generator.rb | 1 + 8 files changed, 57 insertions(+), 30 deletions(-) mode change 100644 => 100755 Rakefile diff --git a/.rubocop.yml b/.rubocop.yml index afc0240..06a542d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,3 +16,5 @@ Metrics/MethodLength: - 'lib/calligraphy/rails/mapper.rb' Style/ClassVars: Enabled: False +Style/DocumentationMethod: + Enabled: True diff --git a/Gemfile b/Gemfile index a669694..1d84d35 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 index ce8e76f..87ba2f1 --- a/Rakefile +++ b/Rakefile @@ -1,64 +1,73 @@ #!/usr/bin/env rake -require "rake/clean" -require "rspec/core/rake_task" +# frozen_string_literal: true -task default: %w(spec litmus:run) +require 'rake/clean' +require 'rspec/core/rake_task' +require 'rubocop/rake_task' -desc "Run rspec tests" +task default: %w[spec litmus:run] + +desc 'Run rspec tests' RSpec::Core::RakeTask.new :spec -desc "Run litmus test suite" -task :litmus => %w(litmus:run) +desc 'Run litmus test suite' +task litmus: %w[litmus:run] + +desc 'Run Rubocop' +RuboCop::RakeTask.new :rubocop namespace :litmus do tmp_dir = "#{Dir.pwd}/tmp" litmus_archive = "#{tmp_dir}/litmus-0.13.tar.gz" - desc "Fetch litmus test suite zip file" + desc 'Fetch litmus test suite zip file' task :fetch do - sh "mkdir tmp" unless File.directory? "#{tmp_dir}" - sh "mkdir tmp/webdav" unless File.directory? "#{tmp_dir}/webdav" + sh 'mkdir tmp' unless File.directory? tmp_dir.to_s + sh 'mkdir tmp/webdav' unless File.directory? "#{tmp_dir}/webdav" unless File.exist? litmus_archive - sh "wget -O #{tmp_dir}/litmus-0.13.tar.gz https://github.com/eanlain/litmus/releases/download/v0.13/litmus-0.13.tar.gz" + litmus_url = 'https://github.com/eanlain/litmus/releases/download/v0.13/litmus-0.13.tar.gz' + sh "wget -O #{tmp_dir}/litmus-0.13.tar.gz #{litmus_url}" end end - CLEAN.include("tmp") + CLEAN.include('tmp') - desc "Unarchive litmus test suite zip file" - task :unarchive => :fetch do + desc 'Unarchive litmus test suite zip file' + task unarchive: :fetch do unless File.directory? "#{Dir.pwd}/litmus-0.13" sh "tar -xvzf #{tmp_dir}/litmus-0.13.tar.gz" end end - CLEAN.include("litmus-0.13") + CLEAN.include('litmus-0.13') - desc "Configure litmus test suite" - task :configure => :unarchive do - unless File.exist? "litmus-0.13/configured" - sh "cd litmus-0.13 && ./configure" - sh "cd litmus-0.13 && touch configured" + desc 'Configure litmus test suite' + task configure: :unarchive do + unless File.exist? 'litmus-0.13/configured' + sh 'cd litmus-0.13 && ./configure' + sh 'cd litmus-0.13 && touch configured' end end desc "'make clean' litmus test suite" task :make_clean do - sh "cd litmus-0.13 && make clean" - sh "rm litmus-0.13/configured" + sh 'cd litmus-0.13 && make clean' + sh 'rm litmus-0.13/configured' end - desc "Run litmus test suite" - task :run => :configure do - sh "cd spec/dummy/ && rails server -d" + desc 'Run litmus test suite' + task run: :configure do + sh 'cd spec/dummy/ && rails server -d' sleep 1 puma_pid = `cat spec/dummy/tmp/pids/server.pid` exit_code = 0 begin - sh "cd litmus-0.13 && make URL=http://localhost:3000/webdav/ CREDS='jon_deaux changeme!' check" - rescue + sh 'cd litmus-0.13 &&'\ + ' make URL=http://localhost:3000/webdav/'\ + ' CREDS=\'jon_deaux changeme!\' check' + rescue StandardError exit_code = 1 - puts "!!!!! Failure encountered during litmus test suite !!!!!" + puts '!!!!! Failure encountered during litmus test suite !!!!!' end sh "kill #{puma_pid}" diff --git a/calligraphy.gemspec b/calligraphy.gemspec index a78153f..cbf4678 100644 --- a/calligraphy.gemspec +++ b/calligraphy.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) @@ -13,7 +15,7 @@ Gem::Specification.new do |s| s.homepage = 'http://www.github.com/eanlain/calligraphy' s.license = 'MIT' - s.required_ruby_version = ">= 2.3.0" + s.required_ruby_version = '>= 2.3.0' s.files = Dir['lib/**/*', 'LICENSE', 'README.md'] s.test_files = Dir['spec/**/*'] diff --git a/lib/calligraphy/resource/resource.rb b/lib/calligraphy/resource/resource.rb index 89e5dc6..2204a2e 100644 --- a/lib/calligraphy/resource/resource.rb +++ b/lib/calligraphy/resource/resource.rb @@ -11,6 +11,7 @@ module Calligraphy attr_reader :full_request_path, :mount_point, :request_body, :request_path, :root_dir + #:nodoc: 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 } diff --git a/lib/calligraphy/utils.rb b/lib/calligraphy/utils.rb index 827367f..4e3b1f1 100644 --- a/lib/calligraphy/utils.rb +++ b/lib/calligraphy/utils.rb @@ -1,44 +1,53 @@ # frozen_string_literal: true module Calligraphy - # Miscellaneous convenience methods. + # Miscellaneous general convenience methods. module Utils TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].freeze FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE'].freeze + # Determines if a value is truthy. def true?(val) TRUE_VALUES.include? val end + # Determines if a value is falsy. def false?(val) FALSE_VALUES.include? val end + # Joins paths. def join_paths(*paths) paths.join '/' end + # Given a path and separator, splits the path string using the separator + # and pops off the last element of the split array. def split_and_pop(path:, separator: '/') path.split(separator)[0..-2] end + # Determines if object exists and if existing object is of a given type. def obj_exists_and_is_not_type?(obj:, type:) obj.nil? ? false : obj != type end + # Given an array of hashes, returns an array of hash values. def map_array_of_hashes(arr_hashes) [].tap do |output_array| arr_hashes.each do |hash| - output_array.push(hash.map { |_k, v| v }) + output_array.push hash.values end end end + # Extracts a lock token from an If headers. def extract_lock_token(if_header) token = if_header.scan(Calligraphy::LOCK_TOKEN_REGEX) token.flatten.first if token.is_a? Array end + # Hash used in describing a supportedlock. def lockentry_hash(scope, type) { lockentry: { lockscope: scope, locktype: type } } end diff --git a/lib/calligraphy/web_dav_request/web_dav_request.rb b/lib/calligraphy/web_dav_request/web_dav_request.rb index e4efd92..8a03bb9 100644 --- a/lib/calligraphy/web_dav_request/web_dav_request.rb +++ b/lib/calligraphy/web_dav_request/web_dav_request.rb @@ -11,6 +11,7 @@ module Calligraphy attr_accessor :resource, :response attr_reader :headers, :request + #:nodoc: def initialize(headers:, request:, response:, resource:) @headers = headers @request = request diff --git a/lib/generators/calligraphy/install_generator.rb b/lib/generators/calligraphy/install_generator.rb index 45cb68c..7f71f8b 100644 --- a/lib/generators/calligraphy/install_generator.rb +++ b/lib/generators/calligraphy/install_generator.rb @@ -10,6 +10,7 @@ module Calligraphy desc 'Creates a Calligraphy initializer for your application' + #:nodoc: def copy_initializer template 'calligraphy.rb', 'config/initializers/calligraphy.rb' end