Skip to content

Commit

Permalink
KBP-175 #time 5h improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
İsmail Akbudak committed Jan 3, 2018
1 parent 2daa208 commit f45680e
Show file tree
Hide file tree
Showing 90 changed files with 766 additions and 510 deletions.
3 changes: 3 additions & 0 deletions .haml-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linters:
LineLength:
max: 100
7 changes: 7 additions & 0 deletions .poper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
character_limit:
enabled: false
number: 72

summary_character_limit:
enabled: false
number: 50
10 changes: 8 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Metrics/ClassLength:
Exclude:
- 'lib/cybele/generators/app_generator.rb'

Style/AccessorMethodName:
Naming/AccessorMethodName:
Exclude:
- 'lib/cybele/generators/app_generator.rb'

Expand All @@ -38,8 +38,10 @@ Metrics/BlockLength:

Style/FrozenStringLiteralComment:
EnforcedStyle: when_needed
Exclude:
- 'templates/error_pages/**/*.rb'

Style/IndentHeredoc:
Layout/IndentHeredoc:
Exclude:
- 'spec/features/cli_help_spec.rb'

Expand All @@ -48,6 +50,10 @@ Naming/HeredocDelimiterNaming:
- 'spec/features/cli_help_spec.rb'
- 'spec/features/git_and_git_flow_spec.rb'

Layout/InitialIndentation:
Exclude:
- 'templates/error_pages/**/*.rb'

Style/ClassAndModuleChildren:
Exclude:
- 'templates/app_files/app/controllers/**/*.rb'
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.3
2.3.5
19 changes: 19 additions & 0 deletions config.reek
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"lib/cybele/":
IrresponsibleModule:
enabled: false
"templates/":
IrresponsibleModule:
enabled: false
"templates/app_files/app/controllers/":
InstanceVariableAssumption:
enabled: false
IrresponsibleModule:
enabled: false
"templates/app_files/app/mailers":
InstanceVariableAssumption:
enabled: false
IrresponsibleModule:
enabled: false

UtilityFunction:
public_methods_only: true
6 changes: 2 additions & 4 deletions cybele.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ Gem::Specification.new do |spec|
spec.add_dependency 'bundler', '~> 1.5'
spec.add_runtime_dependency 'rails', '~> 5.0', Cybele::RAILS_VERSION
spec.add_development_dependency 'pronto', '~> 0.9.5'
spec.add_development_dependency 'pronto-flay', '~> 0.9.0'
spec.add_development_dependency 'pronto-rubocop', '~> 0.9.0'
spec.add_development_dependency 'pronto-fasterer', '~> 0.9.0'
spec.add_development_dependency 'pronto-flay', '~> 0.9.0'
spec.add_development_dependency 'pronto-reek', '~> 0.9.0'
spec.add_development_dependency 'pronto-poper', '~> 0.9.0'
spec.add_development_dependency 'pronto-spell', '~> 0.9.0'
spec.add_development_dependency 'pronto-rubocop', '~> 0.9.0'
spec.add_development_dependency 'rspec', '~> 3.5'
spec.add_development_dependency 'thor', '~> 0.19.4'

Expand Down
1 change: 1 addition & 0 deletions lib/cybele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require 'cybele/helpers/error_pages'
require 'cybele/helpers/audited'
require 'cybele/helpers/routes'
require 'cybele/helpers/general'
require 'cybele/helpers/basic_authentication'
require 'cybele/helpers/app_files/assets_files'
require 'cybele/helpers/app_files/controller_files'
Expand Down
80 changes: 1 addition & 79 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,75 +29,7 @@ class AppBuilder < Rails::AppBuilder # rubocop:disable Metrics/ClassLength
include Cybele::Helpers::AppFiles::ViewGems
include Cybele::Helpers::Docker
include Cybele::Helpers::Pronto

def readme
template 'README.md.erb',
'README.md',
force: true
end

def remove_readme_rdoc
remove_file 'README.rdoc',
force: true
end

def add_gems
# Add gems
append_file('Gemfile', template_content('Gemfile.erb'))
end

def force_ssl_setting
gsub_file 'config/environments/production.rb',
/# config.force_ssl = true/, "config.force_ssl = ENV['RAILS_FORCE_SSL'].present?"
gsub_file 'config/environments/staging.rb',
/# config.force_ssl = true/, "config.force_ssl = ENV['RAILS_FORCE_SSL'].present?"
append_file('.env.staging', template_content('ssl/ssl_env_staging.erb'))
append_file('.env.production', template_content('ssl/ssl_env_production.erb'))
end

def add_editor_config
copy_file 'editorconfig', '.editorconfig'
end

def add_ruby_version
copy_file 'ruby-version', '.ruby-version'
end

def add_cybele_version
copy_file 'VERSION.txt', 'VERSION.txt'
run 'ln -s ../VERSION.txt public/VERSION.txt'
end

def use_postgres_config_template
template 'postgresql_database.yml.erb',
'config/database.yml',
force: true
end

def create_database
bundle_command 'exec rake db:create db:migrate'
end

def generate_config
generate 'config:install'
run 'cp config/settings/development.yml config/settings/staging.yml'
append_file('config/settings.yml', template_content('settings.yml.erb'))
remove_file 'config/settings.local.yml', force: true
end

def generate_rollbar
generate 'rollbar'
end

def generate_guard
bundle_command 'exec guard init'
inject_into_file('Guardfile', "\n\n#{template_content('guardfile/guardfile_settings.rb.erb')}",
after: 'config/Guardfile" instead of "Guardfile"')
end

def configure_bullet
configure_environment 'development', template_content('bullet/bullet_settings.rb.erb')
end
include Cybele::Helpers::General

def setup_gitignore_files
remove_file '.gitignore', force: true
Expand Down Expand Up @@ -125,15 +57,5 @@ def git_and_git_flow_commands
git add: '.'
git commit: '-m "Project initialized"'
end

private

def configure_environment(rails_env, config)
inject_into_file("config/environments/#{rails_env}.rb", "\n#{config}", before: "\nend")
end

def action_mailer_host(rails_env)
configure_environment(rails_env, template_content('mailer/host.rb.erb'))
end
end
end
1 change: 0 additions & 1 deletion lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def setup_devise
build :generate_devise_settings
say 'Adding devise models'
build :generate_devise_models
say 'Generate devise'
end

def configure_mail_setting
Expand Down
14 changes: 11 additions & 3 deletions lib/cybele/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ module Helpers
def replace_in_file(relative_path, find, replace)
path = File.join(destination_root, relative_path)
contents = IO.read(path)
unless contents.gsub!(find, replace)
raise "#{find.inspect} not found in #{relative_path}"
end
raise "#{find.inspect} not found in #{relative_path}" unless contents.gsub!(find, replace)
File.open(path, 'w') { |file| file.write(contents) }
end

Expand All @@ -22,5 +20,15 @@ def configure_app_name(files)
gsub_file file, /<%= app_name %>/, app_name
end
end

def append_template_to_file(file, template_file)
append_file(file, template_content(template_file))
end

def files_to_template(files)
files.each do |key, value|
template key, value, force: true
end
end
end
end
3 changes: 3 additions & 0 deletions lib/cybele/helpers/app_files/controller_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module Helpers
module AppFiles
module ControllerFiles
def customize_controller_files
# Controller concern files
directory 'app_files/app/controllers/concerns', 'app/controllers/concerns'

# Hq controller files
directory 'app_files/app/controllers/hq', 'app/controllers/hq'

Expand Down
20 changes: 9 additions & 11 deletions lib/cybele/helpers/app_files/view_gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ module Helpers
module AppFiles
module ViewGems
def add_required_view_gems
# Add bootstrap gem
append_file('Gemfile', template_content('app_files/bootstrap_Gemfile.erb'))

# Add blankable gem
append_file('Gemfile', template_content('app_files/blankable_Gemfile.erb'))

# Add breadcrumb gem
append_file('Gemfile', template_content('app_files/breadcrumb_Gemfile.erb'))

# Add jquery gem
append_file('Gemfile', template_content('app_files/jquery_Gemfile.erb'))
files = %w[
app_files/bootstrap_Gemfile.erb
app_files/blankable_Gemfile.erb
app_files/breadcrumb_Gemfile.erb
app_files/jquery_Gemfile.erb
]
files.each do |file|
append_template_to_file('Gemfile', file)
end
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/cybele/helpers/basic_authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ def create_basic_authentication_files

def add_to_settings_yml
# Add basic authentication settings to the config/settings.yml file
append_file 'config/settings.yml',
template_content('basic_authentication/basic_authentication_settings.yml.erb')
append_template_to_file 'config/settings.yml',
'basic_authentication/basic_authentication_settings.yml.erb'
end

def add_to_dotenv_files
# Add basic authentication env to the all env files
append_file('env.sample', template_content('basic_authentication/no_basic_authentication.erb'))
append_file('.env.local', template_content('basic_authentication/no_basic_authentication.erb'))
append_file('.env.staging', template_content('basic_authentication/yes_basic_authentication.erb'))
append_file('.env.production', template_content('basic_authentication/no_basic_authentication.erb'))
append_template_to_file('env.sample', 'basic_authentication/no_basic_authentication.erb')
append_template_to_file('.env.local', 'basic_authentication/no_basic_authentication.erb')
append_template_to_file('.env.staging', 'basic_authentication/yes_basic_authentication.erb')
append_template_to_file('.env.production', 'basic_authentication/no_basic_authentication.erb')
end

def include_basic_authentication_module
Expand Down
86 changes: 86 additions & 0 deletions lib/cybele/helpers/general.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# frozen_string_literal: true

module Cybele
module Helpers
module General
def readme
template 'README.md.erb',
'README.md',
force: true
end

def remove_readme_rdoc
remove_file 'README.rdoc',
force: true
end

def add_gems
# Add gems
append_file('Gemfile', template_content('Gemfile.erb'))
end

def force_ssl_setting
gsub_file 'config/environments/production.rb',
/# config.force_ssl = true/, "config.force_ssl = ENV['RAILS_FORCE_SSL'].present?"
gsub_file 'config/environments/staging.rb',
/# config.force_ssl = true/, "config.force_ssl = ENV['RAILS_FORCE_SSL'].present?"
append_file('.env.staging', template_content('ssl/ssl_env_staging.erb'))
append_file('.env.production', template_content('ssl/ssl_env_production.erb'))
end

def add_editor_config
copy_file 'editorconfig', '.editorconfig'
end

def add_ruby_version
copy_file 'ruby-version', '.ruby-version'
end

def add_cybele_version
copy_file 'VERSION.txt', 'VERSION.txt'
run 'ln -s ../VERSION.txt public/VERSION.txt'
end

def use_postgres_config_template
template 'postgresql_database.yml.erb',
'config/database.yml',
force: true
end

def create_database
bundle_command 'exec rake db:create db:migrate'
end

def generate_config
generate 'config:install'
run 'cp config/settings/development.yml config/settings/staging.yml'
append_file('config/settings.yml', template_content('settings.yml.erb'))
remove_file 'config/settings.local.yml', force: true
end

def generate_rollbar
generate 'rollbar'
end

def generate_guard
bundle_command 'exec guard init'
inject_into_file('Guardfile', "\n\n#{template_content('guardfile/guardfile_settings.rb.erb')}",
after: 'config/Guardfile" instead of "Guardfile"')
end

def configure_bullet
configure_environment 'development', template_content('bullet/bullet_settings.rb.erb')
end

private

def configure_environment(rails_env, config)
inject_into_file("config/environments/#{rails_env}.rb", "\n#{config}", before: "\nend")
end

def action_mailer_host(rails_env)
configure_environment(rails_env, template_content('mailer/host.rb.erb'))
end
end
end
end
2 changes: 1 addition & 1 deletion lib/cybele/helpers/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def configure_smtp
template_content('recipient_interceptor/recipient_interceptor_staging.rb.erb')
configure_environment 'production', template_content('mailer/smtp.rb.erb')
configure_environment 'staging', template_content('mailer/smtp.rb.erb')
append_file 'config/settings.yml', template_content('mailer/mailer_settings.yml.erb')
append_template_to_file 'config/settings.yml', 'mailer/mailer_settings.yml.erb'
end

def setup_mailtrap
Expand Down
Loading

0 comments on commit f45680e

Please sign in to comment.