-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
130 lines (104 loc) · 2.88 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
125
126
127
128
129
130
# frozen_string_literal: true
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['RACK_ENV'] || '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 = Credence::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
Credence::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/#{Credence::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)
Credence::Account.dataset.destroy
end
desc 'Seeds the development database'
task :seed => :load_models do
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
task(:load_libs) { require_app 'lib' }
desc 'Create sample cryptographic key for database'
task :db => :load_libs do
require_app('lib')
puts "DB_KEY: #{SecureDB.generate_key}"
end
desc 'Create sample cryptographic key for tokens and messaging'
task :msg => :load_libs do
require_app('lib')
puts "MSG_KEY: #{AuthToken.generate_key}"
end
desc 'Create sample sign/verify keypair for signed communication'
task :signing => :load_libs do
keypair = SignedRequest.generate_keypair
puts "SIGNING_KEY: #{keypair[:signing_key]}"
puts " VERIFY_KEY: #{keypair[:verify_key]}"
end
end
namespace :run do
# Run in development mode
task :dev do
sh 'rackup -p 3000'
end
end