-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
124 lines (101 loc) · 2.8 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# frozen_string_literal: true
# rubocop:disable Style/HashSyntax, Style/SymbolArray, Metrics/BlockLength
require 'rake/testtask'
require './require_app'
task :default => :spec
desc 'Tests API specs only'
task :api_spec do
sh 'ruby spec/api_spec.rb'
end
desc 'Test all the specs'
Rake::TestTask.new(:spec) do |t|
t.pattern = 'spec/**/*_spec.rb'
t.warning = false
end
desc 'Rerun tests on live code changes'
task :respec do
sh 'rerun -c rake spec'
end
desc 'Runs rubocop on tested code'
task :style => [:spec, :audit] do
sh 'rubocop .'
end
desc 'Update vulnerabilities lit and audit gems'
task :audit do
sh 'bundle audit check --update'
end
desc 'Checks for release'
task :release? => [:spec, :style, :audit] do
puts "\nReady for release!"
end
task :print_env do
puts "Environment: #{ENV.fetch('RACK_ENV', nil) || 'development'}"
end
desc 'Run application console (pry)'
task :console => :print_env do
sh 'pry -r ./spec/test_load_all'
end
namespace :db do
task :load do
require_app(nil) # loads config code files only
require 'sequel'
Sequel.extension :migration
@app = DFans::Api
end
task :load_models => :load do
require_app(%w[lib models policies services])
end
desc 'Run migrations'
task :migrate => [:load, :print_env] do
puts 'Migrating database to latest'
Sequel::Migrator.run(@app.DB, 'app/db/migrations')
end
desc 'Destroy data in database; maintain tables'
task :delete => :load do
DFans::Account.dataset.destroy
end
desc 'Delete dev or test database file'
task :drop => :load do
if @app.environment == :production
puts 'Cannot wipe production database!'
return
end
db_filename = "app/db/store/#{DFans::Api.environment}.db"
FileUtils.rm(db_filename)
puts "Deleted #{db_filename}"
end
task :reset_seeds => :load_models do
@app.DB[:schema_seeds].delete if @app.DB.tables.include?(:schema_seeds)
DFans::Account.dataset.destroy
end
desc 'Seeds the development database'
task :seed => :load_models do
require_app(%w[lib models policies services])
require 'sequel/extensions/seed'
Sequel::Seed.setup(:development)
Sequel.extension :seed
Sequel::Seeder.apply(@app.DB, 'app/db/seeds')
end
desc 'Delete all data and reseed'
task reseed: [:reset_seeds, :seed]
end
namespace :newkey do
desc 'Create sample cryptographic key for database'
task :db do
require_app('lib')
puts "DB_KEY: #{SecureDB.generate_key}"
end
desc 'Create sample cryptographic key for tokens and messaging'
task :msg do
require_app('lib')
puts "MSG_KEY: #{AuthToken.generate_key}"
end
end
namespace :run do
# Run in development mode
desc 'Run API in development mode'
task :dev do
sh 'rackup -p 3000'
end
end
# rubocop:enable Style/HashSyntax, Style/SymbolArray, Metrics/BlockLength