semi 0.5.0 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8900c56654ccdb2e841d4f73f7581aab3fa9e1b
4
- data.tar.gz: a6ddfce5bccc3ce13570dc4b12f8e6b9027cd4ac
3
+ metadata.gz: 4fce5fc892b8b2580065e3ea26962266cc3c5e94
4
+ data.tar.gz: e7838ad1cd46b5eeb41bdc0c900035620e43db85
5
5
  SHA512:
6
- metadata.gz: c72cfef1461dae9bc15bc4751274eb3c32ef7580143b146ecd22d0986258db71e3c72fd894f983dc76ce7caefa141e4513529184d9c99bf753de71e494227ae7
7
- data.tar.gz: 05d193e0858b084f1b20946dea0168a5d8cd7387eabb985f9099e1df452f30ca7858f0176ebbfd3ba7fffae6a2016a4cc1b204c920f505312b7f9415a98c4bf2
6
+ metadata.gz: 3c77242bcc00ffdc56f833534aa8aea287012e9b8bb6ecb6916f8037b89acd0133e72f4075049c1032ce20acc6c3902607b4c58c077595693f8c55aaa4eae6fd
7
+ data.tar.gz: 7895df9833744e8d0e8528865bad7017932da4fb1582b7d95b669bba12758284aa68169e423610d849c675108b64d05b51415dee5f0f7659999ae58ccc3cc144
data/lib/semi/config.rb CHANGED
@@ -49,7 +49,13 @@ module Semi
49
49
  # Read the file and apply @dictionary values
50
50
  contents = File.open(filename, 'r') do |fp|
51
51
  renderer = ERB.new(fp.readlines.join, nil, '%<>-')
52
- renderer.result(dictionary.instance_eval {binding})
52
+ begin
53
+ renderer.result(dictionary.instance_eval {binding})
54
+ rescue SyntaxError => e
55
+ $stderr.puts "Error processing ERB expressions in #{filename}"
56
+ $stderr.puts "ERB reported #{e}"
57
+ exit 1
58
+ end
53
59
  end
54
60
 
55
61
  # Reopen the file and write the rendered contents
data/lib/semi/driver.rb CHANGED
@@ -22,6 +22,11 @@ module Semi
22
22
  @dictionary[name.downcase] = Semi::Variable.import(val, hints)
23
23
  end
24
24
 
25
+ # Now that all values should be present in @dictionary, do any expansions
26
+ @dictionary.each_pair do |name, val|
27
+ @dictionary[name] = Semi::Variable.expand(val, @dictionary)
28
+ end
29
+
25
30
  # Check any validations being asserted
26
31
  @config.validators.each_key { |key|
27
32
  begin
data/lib/semi/variable.rb CHANGED
@@ -5,6 +5,7 @@ require 'semi/variables/boolean'
5
5
  require 'semi/variables/path'
6
6
  require 'semi/variables/url'
7
7
 
8
+
8
9
  module Semi
9
10
 
10
11
  class VariableError < RuntimeError; end
@@ -46,11 +47,28 @@ module Semi
46
47
  else
47
48
  return Semi::Variables::String.new(val)
48
49
  end
49
-
50
+
50
51
  end
51
52
 
52
-
53
53
 
54
+ def self.expand(val, dict)
55
+ check = true
56
+ while check
57
+ # Look for simple variable expansion
58
+ if val =~ /\$\{?(\w+)\}?/
59
+ Regexp.last_match
60
+ val = $` + expand($1, dict) + $'
61
+ elsif val =~ /\$\((.*)\)/
62
+ Regexp.last_match
63
+ val = $` + `$1` + $'
64
+ else
65
+ # no more matches... we must be done...
66
+ check = false
67
+ end
68
+ end
69
+
70
+ return val
71
+ end
54
72
 
55
73
  end
56
74
  end
@@ -33,9 +33,9 @@ module Semi::Variables
33
33
  end
34
34
 
35
35
  # test to see if the value is a common true value
36
- if value =~ /true|yes|enable/i
36
+ if value =~ /true|yes|on|enable/i
37
37
  real_value = true
38
- elsif value =~ /false|no|disable/i
38
+ elsif value =~ /false|no|off|disable/i
39
39
  real_value = false
40
40
  end
41
41
 
data/lib/semi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Semi
2
- version = '0.5.0'
2
+ version = '0.5.1'
3
3
  end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Semi::Variable do
5
+
6
+ [
7
+ # value, var type, hints
8
+ ['/etc/passwd', 'Semi::Variables::Path', nil],
9
+ ['./file.txt', 'Semi::Variables::Path', nil],
10
+ ['~root/.bashrc', 'Semi::Variables::Path', nil],
11
+ ['../../bin/ls', 'Semi::Variables::Path', nil],
12
+ ['/etc/passwd', 'Semi::Variables::Path', 'path'],
13
+ ['./file.txt', 'Semi::Variables::Path', 'path'],
14
+ ['~root/.bashrc', 'Semi::Variables::Path', 'path'],
15
+ ['../../bin/ls', 'Semi::Variables::Path', 'path'],
16
+ ['/etc/passwd', 'Semi::Variables::String', 'string'],
17
+ ['./file.txt', 'Semi::Variables::String', 'string'],
18
+ ['~root/.bashrc', 'Semi::Variables::String', 'string'],
19
+ ['../../bin/ls', 'Semi::Variables::String', 'string'],
20
+ [849234, 'Semi::Variables::Integer', nil],
21
+ [0x8849, 'Semi::Variables::Integer', nil],
22
+ [7_849, 'Semi::Variables::Integer', nil],
23
+ ['849234', 'Semi::Variables::String', nil],
24
+ ['0x8849', 'Semi::Variables::String', nil],
25
+ ['7_849', 'Semi::Variables::String', nil],
26
+ ['849234', 'Semi::Variables::Integer', 'integer'],
27
+ ['0x8849', 'Semi::Variables::Integer', 'integer'],
28
+ ['7_849', 'Semi::Variables::Integer', 'integer'],
29
+ [true, 'Semi::Variables::Boolean', nil],
30
+ [false, 'Semi::Variables::Boolean', nil],
31
+ ['true', 'Semi::Variables::Boolean', nil],
32
+ ['false', 'Semi::Variables::Boolean', nil],
33
+ ['on', 'Semi::Variables::Boolean', nil],
34
+ ['off', 'Semi::Variables::Boolean', nil],
35
+ ['yes', 'Semi::Variables::Boolean', nil],
36
+ ['no', 'Semi::Variables::Boolean', nil],
37
+ ['enable', 'Semi::Variables::Boolean', nil],
38
+ ['disable', 'Semi::Variables::Boolean', nil],
39
+ ['TRUE', 'Semi::Variables::Boolean', nil],
40
+ ['FALSE', 'Semi::Variables::Boolean', nil],
41
+ ['ON', 'Semi::Variables::Boolean', nil],
42
+ ['OFF', 'Semi::Variables::Boolean', nil],
43
+ ['YES', 'Semi::Variables::Boolean', nil],
44
+ ['NO', 'Semi::Variables::Boolean', nil],
45
+ ['ENABLE', 'Semi::Variables::Boolean', nil],
46
+ ['DISABLE', 'Semi::Variables::Boolean', nil],
47
+ ['True', 'Semi::Variables::Boolean', nil],
48
+ ['False', 'Semi::Variables::Boolean', nil],
49
+ ['On', 'Semi::Variables::Boolean', nil],
50
+ ['Off', 'Semi::Variables::Boolean', nil],
51
+ ['Yes', 'Semi::Variables::Boolean', nil],
52
+ ['No', 'Semi::Variables::Boolean', nil],
53
+ ['Enable', 'Semi::Variables::Boolean', nil],
54
+ ['Disable', 'Semi::Variables::Boolean', nil],
55
+ ['true', 'Semi::Variables::Boolean', 'boolean'],
56
+ ['false', 'Semi::Variables::Boolean', 'boolean'],
57
+ ['on', 'Semi::Variables::Boolean', 'boolean'],
58
+ ['off', 'Semi::Variables::Boolean', 'boolean'],
59
+ ['yes', 'Semi::Variables::Boolean', 'boolean'],
60
+ ['no', 'Semi::Variables::Boolean', 'boolean'],
61
+ ['enable', 'Semi::Variables::Boolean', 'boolean'],
62
+ ['disable', 'Semi::Variables::Boolean', 'boolean'],
63
+ ['true', 'Semi::Variables::String', 'string'],
64
+ ['false', 'Semi::Variables::String', 'string'],
65
+ ['on', 'Semi::Variables::String', 'string'],
66
+ ['off', 'Semi::Variables::String', 'string'],
67
+ ['yes', 'Semi::Variables::String', 'string'],
68
+ ['no', 'Semi::Variables::String', 'string'],
69
+ ['enable', 'Semi::Variables::String', 'string'],
70
+ ['disable', 'Semi::Variables::String', 'string'],
71
+ ['http://www.google.com/', 'Semi::Variables::Url', nil],
72
+ ['https://www.google.com/', 'Semi::Variables::Url', nil],
73
+ ['http://www.google.com', 'Semi::Variables::Url', nil],
74
+ ['https://www.google.com', 'Semi::Variables::Url', nil],
75
+ ['https://www.google.com:80/', 'Semi::Variables::Url', nil],
76
+ ['http://www.google.com:808/', 'Semi::Variables::Url', nil],
77
+ ['http://www.google.com:8080/', 'Semi::Variables::Url', nil],
78
+ ['https://www.google.com:80808/', 'Semi::Variables::Url', nil],
79
+ ['https://www.google.com:80', 'Semi::Variables::Url', nil],
80
+ ['http://www.google.com:808', 'Semi::Variables::Url', nil],
81
+ ['http://www.google.com:8080', 'Semi::Variables::Url', nil],
82
+ ['https://www.google.com:80808', 'Semi::Variables::Url', nil],
83
+ ['ftp://ftp.ftp.com', 'Semi::Variables::Url', nil],
84
+ ['ftp://ftp.com/', 'Semi::Variables::Url', nil],
85
+ ['ftp://ftp.com/foo.baz', 'Semi::Variables::Url', nil],
86
+ ['ftp://ftp.com/foo/bar/foo.baz',
87
+ 'Semi::Variables::Url', nil],
88
+ ['http://www/', 'Semi::Variables::Url', nil],
89
+ ['http://www', 'Semi::Variables::Url', nil],
90
+ ['http://www:888', 'Semi::Variables::Url', nil],
91
+ ['http://www/some/file', 'Semi::Variables::Url', nil],
92
+ ['http:/www/', 'Semi::Variables::Path', nil],
93
+
94
+ ].each do |test|
95
+ it "#import identifies #{test[0]} as #{test[1]}" do
96
+ if test[2].nil?
97
+ # no hints given
98
+ expect(Semi::Variable.import(test[0]).class.to_s).to eql test[1]
99
+ else
100
+ expect(Semi::Variable.import(test[0], test[2]).class.to_s).to eql test[1]
101
+ end
102
+ end
103
+ end
104
+
105
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerard Hickey
@@ -91,6 +91,7 @@ files:
91
91
  - lib/semi/variables/url.rb
92
92
  - lib/semi/version.rb
93
93
  - spec/semi_validator_spec.rb
94
+ - spec/semi_variable_spec.rb
94
95
  - spec/semi_variables_boolean_spec.rb
95
96
  - spec/semi_variables_path_spec.rb
96
97
  - spec/semi_variables_url_spec.rb