charmkit 0.2.0 → 0.3.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: 0e1aec7a646008b66df0df8b8729f0818c2903a8
4
- data.tar.gz: 0564348c8875d8d0846e15047f4b74f03d5e2aa6
3
+ metadata.gz: a4aaf465f5e2188921b780a65855c2b2882488c5
4
+ data.tar.gz: 746c903f97888841dbc6f9a123600fe5e01fe7af
5
5
  SHA512:
6
- metadata.gz: f52e66268446c28f8c11f2510830f280fff8455e677b8f02f87e304083c24f2b92b48fdc7b73467efe8f8412ab5f41cb0b1230f7f687601f5defdcb4be42fd27
7
- data.tar.gz: 28d6b9622582631e34c2123fd493270f8b66b1ecb5903cf1acd8bb76402126c2538d75a5b92c1835fc14688c57efe546eb24fd03053baa471b2c0274db2fbcfd
6
+ metadata.gz: 104024317ce841e1c8094b015250934b543292580adab0b93f11a8e0f9963b938b5828defc1847020296744a9228150a0f670e80876d15b80e1f9e80754f4d52
7
+ data.tar.gz: 04f4d7957d325899ef13ac254d4833550e732f9558ac12260a19e98de8362e99e2bf840510b04741626c476aba409e028c1ed64ab7a9d9ff18100a5b862016e6
@@ -0,0 +1,6 @@
1
+ require 'charmkit'
2
+
3
+ template 'templates/user_auth.txt', '/tmp/user_auth.txt',
4
+ firstname: "joe", lastname: "bob"
5
+
6
+ file "/tmp/another-test.txt", content: "owned"
@@ -0,0 +1 @@
1
+ Hi there <%= firstname %> <%= lastname %>
data/lib/charmkit.rb CHANGED
@@ -2,6 +2,7 @@ require "charmkit/runner"
2
2
  require "charmkit/hook-tools"
3
3
  require "charmkit/package"
4
4
  require "charmkit/template"
5
+ require "charmkit/fs"
5
6
  require "charmkit/version"
6
7
 
7
8
  module Charmkit end
@@ -9,16 +9,32 @@ module Charmkit
9
9
  end
10
10
 
11
11
  def config(item)
12
- run "config-get #{item}"
12
+ out, err = run "config-get #{item}"
13
+ return out.chomp
13
14
  end
14
15
 
15
16
  def resource(item)
16
- run "resource-get #{item}"
17
+ out, err = run "resource-get #{item}"
18
+ return out.chomp
17
19
  end
18
20
 
19
21
  def unit(item)
20
- run "unit-get #{item}"
22
+ out, err = run "unit-get #{item}"
23
+ return out.chomp
21
24
  end
22
25
 
26
+ def action(item)
27
+ out, err = run "action-get #{item}"
28
+ return out.chomp
29
+ end
30
+
31
+ def action=(item)
32
+ out, err = run "action-set #{item}"
33
+ return out.chomp
34
+ end
35
+
36
+ def log(msg)
37
+ run "juju-log #{msg}"
38
+ end
23
39
  end
24
40
  end
@@ -1,8 +1,22 @@
1
- # Hook tools module for exposing things such as status-set and action-set
1
+ require 'erb'
2
+
2
3
  module Charmkit
3
4
  module DSL
4
- def template(src, dst, context)
5
- puts "template"
5
+ class TemplateRenderer
6
+ def self.empty_binding
7
+ binding
8
+ end
9
+
10
+ def self.render(template_content, locals = {})
11
+ b = empty_binding
12
+ locals.each { |k, v| b.local_variable_set(k, v) }
13
+ ERB.new(template_content).result(b)
14
+ end
15
+ end
16
+
17
+ def template(src, dst, **context)
18
+ rendered = TemplateRenderer.render(File.read(src), context)
19
+ File.write(dst, rendered)
6
20
  end
7
21
  end
8
22
  end
@@ -1,3 +1,3 @@
1
1
  module Charmkit
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charmkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Stokes
@@ -85,6 +85,8 @@ files:
85
85
  - bin/setup
86
86
  - charmkit.gemspec
87
87
  - examples/basic.rb
88
+ - examples/template.rb
89
+ - examples/templates/user_auth.txt
88
90
  - lib/charmkit.rb
89
91
  - lib/charmkit/hook-tools.rb
90
92
  - lib/charmkit/package.rb