yaml-env-tag 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 320980f6b147ebb155338595cf94876182b2e60b
4
+ data.tar.gz: d5047c9c8494a2cb074eb7337bfc0f287877b8ec
5
+ SHA512:
6
+ metadata.gz: c06d3fa7961c410439a962065700acc68abfb404d7de3f57fb12b3def14d9d97bfa1235082ca576268da923adbe9caa19dc611a22eb67f2049aa64e63d7c3d33
7
+ data.tar.gz: 7ba5b9c211012b6831acb90a7699e311a5aa014709f504217f24918708280eb20f601da1d451b9dccd19383ba26f4b5d2057fcf2c887ada46b209ce395381bfa
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright 2017 Jakub Jirutka <jakub@jirutka.cz>.
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ = YAML !ENV tag
2
+ Jakub Jirutka <https://github.com/jirutka>
3
+ // custom
4
+ :gem-name: yaml-env-tag
5
+ :gh-name: jirutka/{gem-name}
6
+ :gh-branch: master
7
+ :codacy-id: d1b32c16409c46a0b81882a679713a67
8
+
9
+ ifdef::env-github[]
10
+ image:https://travis-ci.org/{gh-name}.svg?branch={gh-branch}[Build Status, link="https://travis-ci.org/{gh-name}"]
11
+ image:https://api.codacy.com/project/badge/Coverage/{codacy-id}["Test Coverage", link="https://www.codacy.com/app/{gh-name}"]
12
+ image:https://api.codacy.com/project/badge/Grade/{codacy-id}["Codacy Code quality", link="https://www.codacy.com/app/{gh-name}"]
13
+ image:https://img.shields.io/gem/v/{gem-name}.svg?style=flat[Gem Version, link="https://rubygems.org/gems/{gem-name}"]
14
+ endif::env-github[]
15
+
16
+ A custom YAML tag for referring environment variables in YAML files.
17
+ No need to use ERB in YAML just to set some keys from environment variables.
18
+
19
+ [source, yaml]
20
+ .*Sample YAML file using ENV! tag*
21
+ oauth:
22
+ client_id: ENV! API_CLIENT_ID
23
+ client_secret: ENV! API_CLIENT_SECRET
24
+
25
+
26
+ == Usage
27
+
28
+ Just require `{gem-name}` and load YAML as you’re used to:
29
+
30
+ [source, rb, subs="+attributes"]
31
+ ----
32
+ require '{gem-name}'
33
+
34
+ yaml = YAML.load('secret: ENV! API_CLIENT_SECRET')
35
+ yaml['secret'] # => "top-secret"
36
+ ----
37
+
38
+ However, if you use `YAML.safe_load` (which is highly recommended), you need to explicitly whitelist `YamlEnvTag::EnvVariable`:
39
+
40
+ [source, rb]
41
+ YAML.safe_load(..., [YamlEnvTag::EnvVariable])
42
+
43
+ If the specified environment variable does not exist (i.e. is not set), `YAML` will raise exception `YamlEnvTag::MissingEnvVariableError` when loading the file.
44
+
45
+
46
+ == License
47
+
48
+ This project is licensed under http://opensource.org/licenses/MIT/[MIT License].
49
+ For the full text of the license, see the link:LICENSE[LICENSE] file.
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml_env_tag'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml_env_tag/version'
3
+ require 'yaml_env_tag/errors'
4
+ require 'yaml_env_tag/env_variable'
5
+ require 'yaml'
6
+
7
+ YAML.add_tag '!ENV', YamlEnvTag::EnvVariable
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml_env_tag/errors'
3
+
4
+ module YamlEnvTag
5
+ # A specialized String that holds a value of environment variable specified
6
+ # by +!ENV+ tag.
7
+ class EnvVariable < String
8
+
9
+ # Deserializes from YAML. This method is called by {Psych}.
10
+ #
11
+ # @param coder [Psych::Coder, #scalar] coder with name of the environment
12
+ # variable to read.
13
+ # @raise MissingEnvVariableError if the specified environment variable
14
+ # is not set (i.e. does not exist in +ENV+).
15
+ def init_with(coder)
16
+ var_name = coder.scalar
17
+ value = ::ENV[var_name] or raise MissingEnvVariableError, var_name
18
+ initialize(value)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YamlEnvTag
4
+ # An error class raised when environment variable specified by the `!ENV` tag
5
+ # is not set.
6
+ class MissingEnvVariableError < ::RuntimeError
7
+
8
+ attr_reader :variable_name
9
+
10
+ # @param variable_name [String] name of the environment variable.
11
+ def initialize(variable_name)
12
+ @variable_name = variable_name
13
+ super("Environment variable '#{variable_name}' is not set")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YamlEnvTag
4
+ VERSION = '0.1.0'.freeze
5
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../lib/yaml_env_tag/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'yaml-env-tag'
5
+ s.version = YamlEnvTag::VERSION
6
+ s.author = 'Jakub Jirutka'
7
+ s.email = 'jakub@jirutka.cz'
8
+ s.homepage = 'https://github.com/jirutka/yaml-env-tag'
9
+ s.license = 'MIT'
10
+
11
+ s.summary = 'Custom YAML tag for referring environment variables in YAML files'
12
+
13
+ s.files = Dir['lib/**/*', '*.gemspec', 'LICENSE*', 'README*']
14
+
15
+ s.required_ruby_version = '>= 2.0'
16
+
17
+ s.add_development_dependency 'rake', '~> 12.0'
18
+ s.add_development_dependency 'rspec', '~> 3.6'
19
+ s.add_development_dependency 'rubocop', '~> 0.49.0'
20
+ s.add_development_dependency 'simplecov', '~> 0.14'
21
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yaml-env-tag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jakub Jirutka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.49.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.49.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.14'
69
+ description:
70
+ email: jakub@jirutka.cz
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - LICENSE
76
+ - README.adoc
77
+ - lib/yaml-env-tag.rb
78
+ - lib/yaml_env_tag.rb
79
+ - lib/yaml_env_tag/env_variable.rb
80
+ - lib/yaml_env_tag/errors.rb
81
+ - lib/yaml_env_tag/version.rb
82
+ - yaml-env-tag.gemspec
83
+ homepage: https://github.com/jirutka/yaml-env-tag
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '2.0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.6.11
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Custom YAML tag for referring environment variables in YAML files
107
+ test_files: []