vars 0.0.4 → 0.0.5
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 +4 -4
- data/.travis.yml +3 -0
- data/README.md +14 -2
- data/lib/vars/options.rb +27 -16
- data/lib/vars/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f089dad07e951ae88cd1d8e9c69bf0aa25d2c3f344ddeed6a78879609d8bb69f
|
4
|
+
data.tar.gz: 57558dd28e1d9a36bf716dccab2afc708e7f6b61318492a2dd401458ff462580
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0055ac7e2c385f51c6ee41d3151c91c65f5db769b143198d513c55f74caecd781ef4abb60782dc78a061ca581eeff5a7d56b8fe8a619a11cbb8b22c99e5c84b
|
7
|
+
data.tar.gz: beaa4187761f12c02c2bbb54f5daf0159efd041746618d98518d56c5ba1c8052ff9c4a330dff06106700e2725a6c4f0799cf845ccaed57648f6952c78ad6b020
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Vars
|
2
2
|
|
3
|
+
[](https://travis-ci.org/i2bskn/vars)
|
4
|
+
|
3
5
|
`vars` is provide configuration each environments.
|
4
6
|
|
5
7
|
## Installation
|
@@ -23,7 +25,10 @@ vars = Vars.new(path: "path/to/environment.yml", name: "production")
|
|
23
25
|
vars.rails_env # => "production"
|
24
26
|
vars.app_root # => "/var/www/app/current"
|
25
27
|
|
26
|
-
|
28
|
+
# Create config/database.yml from template.
|
29
|
+
vars.resolve_template("config/deploy/templates/database.yml.erb", "config/database.yml")
|
30
|
+
|
31
|
+
# Create config files from templates. (config/deploy/templates/**/*)
|
27
32
|
vars.resolve_templates("config/deploy/templates", "config")
|
28
33
|
```
|
29
34
|
|
@@ -35,9 +40,16 @@ default:
|
|
35
40
|
app_root: /var/www/app/current
|
36
41
|
db_host: localhost
|
37
42
|
|
43
|
+
development:
|
44
|
+
db_host: app-development-db-01.xxx.ap-northeast-1.rds.amazonaws.com
|
45
|
+
|
46
|
+
staging:
|
47
|
+
rails_env: staging
|
48
|
+
db_host: app-staging-db-01.xxx.ap-northeast-1.rds.amazonaws.com
|
49
|
+
|
38
50
|
production:
|
39
51
|
rails_env: production
|
40
|
-
db_host: app-db-01.
|
52
|
+
db_host: app-db-01.xxx.ap-northeast-1.rds.amazonaws.com
|
41
53
|
```
|
42
54
|
|
43
55
|
## Development
|
data/lib/vars/options.rb
CHANGED
@@ -5,17 +5,21 @@ class Vars
|
|
5
5
|
module Defaults
|
6
6
|
BRANCH = "master".freeze
|
7
7
|
ENV_NAME = "development".freeze
|
8
|
+
REMOTE_NAME = "origin".freeze
|
8
9
|
SOURCE_PATH = "config/vars.yml".freeze
|
9
10
|
SOURCE_TYPE = :path
|
10
11
|
end
|
11
12
|
|
12
13
|
module EnvKeys
|
13
|
-
BRANCH
|
14
|
-
ENV_NAME
|
14
|
+
BRANCH = "TARGET_BRANCH".freeze
|
15
|
+
ENV_NAME = "APP_ENV".freeze
|
16
|
+
REMOTE_NAME = "REMOTE_NAME".freeze
|
15
17
|
end
|
16
18
|
|
17
19
|
def initialize(opts = {})
|
18
20
|
@opts = opts.transform_keys(&:to_sym)
|
21
|
+
# Use only when source_type is git.
|
22
|
+
@need_fetch = true
|
19
23
|
end
|
20
24
|
|
21
25
|
def hash(reload = false)
|
@@ -25,6 +29,8 @@ class Vars
|
|
25
29
|
|
26
30
|
def load_source
|
27
31
|
src = YAML.safe_load(ERB.new(raw_source, nil, "-").result(Class.new.__binding__), [], [], true)
|
32
|
+
return {} if src.nil?
|
33
|
+
|
28
34
|
src.fetch("default", {}).merge(src.fetch(name.to_s))
|
29
35
|
end
|
30
36
|
|
@@ -33,35 +39,40 @@ class Vars
|
|
33
39
|
end
|
34
40
|
|
35
41
|
def repo_path
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
opts[:repo_path] = capture("git rev-parse --show-toplevel")
|
41
|
-
else
|
42
|
-
nil
|
43
|
-
end
|
42
|
+
return opts.fetch(:repo_path) if opts.key?(:repo_path)
|
43
|
+
return nil unless in_repository?
|
44
|
+
|
45
|
+
opts[:repo_path] = capture("git rev-parse --show-toplevel")
|
44
46
|
end
|
45
47
|
|
46
48
|
def branch
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
when ENV.key?(EnvKeys::BRANCH)
|
49
|
+
return opts.fetch(:branch) if opts.key?(:branch)
|
50
|
+
|
51
|
+
if ENV.key?(EnvKeys::BRANCH)
|
51
52
|
opts[:branch] = ENV.fetch(EnvKeys::BRANCH)
|
52
|
-
|
53
|
+
elsif in_repository?
|
53
54
|
opts[:branch] = capture("git symbolic-ref --short HEAD")
|
54
55
|
else
|
55
56
|
Defaults::BRANCH
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
60
|
+
def remote_name
|
61
|
+
ENV.fetch(EnvKeys::REMOTE_NAME, Defaults::REMOTE_NAME)
|
62
|
+
end
|
63
|
+
|
59
64
|
def source_type
|
60
65
|
opts.fetch(:source_type, Defaults::SOURCE_TYPE)
|
61
66
|
end
|
62
67
|
|
63
68
|
def in_repository?
|
64
69
|
opts[:in_repository] = success?("git rev-parse --git-dir") unless opts.key?(:in_repository)
|
70
|
+
# Update remote repositories.
|
71
|
+
if opts[:in_repository] && @need_fetch
|
72
|
+
execute("git fetch #{remote_name}")
|
73
|
+
@need_fetch = false
|
74
|
+
end
|
75
|
+
|
65
76
|
opts.fetch(:in_repository)
|
66
77
|
end
|
67
78
|
|
@@ -75,7 +86,7 @@ class Vars
|
|
75
86
|
when :path
|
76
87
|
File.read(path)
|
77
88
|
when :git
|
78
|
-
Dir.chdir(repo_path) { capture("git show #{branch}:#{path}") }
|
89
|
+
Dir.chdir(repo_path) { capture("git show #{remote_name}/#{branch}:#{path}") }
|
79
90
|
else
|
80
91
|
raise "unknown source_type: #{source_type}"
|
81
92
|
end
|
data/lib/vars/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2bskn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|