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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa1be53e7b891ccc7e1bb8b12946e50ef5851d98
4
- data.tar.gz: 1e41078471446335b139f6ab8a5cb7246c836f52
3
+ metadata.gz: 3744b08b2cac266833ffcb26fa59acfcc32560ef
4
+ data.tar.gz: b9c7df8b15e479390d0ae9375592355f11b03b6b
5
5
  SHA512:
6
- metadata.gz: b556058e760e7591e44060b6adbd68c7afdf06c69f4d452a2bfcc05b71ca45f170e1c9ea5c2c7161642732dff5fb291390013f9cd1b64496c0ce6de931434f12
7
- data.tar.gz: e7c8f9043c9d0d553b7b535f1648399807f5ae9c35885443ae7e680fe87d9901918ecfa427542b7f7185156aaff6f63b33dfe3fb891890686febebbdd641f43e
6
+ metadata.gz: 9e66a0b0c755dfcab9693436015b7813a555c83088204cd27fc2de2848e1498be9dc35c92862fa83b9b8afc105ff640c6a281f9ce788f28f4ec923c33876fa15
7
+ data.tar.gz: d0729dafcc6b13cb21295a316c08288380a0b1e79bac4af357c8b8585d082dc7b2341b99b5aae0418a6ec17975bcbe2cbcbf13a2c66d86526e1792ea1b9f0984
data/lib/batteries.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "batteries/tasks/notes"
1
+ require "batteries/tasks"
2
2
 
3
3
  module Batteries
4
4
  end
@@ -0,0 +1,15 @@
1
+ require "batteries/tasks/notes"
2
+ require "batteries/tasks/migrations"
3
+ require "batteries/tasks/secret"
4
+
5
+ module Batteries
6
+ module Tasks
7
+ module_function
8
+
9
+ def new
10
+ Notes.new
11
+ Migrations.new
12
+ Secret.new
13
+ end
14
+ end
15
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Batteries
2
- VERSION = "0.0.1"
2
+ VERSION = "0.2.0"
3
3
  end
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.1
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-28 00:00:00.000000000 Z
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: