Skip to content

Commit

Permalink
Daily code cleanup, guided byRubocop. Clarify VERIFY_NONE rationale.
Browse files Browse the repository at this point in the history
  • Loading branch information
subelsky committed Jul 24, 2017
1 parent 654a194 commit 1887b21
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 75 deletions.
15 changes: 15 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@ inherit_from: .rubocop_todo.yml

Bundler/OrderedGems:
Enabled: false

Layout/AlignParameters:
Exclude:
- 'bin/*' # most/all of these are autogenerated binstubs
Layout/SpaceAfterComma:
Enabled: false

Layout/EmptyLineAfterMagicComment:
Exclude:
- 'bin/*' # most/all of these are autogenerated binstubs
- 'db/schema.rb'

Metrics/MethodLength:
Exclude:
- 'lib/coyote/strategies/mca.rb'
51 changes: 0 additions & 51 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 16
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: with_first_parameter, with_fixed_indentation
Layout/AlignParameters:
Exclude:
- 'app/views/images/_image.json.jbuilder'
- 'bin/_guard-core'
- 'bin/guard'
- 'bin/puma'
- 'bin/pumactl'
- 'bin/yard'
- 'bin/yardoc'
- 'bin/yri'

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentOneStep, IndentationWidth.
# SupportedStyles: case, end
Layout/CaseIndentation:
Exclude:
- 'app/helpers/application_helper.rb'

# Offense count: 24
# Cop supports --auto-correct.
Layout/CommentIndentation:
Expand All @@ -49,19 +26,6 @@ Layout/DotPosition:
- 'app/controllers/images_controller.rb'
- 'spec/features/adding_and_describing_an_image_spec.rb'

# Offense count: 8
# Cop supports --auto-correct.
Layout/EmptyLineAfterMagicComment:
Exclude:
- 'bin/_guard-core'
- 'bin/guard'
- 'bin/puma'
- 'bin/pumactl'
- 'bin/yard'
- 'bin/yardoc'
- 'bin/yri'
- 'db/schema.rb'

# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines.
Expand Down Expand Up @@ -224,21 +188,6 @@ Layout/SpaceAfterColon:
Exclude:
- 'Guardfile'

# Offense count: 39
# Cop supports --auto-correct.
Layout/SpaceAfterComma:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/models/description.rb'
- 'config/puma.rb'
- 'db/seeds.rb'
- 'lib/tasks/coyote.rake'
- 'spec/features/adding_and_describing_an_image_spec.rb'
- 'spec/features/logging_in_and_out_spec.rb'
- 'spec/spec_helper.rb'
- 'spec/support/feature_user_login.rb'
- 'spec/support/logged_in_user_contexts.rb'

# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def current_tag?(*tag)

def flash_class(level)
case level.to_sym
when :notice then "alert alert-info alert-dismissable"
when :success then "alert alert-success alert-dismissable"
when :error then "alert alert-warning alert-dismissable"
when :alert then "alert alert-danger alert-dismissable"
when :notice then "alert alert-info alert-dismissable"
when :success then "alert alert-success alert-dismissable"
when :error then "alert alert-warning alert-dismissable"
when :alert then "alert alert-danger alert-dismissable"
end
end

Expand Down
23 changes: 13 additions & 10 deletions app/views/images/_image.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#TODO move description look up into controller
json.extract! image,
:id,
:canonical_id,
:path,
:page_urls,
:priority,
:group_id,
:website_id,
:created_at,
# TODO move description look up into controller

json.extract!(
image,
:id,
:canonical_id,
:path,
:page_urls,
:priority,
:group_id,
:website_id,
:created_at,
:updated_at
)

json.url image_url(image, format: 'html')
json.title image.title
Expand Down
1 change: 0 additions & 1 deletion bin/rubocop
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#
# The application 'rubocop' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Expand Down
8 changes: 7 additions & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
require "factory_girl_rails"
FactoryGirl.find_definitions rescue FactoryGirl::DuplicateDefinitionError # necessary to be able to use the rake db:seed task where we want, argh

begin
FactoryGirl.find_definitions
rescue FactoryGirl::DuplicateDefinitionError
# necessary to be able to use the rake db:seed task where we want, argh
Rails.logger.debug "Factory Girl definitions previously loaded"
end

Group.create!([
{ title: "collection" },
Expand Down
19 changes: 11 additions & 8 deletions lib/coyote/strategies/mca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def patch(image)
url = URI.parse(url)
req = Net::HTTP::Patch.new(url)

Net::HTTP.start(url.host,url.port,:use_ssl => url.scheme == 'https',:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
# Deciding to use VERIFY_NONE here because this is binary image date we are sending; not likely to be an MITM threat
Net::HTTP.start(url.host,url.port,use_ssl: url.scheme == 'https',verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
http.request(req)
end

Expand All @@ -44,16 +45,18 @@ def update(website, minutes_ago)
errors = 0
images = {}
while length != 0 do
#some images have a null updated at
if updated_at
url = root + "/api/v1/attachment_images?updated_at=#{updated_at}&offset=#{offset}&limit=#{limit}"
else
url = root + "/api/v1/attachment_images?offset=#{offset}&limit=#{limit}"
end
path = if updated_at
"/api/v1/attachment_images?updated_at=#{updated_at}&offset=#{offset}&limit=#{limit}"
else
"/api/v1/attachment_images?offset=#{offset}&limit=#{limit}"
end

url = root + path

Rails.logger.info "grabbing images for #{url}"

begin
content = open(url, { "Content-Type" => "application/json", ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}).read
content = open(url,"Content-Type" => "application/json",ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE).read
rescue OpenURI::HTTPError => error
response = error.io
Rails.logger.error response.string
Expand Down

0 comments on commit 1887b21

Please sign in to comment.