starenv 0.0.2 → 0.0.3
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/starenv/environment.rb +12 -4
- data/lib/starenv/file/node.rb +26 -7
- data/lib/starenv/file/template.rb +0 -1
- data/lib/starenv/tasks.rb +4 -4
- data/lib/starenv.rb +64 -2
- data/starenv.gemspec +1 -1
- metadata +2 -3
- data/lib/starenv/env_file.rb +0 -85
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7376688a18f0a2a550a90d94cb28bac78c62a499
|
|
4
|
+
data.tar.gz: 63adad010a428cc1d3763c40c9d426ba64836740
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c4e433ce4d2f660f77700e402614c637dc9261717bdcc7428f221577ac80344bbcbfae7c8e6859185f7fe01842e63cc159dee6e3fcb762b2b27e555695604780
|
|
7
|
+
data.tar.gz: 5bb6f10d5c1c03daddfa992771bfe87419c3ca8278cdd04e80d4e0ea74b02cb3a60aed5489faf2f86229d83f00a5035f5c0bb6c61c4b849a1ed13f885df32a57
|
data/lib/starenv/environment.rb
CHANGED
|
@@ -26,18 +26,26 @@ module Starenv
|
|
|
26
26
|
self[key] and not self[key].to_s.empty?
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def apply(
|
|
29
|
+
def apply(other)
|
|
30
30
|
self.tap do |env|
|
|
31
|
-
|
|
31
|
+
other.each do |key, value|
|
|
32
32
|
if has_key? key
|
|
33
|
-
|
|
33
|
+
ignore!(key, value) and other.ignore!(key, value)
|
|
34
34
|
else
|
|
35
|
-
|
|
35
|
+
apply!(key, value) and other.apply!(key, value)
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
+
def ignore!(key, value)
|
|
42
|
+
@ignored[key] = value
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def apply!(key, value)
|
|
46
|
+
self[key], @applied[key] = value, value
|
|
47
|
+
end
|
|
48
|
+
|
|
41
49
|
def respond_to_missing?(method)
|
|
42
50
|
@source.respond_to?(method) or super
|
|
43
51
|
end
|
data/lib/starenv/file/node.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
require 'starenv/file'
|
|
2
|
+
require 'starenv/environment'
|
|
2
3
|
|
|
3
4
|
module Starenv
|
|
4
5
|
class File < ::File
|
|
5
6
|
class Node < Struct.new(:name, :dependencies, :hook)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
attr_accessor :loaded
|
|
9
|
+
attr_reader :environment, :file
|
|
8
10
|
|
|
9
11
|
def initialize(name, dependencies = [], hook = nil)
|
|
10
12
|
super name, dependencies, hook
|
|
@@ -18,20 +20,37 @@ module Starenv
|
|
|
18
20
|
|
|
19
21
|
def load!
|
|
20
22
|
tap do
|
|
21
|
-
@
|
|
22
|
-
|
|
23
|
-
end
|
|
23
|
+
@file = File.new(name)
|
|
24
|
+
@environment = Loader.new(self, hook).call
|
|
24
25
|
end
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
def loaded?
|
|
28
|
-
|
|
29
|
+
!!loaded
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
private
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
class Loader < Struct.new(:node, :hook)
|
|
35
|
+
|
|
36
|
+
def initialize(node, hook = nil)
|
|
37
|
+
super node, hook || default_hook
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def load
|
|
41
|
+
node.file.parse.environment.tap do
|
|
42
|
+
node.loaded = true
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def call
|
|
47
|
+
instance_exec node, &hook or Environment.new({})
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def default_hook
|
|
51
|
+
@@default_hook ||= -> (node) { load }
|
|
52
|
+
end
|
|
53
|
+
|
|
35
54
|
end
|
|
36
55
|
|
|
37
56
|
end
|
data/lib/starenv/tasks.rb
CHANGED
|
@@ -55,7 +55,7 @@ module Starenv
|
|
|
55
55
|
|
|
56
56
|
def init_from(template: :example, noop: false, verbose: true)
|
|
57
57
|
File::Template.touch(template, noop: noop, verbose: verbose).parse.files.each do |file, env|
|
|
58
|
-
require 'pry'; binding.pry
|
|
58
|
+
# require 'pry'; binding.pry
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
|
|
@@ -78,15 +78,15 @@ module Starenv
|
|
|
78
78
|
# end
|
|
79
79
|
|
|
80
80
|
def new_variable(name:, value:, file: Starenv.files.tsort.last || :core)
|
|
81
|
-
file = EnvFile.new(file, [], pattern, nil)
|
|
81
|
+
# file = EnvFile.new(file, [], pattern, nil)
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
def set_variable(name, value:, file: Starenv.files.tsort.last || :core)
|
|
85
|
-
file = EnvFile.new(file, [], pattern, nil)
|
|
85
|
+
# file = EnvFile.new(file, [], pattern, nil)
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
def get_variable(name, value:, file: Starenv.files.tsort.last || :core)
|
|
89
|
-
file = EnvFile.new(file, [], pattern, nil)
|
|
89
|
+
# file = EnvFile.new(file, [], pattern, nil)
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
private
|
data/lib/starenv.rb
CHANGED
|
@@ -27,8 +27,11 @@ module Starenv
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def load(env = nil)
|
|
30
|
-
files.tsort.reduce(Environment.new(env)) do |environment,
|
|
31
|
-
|
|
30
|
+
files.tsort.reduce(Environment.new(env)) do |environment, name|
|
|
31
|
+
node = files[name].load
|
|
32
|
+
environment.apply(node.environment).tap do |environment|
|
|
33
|
+
puts info node if node.loaded?
|
|
34
|
+
end
|
|
32
35
|
end
|
|
33
36
|
end
|
|
34
37
|
|
|
@@ -38,4 +41,63 @@ private
|
|
|
38
41
|
'envs/%s.env'
|
|
39
42
|
end
|
|
40
43
|
|
|
44
|
+
def info(node)
|
|
45
|
+
longest = node.environment.variables.keys.group_by(&:size).max
|
|
46
|
+
length = longest.nil? ? 0 : longest.first
|
|
47
|
+
[
|
|
48
|
+
Results.for(:applied).new(node.file.filename, node.environment.applied, length),
|
|
49
|
+
Results.for(:ignored).new(node.file.filename, node.environment.ignored, length),
|
|
50
|
+
].map(&:to_s).compact.push("\n").join("\n")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class Results < Struct.new(:filename, :variables, :name_length)
|
|
54
|
+
|
|
55
|
+
class << self
|
|
56
|
+
def for(type)
|
|
57
|
+
const_get type.to_s.capitalize
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def display
|
|
62
|
+
formatted(variables).unshift(header).join("\n") unless variables.empty?
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def to_s
|
|
66
|
+
display or ''
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def formatted(variables)
|
|
72
|
+
variables.map do |name, value|
|
|
73
|
+
format_variable name, value
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
class Applied < self
|
|
78
|
+
|
|
79
|
+
def header
|
|
80
|
+
"Applied variables from #{filename}:"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def format_variable(name, value)
|
|
84
|
+
format " %-#{name_length}s => %s", name, value
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
class Ignored < self
|
|
90
|
+
|
|
91
|
+
def header
|
|
92
|
+
'Ignored already set variables:'
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def format_variable(name, value)
|
|
96
|
+
format " %-#{name_length}s => %s\n %-#{length-1}s => %s", name, value, 'already', ENV[name]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
102
|
+
|
|
41
103
|
end
|
data/starenv.gemspec
CHANGED
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = "starenv"
|
|
7
|
-
spec.version = '0.0.
|
|
7
|
+
spec.version = '0.0.3'
|
|
8
8
|
spec.authors = ["Chris Keele"]
|
|
9
9
|
spec.email = ["dev@chriskeele.com"]
|
|
10
10
|
spec.summary = 'Load and manage suites of environment variables.'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: starenv
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Keele
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-07-
|
|
11
|
+
date: 2015-07-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -81,7 +81,6 @@ files:
|
|
|
81
81
|
- Rakefile
|
|
82
82
|
- bin/rake
|
|
83
83
|
- lib/starenv.rb
|
|
84
|
-
- lib/starenv/env_file.rb
|
|
85
84
|
- lib/starenv/environment.rb
|
|
86
85
|
- lib/starenv/file.rb
|
|
87
86
|
- lib/starenv/file/node.rb
|
data/lib/starenv/env_file.rb
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
require 'starenv/results'
|
|
2
|
-
|
|
3
|
-
class EnvFile < Struct.new(:name, :dependencies, :pattern, :hook)
|
|
4
|
-
|
|
5
|
-
def load
|
|
6
|
-
(hook || default_hook).call self do
|
|
7
|
-
Dotenv.load(filename).tap do |results|
|
|
8
|
-
puts info results
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def filename
|
|
14
|
-
format pattern, name
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
alias_method :to_s, :filename
|
|
18
|
-
|
|
19
|
-
def info(results)
|
|
20
|
-
longest = results.keys.group_by(&:size).max
|
|
21
|
-
length = longest.nil? ? 0 : longest.first
|
|
22
|
-
applied, ignored = results.partition do |key, value|
|
|
23
|
-
ENV[key] == value
|
|
24
|
-
end
|
|
25
|
-
[
|
|
26
|
-
Results.for(:applied).new(self, applied, length),
|
|
27
|
-
Results.for(:ignored).new(self, ignored, length),
|
|
28
|
-
].map(&:to_s).compact.push("\n").join("\n")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
@@default_hook = -> file, &loader { loader.call }
|
|
34
|
-
|
|
35
|
-
def default_hook
|
|
36
|
-
@@default_hook
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
module Utils
|
|
40
|
-
|
|
41
|
-
def without_leading_comments(file)
|
|
42
|
-
file.each_line.drop_while do |line|
|
|
43
|
-
comment? line
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def comment?(line)
|
|
48
|
-
line.start_with? '#'
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def variable(line)
|
|
52
|
-
line.match(/^\s*?(?<name>\b.*\b)=(?<value>\b\S*\b)?\s*?$/)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
class Template < self
|
|
58
|
-
|
|
59
|
-
include Utils
|
|
60
|
-
|
|
61
|
-
attr_reader :content
|
|
62
|
-
|
|
63
|
-
def initialize(name, pattern = Starenv.pattern, content = [])
|
|
64
|
-
@content = content
|
|
65
|
-
super name, [], pattern, nil
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def parse
|
|
69
|
-
File.open(filename) do |lines|
|
|
70
|
-
yield without_leading_comments lines
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def write
|
|
75
|
-
File.open(filename, 'w') do |file|
|
|
76
|
-
content.each do |line|
|
|
77
|
-
line = yield line
|
|
78
|
-
file.puts line if line
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
end
|