vars 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e6341fa4ac7c3a051106ecf7fccaa3f38d4002daaeeabe55d6c9b01ef1e6a753
4
+ data.tar.gz: 3f46d488a2e31d41488ed72b87bb759ce6ac419c352a23376dd504bbfa38fd59
5
+ SHA512:
6
+ metadata.gz: d303cf2dcfc87c1af59db0ab2556cba4c2a7e54902434c11f11ac9a30d35555ff141d524e41cec60bd2f9619c3b87f00cf4a9f277bda73aa184d328e24dbd985
7
+ data.tar.gz: a6036491814ce2b923f467b6d3d8487c7af3e137c6ae7d2b5e0ff366fc1ee60c6b1d7b2ff77f0de7f6c19e20a07e61d6bedc6e6dfb997f499c5f78f4c6f42352
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,27 @@
1
+ Style/StringLiterals:
2
+ EnforcedStyle: double_quotes
3
+
4
+ Style/StringLiteralsInInterpolation:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ Style/BlockDelimiters:
11
+ Enabled: false
12
+
13
+ Style/MultilineBlockChain:
14
+ Enabled: false
15
+
16
+ Style/ClassAndModuleChildren:
17
+ Enabled: false
18
+
19
+ Layout/IndentationConsistency:
20
+ Enabled: true
21
+ EnforcedStyle: rails
22
+
23
+ Metrics/LineLength:
24
+ Max: 120
25
+
26
+ Metrics/AbcSize:
27
+ Max: 20
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in vars.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Ken Iiboshi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Vars
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vars`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vars'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vars
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/i2bskn/vars.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vars"
5
+
6
+ require "pry"
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install --path .bundle
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,59 @@
1
+ class Vars < BasicObject
2
+ class Options
3
+ attr_reader :opts
4
+
5
+ DEFAULT_NAME = "default".freeze
6
+ DEFAULT_BRANCH = "master".freeze
7
+
8
+ def initialize(opts = {})
9
+ @opts = opts.transform_keys(&:to_sym)
10
+ end
11
+
12
+ def name
13
+ opts.fetch(:name, ENV.fetch("APP_ENV", DEFAULT_NAME))
14
+ end
15
+
16
+ def repo_path
17
+ return opts.fetch(:repo_path) if opts.key?(:repo_path)
18
+
19
+ in_repository? ? `git rev-parse --show-toplevel`.chomp : nil
20
+ end
21
+
22
+ def branch
23
+ return opts.fetch(:branch) if opts.key?(:branch)
24
+ return ENV["TARGET_BRANCH"] if ENV.key?("TARGET_BRANCH")
25
+
26
+ in_repository? ? `git symbolic-ref --short HEAD`.chomp : DEFAULT_BRANCH
27
+ end
28
+
29
+ def source_type
30
+ opts.fetch(:source_type, :path)
31
+ end
32
+
33
+ def load_source(path)
34
+ src = YAML.safe_load(ERB.new(raw_source(path), nil, "-").result(binding), [], [], true)
35
+ src.fetch("default", {}).merge(src.fetch(name.to_s))
36
+ end
37
+
38
+ def in_repository?
39
+ return @in_repository if instance_variable_defined?(:@in_repository)
40
+
41
+ _, _, status = Open3.capture3("git rev-parse --git-dir")
42
+ @in_repository = status.exitstatus.zero?
43
+ end
44
+
45
+ private
46
+
47
+ def raw_source(path)
48
+ case source_type
49
+ when :path
50
+ File.read(path)
51
+ when :git
52
+ raise "repo_path is nil" if repo_path.nil?
53
+ Dir.chdir(repo_path) { `git show #{branch}:#{path}` }
54
+ else
55
+ raise "Unknown source_type: #{source_type}"
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ class Vars < BasicObject
2
+ VERSION = "0.0.1".freeze
3
+ end
data/lib/vars.rb ADDED
@@ -0,0 +1,59 @@
1
+ require "erb"
2
+ require "open3"
3
+ require "pathname"
4
+ require "yaml"
5
+
6
+ require "vars/options"
7
+ require "vars/version"
8
+
9
+ class Vars < BasicObject
10
+ attr_reader :path, :options
11
+
12
+ def initialize(path, opts = {})
13
+ @path = path
14
+ @options = Options.new(opts)
15
+ end
16
+
17
+ def [](key)
18
+ hash.fetch(key.to_s, nil)
19
+ end
20
+
21
+ def resolve_templates(template_path, output_path, excludes: [])
22
+ template_path = ::Pathname.new(template_path)
23
+ output_path = ::Pathname.new(output_path)
24
+ excludes = excludes.map(&:to_s)
25
+ template_path.glob("**/*").each do |template_file|
26
+ next if template_file.directory?
27
+
28
+ filename = template_file.basename(".erb")
29
+ next unless ([filename.to_s, template_file.basename.to_s] & excludes).empty?
30
+
31
+ create_file(
32
+ template_file,
33
+ output_path.join(template_file.dirname.join(filename).relative_path_from(template_path)),
34
+ )
35
+ end
36
+ end
37
+
38
+ def create_file(template_file, output_file)
39
+ ::File.open(output_file, "w") do |f|
40
+ f.write(::ERB.new(::File.read(template_file), nil, "-").result(__binding__))
41
+ end
42
+ end
43
+
44
+ def hash
45
+ @hash ||= options.load_source(path)
46
+ end
47
+
48
+ private
49
+
50
+ def method_missing(name, *args, &block)
51
+ super unless hash.key?(name.to_s)
52
+
53
+ hash.fetch(name.to_s)
54
+ end
55
+
56
+ def respond_to_missing?(name, _include_private = false)
57
+ hash.key?(name.to_s)
58
+ end
59
+ end
data/vars.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "vars/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "vars"
7
+ spec.version = Vars::VERSION
8
+ spec.authors = ["i2bskn"]
9
+ spec.email = ["i2bskn@gmail.com"]
10
+
11
+ spec.summary = "Configuration each environments."
12
+ spec.description = "Configuration each environments."
13
+ spec.homepage = "https://github.com/i2bskn/vars"
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(__dir__) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rubocop"
29
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vars
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - i2bskn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Configuration each environments.
84
+ email:
85
+ - i2bskn@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/vars.rb
100
+ - lib/vars/options.rb
101
+ - lib/vars/version.rb
102
+ - vars.gemspec
103
+ homepage: https://github.com/i2bskn/vars
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.7.6
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Configuration each environments.
126
+ test_files: []