dice_bag 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dice_bag.rb +2 -2
- data/lib/dice_bag/available_templates.rb +10 -18
- data/lib/dice_bag/command.rb +12 -13
- data/lib/dice_bag/config_file.rb +5 -5
- data/lib/dice_bag/configuration.rb +6 -9
- data/lib/dice_bag/default_template_file.rb +8 -10
- data/lib/dice_bag/dice_bag_file.rb +9 -8
- data/lib/dice_bag/private_key.rb +14 -15
- data/lib/dice_bag/project.rb +6 -7
- data/lib/dice_bag/railtie.rb +1 -1
- data/lib/dice_bag/tasks.rb +1 -1
- data/lib/dice_bag/template_file.rb +8 -11
- data/lib/dice_bag/template_helpers.rb +5 -5
- data/lib/dice_bag/templates/databases/postgres.yml.dice +1 -1
- data/lib/dice_bag/templates/gems_checker.rb +6 -9
- data/lib/dice_bag/version.rb +1 -1
- data/lib/dice_bag/warning.rb +1 -2
- data/spec/command_spec.rb +3 -4
- data/spec/configuration_spec.rb +20 -22
- data/spec/spec_helper.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bba64cc1853c6fdbe6e9b72296d3b9abc0328b70879ec5c82d1677b5087bce9b
|
4
|
+
data.tar.gz: 3e08e39da404c1d8895b21b86f64021a6be0cf83636ff0d26d7d401d63c4b3eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96ba2f199d24072a5ce4346a0c7baee2f675b74a2971351f94da05ea829d7c0b203535f860e8f46b43d80c5c481997d84193428aa74a945d7b3954e88fe58f04
|
7
|
+
data.tar.gz: ee80ccf235e0835a36a7cc25a56d4b176ebd9440c683ad662e97b27399dd26c09f805d4fa2aaa2a73d31bc77f375b668335e95a6208d228df23daf9f451036c3
|
data/lib/dice_bag.rb
CHANGED
@@ -1,21 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "dice_bag/default_template_file"
|
3
3
|
|
4
4
|
# This class returns all the templates we can generate in this particular project
|
5
5
|
module DiceBag
|
6
|
-
|
7
6
|
class AvailableTemplates
|
8
|
-
|
9
7
|
# By default the final location for any template will be the config directory.
|
10
8
|
# If any template 'plugin' wants to overwrite the directory where its template will be written
|
11
9
|
# it needs to overwrite this method and return a string with the new location as relative
|
12
10
|
# path inside the project.
|
13
11
|
def templates_location
|
14
|
-
|
12
|
+
"config"
|
15
13
|
end
|
16
14
|
|
17
15
|
class << self
|
18
|
-
|
19
16
|
def gem_specs
|
20
17
|
@gem_specs ||= begin
|
21
18
|
Gem::Specification.sort.each_with_object({}) do |spec, hsh|
|
@@ -29,6 +26,7 @@ module DiceBag
|
|
29
26
|
gem_specs.each do |name, location|
|
30
27
|
return true if checker_file.start_with?(location) && gem_names.include?(name)
|
31
28
|
end
|
29
|
+
|
32
30
|
false
|
33
31
|
end
|
34
32
|
|
@@ -40,36 +38,30 @@ module DiceBag
|
|
40
38
|
template_checkers << base
|
41
39
|
end
|
42
40
|
|
43
|
-
def all(gem_names=[])
|
44
|
-
#all the classes than inherit from us in the ruby runtime
|
41
|
+
def all(gem_names = [])
|
42
|
+
# all the classes than inherit from us in the ruby runtime
|
45
43
|
available_templates = []
|
46
44
|
|
47
45
|
template_checkers.each do |template_checker|
|
48
46
|
checker = template_checker.new
|
49
47
|
next if !gem_names.empty? && !checker_within_given_gems?(checker, gem_names)
|
48
|
+
|
50
49
|
location = checker.templates_location
|
51
50
|
checker.templates.each do |template, save_as|
|
52
|
-
available_templates.push(
|
51
|
+
available_templates.push(DefaultTemplateFile.new(template, location, save_as))
|
53
52
|
end
|
54
53
|
end
|
55
54
|
available_templates
|
56
55
|
end
|
57
56
|
|
58
57
|
def template_filename_for(filename)
|
59
|
-
|
60
|
-
if template.filename.include? filename
|
61
|
-
return template.file
|
62
|
-
end
|
63
|
-
end
|
58
|
+
all.find { |template| template.filename.include?(filename) }
|
64
59
|
end
|
65
60
|
end
|
66
|
-
|
67
61
|
end
|
68
|
-
|
69
62
|
end
|
70
63
|
|
71
|
-
|
72
64
|
# we require our own templates checker here, for other gems we just need
|
73
65
|
# them to inherit from DiceBag::AvailableTemplates and require the file
|
74
66
|
# If Ruby loads the file we can find the class in the object space and call it
|
75
|
-
require_relative
|
67
|
+
require_relative "templates/gems_checker"
|
data/lib/dice_bag/command.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require "dice_bag/available_templates"
|
2
|
+
require "dice_bag/project"
|
3
|
+
require "dice_bag/config_file"
|
4
|
+
require "dice_bag/template_file"
|
5
|
+
require "dice_bag/default_template_file"
|
6
|
+
require "thor"
|
7
7
|
|
8
8
|
module DiceBag
|
9
|
-
#This class seems a candidate to be converted to Thor, the problem is that we need to run
|
10
|
-
#in the same process than the rake task so all the gems are loaded before dice_bag
|
11
|
-
#is called and dice_bag can find what software is used in this project
|
9
|
+
# This class seems a candidate to be converted to Thor, the problem is that we need to run
|
10
|
+
# in the same process than the rake task so all the gems are loaded before dice_bag
|
11
|
+
# is called and dice_bag can find what software is used in this project
|
12
12
|
class Command
|
13
13
|
include Thor::Base
|
14
14
|
include Thor::Actions
|
@@ -31,21 +31,20 @@ module DiceBag
|
|
31
31
|
template_file.create_file(config_file, params)
|
32
32
|
end
|
33
33
|
|
34
|
-
def generate_all_templates(force=false)
|
34
|
+
def generate_all_templates(force = false)
|
35
35
|
AvailableTemplates.all.each do |template|
|
36
36
|
generate_template(template, force)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def generate_template(default_template, force=false)
|
40
|
+
def generate_template(default_template, force = false)
|
41
41
|
copy_file default_template.file, default_template.destination, force: force
|
42
42
|
end
|
43
43
|
|
44
|
-
def generate_gems_templates(gem_names, force=false)
|
44
|
+
def generate_gems_templates(gem_names, force = false)
|
45
45
|
AvailableTemplates.all(gem_names).each do |template|
|
46
46
|
generate_template(template, force)
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
50
49
|
end
|
51
50
|
end
|
data/lib/dice_bag/config_file.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "dice_bag/dice_bag_file.rb"
|
2
|
+
require "dice_bag/project"
|
3
3
|
|
4
|
-
#this class encapsulate a configuration file of the project
|
4
|
+
# this class encapsulate a configuration file of the project
|
5
5
|
module DiceBag
|
6
|
-
|
7
6
|
class ConfigFile
|
8
7
|
include DiceBagFile
|
8
|
+
|
9
9
|
def initialize(name)
|
10
10
|
# The 'local', 'erb', and 'template' file extension are deprecated and
|
11
11
|
# will be removed some time prior to v1.
|
12
|
-
@filename = name.gsub(
|
12
|
+
@filename = name.gsub(".local", "").gsub(".erb", "").gsub(".template", "").gsub(".dice", "")
|
13
13
|
@file = Project.config_files(@filename)
|
14
14
|
end
|
15
15
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module DiceBag
|
2
|
-
|
3
2
|
# This class abstracts access to configuration values, to be used within ERB
|
4
3
|
# templates. Currently, the values are read from the environment, as per the
|
5
4
|
# Twelve-Factor App principles.
|
6
5
|
class Configuration
|
7
|
-
|
8
6
|
def initialize
|
9
|
-
@prefixed =
|
7
|
+
@prefixed = {}
|
10
8
|
end
|
11
9
|
|
12
10
|
# Returns a Configuration::PrefixedWithFallback using the given +prefix+.
|
@@ -16,7 +14,7 @@ module DiceBag
|
|
16
14
|
end
|
17
15
|
|
18
16
|
def method_missing(name)
|
19
|
-
if name.to_s.end_with?(
|
17
|
+
if name.to_s.end_with?("!")
|
20
18
|
ensured_in_production(name)
|
21
19
|
else
|
22
20
|
ENV[name.to_s.upcase]
|
@@ -26,7 +24,7 @@ module DiceBag
|
|
26
24
|
private
|
27
25
|
|
28
26
|
def ensured_in_production(name)
|
29
|
-
variable_name = name.to_s.chomp(
|
27
|
+
variable_name = name.to_s.chomp("!").upcase
|
30
28
|
value = ENV[variable_name]
|
31
29
|
if in_production? && value.nil?
|
32
30
|
raise "Environment variable #{variable_name} required in production but it was not provided"
|
@@ -36,8 +34,8 @@ module DiceBag
|
|
36
34
|
|
37
35
|
def in_production?
|
38
36
|
(defined?(Rails) && Rails.env.production?) ||
|
39
|
-
|
40
|
-
|
37
|
+
(defined?(Sinatra) && Sinatra::Application.production?) ||
|
38
|
+
ENV["RACK_ENV"] == "production"
|
41
39
|
end
|
42
40
|
|
43
41
|
# This class acts like +Configuration+ but with a prefix applied to the
|
@@ -53,9 +51,8 @@ module DiceBag
|
|
53
51
|
end
|
54
52
|
|
55
53
|
def method_missing(name)
|
56
|
-
ENV["#{
|
54
|
+
ENV["#{@prefix}_#{name.to_s.upcase}"] || @fallback.send(name)
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
60
|
-
|
61
58
|
end
|
@@ -1,18 +1,17 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "dice_bag/dice_bag_file"
|
2
|
+
require "dice_bag/project"
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "fileutils"
|
5
|
+
require "tempfile"
|
6
6
|
|
7
|
-
#This file encapsulate the template files Dicebag brings with itself
|
7
|
+
# This file encapsulate the template files Dicebag brings with itself
|
8
8
|
module DiceBag
|
9
|
-
|
10
9
|
class DefaultTemplateFile
|
11
10
|
include DiceBagFile
|
12
11
|
|
13
|
-
def initialize(name, location=nil, save_as=nil)
|
14
|
-
#if called from command line with only a name we search in all our templates for the file
|
15
|
-
if
|
12
|
+
def initialize(name, location = nil, save_as = nil)
|
13
|
+
# if called from command line with only a name we search in all our templates for the file
|
14
|
+
if File.dirname(name) == "."
|
16
15
|
name = AvailableTemplates.template_filename_for(name)
|
17
16
|
end
|
18
17
|
@filename = File.basename(save_as || name)
|
@@ -20,6 +19,5 @@ module DiceBag
|
|
20
19
|
@template_location = location
|
21
20
|
@destination = File.join(Project.root, @template_location, @filename)
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
25
23
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "dice_bag/version"
|
2
2
|
|
3
3
|
# This module contains common methods for all the type of files Dicebag knows about:
|
4
4
|
# configuration files, templates files in the project an templates files shipped with dicebag
|
@@ -14,7 +14,7 @@ module DiceBag
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def write(contents)
|
17
|
-
File.open(@file,
|
17
|
+
File.open(@file, "w") do |file|
|
18
18
|
file.puts(contents)
|
19
19
|
end
|
20
20
|
end
|
@@ -29,15 +29,15 @@ module DiceBag
|
|
29
29
|
answer = $stdin.gets
|
30
30
|
answer &&= answer.chars.first.downcase
|
31
31
|
case answer
|
32
|
-
when
|
32
|
+
when "y"
|
33
33
|
return true
|
34
|
-
when
|
34
|
+
when "n"
|
35
35
|
return false
|
36
|
-
when
|
36
|
+
when "a"
|
37
37
|
return @@overwrite_all = true
|
38
|
-
when
|
38
|
+
when "q"
|
39
39
|
exit
|
40
|
-
when
|
40
|
+
when "d"
|
41
41
|
puts diff(file, new_contents)
|
42
42
|
else
|
43
43
|
return true
|
@@ -46,8 +46,9 @@ module DiceBag
|
|
46
46
|
end
|
47
47
|
|
48
48
|
private
|
49
|
+
|
49
50
|
def diff(destination, content)
|
50
|
-
diff_cmd = ENV[
|
51
|
+
diff_cmd = ENV["RAILS_DIFF"] || "diff -u"
|
51
52
|
Tempfile.open(File.basename(destination), File.dirname(destination)) do |temp|
|
52
53
|
temp.write content
|
53
54
|
temp.rewind
|
data/lib/dice_bag/private_key.rb
CHANGED
@@ -1,40 +1,39 @@
|
|
1
1
|
module DiceBag
|
2
2
|
class PrivateKey
|
3
|
-
|
4
3
|
attr_accessor :private_key
|
5
|
-
@@header = "-----BEGIN RSA PRIVATE KEY-----"
|
6
|
-
@@footer = "-----END RSA PRIVATE KEY-----"
|
7
4
|
|
8
5
|
def initialize(key)
|
9
6
|
@private_key = key
|
10
7
|
end
|
11
8
|
|
12
|
-
def
|
13
|
-
require
|
9
|
+
def valid_private_key?
|
10
|
+
require "openssl"
|
11
|
+
|
14
12
|
begin
|
15
13
|
OpenSSL::PKey::RSA.new @private_key
|
16
|
-
|
14
|
+
true
|
17
15
|
rescue => e
|
18
|
-
|
19
|
-
|
20
|
-
return false
|
16
|
+
puts "#{e.message}\n#{e.backtrace}"
|
17
|
+
false
|
21
18
|
end
|
22
|
-
end
|
19
|
+
end
|
23
20
|
|
24
21
|
def to_rsa_format!
|
25
22
|
strip_down_key
|
26
23
|
body = @private_key.split(/\s+/)
|
27
24
|
body = body.first.scan(/.{1,64}/) if body.length == 1
|
28
|
-
|
25
|
+
@private_key = [HEADER, body, FOOTER].flatten.join("\n")
|
29
26
|
end
|
30
27
|
|
31
28
|
private
|
32
29
|
|
30
|
+
HEADER = "-----BEGIN RSA PRIVATE KEY-----".freeze
|
31
|
+
FOOTER = "-----END RSA PRIVATE KEY-----".freeze
|
32
|
+
|
33
33
|
def strip_down_key
|
34
|
-
@private_key.gsub!(
|
35
|
-
@private_key.gsub!(
|
34
|
+
@private_key.gsub!(HEADER, "")
|
35
|
+
@private_key.gsub!(FOOTER, "")
|
36
36
|
@private_key.strip!
|
37
37
|
end
|
38
|
-
|
39
38
|
end
|
40
|
-
end
|
39
|
+
end
|
data/lib/dice_bag/project.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
|
-
#This class encapsulate data about the project dice_bag got in
|
1
|
+
# This class encapsulate data about the project dice_bag got in
|
2
2
|
module DiceBag
|
3
|
-
|
4
3
|
class Project
|
4
|
+
DEFAULT_NAME = "project"
|
5
5
|
|
6
|
-
DEFAULT_NAME = 'project'
|
7
6
|
def self.name
|
8
|
-
#TODO: how to do find the name of the project in no-rails environments?
|
7
|
+
# TODO: how to do find the name of the project in no-rails environments?
|
9
8
|
defined?(Rails) ? Rails.application.class.parent_name.downcase : DEFAULT_NAME
|
10
9
|
end
|
11
10
|
|
12
11
|
def self.config_files(filename)
|
13
|
-
File.join(
|
12
|
+
File.join(root, filename)
|
14
13
|
end
|
15
14
|
|
16
15
|
def self.root
|
@@ -18,8 +17,8 @@ module DiceBag
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def self.templates_to_generate
|
21
|
-
FileList.new(
|
22
|
-
fl.exclude(File.join(Bundler.settings[:path],
|
20
|
+
FileList.new("**/*.dice") do |fl|
|
21
|
+
fl.exclude(File.join(Bundler.settings[:path], "/**/*")) if defined?(Bundler) && Bundler.settings[:path]
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
data/lib/dice_bag/railtie.rb
CHANGED
data/lib/dice_bag/tasks.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
load
|
1
|
+
load "dice_bag/tasks/config.rake"
|
@@ -1,17 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "dice_bag/dice_bag_file.rb"
|
2
|
+
require "dice_bag/template_helpers"
|
3
|
+
require "dice_bag/configuration"
|
4
|
+
require "dice_bag/warning"
|
5
5
|
|
6
|
-
#
|
7
|
-
#using this gem
|
6
|
+
# This class encapsulates the template files we will generate in the project using this gem.
|
8
7
|
module DiceBag
|
9
|
-
|
10
8
|
class TemplateFile
|
11
9
|
include DiceBagFile
|
12
10
|
|
13
|
-
# Methods from this module need to be called directly from within the ERB
|
14
|
-
# templates.
|
11
|
+
# Methods from this module need to be called directly from within the ERB templates.
|
15
12
|
include DiceBag::TemplateHelpers
|
16
13
|
|
17
14
|
def initialize(name)
|
@@ -25,15 +22,15 @@ module DiceBag
|
|
25
22
|
# like mauth_key where we want to control newlines carefully.
|
26
23
|
template = ERB.new(File.read(@file), nil, "<>")
|
27
24
|
|
28
|
-
#templates expect a configured object
|
25
|
+
# templates expect a configured object
|
29
26
|
configured = Configuration.new
|
30
27
|
warning = Warning.new(@filename)
|
31
28
|
contents = template.result(binding)
|
32
29
|
|
33
30
|
return unless params[:deploy] || config_file.should_write?(contents)
|
31
|
+
|
34
32
|
config_file.write(contents)
|
35
33
|
puts "File '#{config_file.file}' created"
|
36
34
|
end
|
37
|
-
|
38
35
|
end
|
39
36
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
require
|
1
|
+
require "dice_bag/private_key"
|
2
2
|
|
3
3
|
module DiceBag
|
4
4
|
module TemplateHelpers
|
5
5
|
def generate_private_key
|
6
|
-
require
|
6
|
+
require "openssl"
|
7
7
|
OpenSSL::PKey::RSA.generate(2048)
|
8
8
|
end
|
9
9
|
|
10
10
|
def ensure_is_private_key(key)
|
11
|
-
|
11
|
+
pkey = PrivateKey.new key.dup
|
12
12
|
pkey.to_rsa_format!
|
13
|
-
|
13
|
+
|
14
|
+
if pkey.valid_private_key?
|
14
15
|
pkey.private_key
|
15
16
|
else
|
16
17
|
raise "The private key provided is invalid"
|
17
18
|
end
|
18
19
|
end
|
19
|
-
|
20
20
|
end
|
21
21
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
<% environments.each do |env| %>
|
6
6
|
<%= env %>:
|
7
|
-
adapter: <%= configured[env].database_driver || '
|
7
|
+
adapter: <%= configured[env].database_driver || 'postgresql' %>
|
8
8
|
database: <%= configured[env].database_name! || "PROJECT_NAME_#{env}" %><%= ('<'+'%=ENV["TEST_ENV_NUMBER"] %'+'>') if (env == :test) %>
|
9
9
|
username: <%= configured[env].database_username! || 'postgres' %>
|
10
10
|
password: <%= configured[env].database_password! %>
|
@@ -2,31 +2,30 @@
|
|
2
2
|
# generated for this project.
|
3
3
|
# this file lives in the same directory than all the templates it
|
4
4
|
# provides logic for.
|
5
|
-
require
|
5
|
+
require "dice_bag"
|
6
6
|
|
7
7
|
module DiceBag
|
8
8
|
class CommonTemplatesBag < AvailableTemplates
|
9
|
-
|
10
9
|
def templates
|
11
10
|
@needed_templates = []
|
12
11
|
configured = Configuration.new
|
13
12
|
|
14
13
|
if defined?(Dalli)
|
15
|
-
add_template(
|
14
|
+
add_template("dalli.yml.dice")
|
16
15
|
end
|
17
16
|
|
18
17
|
if defined?(Mysql2)
|
19
|
-
add_template(
|
18
|
+
add_template("databases/mysql.yml.dice", save_as: "database.yml.dice")
|
20
19
|
elsif defined?(PG)
|
21
|
-
add_template(
|
20
|
+
add_template("databases/postgres.yml.dice", save_as: "database.yml.dice")
|
22
21
|
end
|
23
22
|
|
24
23
|
if defined?(AWS)
|
25
|
-
add_template(
|
24
|
+
add_template("aws.yml.dice")
|
26
25
|
end
|
27
26
|
|
28
27
|
if configured.google_analytics_id
|
29
|
-
add_template(
|
28
|
+
add_template("google_analytics.yml.dice")
|
30
29
|
end
|
31
30
|
|
32
31
|
@needed_templates
|
@@ -36,7 +35,5 @@ module DiceBag
|
|
36
35
|
pwd = File.dirname(__FILE__)
|
37
36
|
@needed_templates.push([File.join(pwd, file), save_as])
|
38
37
|
end
|
39
|
-
|
40
38
|
end
|
41
|
-
|
42
39
|
end
|
data/lib/dice_bag/version.rb
CHANGED
data/lib/dice_bag/warning.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module DiceBag
|
2
2
|
class Warning
|
3
|
-
|
4
3
|
def initialize(template_filename)
|
5
4
|
@template_filename = template_filename
|
6
5
|
end
|
@@ -12,7 +11,7 @@ module DiceBag
|
|
12
11
|
alias :as_yaml_comment :as_ruby_comment
|
13
12
|
|
14
13
|
def as_xml_comment
|
15
|
-
[
|
14
|
+
["<!--", lines, "-->"].flatten.join("\n")
|
16
15
|
end
|
17
16
|
|
18
17
|
protected
|
data/spec/command_spec.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "dice_bag/project"
|
3
3
|
|
4
4
|
describe DiceBag::Project do
|
5
5
|
let(:project) { DiceBag::Project }
|
6
6
|
|
7
|
-
describe "#name" do
|
7
|
+
describe "#name" do
|
8
8
|
it "should give me a default name for non Rails apps" do
|
9
9
|
expect(project.name).to eq(DiceBag::Project::DEFAULT_NAME)
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
13
12
|
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
module DiceBag
|
1
|
+
require "spec_helper"
|
2
|
+
require "dice_bag/configuration"
|
4
3
|
|
5
|
-
|
6
|
-
|
4
|
+
module DiceBag
|
5
|
+
shared_examples_for "configuration in production" do
|
6
|
+
it "returns values ending in ! available in the environment" do
|
7
7
|
expect(Configuration.new.test_var!).to eq(value)
|
8
8
|
end
|
9
|
-
it
|
9
|
+
it "returns values not ending in ! not available in the environment" do
|
10
10
|
expect(Configuration.new.idontexist).to eq(nil)
|
11
11
|
end
|
12
|
-
it
|
13
|
-
expect{Configuration.new.idontexist!}.to raise_exception(StandardError)
|
12
|
+
it "raises an exception when the value ends in ! and is not available in the environment" do
|
13
|
+
expect { Configuration.new.idontexist! }.to raise_exception(StandardError)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
17
|
RSpec.describe Configuration do
|
19
|
-
let(:value) {
|
18
|
+
let(:value) { "42" }
|
20
19
|
before(:each) do
|
21
|
-
ENV[
|
20
|
+
ENV["TEST_VAR"] = value
|
22
21
|
end
|
23
22
|
|
24
23
|
it "returns values" do
|
@@ -28,34 +27,33 @@ module DiceBag
|
|
28
27
|
expect(Configuration.new.test_var!).to eq(value)
|
29
28
|
end
|
30
29
|
|
31
|
-
context
|
30
|
+
context "Running in Rails production environment" do
|
32
31
|
before(:each) do
|
33
|
-
rails = class_double(
|
32
|
+
rails = class_double("Rails")
|
34
33
|
allow(rails).to receive_message_chain("env.production?") { true }
|
35
34
|
stub_const("Rails", rails)
|
36
35
|
end
|
37
|
-
it_behaves_like
|
36
|
+
it_behaves_like "configuration in production"
|
38
37
|
end
|
39
38
|
|
40
|
-
context
|
39
|
+
context "Running in Sinatra production environment" do
|
41
40
|
before(:each) do
|
42
|
-
sinatra = class_double(
|
41
|
+
sinatra = class_double("Sinatra")
|
43
42
|
allow(sinatra).to receive(:production?).and_return(true)
|
44
43
|
stub_const("Sinatra::Application", sinatra)
|
45
44
|
end
|
46
|
-
it_behaves_like
|
45
|
+
it_behaves_like "configuration in production"
|
47
46
|
end
|
48
47
|
|
49
|
-
context
|
48
|
+
context "Running in a rack app production environment" do
|
50
49
|
# Not the most elegant but given how much we use ENV in these tests, does seem good enough
|
51
50
|
before(:each) do
|
52
|
-
ENV[
|
51
|
+
ENV["RACK_ENV"] = "production"
|
53
52
|
end
|
54
53
|
after(:each) do
|
55
|
-
ENV[
|
54
|
+
ENV["RACK_ENV"] = nil
|
56
55
|
end
|
57
|
-
it_behaves_like
|
56
|
+
it_behaves_like "configuration in production"
|
58
57
|
end
|
59
|
-
|
60
58
|
end
|
61
59
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Require this file using `require "spec_helper"` to ensure that it is only
|
2
2
|
# loaded once.
|
3
3
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "dice_bag"
|
5
|
+
require "rspec"
|
6
6
|
|
7
7
|
RSpec.configure do |config|
|
8
8
|
config.run_all_when_everything_filtered = true
|
9
9
|
config.filter_run :focus
|
10
|
-
config.order =
|
10
|
+
config.order = "random"
|
11
11
|
end
|
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.3.
|
4
|
+
version: 1.3.1
|
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: 2018-
|
12
|
+
date: 2018-09-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|