Skip to content

Commit

Permalink
add rubocop and coveralls integration; fix some of the rubocop violat…
Browse files Browse the repository at this point in the history
…ions; adjust goobi post params
  • Loading branch information
peetucket committed Nov 1, 2016
1 parent 5360968 commit 9136314
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 186 deletions.
102 changes: 95 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-01-14 19:01:00 -0800 using RuboCop version 0.35.1.
# on 2016-11-01 16:19:24 -0700 using RuboCop version 0.44.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -11,40 +11,115 @@ Lint/HandleExceptions:
Exclude:
- 'lib/tasks/rspec.rake'

# Offense count: 2
Metrics/AbcSize:
Max: 29

# Offense count: 7
# Configuration parameters: CountComments.
Metrics/BlockLength:
Max: 113

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 161
Max: 207

# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 7

# Offense count: 2
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
# URISchemes: http, https
Metrics/LineLength:
Max: 286

# Offense count: 3
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 17

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 8

# Offense count: 8
Style/AccessorMethodName:
Exclude:
- 'lib/update_marc_record_service.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: prefer_alias, prefer_alias_method
Style/Alias:
Exclude:
- 'config/boot.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'old_cap/Capfile'

# Offense count: 2
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'config/boot.rb'

# Offense count: 4
# Configuration parameters: Exclude.
# Offense count: 7
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'config/boot.rb'
- 'lib/dor_services_app.rb'
- 'lib/goobi.rb'
- 'lib/grape_overrides.rb'
- 'lib/registration_response.rb'
- 'lib/service_item.rb'
- 'lib/update_marc_record_service.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, no_empty_lines
Style/EmptyLinesAroundBlockBody:
Exclude:
- 'config/environments/production.rb'
- 'config/environments/stage.rb'

# Offense count: 40
# Offense count: 55
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
Enabled: false
Exclude:
- 'config/deploy.rb'
- 'lib/dor_services_app.rb'
- 'lib/goobi.rb'
- 'lib/grape_overrides.rb'
- 'lib/tasks/rspec.rake'
- 'old_cap/Capfile'
- 'spec/dor_services_app_spec.rb'
- 'spec/registration_response_spec.rb'
- 'spec/service_item_spec.rb'
- 'spec/spec_helper.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Style/IndentArray:
EnforcedStyle: consistent

# Offense count: 1
# Cop supports --auto-correct.
Expand All @@ -56,3 +131,16 @@ Style/MultilineBlockLayout:
# Cop supports --auto-correct.
Style/NumericLiterals:
MinDigits: 11

# Offense count: 2
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: snake_case, camelCase
Style/VariableName:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/ZeroLengthPredicate:
Exclude:
- 'lib/update_marc_record_service.rb'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ To run the tests:

`bundle exec rake`

To run rubocop (not autorun with tests):
To run rubocop separately (auto run with tests):

`bundle exec rake rubocop`

Expand Down
2 changes: 1 addition & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
set :stages, %w(dev staging production)

set :linked_dirs, %w(log config/environments config/certs)
set :linked_files, %w{bin/write_marc_record}
set :linked_files, %w(bin/write_marc_record)

set :bundle_env_variables, :ld_library_path => '/usr/lib/oracle/11.2/client64/lib:$LD_LIBRARY_PATH'

Expand Down
9 changes: 4 additions & 5 deletions config/environments/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@
release do
symphony_path './'
write_marc_script 'bin/write_marc_record_test'
purl_base_uri "http://purl.stanford.edu"
purl_base_uri 'http://purl.stanford.edu'
end

goobi do
url 'https://goobi-api-url'
max_tries 5 # the number of attempts to retry service calls before failing
max_sleep_seconds 120 # max sleep seconds between tries
base_sleep_seconds 10 # base sleep seconds between tries
max_tries 5 # the number of attempts to retry service calls before failing
max_sleep_seconds 120 # max sleep seconds between tries
base_sleep_seconds 10 # base sleep seconds between tries
end

end

Dor::WorkflowArchiver.config.configure do
Expand Down
6 changes: 3 additions & 3 deletions lib/dor_services_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def proxy_rest_client_response(response)
end

get '/objects/:druid/content/:filename', requirements: { filename: /.*/ } do
query_string = URI.encode_www_form({ version: params[:version].to_s })
query_string = URI.encode_www_form(version: params[:version].to_s)
encoded_filename = URI.encode(params[:filename])
url = "objects/#{params[:druid]}/content/#{encoded_filename}?#{query_string}"
sdr_response = sdr_client[url].get { |response, _request, _result| response }
Expand Down Expand Up @@ -207,11 +207,11 @@ def load_item
post '/update_marc_record' do
Dor::UpdateMarcRecordService.new(@item).update
end

post '/notify_goobi' do
Dor::GoobiNotify.new(@item).register
end

resource :versions do
post do
@item.open_new_version
Expand Down
24 changes: 11 additions & 13 deletions lib/goobi.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
module Dor
class Goobi < ServiceItem

def register
handler = proc do |exception, attempt_number, _total_delay|
error!("#{exception.class} on goobi notification web service call #{attempt_number} for #{@druid_obj.id}", 500) if attempt_number >= Dor::Config.goobi.max_tries
end

# rubocop:disable Metrics/LineLength
with_retries(max_tries: Dor::Config.goobi.max_tries, handler: handler, base_sleep_seconds: Dor::Config.goobi.base_sleep_seconds, max_sleep_seconds: Dor::Config.goobi.max_sleep_seconds) do |_attempt|
url = "#{Dor::Config.goobi.url}"
response = RestClient.post url, xml_request, :content_type => 'text/xml'
response.code
end
response = RestClient.post Dor::Config.goobi.url, xml_request, :content_type => 'text/xml'
response.code
end
# rubocop:enable Metrics/LineLength
end

def xml_request
<<-END
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<creationRequest>
<stanfordCreationRequest>
<objectId>#{@druid_obj.id}</objectId>
<objectType>#{object_type}</objectType>
<sourceID>#{@druid_obj.source_id.encode(:xml => :text)}</sourceID>
Expand All @@ -25,13 +24,12 @@ def xml_request
<project>#{project_name.encode(:xml => :text)}</project>
<catkey>#{ckey}</catkey>
<barcode>#{barcode}</barcode>
<collectionId>#{collection_id}</collecitonId>
<collectionId>#{collection_id}</collectionId>
<collectionName>#{collection_name.encode(:xml => :text)}</collectionName>
<sdrWorkflow>dpgImageWF</sdrWorkflow>
<goobiWorkflow>name</goobiWorkflow>
</creationRequest>
<goobiWorkflow>Example_workflow_LayoutWizzard_Stanford</goobiWorkflow>
</stanfordCreationRequest>
END
end

end
end
end
19 changes: 8 additions & 11 deletions lib/service_item.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Dor
class ServiceItem

# @return [String] value with SIRSI/Symphony numeric catkey in it for specified object, or nil if none exists
# look in identityMetadata/otherId[@name='catkey']
def self.get_ckey(object)
Expand All @@ -22,12 +21,11 @@ def initialize(druid_obj)
def ckey
self.class.get_ckey(@druid_obj)
end

# @return [String] value with object_type in it, or empty x subfield if none exists
# look in identityMetadata/objectType
def object_type
@object_type ||= begin
object_type = ''
node = @druid_obj.datastreams['identityMetadata'].ng_xml.at_xpath('//identityMetadata/objectType')
node.content unless node.nil?
end
Expand All @@ -48,25 +46,24 @@ def barcode
def thumb
@druid_obj.encoded_thumb unless @druid_obj.datastreams.nil?
end

# returns the first collection_id the object is contained in (if any)
# @return [String] collection druid the item is in (blank if none)
def collection_id
@druid_obj.collections.size > 0 ? @druid_obj.collections.first.id : ""
@druid_obj.collections.empty? ? '' : @druid_obj.collections.first.id
end

# returns the name of the first collection the object is contained in (if any)
# @return [String] first collection name the item is in (blank if none)
def collection_name
@druid_obj.collections.size > 0 ? @druid_obj.collections.first.label : ""
@druid_obj.collections.empty? ? '' : @druid_obj.collections.first.label
end

# returns the name of the project by examining the objects tags
# @return [String] project tag value if one exists (blank if none)
def project_name
content_tag = @druid_obj.tags.select {|tag| tag.include?('Project : ')}
content_tag.size > 0 ? content_tag[0].gsub('Project : ','').strip : ''
content_tag = @druid_obj.tags.select { |tag| tag.include?('Project : ') }
content_tag.empty? ? '' : content_tag[0].gsub('Project : ', '').strip
end

end
end
end
4 changes: 2 additions & 2 deletions lib/tasks/rspec.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ begin
ENV['RACK_ENV'] = 'local'
end

task :default => [:spec]
task :default => [:spec, :rubocop]
rescue LoadError
end

require 'rubocop/rake_task'

RuboCop::RakeTask.new
RuboCop::RakeTask.new
Loading

0 comments on commit 9136314

Please sign in to comment.