egg 0.5.2 → 0.6.0

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: 2329fcef558e7404fd20582870b5ee4ffe7601ea
4
- data.tar.gz: 2cee907b6a7657cac5559012433e4054e2818bb3
3
+ metadata.gz: 6537dd12342b2469b062c681875a6048849584d0
4
+ data.tar.gz: 7cdb22c0856264963f77894ac850101f3d687dbb
5
5
  SHA512:
6
- metadata.gz: c6866ee5948c69de27b010a343dc2c3cdb708cbf00cc550602d431bdccb03f898b59f03ffcc120088c3743b06177ab83ab86c77dec95d1525b89d97d09238d29
7
- data.tar.gz: 109a3af6b131fae7df954d79b4dd781a8d1fc353d01a3375234f1f205ee59fcc5479caaa84844bd2a0415e03a5d4b66f40d860854ff505cbe5228b67535a3944
6
+ metadata.gz: 193ec0da7471c0dcadc163a3649ceb841037f0f3d757f73b48b3cae65d16f1cffbb37850a8b9f59d7016b94e118f28de97f8ea977e1da6c25d9e18e0d0ee90a1
7
+ data.tar.gz: b54dbf63a476199020b8f33e27a41df25ef3a8dfeb849e42a12779a284a28f82c5d3702cdb677e6e241853c0bf4478529b184f6898c767f15dacbb36d704a5ef
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- egg (0.5.2)
4
+ egg (0.6.0)
5
5
  thor (~> 0.19.0)
6
6
 
7
7
  GEM
@@ -2,6 +2,13 @@ module Egg
2
2
  module Dockerfile
3
3
  # Provides shared behavior for dockerfile template classes.
4
4
  class Base
5
+ # Raise when before and after are both used at the same time.
6
+ class QuantumStateError < RuntimeError
7
+ def message
8
+ "Directives cannot happen both before and after a given directive"
9
+ end
10
+ end
11
+
5
12
  attr_reader :template
6
13
  attr_accessor :command
7
14
 
@@ -23,22 +30,38 @@ module Egg
23
30
  ERB.new(unrendered_output).result(binding)
24
31
  end
25
32
 
26
- def run(command, before: [:cmd])
27
- template.insert(do_before(before), [:run, command])
33
+ def run(command, before: [:cmd], after: nil)
34
+ insert_with_before_after([:run, command], before: before, after: after)
28
35
  end
29
36
 
30
- def env(env_hash)
37
+ def env(env_hash, **before_after)
31
38
  env_string = env_hash.reduce("") do |out, (key, value)|
32
39
  out << key.to_s.upcase << '="' << value.to_s << '" '
33
40
  end
34
- template << [:env, env_string]
41
+ insert_with_before_after([:env, env_string], before_after)
42
+ end
43
+
44
+ def add(localpath, containerpath, **before_after)
45
+ directive = [:add, localpath + " " + containerpath]
46
+ insert_with_before_after(directive, before_after)
35
47
  end
36
48
 
37
49
  private
38
50
 
39
- def do_before(before)
40
- template.index(before) ||
41
- template.index { |tc| tc[0] == before[0] } ||
51
+ def insert_with_before_after(directive, before: nil, after: nil)
52
+ raise(QuantumStateError) if before && after
53
+ if before
54
+ template.insert(find_directive_in_template(before), directive)
55
+ elsif after
56
+ template.insert(find_directive_in_template(after) + 1, directive)
57
+ else
58
+ template << directive
59
+ end
60
+ end
61
+
62
+ def find_directive_in_template(directive)
63
+ template.index(directive) ||
64
+ template.index { |tc| tc[0] == directive[0] } ||
42
65
  -1
43
66
  end
44
67
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Egg
4
- VERSION = "0.5.2".freeze
4
+ VERSION = "0.6.0".freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Thuringer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-09-15 00:00:00.000000000 Z
12
+ date: 2017-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor