Enable Style/DocumentationMethod cop

This commit is contained in:
Brandon Robins
2017-12-30 22:06:28 -06:00
parent b9a7cb88f9
commit 9ee8d1c528
8 changed files with 57 additions and 30 deletions

View File

@@ -16,3 +16,5 @@ Metrics/MethodLength:
- 'lib/calligraphy/rails/mapper.rb'
Style/ClassVars:
Enabled: False
Style/DocumentationMethod:
Enabled: True

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
source 'https://rubygems.org'
gemspec

63
Rakefile Normal file → Executable file
View File

@@ -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}"

View File

@@ -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/**/*']

View File

@@ -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 }

View File

@@ -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

View File

@@ -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

View File

@@ -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