dockerfilemerge 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fef351e34b52670bc2b33ec521d4004358207d4
4
- data.tar.gz: 174fcad67e0db8754b0a1ab68e078b4e599c8ab8
3
+ metadata.gz: 6a99f814ecfdd55129c8b94c428f248151a66bc1
4
+ data.tar.gz: 1e528f38b25380403559dddc2d4e5cbcc8179aad
5
5
  SHA512:
6
- metadata.gz: 79b33c82b3540624a16d7da003b1d12acdc29eb3ebbbfb771999ab1ad7d46c40894c65edd0d92d16214eddc4253c01641970ed8a6d6021cf35a3a58e2d9c082b
7
- data.tar.gz: 6d0d2c377f6a8045b802281cb22b44347d6d03a363b6029a80980d03008652d86aef3d02a8c46d423802fa623366555f941f9e0fe6a731933b1ab570d651b889
6
+ metadata.gz: 44ac5460fe56b56a8b3eb87b2e9e790bcfc703763ff14cf619031f2fdb4925c875e60549107702cb8e200121478768dada5381e8296f1f8a0301f18c3d2ab256
7
+ data.tar.gz: 29b0d1dc7d5da86a58c3a6807e64779d54dfe0c446e234b18b3283e6213d20362b88c5a85881d84c5bce1ff2822b4bba9cb7b5f34849a5d9d5d551b7f5dabb50
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -19,63 +19,64 @@ class DockerfileMerge
19
19
  [:all, /#/, :comment]
20
20
  ]
21
21
 
22
- lp = LineParser.new patterns, ignore_blank_lines: false
23
- a = lp.parse s
22
+ a = LineParser.new(patterns, ignore_blank_lines: false).parse s
24
23
 
25
24
  lines = []
26
25
 
27
- a.each do |x|
26
+ a.each do |label, h, r, c| # h=hash, r=remaining, c=children
28
27
 
29
- case x.first
28
+ case label
30
29
  when :comment
31
- lines << x[2].first
32
- lines << '' if x[2].length > 1
30
+
31
+ lines << r.first
32
+ lines << '' if r.length > 1
33
33
 
34
34
  when :include
35
35
 
36
- if x[1][:path].length > 0 then
37
-
38
- path = x[1][:path]
39
-
40
- buffer, type = RXFHelper.read(path)
41
- rows = buffer.lines.map(&:chomp)
42
- lines << "\n\n# copied from " + path if type == :url
43
- rows.grep(/^# Pull /).each {|x| rows.delete x}
44
- lines.concat rows
45
-
46
- else
47
-
48
- x[3].each do |source|
49
- path = source[1][:path]
50
- buffer, type = RXFHelper.read(path)
51
- rows = buffer.lines.map(&:chomp)
52
- lines << "\n\n# copied from " + path if type == :url
53
- rows.grep(/^# Pull /).each {|x| rows.delete x}
54
- lines.concat rows
55
-
56
- end
57
- end
58
-
59
- lines << '' if x[2].length > 1
36
+ h[:path].length > 0 ? merge_file(lines, h[:path]) :
37
+ c.each {|source| merge_file lines, source[1][:path] }
38
+ lines << '' if r.length > 1
60
39
 
61
40
  when :maintainer
62
41
 
63
42
  maintainers = lines.grep(/MAINTAINER/)
64
43
  i = lines.index maintainers.shift
65
- lines[i] = x[2].first
44
+ lines[i] = r.first
45
+
66
46
  maintainers.each {|x| lines.delete x}
67
47
 
68
48
  when :run
49
+
69
50
  i = lines.index lines.grep(/RUN/).last
70
- lines.insert(i+1, x[2].first)
71
- lines.insert(i+2, '') if x[2].length > 1
51
+ lines.insert(i+1, r.first)
52
+
53
+ if r.length > 1 then
54
+ lines.insert(i+2, ' ' + r[1..-1].join("\n ").rstrip)
55
+ end
72
56
  end
73
57
 
74
58
  end
75
59
 
76
- lines.grep(/^FROM /)[1..-1].each {|x| lines.delete x}
77
- lines.grep(/^CMD/)[0..-2].each {|x| lines.delete x}
60
+ singlify lines, /^FROM /
61
+ singlify lines, /^CMD /
78
62
 
79
63
  @to_s = lines.join("\n")
80
64
  end
65
+
66
+ private
67
+
68
+ def merge_file(lines, path)
69
+
70
+ buffer, type = RXFHelper.read(path)
71
+ rows = buffer.lines.map(&:chomp)
72
+ lines << "\n\n# copied from " + path if type == :url
73
+ rows.grep(/^# Pull /).each {|x| rows.delete x}
74
+
75
+ lines.concat rows
76
+ end
77
+
78
+ def singlify(lines, regex)
79
+ i = 0
80
+ lines.reject! {|x| found = x[regex]; i += 1 if found; i > 1 and found }
81
+ end
81
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockerfilemerge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  WHpJ21HYl4KWG8TISerrdwpQAZ5dhV2Yy/4q0MWSnDcMRSYdRAixOcdYW+U+R8cz
32
32
  pf2JrQZNdYZXIg==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-07-09 00:00:00.000000000 Z
34
+ date: 2015-07-10 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: lineparser
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.4.6
103
+ rubygems_version: 2.4.8
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Merge 2 or more Dockerfiles into 1 Dockerfile
metadata.gz.sig CHANGED
Binary file