Skip to content

Commit

Permalink
Rubocop tidyup
Browse files Browse the repository at this point in the history
  • Loading branch information
camillavk committed Mar 1, 2020
1 parent fd020d5 commit aaed66b
Show file tree
Hide file tree
Showing 74 changed files with 393 additions and 337 deletions.
25 changes: 25 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
AllCops:
Exclude:
- 'db/**/*'
- 'test/dummy/db/**/*'
- 'config/**/*'
- 'test/dummy/config/**/*'
- 'script/**/*'
- 'test/dummy/script/**/*'
- 'bin/{rails,rake}'
- 'test/dummy/bin/*'
- 'test/test_helper.rb'
- 'spec/rails_helper.rb'
- 'mission_kontrol_relay.gemspec'

Style/Documentation:
Enabled: false

Metrics/LineLength:
IgnoredPatterns: ['(\A|\s)#']
Exclude:
- 'spec/**/*'

Metrics/BlockLength:
Exclude:
- 'spec/**/*'
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
Expand All @@ -9,4 +11,4 @@ group :development, :test do
gem 'rspec-rails', '3.8.2'
gem 'rubocop'
gem 'simplecov'
end
end
13 changes: 6 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
# load 'rails/tasks/engine.rake'

# load 'rails/tasks/statistics.rake'
load 'rails/tasks/engine.rake'


load 'rails/tasks/statistics.rake'



require 'bundler/gem_tasks'

Bundler::GemHelper.install_tasks
Expand All @@ -26,4 +25,4 @@ Rake::TestTask.new(:test) do |t|
t.verbose = false
end

task :default => :test
task default: :test
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module MissionKontrolRelay
class ApplicationController < ActionController::Base
def index; end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/mission_kontrol_relay/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module MissionKontrolRelay
module ApplicationHelper
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module MissionKontrolRelay
class AssociationMappingService
def initialize(model)
Expand Down Expand Up @@ -42,4 +44,4 @@ def model_associations
associations
end
end
end
end
10 changes: 7 additions & 3 deletions app/services/mission_kontrol_relay/model_retrieval_service.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# frozen_string_literal: true

module MissionKontrolRelay
class ModelRetrievalService
class << self
def build
Rails.application.eager_load!
ActiveRecord::Base.descendants.collect{ |t| t.to_s if valid_table?(t) }.compact
ActiveRecord::Base.descendants.collect do |t|
t.to_s if valid_table?(t)
end .compact
end

private
Expand All @@ -13,8 +17,8 @@ def valid_table?(table)
end

def not_join_table?(table)
table.to_s.split('::').last.split('_').first != "HABTM"
table.to_s.split('::').last.split('_').first != 'HABTM'
end
end
end
end
end
26 changes: 16 additions & 10 deletions app/services/mission_kontrol_relay/validation_mapping_service.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module MissionKontrolRelay
class ValidationMappingService
def initialize(model)
Expand All @@ -17,18 +19,22 @@ def model_validations
validations = []

@model._validate_callbacks.to_a.each do |validation|
validations << {
key: validation.instance_variable_get(:@key),
type: validation.instance_variable_get(:@key).try(:kind),
kind: validation.kind,
name: validation.name,
attributes: validation.try(:filter).try(:attributes),
if: validation.instance_variable_get(:@if),
unless: validation.instance_variable_get(:@unless)
}
validations << validation_attributes(validation)
end

validations
end

def validation_attributes(validation)
{
key: validation.instance_variable_get(:@key),
type: validation.instance_variable_get(:@key).try(:kind),
kind: validation.kind,
name: validation.name,
attributes: validation.try(:filter).try(:attributes),
if: validation.instance_variable_get(:@if),
unless: validation.instance_variable_get(:@unless)
}
end
end
end
end
7 changes: 4 additions & 3 deletions bin/console
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "mission_kontrol_relay"
require 'bundler/setup'
require 'mission_kontrol_relay'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -10,5 +11,5 @@ require "mission_kontrol_relay"
# require "pry"
# Pry.start

require "irb"
require 'irb'
IRB.start(__FILE__)
10 changes: 6 additions & 4 deletions bin/rails
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.

ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/mission_kontrol_relay/engine', __FILE__)
APP_PATH = File.expand_path('../../test/dummy/config/application', __FILE__)
ENGINE_ROOT = File.expand_path('..', __dir__)
ENGINE_PATH = File.expand_path('../lib/mission_kontrol_relay/engine', __dir__)
APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

require 'rails/all'
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

MissionKontrolRelay::Engine.routes.draw do
get '/' => 'application#index'
end
4 changes: 3 additions & 1 deletion lib/mission_kontrol_relay.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "mission_kontrol_relay/engine"
# frozen_string_literal: true

require 'mission_kontrol_relay/engine'

module MissionKontrolRelay
end
4 changes: 3 additions & 1 deletion lib/mission_kontrol_relay/engine.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

module MissionKontrolRelay
class Engine < ::Rails::Engine
isolate_namespace MissionKontrolRelay
end
end
end
5 changes: 3 additions & 2 deletions lib/mission_kontrol_relay/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module MissionKontrolRelay
VERSION = "0.1.0"
VERSION = '0.1.0'
end

31 changes: 16 additions & 15 deletions mission_kontrol_relay.gemspec
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
# frozen_string_literal: true

lib = File.expand_path("../lib", __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "mission_kontrol_relay/version"
require 'mission_kontrol_relay/version'

Gem::Specification.new do |spec|
spec.name = "mission_kontrol_relay"
spec.name = 'mission_kontrol_relay'
spec.version = MissionKontrolRelay::VERSION
spec.authors = ["Camilla"]
spec.email = ["[email protected]"]
spec.authors = ['Camilla']
spec.email = ['[email protected]']

spec.summary = "Write a short summary, because RubyGems requires one."
spec.description = "Write a longer description or delete this line."
spec.homepage = "https://kuwinda.io"
spec.summary = 'Write a short summary, because RubyGems requires one.'
spec.description = 'Write a longer description or delete this line.'
spec.homepage = 'https://kuwinda.io'

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_development_dependency "bundler", "~> 1.17"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "sqlite3"
spec.add_dependency "rails", "~> 5.1"
spec.add_development_dependency 'bundler', '~> 1.17'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'sqlite3'
spec.add_dependency 'rails', '~> 5.1'
end
2 changes: 1 addition & 1 deletion spec/mission_kontrol_relay_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe MissionKontrolRelay do
it "has a version number" do
it 'has a version number' do
expect(MissionKontrolRelay::VERSION).not_to be nil
end
end
10 changes: 5 additions & 5 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# frozen_string_literal: true

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
require File.expand_path('../test/dummy/config/environment.rb', __dir__)

require 'rspec/rails'

ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')

ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
ActiveRecord::Migrator.migrations_paths = [File.expand_path('../test/dummy/db/migrate', __dir__)]
ActiveRecord::Migrator.migrations_paths << File.expand_path('../db/migrate', __dir__)
# Prevent database truncation if the environment is production
abort('The Rails environment is in production mode!') if Rails.env.production?

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
Dir[Rails.root.join('spec/support/**/*.rb')].sort.each { |f| require f }

RSpec.configure do |config|
config.backtrace_exclusion_patterns = [
Expand Down
Loading

0 comments on commit aaed66b

Please sign in to comment.