dice_bag 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dice_bag/available_templates.rb +22 -5
- data/lib/dice_bag/command.rb +6 -1
- data/lib/dice_bag/tasks/config.rake +16 -6
- data/lib/dice_bag/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e411c7158a8d1862207f60e5ce491849a3ae6a57
|
4
|
+
data.tar.gz: ff3f71df983d8c23a8609cee44f84ab996a30703
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a2c9da3b3accf242da8cb7cfebddd9c32cb6b29f01ad6917ea5a39d0c10bb1b4f1a8c68505b830d89b0b49ca2dcf5367ef944b9f2a845c6f61932fea0556cba
|
7
|
+
data.tar.gz: 22f058c0eb1cee9727d9670c9049155ceee38c03e5398d5dc2a527ecfa8e371aa5eaeb7d4a32f12febf3ae3b3d2f565e36ecc4ce9f3812c2610a6be70e6d6ed1
|
@@ -1,10 +1,10 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'dice_bag/default_template_file'
|
2
3
|
|
3
4
|
# This class returns all the templates we can generate in this particular project
|
4
5
|
module DiceBag
|
5
|
-
|
6
|
-
class AvailableTemplates
|
7
6
|
|
7
|
+
class AvailableTemplates
|
8
8
|
|
9
9
|
# By default the final location for any template will be the config directory.
|
10
10
|
# If any template 'plugin' wants to overwrite the directory where its template will be written
|
@@ -16,6 +16,22 @@ module DiceBag
|
|
16
16
|
|
17
17
|
class << self
|
18
18
|
|
19
|
+
def gem_specs
|
20
|
+
@gem_specs ||= begin
|
21
|
+
Gem::Specification.sort.each_with_object({}) do |spec, hsh|
|
22
|
+
hsh[spec.name] = spec.full_gem_path
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def checker_within_given_gems?(checker, gem_names)
|
28
|
+
checker_file = checker.method(:templates).source_location[0]
|
29
|
+
gem_specs.each do |name, location|
|
30
|
+
return true if checker_file.starts_with?(location) && gem_names.include?(name)
|
31
|
+
end
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
19
35
|
def template_checkers
|
20
36
|
@template_checkers ||= []
|
21
37
|
end
|
@@ -24,12 +40,13 @@ module DiceBag
|
|
24
40
|
template_checkers << base
|
25
41
|
end
|
26
42
|
|
27
|
-
def all
|
43
|
+
def all(gem_names=[])
|
28
44
|
#all the classes than inherit from us in the ruby runtime
|
29
45
|
available_templates = []
|
30
46
|
|
31
47
|
template_checkers.each do |template_checker|
|
32
48
|
checker = template_checker.new
|
49
|
+
next if !gem_names.empty? && !checker_within_given_gems?(checker, gem_names)
|
33
50
|
location = checker.templates_location
|
34
51
|
checker.templates.each do |template|
|
35
52
|
available_templates.push( DefaultTemplateFile.new(template, location) )
|
@@ -52,7 +69,7 @@ module DiceBag
|
|
52
69
|
end
|
53
70
|
|
54
71
|
|
55
|
-
# we require
|
56
|
-
# them to inherit from DiceBag::AvailableTemplates and require the file
|
72
|
+
# we require our own templates checker here, for other gems we just need
|
73
|
+
# them to inherit from DiceBag::AvailableTemplates and require the file
|
57
74
|
# If Ruby loads the file we can find the class in the object space and call it
|
58
75
|
require_relative 'templates/gems_checker'
|
data/lib/dice_bag/command.rb
CHANGED
@@ -31,7 +31,6 @@ module DiceBag
|
|
31
31
|
template_file.create_file(config_file, params)
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
34
|
def generate_all_templates(force=false)
|
36
35
|
AvailableTemplates.all.each do |template|
|
37
36
|
generate_template(template, force)
|
@@ -42,5 +41,11 @@ module DiceBag
|
|
42
41
|
copy_file default_template.file, default_template.destination, force: force
|
43
42
|
end
|
44
43
|
|
44
|
+
def generate_gems_templates(gem_names, force=false)
|
45
|
+
AvailableTemplates.all(gem_names).each do |template|
|
46
|
+
generate_template(template, force)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
45
50
|
end
|
46
51
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "erb"
|
2
|
+
require "dice_bag/command"
|
3
|
+
|
4
|
+
FORCE_ENV_VAR = "DICEBAG_FORCE".freeze
|
3
5
|
|
4
6
|
desc "Populate all templates using values from the environment to create configuration files"
|
5
|
-
task :config => [
|
7
|
+
task :config => ["config:all"]
|
6
8
|
|
7
9
|
namespace :config do
|
8
10
|
# Deprecated, present only for backward compatibility.
|
@@ -22,7 +24,7 @@ namespace :config do
|
|
22
24
|
DiceBag::Command.new.write(filename)
|
23
25
|
end
|
24
26
|
|
25
|
-
desc
|
27
|
+
desc "Generate all configuration file templates with interactive commands (use config:generate_all:force to replace all without asking for input)"
|
26
28
|
task :generate_all do
|
27
29
|
DiceBag::Command.new.generate_all_templates(false)
|
28
30
|
end
|
@@ -33,11 +35,19 @@ namespace :config do
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
desc
|
38
|
+
desc "Generate specified template, optionally in the specified location with options to control file actions"
|
37
39
|
task :generate, :filename, :location do |t, args|
|
38
40
|
filename = args[:filename]
|
39
41
|
location = args[:location]
|
40
|
-
raise
|
42
|
+
raise "A filename needs to be provided" if filename.nil?
|
41
43
|
DiceBag::Command.new.generate_template(DiceBag::DefaultTemplateFile.new(filename, location), false)
|
42
44
|
end
|
45
|
+
|
46
|
+
desc "Generate the templates from the specified gems only ('config:generate_from_gems gem1 gem2 gemN', set the env variable '#{FORCE_ENV_VAR}' to overwrite the templates without asking for confirmation)"
|
47
|
+
task :generate_from_gems, :names do |t, args|
|
48
|
+
ARGV.each { |a| task a.to_sym do ; end }
|
49
|
+
names = ARGV[1..-1]
|
50
|
+
raise "One or more gem names need to be provided" if names.empty?
|
51
|
+
DiceBag::Command.new.generate_gems_templates(names, !ENV[FORCE_ENV_VAR].nil?)
|
52
|
+
end
|
43
53
|
end
|
data/lib/dice_bag/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dice_bag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Smith
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -156,4 +156,3 @@ test_files:
|
|
156
156
|
- spec/command_spec.rb
|
157
157
|
- spec/configuration_spec.rb
|
158
158
|
- spec/spec_helper.rb
|
159
|
-
has_rdoc:
|