batteries 0.2.0 → 0.3.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/tasks/migrations.rb +8 -9
- data/lib/batteries/tasks/notes.rb +5 -5
- data/lib/batteries/tasks/secret.rb +8 -4
- data/lib/batteries/tasks.rb +19 -4
- data/lib/batteries/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b72dbe55d0b2e75ac7f7252523cc0a6e9aa0e8c
|
4
|
+
data.tar.gz: 14941b0f5403a9f8d808dab344a1311ba478d5e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a580120bb878da83920740b14f0897633026a4fbdb080df8a206fd8ade2c7351e7ea461e7bebd4220b9d301f50c7e88060479e540fff04dd6b07f4fa4a5abf28
|
7
|
+
data.tar.gz: a2d3ed6ab93bed2e952dd51e387be6c3a6cdb549521a8e2057649390a540b7d4397e89ad1f65be24a9809a93e1689bce5810ed3916ab7ed45102ed15f245adb4
|
@@ -1,15 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "rake"
|
3
3
|
require "rake/tasklib"
|
4
|
+
require "logger"
|
4
5
|
|
5
6
|
module Batteries
|
6
7
|
module Tasks
|
7
8
|
class Migrations < ::Rake::TaskLib
|
8
|
-
attr_accessor :migrations_path, :
|
9
|
+
attr_accessor :migrations_path, :database, :logger
|
9
10
|
|
10
|
-
def initialize
|
11
|
-
@migrations_path = "migrate"
|
12
|
-
@
|
11
|
+
def initialize(options: {})
|
12
|
+
@migrations_path = options.fetch(:migrations_path) { "migrate" }
|
13
|
+
@database = options.fetch(:database) { DB if defined?(DB) }
|
14
|
+
@logger = options.fetch(:logger) { Logger.new($stdout) }
|
13
15
|
|
14
16
|
yield self if block_given?
|
15
17
|
|
@@ -61,12 +63,9 @@ module Batteries
|
|
61
63
|
end
|
62
64
|
|
63
65
|
def migrate(env, version)
|
64
|
-
ENV["RACK_ENV"] = env
|
65
|
-
require "logger"
|
66
|
-
requires.each { |f| require f }
|
67
66
|
Sequel.extension :migration
|
68
|
-
|
69
|
-
Sequel::Migrator.apply(
|
67
|
+
database.loggers << logger if logger
|
68
|
+
Sequel::Migrator.apply(database, migrations_path, version)
|
70
69
|
end
|
71
70
|
end
|
72
71
|
end
|
@@ -7,11 +7,11 @@ module Batteries
|
|
7
7
|
class Notes < ::Rake::TaskLib
|
8
8
|
attr_accessor :name, :description, :excluded_dirs, :matchers
|
9
9
|
|
10
|
-
def initialize(name = :notes)
|
11
|
-
@name = name
|
12
|
-
@description = "Notes"
|
13
|
-
@excluded_dirs = %w(node_modules public)
|
14
|
-
@matchers = %w(FIXME TODO)
|
10
|
+
def initialize(name = :notes, options: {})
|
11
|
+
@name = options[:name] || name
|
12
|
+
@description = options.fetch(:description) { "Notes" }
|
13
|
+
@excluded_dirs = options.fetch(:excluded_dirs) { %w(node_modules public) }
|
14
|
+
@matchers = options.fetch(:matchers) { %w(FIXME TODO) }
|
15
15
|
|
16
16
|
yield self if block_given?
|
17
17
|
|
@@ -7,11 +7,11 @@ module Batteries
|
|
7
7
|
class Secret < ::Rake::TaskLib
|
8
8
|
attr_accessor :name, :description, :secret_file, :generator
|
9
9
|
|
10
|
-
def initialize(name = :secret)
|
10
|
+
def initialize(name = :secret, options: {})
|
11
11
|
@name = name
|
12
|
-
@secret_file = ".session_secret"
|
13
|
-
@description =
|
14
|
-
@generator = method(:default_generator)
|
12
|
+
@secret_file = options.fetch(:secret_file) { ".session_secret" }
|
13
|
+
@description = options.fetch(:description) { default_description }
|
14
|
+
@generator = options.fetch(:generator) { method(:default_generator) }
|
15
15
|
|
16
16
|
yield self if block_given?
|
17
17
|
|
@@ -29,6 +29,10 @@ module Batteries
|
|
29
29
|
require "securerandom"
|
30
30
|
File.write(secret_file, SecureRandom.random_bytes(40))
|
31
31
|
end
|
32
|
+
|
33
|
+
def default_description
|
34
|
+
"Generate a session secret in #{secret_file}"
|
35
|
+
end
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
data/lib/batteries/tasks.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "ostruct"
|
1
2
|
require "batteries/tasks/notes"
|
2
3
|
require "batteries/tasks/migrations"
|
3
4
|
require "batteries/tasks/secret"
|
@@ -6,10 +7,24 @@ module Batteries
|
|
6
7
|
module Tasks
|
7
8
|
module_function
|
8
9
|
|
9
|
-
def new
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def new(tasks: default_tasks)
|
11
|
+
task_options = setup_task_options(tasks)
|
12
|
+
|
13
|
+
yield task_options if block_given?
|
14
|
+
|
15
|
+
tasks.each do |task|
|
16
|
+
const_get(task.to_s.capitalize).new(options: task_options[task].to_h)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_tasks
|
21
|
+
%i(notes migrations secret)
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup_task_options(tasks)
|
25
|
+
tasks.each_with_object(OpenStruct.new) do |task, memo|
|
26
|
+
memo.send("#{task}=", OpenStruct.new)
|
27
|
+
end
|
13
28
|
end
|
14
29
|
end
|
15
30
|
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.
|
4
|
+
version: 0.3.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-
|
11
|
+
date: 2017-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubygems-tasks
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
89
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.6.
|
90
|
+
rubygems_version: 2.6.12
|
91
91
|
signing_key:
|
92
92
|
specification_version: 4
|
93
93
|
summary: Powering your Roda/Sinatra applications
|