diff --git a/.hound.yml b/.hound.yml new file mode 100644 index 0000000..142fed4 --- /dev/null +++ b/.hound.yml @@ -0,0 +1,7 @@ +fail_on_violations: true + +ruby: + config_file: config/style_guides/ruby.yml + +AllCops: + RunRailsCops: false diff --git a/config/style_guides/ruby.yml b/config/style_guides/ruby.yml new file mode 100644 index 0000000..a5937f8 --- /dev/null +++ b/config/style_guides/ruby.yml @@ -0,0 +1,238 @@ +AllCops: + Exclude: + - "vendor/**/*" + - "db/schema.rb" + UseCache: false +Style/CollectionMethods: + Description: Preferred collection methods. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size + Enabled: false + PreferredMethods: + collect: map + collect!: map! + find_all: select + reduce: inject +Style/DotPosition: + Description: Checks the position of the dot in multi-line method calls. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains + Enabled: true + EnforcedStyle: trailing + SupportedStyles: + - leading + - trailing +Style/FileName: + Description: Use snake_case for source file names. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files + Enabled: false + Exclude: [] +Style/GuardClause: + Description: Check for conditionals that can be replaced with guard clauses + StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals + Enabled: false + MinBodyLength: 1 +Style/IfUnlessModifier: + Description: Favor modifier if/unless usage when you have a single-line body. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier + Enabled: false + MaxLineLength: 100 +Style/OptionHash: + Description: Don't use option hashes when you can use keyword arguments. + Enabled: false +Style/PercentLiteralDelimiters: + Description: Use `%`-literal delimiters consistently + StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces + Enabled: false + PreferredDelimiters: + "%": "()" + "%i": "()" + "%q": "()" + "%Q": "()" + "%r": "{}" + "%s": "()" + "%w": "()" + "%W": "()" + "%x": "()" +Style/PredicateName: + Description: Check the names of predicate methods. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark + Enabled: true + NamePrefix: + - is_ + - has_ + - have_ + NamePrefixBlacklist: + - is_ + Exclude: + - spec/**/* +Style/RaiseArgs: + Description: Checks the arguments passed to raise/fail. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages + Enabled: false + EnforcedStyle: exploded + SupportedStyles: + - compact + - exploded +Style/SignalException: + Description: Checks for proper usage of fail and raise. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method + Enabled: false + EnforcedStyle: semantic + SupportedStyles: + - only_raise + - only_fail + - semantic +Style/SingleLineBlockParams: + Description: Enforces the names of some block params. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks + Enabled: false + Methods: + - reduce: + - a + - e + - inject: + - a + - e +Style/SingleLineMethods: + Description: Avoid single-line methods. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods + Enabled: false + AllowIfMethodIsEmpty: true +Style/StringLiterals: + Enabled: false +Style/StringLiteralsInInterpolation: + Description: Checks if uses of quotes inside expressions in interpolated strings + match the configured preference. + Enabled: false + EnforcedStyle: single_quotes + SupportedStyles: + - single_quotes + - double_quotes +Style/TrailingComma: + Description: Checks for trailing comma in parameter lists and literals. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas + Enabled: false + EnforcedStyleForMultiline: no_comma + SupportedStyles: + - comma + - no_comma +Metrics/AbcSize: + Description: A calculated magnitude based on number of assignments, branches, and + conditions. + Enabled: false + Max: 15 +Metrics/ClassLength: + Description: Avoid classes longer than 100 lines of code. + Enabled: false + CountComments: false + Max: 100 +Metrics/ModuleLength: + CountComments: false + Max: 100 + Description: Avoid modules longer than 100 lines of code. + Enabled: false +Metrics/CyclomaticComplexity: + Description: A complexity metric that is strongly correlated to the number of test + cases needed to validate a method. + Enabled: false + Max: 6 +Metrics/MethodLength: + Description: Avoid methods longer than 10 lines of code. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods + Enabled: false + CountComments: false + Max: 10 +Metrics/ParameterLists: + Description: Avoid parameter lists longer than three or four parameters. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params + Enabled: false + Max: 5 + CountKeywordArgs: true +Metrics/PerceivedComplexity: + Description: A complexity metric geared towards measuring complexity for a human + reader. + Enabled: false + Max: 7 +Metrics/LineLength: + Max: 100 + # To make it possible to copy or click on URIs in the code, we allow lines + # contaning a URI to be longer than Max. + AllowURI: true + URISchemes: + - http + - https +Lint/AssignmentInCondition: + Description: Don't use assignment in conditions. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition + Enabled: false + AllowSafeAssignment: true +Style/ClassAndModuleChildren: + Enabled: false +Style/InlineComment: + Description: Avoid inline comments. + Enabled: false +Style/AccessorMethodName: + Description: Check the naming of accessor methods for get_/set_. + Enabled: fals +Style/Alias: + Description: Use alias_method instead of alias. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method + Enabled: false +Style/Documentation: + Description: Document classes and non-namespace modules. + Enabled: false +Style/DoubleNegation: + Description: Checks for uses of double negation (!!). + StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang + Enabled: false +Style/EachWithObject: + Description: Prefer `each_with_object` over `inject` or `reduce`. + Enabled: false +Style/EmptyLiteral: + Description: Prefer literals to Array.new/Hash.new/String.new. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash + Enabled: false +Style/ModuleFunction: + Description: Checks for usage of `extend self` in modules. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function + Enabled: false +Style/OneLineConditional: + Description: Favor the ternary operator(?:) over if/then/else/end constructs. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator + Enabled: false +Style/PerlBackrefs: + Description: Avoid Perl-style regex back references. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers + Enabled: false +Style/Send: + Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send` + may overlap with existing methods. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send + Enabled: false +Style/SpecialGlobalVars: + Description: Avoid Perl-style global variables. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms + Enabled: false +Style/VariableInterpolation: + Description: Don't interpolate global, instance and class variables directly in + strings. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate + Enabled: false +Style/WhenThen: + Description: Use when x then ... for one-line cases. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases + Enabled: false +Lint/EachWithObjectArgument: + Description: Check for immutable argument given to each_with_object. + Enabled: true +Lint/HandleExceptions: + Description: Don't suppress exception. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions + Enabled: false +Lint/LiteralInCondition: + Description: Checks of literals used in conditions. + Enabled: false +Lint/LiteralInInterpolation: + Description: Checks for literals used in interpolation. + Enabled: false +Rails/Output: + Enabled: false diff --git a/lib/tape/ansible_runner.rb b/lib/tape/ansible_runner.rb index f570737..3e48bbc 100644 --- a/lib/tape/ansible_runner.rb +++ b/lib/tape/ansible_runner.rb @@ -1,58 +1,54 @@ class Something - def method arg1, arg2 - return arg1 + def method(arg1, arg2) + arg1 end end -def madMethodName - "String" -end - # Executes ansible commands module TapeBoxer class AnsibleRunner < ExecutionModule TapeBoxer.register_module :ansible, self action :configure_dj_runner, - proc {ansible '-t configure_dj_runner -e force_dj_runner_restart=true'}, - "Configures and restarts the delayed job runner" + proc {ansible '-t configure_dj_runner -e force_dj_runner_restart=true'}, + "Configures and restarts the delayed job runner" action :restart_unicorn, - proc {ansible '-t unicorn_restart'}, - "Restarts the unicorns running on the app servers" + proc {ansible '-t unicorn_restart'}, + "Restarts the unicorns running on the app servers" action :stop_unicorn, - proc {ansible '-t unicorn_stop -e kill_unicorn=true'}, - "Stops the unicorns running on the app servers" + proc {ansible '-t unicorn_stop -e kill_unicorn=true'}, + "Stops the unicorns running on the app servers" action :force_stop_unicorn, - proc {ansible '-t unicorn_force_stop -e kill_unicorn=true'}, - "Stops the unicorns running on the app servers" + proc {ansible '-t unicorn_force_stop -e kill_unicorn=true'}, + "Stops the unicorns running on the app servers" action :start_unicorn, - proc {ansible '-t unicorn_start'}, - "Starts the unicorns running on the app servers" + proc {ansible '-t unicorn_start'}, + "Starts the unicorns running on the app servers" action :restart_nginx, - proc {ansible '-t restart_nginx'}, - "Restarts Nginx" + proc {ansible '-t restart_nginx'}, + "Restarts Nginx" action :configure_deployer_user, - proc {ansible '-t deployer'}, - "Ensures the deployer user is present and configures his SSH keys" + proc {ansible '-t deployer'}, + "Ensures the deployer user is present and configures his SSH keys" action :reset_db, - proc {ansible '-t db_reset -e force_db_reset=true'}, - "wipes and re-seeds the DB" + proc {ansible '-t db_reset -e force_db_reset=true'}, + "wipes and re-seeds the DB" action :bundle, - proc {ansible '-t bundle -e force_bundle=true'}, - "Bundles the gems running on the app servers" + proc {ansible '-t bundle -e force_bundle=true'}, + "Bundles the gems running on the app servers" action :be_deploy, - proc {ansible_deploy '-t be_deploy'}, - "Re-deploys fe code" + proc {ansible_deploy '-t be_deploy'}, + "Re-deploys fe code" action :fe_deploy, - proc {ansible_deploy '-t fe_deploy'}, - "Re-deploys fe code" + proc {ansible_deploy '-t fe_deploy'}, + "Re-deploys fe code" action :deploy, - proc {ansible_deploy '-t be_deploy,fe_deploy'}, - "Checks out app code, installs dependencies and restarts unicorns for "\ - "both FE and BE code." + proc {ansible_deploy '-t be_deploy,fe_deploy'}, + "Checks out app code, installs dependencies and restarts unicorns for "\ + "both FE and BE code." action :everything, - proc { ansible if valid_preconfigs }, - "This does it all." + proc { ansible if valid_preconfigs }, + "This does it all." def initialize(*args) super @@ -97,8 +93,8 @@ def exec_ansible(playbook, args) Kernel.exec(cmd) end - - def enforce_roles_path! + + def enforce_roles_path! Dir.mkdir('.tape') unless Dir.exists?('.tape') File.open("#{local_dir}/.tape/ansible.cfg", 'w') do |f| @@ -106,7 +102,7 @@ def enforce_roles_path! f.puts "roles_path=.tape/roles:#{tape_dir}/roles:#{tape_dir}/vendor" f.puts "inventory=#{tapefiles_dir}/hosts" f.puts "retries-dir=/dev/null" - f.puts "retry_files_enabled = False" + f.puts "retry_files_enabled = False" f.puts '[ssh_connection]' f.puts 'ssh_args = -o ForwardAgent=yes' end diff --git a/lib/tape/installer.rb b/lib/tape/installer.rb index a0deebe..2ae0a39 100644 --- a/lib/tape/installer.rb +++ b/lib/tape/installer.rb @@ -3,11 +3,11 @@ class Installer < ExecutionModule TapeBoxer.register_module :installer, self action :install, - proc {install}, - 'Creates all necessary hosts and config files' + proc {install}, + 'Creates all necessary hosts and config files' action :uninstall, - proc {uninstall}, - 'Cleans up files generated by the installer' + proc {uninstall}, + 'Cleans up files generated by the installer' def initialize(*args) super @@ -56,15 +56,33 @@ def rails_app? end def copy_static_app_examples - copy_example 'templates/static_html/omnibox.example.yml', "#{tapefiles_dir}/omnibox.yml" - copy_example 'templates/static_html/deploy.example.yml', "#{tapefiles_dir}/deploy.yml" - copy_example 'templates/static_html/tape_vars.example.yml', "#{tapefiles_dir}/tape_vars.yml" + copy_example( + 'templates/static_html/omnibox.example.yml', + "#{tapefiles_dir}/omnibox.yml" + ) + copy_example( + 'templates/static_html/deploy.example.yml', + "#{tapefiles_dir}/deploy.yml" + ) + copy_example( + 'templates/static_html/tape_vars.example.yml', + "#{tapefiles_dir}/tape_vars.yml" + ) end def copy_basic_examples - copy_example 'templates/base/omnibox.example.yml', "#{tapefiles_dir}/omnibox.yml" - copy_example 'templates/base/deploy.example.yml', "#{tapefiles_dir}/deploy.yml" - copy_example 'templates/base/tape_vars.example.yml', "#{tapefiles_dir}/tape_vars.yml" + copy_example( + 'templates/base/omnibox.example.yml', + "#{tapefiles_dir}/omnibox.yml" + ) + copy_example( + 'templates/base/deploy.example.yml', + "#{tapefiles_dir}/deploy.yml" + ) + copy_example( + 'templates/base/tape_vars.example.yml', + "#{tapefiles_dir}/tape_vars.yml" + ) end def uninstall @@ -99,7 +117,7 @@ def mkdir(name) def copy_example(file, cp_file) print "#{Pathname.new(cp_file).basename}: " begin - if File.exists?("#{cp_file}") + if File.exist?("#{cp_file}") exists else FileUtils.cp("#{tape_dir}/#{file}", "#{cp_file}")