inprovise 0.2.19 → 0.2.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGEwNTJkZjllZWRhYTNhMTcxYzA0MGQ5MmUzNjAwOWEyNTJiNDJiYQ==
4
+ OGQzNjQ2MjVjMWYxZjM1M2ZmNTYwYjE4MGRhZDhjYjM5NTU5ZjI3Ng==
5
5
  data.tar.gz: !binary |-
6
- ODM2NTExYjVjZWVhNDg3OTQ1Y2ZkODVmM2Y3NDIxMDE3OGM4NmY5Nw==
6
+ OTFmODBiY2YwYmNkZGIxNGUxYTQzOGM0YTUwNmY1Y2ZmZTVkODBkYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmMxY2U1YWE5MTIxZWMxZmZiNjc0MWM5MTAzMDkyZWMwODc2YTZlMWM4N2Iy
10
- YmFkZjhlNTdhNTEwNzMzMmVmOGM5OWFkOWVjNjZiZGY2YzY4MzU3NjA5NTYy
11
- ZjIyMGI5Njg3MzkyZGZkMmMyODU1NWJkZjVkYzk1ZDQ1ZThlMzE=
9
+ NjY4NWQ0ZjA5YjZjNzc4ZjNhNTU2MjA1ZWUxMDEwM2Q5NWI0N2NmZjA1MDk2
10
+ MDlmM2YwMjE5MTk4ZWUzY2ZhM2JkYzE0ZWRlOTU4ZmQ3MzA1ZDQwOGMxMjQx
11
+ YzQ2YjA1ZWQxYjE4NDM2NGRkZjFmZDI2NjdjZjc0NDQyMWQ2MTI=
12
12
  data.tar.gz: !binary |-
13
- OTBiM2RlNTE5MWQxNjJiYzBmNTgzM2Q2NjZhYWM2ZWQ1MjZkOGNiNmUyYWQx
14
- OTUwYzJiMWYzZDk2NGEwYjljMmM3MjUwM2RlMmI5MGU4ZGVkMGExNzc3YzRm
15
- NDQxYjE0YjUwODA0NjYyOWJhNDBjOGQ2YjNkMjZlYTMwYWQ5NDE=
13
+ ZTI0NmQ1ZDQ0MTA3NGI2ZmJlNjY5ZDRiZWI4YzM1MGZlMzIyZTVmZGVlZDQy
14
+ YWUxZWUzOTlkYjI3ZjVjY2JjMmQ5ZDZmMGVjNGY5MWFlYTU3MjliY2FjNjVj
15
+ NDdmZmM3ZmZlZmI1OGMxMzBjNjcxNWY0Nzk4OTE1ZTdhZDM1N2I=
@@ -9,7 +9,7 @@
9
9
  #
10
10
  # description 'description'
11
11
  #
12
- # configuration <data>
12
+ # configuration <data> [{ }]
13
13
  #
14
14
  # action('action1') { }
15
15
  # action('action2') { }
@@ -52,7 +52,7 @@
52
52
  #
53
53
  # run_local 'command' execute command locally
54
54
  #
55
- # log 'msg' log a message
55
+ # log 'msg', color=nil log a message; color is symbol like :red, :blue, :yellow ...
56
56
  #
57
57
  # sudo 'command'[, {}] execute command on current node over SSH connection using 'sudo'
58
58
  # options: see 'run'
@@ -87,6 +87,14 @@
87
87
  # template('/local/file') creates a template object for the specified (ERB) template file
88
88
  # providing 2 rendering options
89
89
  # .render(locals ={}) returns rendered result string
90
- # .render_to_tempfile(locals = {}) returns path of tempfile containing rendered result
90
+ # .render_to_tempfile(locals = {}) returns path of local tempfile containing rendered result
91
+ # .render_to(fname[, mktmp = true], locals={})
92
+ # return remote file object referencing (temp)
93
+ # file containing rendered result
94
+ # .render_to(fname[, mktmp = true], locals={}) { |fremote| ... }
95
+ # yields block with remote file object referencing (temp)
96
+ # file containing rendered result
97
+ # deletes the remote file after block finishes if it still
98
+ # exists
91
99
  #
92
100
 
@@ -15,7 +15,30 @@ class Inprovise::Template
15
15
  end
16
16
 
17
17
  def render(locals={})
18
- @template.render(@context, locals)
18
+ @template.render(Inprovise::ExecutionContext::DSL.new(@context), locals)
19
+ end
20
+
21
+ def render_to(fname, *opts, &block)
22
+ mktmp = opts.size > 1 ? opts.shift : true
23
+ locals = opts.shift || {}
24
+ tmpfile = @context.local(render_to_tempfile(locals))
25
+ fremote = nil
26
+ begin
27
+ # upload to temporary file
28
+ fremote = tmpfile.upload("#{File.basename(fname, '.*')}-#{tmpfile.hash}.#{File.extname(fname)}")
29
+ # move/rename temporary file if required
30
+ unless mktmp && File.dirname(fname) == '.'
31
+ fremote = fremote.move_to(mktmp ? File.dirname(fname) : fname)
32
+ end
33
+ if block_given?
34
+ @context.exec(block, fremote)
35
+ fremote.delete! if mktmp
36
+ fremote = nil
37
+ end
38
+ ensure
39
+ tmpfile.delete!
40
+ end
41
+ fremote
19
42
  end
20
43
 
21
44
  def render_to_tempfile(locals={})
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Inprovise
7
7
 
8
- VERSION = '0.2.19'
8
+ VERSION = '0.2.20'
9
9
 
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inprovise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.19
4
+ version: 0.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Corino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-23 00:00:00.000000000 Z
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored