erb-process 0.1.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.
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'erb-process'
4
+ require 'rbconfig'
5
+
6
+ variables = ARGV[0]
7
+ template = ARGV[1]
8
+ environment = "DEV"
9
+
10
+ if ARGV.length == 3
11
+ environment = ARGV[2]
12
+ else
13
+ os = Config::CONFIG['host_os']
14
+ if os =~ /mswin32/i
15
+ if File.exist?("C:\hosttype")
16
+ environment = File.read("C:\hosttype")
17
+ end
18
+ elsif File.exist?("/hosttype")
19
+ environment = File.read("/hosttype")
20
+ end
21
+ end
22
+
23
+ puts ERBProcess.process(variables, template, environment)
24
+
@@ -0,0 +1,30 @@
1
+ require "erb"
2
+ require "yaml"
3
+ require "erbprocess/version"
4
+
5
+ module ERBProcess
6
+
7
+ def ERBProcess.process variables, template, env = "DEV"
8
+ @variables = variables
9
+ @template = template
10
+ @env = env
11
+
12
+ yml = YAML.load_file(@variables)
13
+ #puts @template
14
+ #puts yml.inspect
15
+ config = {}
16
+ yml.each_key do |key|
17
+ if yml[key].has_key?(env.downcase)
18
+ config[key] = yml[key][env.downcase]
19
+ else
20
+ warn "WARNING: "<< @variables<<" does not have a "<<key<<" for environment "<<env
21
+ end
22
+ end
23
+
24
+ content = File.read(File.expand_path(@template))
25
+ t = ERB.new(content)
26
+ return t.result(binding)
27
+ end
28
+
29
+ end
30
+
@@ -0,0 +1,3 @@
1
+ module ERBProcess
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,10 @@
1
+ # a comment
2
+ hostname:
3
+ dev: http://dev.epals.com
4
+ qa: http://qa.epals.com
5
+ prod: http://prod.epals.com
6
+
7
+ foo:
8
+ dev: http://dev.foo.com
9
+ qa: http://qa.foo.com
10
+ prod: http://prod.foo.com
@@ -0,0 +1,2 @@
1
+ host: <%= config["hostname"]%>
2
+ bar: <%= config['foo']%>
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+ require "lib/erb-process.rb"
3
+
4
+
5
+ class TestERBProcess < Test::Unit::TestCase
6
+ def testVersion
7
+ assert_equal '0.1.0', ERBProcess::VERSION
8
+ end
9
+
10
+ def testTemplate
11
+ result = "host: http://qa.epals.com\nbar: http://qa.foo.com"
12
+ assert_equal result, ERBProcess.process("test/config.yml", "test/example_config.erb", "QA")
13
+ end
14
+ end
15
+
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erb-process
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Patrick O'Leary
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-07-21 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: First Argument is a variables file, second is an ERB template, outputs to STDOUT
22
+ email: pjaol@pjaol.com
23
+ executables:
24
+ - erb-process
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/erb-process.rb
31
+ - lib/erbprocess/version.rb
32
+ - test/config.yml
33
+ - test/example_config.erb
34
+ - test/test_erbprocess.rb
35
+ - bin/erb-process
36
+ homepage: https://github.com/pjaol/erb-configurator
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Merges a variables file and an ERB file
69
+ test_files:
70
+ - test/config.yml
71
+ - test/example_config.erb
72
+ - test/test_erbprocess.rb