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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3744b08b2cac266833ffcb26fa59acfcc32560ef
4
- data.tar.gz: b9c7df8b15e479390d0ae9375592355f11b03b6b
3
+ metadata.gz: 1b72dbe55d0b2e75ac7f7252523cc0a6e9aa0e8c
4
+ data.tar.gz: 14941b0f5403a9f8d808dab344a1311ba478d5e6
5
5
  SHA512:
6
- metadata.gz: 9e66a0b0c755dfcab9693436015b7813a555c83088204cd27fc2de2848e1498be9dc35c92862fa83b9b8afc105ff640c6a281f9ce788f28f4ec923c33876fa15
7
- data.tar.gz: d0729dafcc6b13cb21295a316c08288380a0b1e79bac4af357c8b8585d082dc7b2341b99b5aae0418a6ec17975bcbe2cbcbf13a2c66d86526e1792ea1b9f0984
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, :requires
9
+ attr_accessor :migrations_path, :database, :logger
9
10
 
10
- def initialize
11
- @migrations_path = "migrate"
12
- @requires = ["./db"]
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
- DB.loggers << Logger.new(STDOUT)
69
- Sequel::Migrator.apply(DB, migrations_path, version)
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 = "Generate a session secret in #{secret_file}"
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
@@ -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
- Notes.new
11
- Migrations.new
12
- Secret.new
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
@@ -1,3 +1,3 @@
1
1
  module Batteries
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.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.2.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-03-29 00:00:00.000000000 Z
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.8
90
+ rubygems_version: 2.6.12
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: Powering your Roda/Sinatra applications