batteries 0.0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/batteries.rb +1 -1
- data/lib/batteries/tasks.rb +15 -0
- data/lib/batteries/tasks/migrations.rb +73 -0
- data/lib/batteries/tasks/secret.rb +34 -0
- data/lib/batteries/version.rb +1 -1
- metadata +33 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3744b08b2cac266833ffcb26fa59acfcc32560ef
|
4
|
+
data.tar.gz: b9c7df8b15e479390d0ae9375592355f11b03b6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e66a0b0c755dfcab9693436015b7813a555c83088204cd27fc2de2848e1498be9dc35c92862fa83b9b8afc105ff640c6a281f9ce788f28f4ec923c33876fa15
|
7
|
+
data.tar.gz: d0729dafcc6b13cb21295a316c08288380a0b1e79bac4af357c8b8585d082dc7b2341b99b5aae0418a6ec17975bcbe2cbcbf13a2c66d86526e1792ea1b9f0984
|
data/lib/batteries.rb
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "rake"
|
3
|
+
require "rake/tasklib"
|
4
|
+
|
5
|
+
module Batteries
|
6
|
+
module Tasks
|
7
|
+
class Migrations < ::Rake::TaskLib
|
8
|
+
attr_accessor :migrations_path, :requires
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@migrations_path = "migrate"
|
12
|
+
@requires = ["./db"]
|
13
|
+
|
14
|
+
yield self if block_given?
|
15
|
+
|
16
|
+
define
|
17
|
+
end
|
18
|
+
|
19
|
+
def define
|
20
|
+
desc "Migrate test database to latest version"
|
21
|
+
task :test_up do
|
22
|
+
migrate("test", nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Migrate test database all the way down"
|
26
|
+
task :test_down do
|
27
|
+
migrate("test", 0)
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Migrate test database all the way down and then back up"
|
31
|
+
task :test_bounce do
|
32
|
+
migrate("test", 0)
|
33
|
+
migrate("test", nil)
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Migrate development database to latest version"
|
37
|
+
task :dev_up, [:version] do |_t, args|
|
38
|
+
version = args[:version]
|
39
|
+
version = version ? version.to_i : nil
|
40
|
+
|
41
|
+
migrate("development", version)
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Migrate development database to all the way down"
|
45
|
+
task :dev_down, [:version] do |_t, args|
|
46
|
+
version = args[:version].to_i
|
47
|
+
|
48
|
+
migrate("development", version)
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Migrate development database all the way down and then back up"
|
52
|
+
task :dev_bounce do
|
53
|
+
migrate("development", 0)
|
54
|
+
migrate("development", nil)
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "Migrate production database to latest version"
|
58
|
+
task :prod_up do
|
59
|
+
migrate("production", nil)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def migrate(env, version)
|
64
|
+
ENV["RACK_ENV"] = env
|
65
|
+
require "logger"
|
66
|
+
requires.each { |f| require f }
|
67
|
+
Sequel.extension :migration
|
68
|
+
DB.loggers << Logger.new(STDOUT)
|
69
|
+
Sequel::Migrator.apply(DB, migrations_path, version)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "rake"
|
3
|
+
require "rake/tasklib"
|
4
|
+
|
5
|
+
module Batteries
|
6
|
+
module Tasks
|
7
|
+
class Secret < ::Rake::TaskLib
|
8
|
+
attr_accessor :name, :description, :secret_file, :generator
|
9
|
+
|
10
|
+
def initialize(name = :secret)
|
11
|
+
@name = name
|
12
|
+
@secret_file = ".session_secret"
|
13
|
+
@description = "Generate a session secret in #{secret_file}"
|
14
|
+
@generator = method(:default_generator)
|
15
|
+
|
16
|
+
yield self if block_given?
|
17
|
+
|
18
|
+
define
|
19
|
+
end
|
20
|
+
|
21
|
+
def define
|
22
|
+
desc description
|
23
|
+
task name do
|
24
|
+
default_generator.call if default_generator.respond_to?(:call)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def default_generator
|
29
|
+
require "securerandom"
|
30
|
+
File.write(secret_file, SecureRandom.random_bytes(40))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/batteries/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: batteries
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Daniels
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubygems-tasks
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
27
55
|
description:
|
28
56
|
email:
|
29
57
|
- adam@mediadrive.ca
|
@@ -34,7 +62,10 @@ files:
|
|
34
62
|
- LICENSE.txt
|
35
63
|
- README.md
|
36
64
|
- lib/batteries.rb
|
65
|
+
- lib/batteries/tasks.rb
|
66
|
+
- lib/batteries/tasks/migrations.rb
|
37
67
|
- lib/batteries/tasks/notes.rb
|
68
|
+
- lib/batteries/tasks/secret.rb
|
38
69
|
- lib/batteries/version.rb
|
39
70
|
homepage: https://github.com/adam12/batteries
|
40
71
|
licenses:
|