app_builder 0.2.6 → 0.2.7

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
  SHA256:
3
- metadata.gz: c3b02b45d10717bea5bf4e75f3862ec60a4b10f0edc0b20b0fd0f2d445bad62e
4
- data.tar.gz: 9312743688c2126077e420d5dd9f4b3a313ba0448f17220493ca0c8fe2d2ef59
3
+ metadata.gz: 6f2c3eb1f29506c9d100320779e17513e7c32661209c48f849a31f5cba48bfb3
4
+ data.tar.gz: 68d348db9295814fcb9b351e7e36f97891ff7e501701d5dc661ace572e2e311c
5
5
  SHA512:
6
- metadata.gz: 69e03f7e4feda4f1bb33a88ba311a2018a77fdff3b89ec1914425dbce0d0f8d928cedb89c25a99647faf790fa68ccd1fadd1197ee4c0b17005d40323a1b421cc
7
- data.tar.gz: e67bd657c56b04e85d76043c34a029abe678ba3dc8de7330a6e8b7a355d463df93b30d08a0d8392ca76b5ce499eb99551016561a9e5aad7cad6c02277e276765
6
+ metadata.gz: 3d170c4d5b76988d117e46bce7f40ed5fc56a97cef5732a66c4960ebf5841bcf2e538e2b1245568ebd80b5d08a4a1f600fc3c25614ed2309919728d4c5d4dc58
7
+ data.tar.gz: bb8066f6826e2618c7ad5453a398b74c96e7f76a9ca3994775eb89b30d1bd77d6b2ddade6264e796aea35278d6353a201b59dccf3bceaae83d773613116c80e9
@@ -1,56 +1,58 @@
1
1
  module AppBuilder
2
2
  class Environment
3
3
  attr_accessor :name
4
- attr_reader :repo_path, :branch, :source_path
4
+ attr_reader :repo_path, :branch, :source_path, :source_type
5
5
 
6
6
  def initialize(source_path, options = {})
7
7
  @name = options[:name] || ENV.fetch("APP_ENV", "default")
8
8
  @repo_path = options[:repo_path] || `git rev-parse --show-toplevel`.chomp
9
9
  @branch = options[:branch] || ENV.fetch("TARGET_BRANCH", `git symbolic-ref --short HEAD`.chomp)
10
10
  @source_path = source_path
11
- @from_branch = options.fetch(:from_branch, true)
11
+ @source_type = options.fetch(:source_type, :git) # :git (git show branch:path) or :path (File.read(path))
12
12
  end
13
13
 
14
14
  def create_file(template_path, output_path)
15
15
  File.open(output_path, "w") do |f|
16
- f.write(ERB.new(File.read(template_path)).result(template_binding))
16
+ f.write(ERB.new(File.read(template_path)).result(binding))
17
17
  end
18
18
  end
19
19
 
20
- def template_binding
21
- env = source.fetch(name.to_s)
22
- Class.new.tap { |klass|
23
- klass.define_method(:env) { env }
24
- }.instance_eval { binding }
25
- end
26
-
27
20
  def [](key)
28
21
  hash.fetch(key.to_s, nil)
29
22
  end
30
23
 
31
24
  def to_hash
32
- source.fetch(name.to_s)
25
+ raw_source.fetch(name.to_s)
33
26
  end
34
27
  alias :hash :to_hash
35
28
 
36
- def source
29
+ def raw_source
37
30
  @source ||= load_source
38
31
  end
39
32
 
40
33
  private
41
34
 
42
35
  def load_source
43
- if from_branch
44
- YAML.load(
45
- ERB.new(
46
- Dir.chdir(repo_path) {
47
- `git show #{branch}:#{source_path}`
48
- }
49
- ).result(binding)
50
- )
36
+ case source_type
37
+ when :git
38
+ raw_src = Dir.chdir(repo_path) { `git show #{branch}:#{source_path}` }
39
+ when :path
40
+ raw_src = File.read(source_path)
51
41
  else
52
- YAML.load_file(source_path)
42
+ raise "Unknown source_type: #{source_type}"
53
43
  end
44
+
45
+ YAML.load(ERB.new(raw_src).result(binding))
46
+ end
47
+
48
+ def method_missing(name, *args, &block)
49
+ super unless hash.has_key?(name.to_s)
50
+
51
+ hash.fetch(name.to_s)
52
+ end
53
+
54
+ def respond_to_missing?(name, include_private = false)
55
+ hash.has_key?(name.to_s)
54
56
  end
55
57
  end
56
58
  end
@@ -1,3 +1,3 @@
1
1
  module AppBuilder
2
- VERSION = "0.2.6".freeze
2
+ VERSION = "0.2.7".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - i2bskn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-25 00:00:00.000000000 Z
11
+ date: 2018-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh