Skip to content

Commit

Permalink
fix rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Aug 25, 2019
1 parent 3f0d369 commit f1aa012
Show file tree
Hide file tree
Showing 24 changed files with 105 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ doc/dependencies*
!.env.travis
docker-compose.override.yml
.ruby-version
.vscode
.vscode
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require: rubocop-performance
inherit_from: .rubocop_todo.yml

# from https://github.com/rails/rails/blob/master/.rubocop.yml
Expand Down
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def initialize(credentials, options={})
"uid" => uid,
"name" => payload["name"],
"email" => payload["email"],
"role_id" => researcher.role_id
"role_id" => researcher.role_id,
"beta_tester" => researcher.beta_tester
}

@jwt = encode_token(payload.merge(iat: Time.now.to_i, exp: Time.now.to_i + 3600 * 24 * 30))
Expand Down
24 changes: 12 additions & 12 deletions db/migrate/20190517154500_add_extra_provider_contacts.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# frozen_string_literal: true

class AddExtraProviderContacts < ActiveRecord::Migration[5.2]
def up
add_column :allocator, :general_contact, :json
add_column :allocator, :technical_contact, :json
add_column :allocator, :service_contact, :json
add_column :allocator, :voting_contact, :json
end
def up
add_column :allocator, :general_contact, :json
add_column :allocator, :technical_contact, :json
add_column :allocator, :service_contact, :json
add_column :allocator, :voting_contact, :json
end

def down
remove_column :allocator, :general_contact
remove_column :allocator, :technical_contact
remove_column :allocator, :service_contact
remove_column :allocator, :voting_contact
end
def down
remove_column :allocator, :general_contact
remove_column :allocator, :technical_contact
remove_column :allocator, :service_contact
remove_column :allocator, :voting_contact
end
end
2 changes: 2 additions & 0 deletions db/migrate/20190521152430_add_billing_contact.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddBillingContact < ActiveRecord::Migration[5.2]
def up
add_column :allocator, :billing_contact, :json
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20190522162430_remove_general_contact.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class RemoveGeneralContact < ActiveRecord::Migration[5.2]
def up
remove_column :allocator, :general_contact
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20190604093226_add_events_table.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddEventsTable < ActiveRecord::Migration[5.2]
def change
create_table "events", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20190621202343_remove_general_contact_phone.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class RemoveGeneralContactPhone < ActiveRecord::Migration[5.2]
def up
remove_column :allocator, :contact_name
Expand Down
5 changes: 3 additions & 2 deletions db/migrate/20190629072238_add_researchers_table.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

class AddResearchersTable < ActiveRecord::Migration[5.2]
def up
create_table "researchers", force: :cascade do |t|
Expand All @@ -11,7 +12,7 @@ def up
t.string "authentication_token", limit: 191
t.string "role_id", limit: 255, default: "user"
t.boolean "auto_update", default: true
t.datetime "expires_at", default: '1970-01-01 00:00:00', null: false
t.datetime "expires_at", default: "1970-01-01 00:00:00", null: false
t.datetime "created_at", precision: 3
t.datetime "updated_at", precision: 3
t.text "other_names", limit: 65535
Expand All @@ -28,7 +29,7 @@ def up
t.boolean "is_public", default: true
t.boolean "beta_tester", default: false
end

add_index "researchers", ["uid"], name: "index_researchers_on_uid", unique: true, using: :btree
end

Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20190723114539_add_consortium_lead_id.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddConsortiumLeadId < ActiveRecord::Migration[5.2]
def change
add_column :allocator, :consortium_lead_id, :string
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20190727035047_add_client_type_column.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddClientTypeColumn < ActiveRecord::Migration[5.2]
def change
add_column :datacentre, :client_type, :string, limit: 191
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20190727170040_add_client_fields.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddClientFields < ActiveRecord::Migration[5.2]
def change
remove_index :datacentre, [:re3data]
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20190805190522_rename_consortum_lead_id_column.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class RenameConsortumLeadIdColumn < ActiveRecord::Migration[5.2]
def change
rename_column :allocator, :consortium_lead_id, :consortium_id
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20190807002912_add_salesforce_id_column.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddSalesforceIdColumn < ActiveRecord::Migration[5.2]
def change
add_column :datacentre, :salesforce_id, :string, limit: 191
Expand Down
2 changes: 2 additions & 0 deletions lib/tasks/activity.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

namespace :activity do
desc "Create index for activities"
task :create_index => :environment do
Expand Down
4 changes: 3 additions & 1 deletion lib/tasks/client.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

namespace :client do
desc "Create index for clients"
task :create_index => :environment do
Expand Down Expand Up @@ -184,4 +186,4 @@ namespace :client do
puts "Client prefix for client #{target.symbol} and prefix #{prefix} created."
end
end
end
end
2 changes: 2 additions & 0 deletions lib/tasks/doi.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

namespace :doi do
desc "Create index for dois"
task :create_index => :environment do
Expand Down
3 changes: 2 additions & 1 deletion lib/tasks/elasticsearch.rake
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
require 'elasticsearch/rails/tasks/import'
# frozen_string_literal: true

require 'elasticsearch/rails/tasks/import'
2 changes: 2 additions & 0 deletions lib/tasks/event.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

namespace :event do
desc "Create index for events"
task :create_index => :environment do
Expand Down
54 changes: 28 additions & 26 deletions lib/tasks/handle.rake
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
# frozen_string_literal: true

namespace :handle do
desc 'Get DOIs by prefix'
task :get_dois => :environment do
if ENV['PREFIX'].nil?
puts "ENV['PREFIX'] is required."
desc "Get DOIs by prefix"
task get_dois: :environment do
if ENV["PREFIX"].nil?
puts "ENV[\"PREFIX\"] is required."
exit
end

Doi.get_dois(prefix: ENV['PREFIX'])
Doi.get_dois(prefix: ENV["PREFIX"])
end

desc 'Get DOI'
task :get_doi => :environment do
if ENV['DOI'].nil?
puts "ENV['DOI'] is required."
desc "Get DOI"
task get_doi: :environment do
if ENV["DOI"].nil?
puts "ENV[\"DOI\"] is required."
exit
end

response = Doi.get_doi(doi: ENV['DOI'])
url = response.body.dig('data', 'values', 0, 'data', 'value')
puts "DOI #{ENV['DOI']} uses URL #{url}" if url.present?
response = Doi.get_doi(doi: ENV["DOI"])
url = response.body.dig("data", "values", 0, "data", "value")
puts "DOI #{ENV["DOI"]} uses URL #{url}" if url.present?
end

desc 'Delete DOI'
task :delete_doi => :environment do
if ENV['DOI'].nil?
puts "ENV['DOI'] is required."
desc "Delete DOI"
task delete_doi: :environment do
if ENV["DOI"].nil?
puts "ENV[\"DOI\"] is required."
exit
elsif !ENV['DOI'].start_with?("10.5072")
elsif !ENV["DOI"].start_with?("10.5072")
puts "Only DOIs with prefix 10.5072 can be deleted."
exit
end

response = Doi.delete_doi(doi: ENV['DOI'])
puts "Deleted DOI #{ENV['DOI']}." if response.body.dig('data', 'responseCode') == 1
response = Doi.delete_doi(doi: ENV["DOI"])
puts "Deleted DOI #{ENV["DOI"]}." if response.body.dig("data", "responseCode") == 1
end

desc 'Delete DOIs with test prefix'
task :delete_dois => :environment do
if ENV['PREFIX'].nil?
puts "ENV['PREFIX'] is required."
desc "Delete DOIs with test prefix"
task delete_dois: :environment do
if ENV["PREFIX"].nil?
puts "ENV[\"PREFIX\"] is required."
exit
elsif ENV['PREFIX'] != "10.5072"
elsif ENV["PREFIX"] != "10.5072"
puts "Only DOIs with prefix 10.5072 can be deleted."
exit
end
Expand All @@ -50,7 +52,7 @@ namespace :handle do
puts "Found #{dois.length} DOIs."
dois.each do |doi|
response = Doi.delete_doi(doi: doi)
puts "Deleted DOI #{doi}." if response.body.dig('data', 'responseCode') == 1
puts "Deleted DOI #{doi}." if response.body.dig("data", "responseCode") == 1
end
end
end
end
2 changes: 2 additions & 0 deletions lib/tasks/memcached.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

namespace :memcached do
desc 'Clears the Rails cache'
task :flush => :environment do
Expand Down
2 changes: 2 additions & 0 deletions lib/tasks/prefix.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

namespace :prefix do
desc 'Delete prefix and associated DOIs'
task :delete => :environment do
Expand Down
22 changes: 12 additions & 10 deletions lib/tasks/provider.rake
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
# frozen_string_literal: true

namespace :provider do
desc "Create index for providers"
task :create_index => :environment do
task create_index: :environment do
puts Provider.create_index
end

desc "Delete index for providers"
task :delete_index => :environment do
task delete_index: :environment do
puts Provider.delete_index
end

desc "Upgrade index for providers"
task :upgrade_index => :environment do
task upgrade_index: :environment do
puts Provider.upgrade_index
end

desc "Show index stats for providers"
task :index_stats => :environment do
task index_stats: :environment do
puts Provider.index_stats
end

desc "Switch index for providers"
task :switch_index => :environment do
task switch_index: :environment do
puts Provider.switch_index
end

desc "Return active index for providers"
task :active_index => :environment do
task active_index: :environment do
puts Provider.active_index + " is the active index."
end

desc "Start using alias indexes for providers"
task :start_aliases => :environment do
task start_aliases: :environment do
puts Provider.start_aliases
end

desc "Monitor reindexing for providers"
task :monitor_reindex => :environment do
task monitor_reindex: :environment do
puts Provider.monitor_reindex
end

desc "Wrap up starting using alias indexes for providers"
task :finish_aliases => :environment do
task finish_aliases: :environment do
puts Provider.finish_aliases
end

desc 'Import all providers'
task :import => :environment do
task import: :environment do
Provider.import(index: Provider.inactive_index)
end
end
24 changes: 13 additions & 11 deletions lib/tasks/researcher.rake
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
# frozen_string_literal: true

namespace :researcher do
desc "Create index for researchers"
task :create_index => :environment do
task create_index: :environment do
puts Researcher.create_index
end

desc "Delete index for researchers"
task :delete_index => :environment do
task delete_index: :environment do
puts Researcher.delete_index
end

desc "Upgrade index for researchers"
task :upgrade_index => :environment do
task upgrade_index: :environment do
puts Researcher.upgrade_index
end

desc "Show index stats for researchers"
task :index_stats => :environment do
task index_stats: :environment do
puts Researcher.index_stats
end

desc "Switch index for researchers"
task :switch_index => :environment do
task switch_index: :environment do
puts Researcher.switch_index
end

desc "Return active index for researchers"
task :active_index => :environment do
task active_index: :environment do
puts Researcher.active_index + " is the active index."
end

desc "Start using alias indexes for researchers"
task :start_aliases => :environment do
task start_aliases: :environment do
puts Researcher.start_aliases
end

desc "Monitor reindexing for researchers"
task :monitor_reindex => :environment do
task monitor_reindex: :environment do
puts Researcher.monitor_reindex
end

desc "Wrap up starting using alias indexes for researchers"
task :finish_aliases => :environment do
task finish_aliases: :environment do
puts Researcher.finish_aliases
end

desc 'Import all researchers'
task :import => :environment do
task import: :environment do
Researcher.import(index: Researcher.inactive_index)
end
end
end

0 comments on commit f1aa012

Please sign in to comment.