autostacker24 1.0.26 → 1.0.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac0007f20ca08f1cb9705239b0d9473a6bf80441
4
- data.tar.gz: fb82a1abcbb82108fd8ce04fbd0eb1b28ed7ec54
3
+ metadata.gz: bb33f6ccb4d9c081991bde6bb12c79283672f8e6
4
+ data.tar.gz: 4f166b6956bde0bc0dcee63f29b988062874db8f
5
5
  SHA512:
6
- metadata.gz: e8b963abe01c15b039ccee84edc4c05387d1acac505ed6d60473f0f67854e6178a93e99bbdd0f72d90f07f47cd5ff7566c5861458e97e78087dd73a501c5c1d0
7
- data.tar.gz: 8b050254c30f426e67106bef0ac1d3a410ade76003c2e1bf9f91c73ae80e83e6579a0c9609620b7ddff8b88b1a93ddf5b2713a039043c49b8fc09d7870313f19
6
+ metadata.gz: 292dd8f06c404a9dd2173f2cec11cc350e026b5e6ede4bc9756cb38b0e6d962cde2e25837bdd0b75283ca22b7ad7636da09639116e668fc1940d8dac6a61a37e
7
+ data.tar.gz: da2e04310f05e1c8e3fd1fd9d6c13597fa593c655e320cc09179ed8c99029f5519674beff3a8a745c4c78f2238a9ab390da40408ca588a0389967a8a2ee975b9
@@ -1,6 +1,8 @@
1
1
  require 'aws-sdk-core'
2
2
  require 'set'
3
3
 
4
+ require_relative 'template_preprocessor.rb'
5
+
4
6
  module Stacker
5
7
 
6
8
  attr_reader :region, :credentials
@@ -155,7 +157,7 @@ module Stacker
155
157
 
156
158
  def template_body(template)
157
159
  template = File.read(template) if File.exists?(template)
158
- template.gsub(/(\s*\/\/.*$)|(".*")/) {|m| m[0] == '"' ? m : ''}
160
+ AutoStacker24::Preprocessor.preprocess(template)
159
161
  end
160
162
 
161
163
  extend self
@@ -0,0 +1,69 @@
1
+
2
+ require 'json'
3
+
4
+ module AutoStacker24
5
+
6
+ module Preprocessor
7
+
8
+ def self.preprocess(template)
9
+ template = template.gsub(/(\s*\/\/.*$)|(".*")/) {|m| m[0] == '"' ? m : ''} # replace comments
10
+ preprocess_json(JSON(template)).to_s
11
+ end
12
+
13
+ def self.preprocess_json(json)
14
+ if json.is_a?(Hash)
15
+ json.inject({}){|m, (k, v)| m.merge(k => preprocess_json(v))}
16
+ elsif json.is_a?(Array)
17
+ json.map{|v| preprocess_json(v)}
18
+ elsif json.is_a?(String)
19
+ preprocess_string(json)
20
+ end
21
+ end
22
+
23
+ def self.preprocess_string(s)
24
+ parts = tokenize(s).map do |token|
25
+ case token
26
+ when '@@' then '@'
27
+ when /^@/ then {'Ref' => token[1..-1]}
28
+ else token
29
+ end
30
+ end
31
+
32
+ # merge neighboured strings
33
+ parts = parts.reduce([])do |m, p|
34
+ if m.last.is_a?(String) && p.is_a?(String)
35
+ m[-1] += p
36
+ else
37
+ m << p
38
+ end
39
+ m
40
+ end
41
+
42
+ if parts.length == 1
43
+ parts.first
44
+ else # we need a join construct
45
+ {'Fn::Join' => ['', parts]}
46
+ end
47
+
48
+ end
49
+
50
+ def self.tokenize(s)
51
+ pattern = /@@|@([^@\s]+)/
52
+ tokens = []
53
+ until s.empty?
54
+ m = pattern.match(s)
55
+ if m
56
+ tokens << m.pre_match unless m.pre_match.empty?
57
+ tokens << m.to_s
58
+ s = m.post_match
59
+ else
60
+ tokens << s
61
+ s = ''
62
+ end
63
+ end
64
+ tokens
65
+ end
66
+
67
+ end
68
+
69
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autostacker24
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.26
4
+ version: 1.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Mueller
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-27 00:00:00.000000000 Z
12
+ date: 2015-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk-core
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: '2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: json
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '1.8'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.8'
28
42
  description: n/a
29
43
  email:
30
44
  - jmueller@autoscout24.com
@@ -35,7 +49,7 @@ extra_rdoc_files: []
35
49
  files:
36
50
  - lib/autostacker24.rb
37
51
  - lib/autostacker24/stacker.rb
38
- - lib/autostacker24/stacker_tests.rb
52
+ - lib/autostacker24/template_preprocessor.rb
39
53
  homepage: https://github.com/AutoScout24/autostacker24
40
54
  licenses:
41
55
  - MIT
@@ -1,21 +0,0 @@
1
- require 'openssl'
2
- require_relative 'stacker.rb'
3
-
4
- def template_body
5
- template = <<-EOL
6
- bla bla //comment
7
- bla "//no comment"
8
- bla // still a "comment"
9
- bla "some string" // comment
10
- EOL
11
-
12
- puts Stacker.template_body(template)
13
- end
14
-
15
- if $0 ==__FILE__ # placeholder for interactive testing
16
-
17
- OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE # Windows Hack
18
-
19
- template_body
20
-
21
- end