Skip to content

Instantly share code, notes, and snippets.

@fj
Created November 5, 2014 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fj/9f8b138392f6fd0fe7be to your computer and use it in GitHub Desktop.
Save fj/9f8b138392f6fd0fe7be to your computer and use it in GitHub Desktop.
UpHex's Rubocop and Rakefile
Metrics/LineLength:
Max: 125
require 'bundler/setup'
require 'padrino-core/cli/rake'
PadrinoTasks.use(:database)
PadrinoTasks.use(:activerecord)
PadrinoTasks.init
# Import tasks from task directory.
Dir[File.join %w{lib uphex tasks ** *.rake}].each do |f|
import f
end
def rake_ignore_errors(*errors, &block)
begin
yield block
rescue *errors => e
warn "! ignored #{e.class} ⇒ #{e}"
end
end
def environment_guard(&block)
target_env = ENV['RACK_ENV']
raise ArgumentError, "won't run this task without an environment specified" unless target_env
legal_environments = %w{development test}
unless legal_environments.include? target_env
raise RuntimeError, "environment is \"#{target_env}\", but will only run this task in #{legal_environments}"
end
block.call
end
namespace :uphex do
rake_ignore_errors(LoadError) do
require 'rspec/core/rake_task'
desc 'run specs'
RSpec::Core::RakeTask.new(:spec)
require 'rubocop/rake_task'
desc 'run Rubocop'
RuboCop::RakeTask.new(:rubocop) do |task|
style_cops = [
'Style/CaseIndentation',
'Style/ConstantName',
'Style/EmptyLines',
'Style/IndentationWidth',
'Style/SpaceAroundOperators',
'Style/Tab',
'Style/TrailingWhitespace',
'Metrics/CyclomaticComplexity',
'Metrics/LineLength',
'Metrics/ParameterLists',
'Metrics/PerceivedComplexity',
].join(',')
task.options = [
'-D',
'--lint',
"--only", style_cops,
]
task.formatters = ['fuubar']
directories = %w[
app
db
config
lib
spec
]
task.patterns = directories.map { |prefix| "#{prefix}/**/*.rb" }
end
task :test => [:spec, :rubocop]
end
desc "Write configuration files from templates"
task :make_config_files do
sources = [
'database',
'env',
'newrelic',
'providers',
]
rake_ignore_errors(Errno::ENOENT) do
sources.each do |source|
src = "config/#{source}.yml.template"
dest = "config/#{source}.yml"
FileUtils.cp src, dest, :verbose => true
end
end
end
desc "Initialize the UpHex environment"
task :init => [
'uphex:make_config_files',
'ar:create',
'ar:migrate',
'db:seed'
]
# Sinatra::AssetPack Rake tasks.
APP_FILE = 'config/boot.rb'
APP_CLASS = 'UpHex::Beacon::App'
require 'sinatra/assetpack/rake'
end
task 'db:schema:load' => ['ar:schema:load']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment