Skip to content

Commit

Permalink
Rubocop automated style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Jun 29, 2019
1 parent 789ce87 commit 3e15cbf
Show file tree
Hide file tree
Showing 74 changed files with 592 additions and 550 deletions.
2 changes: 1 addition & 1 deletion Guardfile
Expand Up @@ -30,5 +30,5 @@ guard :rspec, cmd: 'bin/rspec' do

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
5 changes: 2 additions & 3 deletions app/admin/dashboard.rb
@@ -1,8 +1,7 @@
ActiveAdmin.register_page "Dashboard" do
menu priority: 1, label: proc { I18n.t("active_admin.dashboard") }

menu priority: 1, label: proc{ I18n.t("active_admin.dashboard") }

content title: proc{ I18n.t("active_admin.dashboard") } do
content title: proc { I18n.t("active_admin.dashboard") } do
columns do
column do
panel "Users" do
Expand Down
4 changes: 2 additions & 2 deletions app/admin/docker_containers.rb
Expand Up @@ -36,9 +36,9 @@

# Show most recent record first
running_records = records.select { |r| r[:running] == 'yes' }
.sort { |a, b| b[:started_at] <=> a[:started_at] }
.sort { |a, b| b[:started_at] <=> a[:started_at] }
stopped_records = records.select { |r| r[:running] == 'no' }
.sort { |a, b| b[:finished_at] <=> a[:finished_at] }
.sort { |a, b| b[:finished_at] <=> a[:finished_at] }

h1 "#{running_records.count} running"
if running_records.present?
Expand Down
1 change: 0 additions & 1 deletion app/admin/owner.rb
Expand Up @@ -67,5 +67,4 @@ def find_resource
# permitted << :other if resource.something?
# permitted
# end

end
7 changes: 3 additions & 4 deletions app/controllers/api_controller.rb
Expand Up @@ -33,7 +33,7 @@ def run_remote

def data
@scraper = Scraper.friendly.find(params[:id])
#response.stream.write('Hello!')
# response.stream.write('Hello!')
# Check authentication
# We're still allowing authentication via header so that old users
# of the api don't have to change anything
Expand All @@ -56,7 +56,6 @@ def data
format.csv { data_csv(owner) }
format.atom { data_atom(owner) }
end

rescue SQLite3::Exception => e
render_error e.to_s, 400
end
Expand All @@ -76,7 +75,7 @@ def data_sqlite(owner)
end
end
# For some reason the code below just copied across one 16k block
#IO.copy_stream(@scraper.database.sqlite_db_path, response.stream)
# IO.copy_stream(@scraper.database.sqlite_db_path, response.stream)
end
ApiQuery.log!(
query: params[:query],
Expand Down Expand Up @@ -105,7 +104,7 @@ def data_json(owner)
bench = Benchmark.measure do
# Tell nginx and passenger not to buffer this
response.headers['X-Accel-Buffering'] = 'no'
mime_type = params[:callback] ? 'application/javascript': 'application/json'
mime_type = params[:callback] ? 'application/javascript' : 'application/json'
response.headers['Content-Type'] = "#{mime_type}; charset=utf-8"
i = 0
@scraper.database.sql_query_streaming(params[:query]) do |row|
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/examples_controller.rb
Expand Up @@ -17,7 +17,7 @@ def australian_members_of_parliament
website: m[11]
}
end
@members = all.select{|p| p[:house] == "representatives"}
@members = all.select { |p| p[:house] == "representatives" }
@page = params[:page]
@page = @page ? @page.to_i : 1
if @page == 1
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/owners_controller.rb
Expand Up @@ -35,7 +35,8 @@ def settings
def update
if @owner.user?
@owner.update_attributes(
see_downloads: params[:user][:see_downloads])
see_downloads: params[:user][:see_downloads]
)
end
redirect_to @owner
end
Expand Down
8 changes: 5 additions & 3 deletions app/controllers/scrapers_controller.rb
Expand Up @@ -18,7 +18,7 @@ def settings

def index
@scrapers = Scraper.accessible_by(current_ability).order(created_at: :desc)
.page(params[:page])
.page(params[:page])
end

def new
Expand Down Expand Up @@ -195,7 +195,9 @@ def load_resource

def scraper_params
params.require(:scraper).permit(:auto_run, variables_attributes: [
:id, :name, :value, :_destroy], webhooks_attributes: [
:id, :url, :_destroy])
:id, :name, :value, :_destroy
], webhooks_attributes: [
:id, :url, :_destroy
])
end
end
6 changes: 3 additions & 3 deletions app/controllers/search_controller.rb
@@ -1,15 +1,15 @@
class SearchController < ApplicationController
def search
default_owner_search_params = {highlight: {fields: [:nickname, :name, :company, :blog]}, page: params[:page], per_page: 10}
default_scraper_search_params = {fields: [{full_name: :word_middle}, :description, {scraped_domain_names: :word_end}], highlight: true, page: params[:page], per_page: 10}
default_owner_search_params = { highlight: { fields: [:nickname, :name, :company, :blog] }, page: params[:page], per_page: 10 }
default_scraper_search_params = { fields: [{ full_name: :word_middle }, :description, { scraped_domain_names: :word_end }], highlight: true, page: params[:page], per_page: 10 }

@q = params[:q]
@type = params[:type]
@show = params[:show]

@owners = Owner.search @q, default_owner_search_params
@all_scrapers = Scraper.search @q, default_scraper_search_params
@filtered_scrapers = Scraper.search @q, default_scraper_search_params.merge(where: {has_data?: true})
@filtered_scrapers = Scraper.search @q, default_scraper_search_params.merge(where: { has_data?: true })

@scrapers = @show == "all" ? @all_scrapers : @filtered_scrapers
end
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/supporters_controller.rb
Expand Up @@ -8,8 +8,8 @@ def new

def create
customer = Stripe::Customer.create(
email: current_user.email,
card: params[:stripeToken],
email: current_user.email,
card: params[:stripeToken],
description: "morph.io user @#{current_user.nickname}"
)
current_user.update! stripe_customer_id: customer.id
Expand All @@ -20,16 +20,15 @@ def create

session[:new_supporter] = true
redirect_to user_path(current_user), notice: render_to_string(partial: "create_flash")

rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to supporters_path
end

def create_one_time
customer = Stripe::Customer.create(
email: current_user.email,
card: params[:stripeTokenOneTime],
email: current_user.email,
card: params[:stripeTokenOneTime],
description: "morph.io user @#{current_user.nickname}"
)
current_user.update! stripe_customer_id: customer.id
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/omniauth_callbacks_controller.rb
Expand Up @@ -11,6 +11,6 @@ def github
@user.watch_all_owners if new_sign_up

flash[:notice] = render_to_string(partial: "users/sign_in_message")
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
sign_in_and_redirect @user, :event => :authentication # this will throw if @user is not activated
end
end
24 changes: 12 additions & 12 deletions app/helpers/bootstrap_flash_helper.rb
Expand Up @@ -17,18 +17,18 @@ def bootstrap_flash(options = {})

Array(message).each do |msg|
text = content_tag(
:div,
content_tag(
:div,
content_tag(
:button,
raw("&times;"),
:class => "close", "data-dismiss" => "alert"
) + msg.html_safe,
:class => "container"
),
:class => "alert fade in alert-#{type} #{options[:class]}"
)
:div,
content_tag(
:div,
content_tag(
:button,
raw("&times;"),
:class => "close", "data-dismiss" => "alert"
) + msg.html_safe,
:class => "container"
),
:class => "alert fade in alert-#{type} #{options[:class]}"
)
flash_messages << text if msg
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/owners_helper.rb
@@ -1,6 +1,6 @@
module OwnersHelper
def owner_image(owner, size, show_tooltip = true, tooltip_text = nil)
options = {size: "#{size}x#{size}", class: ""}
options = { size: "#{size}x#{size}", class: "" }
if owner.user?
options[:class] += " img-circle"
end
Expand All @@ -14,7 +14,7 @@ def owner_image(owner, size, show_tooltip = true, tooltip_text = nil)
else
html = false
end
options[:data] = {placement: "bottom", title: tooltip_text, html: html, container: 'body'}
options[:data] = { placement: "bottom", title: tooltip_text, html: html, container: 'body' }
end
options[:alt] = owner.nickname
image_tag owner.gravatar_url(size), options
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/runs_helper.rb
Expand Up @@ -11,8 +11,8 @@ def database_changes_in_words(run)
sections << pluralize(run.records_changed, "record") + " updated"
end
if run.records_added && run.records_removed && run.records_changed &&
run.records_added == 0 && run.records_removed == 0 && run.records_changed == 0
sections << "nothing changed"
run.records_added == 0 && run.records_removed == 0 && run.records_changed == 0
sections << "nothing changed"
end
unless sections.empty?
sections.join(", ") + " in the database"
Expand All @@ -33,13 +33,13 @@ def scraped_domain_link(domain)
end

def scraped_domains_list(scraped_domains, with_links = true)
d = scraped_domains.map{|d| (with_links ? scraped_domain_link(d) : h(d.name))}
d = scraped_domains.map { |d| (with_links ? scraped_domain_link(d) : h(d.name)) }
# If there are more than 3 in the list then summarise
summary_of_array(d, "other domain".html_safe).to_sentence.html_safe
end

def simplified_scraped_domains_list(scraped_domains)
d = scraped_domains.map{|d| h(d.name)}
d = scraped_domains.map { |d| h(d.name) }
# If there are more than 3 in the list then summarise
if d.count > 3
summary_of_array(d, "other").to_sentence
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/static_helper.rb
Expand Up @@ -33,6 +33,6 @@ def curl_command_linked(scraper, format, key, sql, callback)
end

def api_url_in_html(scraper, format, key, sql, callback)
api_root.html_safe + scraper + '/data.' + format + '?key='.html_safe + key + '&query='.html_safe + sql + callback
api_root.html_safe + scraper + '/data.' + format + '?key='.html_safe + key + '&query='.html_safe + sql + callback
end
end
2 changes: 1 addition & 1 deletion app/helpers/supporters_helper.rb
Expand Up @@ -3,7 +3,7 @@ def number_in_cents_to_currency(number)
number_to_currency(number.to_f / 100)
end

def plan_image_tag(plan, size='64x64')
def plan_image_tag(plan, size = '64x64')
image_tag(plan.image_name, size: size, class: 'plan')
end

Expand Down
2 changes: 1 addition & 1 deletion app/mailers/alert_mailer.rb
Expand Up @@ -6,7 +6,7 @@ class AlertMailer < ActionMailer::Base

def alert_email(user, broken_scrapers, successful_scrapers)
@user, @broken_scrapers, @successful_scrapers = user, broken_scrapers, successful_scrapers
@analytics_params = {utm_medium: "email", utm_source: "alerts"}
@analytics_params = { utm_medium: "email", utm_source: "alerts" }

@subject = "#{pluralize(broken_scrapers.count, 'scraper')} you are watching #{broken_scrapers.count == 1 ? "has" : "have"} errored in the last 48 hours"

Expand Down
3 changes: 2 additions & 1 deletion app/models/api_query.rb
Expand Up @@ -26,6 +26,7 @@ def self.log!(options)
query: query, scraper_id: scraper.id,
owner_id: owner.id, utime: (benchmark.cutime + benchmark.utime),
stime: (benchmark.cstime + benchmark.stime),
wall_time: benchmark.real, size: size, type: type, format: format)
wall_time: benchmark.real, size: size, type: type, format: format
)
end
end
3 changes: 2 additions & 1 deletion app/models/domain.rb
Expand Up @@ -18,7 +18,8 @@ def update_meta!

def self.lookup_metadata_remote(domain_name)
doc = RestClient::Resource.new(
"http://#{domain_name}", verify_ssl: OpenSSL::SSL::VERIFY_NONE).get
"http://#{domain_name}", verify_ssl: OpenSSL::SSL::VERIFY_NONE
).get
header = Nokogiri::HTML(doc).at('html head')
if header
tag = (header.at("meta[name='description']") ||
Expand Down
3 changes: 2 additions & 1 deletion app/models/organization.rb
Expand Up @@ -24,7 +24,8 @@ def refresh_info_from_github!(octokit_client)
update_attributes(
nickname: data.login, name: data.name, blog: data.blog,
company: data.company, location: data.location, email: data.email,
gravatar_url: data.rels[:avatar].href)
gravatar_url: data.rels[:avatar].href
)
rescue Octokit::Unauthorized, Octokit::NotFound
false
end
Expand Down
23 changes: 14 additions & 9 deletions app/models/scraper.rb
Expand Up @@ -95,9 +95,9 @@ def all_watchers
def download_count_by_owner
# TODO: Simplify this by using an association on api_query
count_by_owner_id = api_queries
.group(:owner_id)
.order('count_all desc')
.count
.group(:owner_id)
.order('count_all desc')
.count
count_by_owner_id.map do |id, count|
[Owner.find(id), count]
end
Expand All @@ -116,7 +116,8 @@ def self.new_from_github(full_name, octokit_client)
Scraper.new(
name: repo.name, full_name: repo.full_name, description: repo.description,
github_id: repo.id, owner_id: repo_owner.id,
github_url: repo.rels[:html].href, git_url: repo.rels[:git].href)
github_url: repo.rels[:html].href, git_url: repo.rels[:git].href
)
end

# Find a user related to this scraper that we can use them to make
Expand Down Expand Up @@ -307,7 +308,8 @@ def scraperwiki_shortname
return if scraperwiki_url.nil?

m = scraperwiki_url.match(
%r{https://classic.scraperwiki.com/scrapers/([-\w]+)(/)?})
%r{https://classic.scraperwiki.com/scrapers/([-\w]+)(/)?}
)
m[1] if m
end

Expand Down Expand Up @@ -416,7 +418,8 @@ def fork_from_scraperwiki!
repo = client.edit_repository(
full_name,
description: scraperwiki.title,
homepage: Rails.application.routes.url_helpers.scraper_url(self))
homepage: Rails.application.routes.url_helpers.scraper_url(self)
)
self.update_attributes(description: scraperwiki.title)

files = {
Expand All @@ -429,15 +432,17 @@ def fork_from_scraperwiki!
end
add_commit_to_root_on_github(
forked_by, files,
"Fork of code from ScraperWiki at #{scraperwiki_url}")
"Fork of code from ScraperWiki at #{scraperwiki_url}"
)

# Add another commit (but only if necessary) to translate the code so it
# runs here
unless scraperwiki.translated_code == scraperwiki.code
add_commit_to_master_on_github(
forked_by,
{scraperwiki.language.scraper_filename => scraperwiki.translated_code},
'Automatic update to make ScraperWiki scraper work on morph.io')
{ scraperwiki.language.scraper_filename => scraperwiki.translated_code },
'Automatic update to make ScraperWiki scraper work on morph.io'
)
end

create_scraper_progress.update('Synching repository', 80)
Expand Down
7 changes: 5 additions & 2 deletions app/models/user.rb
Expand Up @@ -30,7 +30,8 @@ def all_owners

def reset_authorization!
update_attributes(
access_token: Morph::Github.reset_authorization(access_token))
access_token: Morph::Github.reset_authorization(access_token)
)
end

# Send all alerts. This method should be run from a daily cron job
Expand All @@ -40,10 +41,12 @@ def self.process_alerts

def process_alerts
return if watched_broken_scrapers_ordered_by_urgency.empty?

AlertMailer.alert_email(
self,
watched_broken_scrapers_ordered_by_urgency,
watched_successful_scrapers).deliver
watched_successful_scrapers
).deliver
rescue Net::SMTPSyntaxError
puts "Warning: user #{nickname} has invalid email address #{email} " \
'(tried to send alert)'
Expand Down
2 changes: 1 addition & 1 deletion app/models/webhook.rb
@@ -1,7 +1,7 @@
class Webhook < ActiveRecord::Base
belongs_to :scraper
has_many :deliveries, class_name: WebhookDelivery, dependent: :delete_all
validates :url, presence: true, url: true, uniqueness: {scope: :scraper, message: "already another webhook with this URL"}
validates :url, presence: true, url: true, uniqueness: { scope: :scraper, message: "already another webhook with this URL" }

def last_delivery
deliveries.order(sent_at: :desc).first
Expand Down

0 comments on commit 3e15cbf

Please sign in to comment.