env_parser 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 996c5fec8869ff3a8103aba00de5f1a24e342b49
4
+ data.tar.gz: 31edfa384c9241b835856b3e80424c202c0b5a84
5
+ SHA512:
6
+ metadata.gz: 1a60f7d00a885caa1ccc91adb3beaed8bcc010262e7d5c82b9524979e6919d7ffe8aea5ceed53407388b62f09c7d4d684a2bd259c84cce7e3ba0da7cdd711623
7
+ data.tar.gz: e1d19bce6fd537377c1a71458021883870ab3051869a4b410bbf1e1edf1fa3044cc736ebd86af62eb025098c284b3c7e87c33222c23fcfb6ba32538fdd3c5eed
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /pkg/
6
+ /spec/reports/
7
+ /tmp/
8
+ /true/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,78 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+ Include:
4
+ - "**/*.rake"
5
+ - "**/Gemfile"
6
+ - "**/Rakefile"
7
+ - "**/Capfile"
8
+ - "**/Berksfile"
9
+ - "**/Cheffile"
10
+ Exclude:
11
+ - "vendor/**/*"
12
+ - "db/**/*"
13
+ - "tmp/**/*"
14
+ - "true/**/*"
15
+ Metrics/ClassLength:
16
+ Description: Avoid classes longer than 100 lines of code.
17
+ Enabled: false
18
+ CountComments: false
19
+ Max: 100
20
+ Metrics/LineLength:
21
+ Description: Limit lines to 100 characters.
22
+ Enabled: false
23
+ Max: 100
24
+ Metrics/BlockLength:
25
+ Exclude:
26
+ - 'spec/**/*.rb'
27
+ Metrics/MethodLength:
28
+ Description: Avoid methods longer than 10 lines of code.
29
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
30
+ Enabled: false
31
+ CountComments: false
32
+ Max: 10
33
+ Metrics/AbcSize:
34
+ Description: A calculated magnitude based on number of assignments, branches, and conditions.
35
+ Enabled: false
36
+ Max: 15
37
+ Metrics/CyclomaticComplexity:
38
+ Description: A complexity metric that is strongly correlated to the number of test cases needed to validate a method.
39
+ Enabled: false
40
+ Max: 6
41
+ Lint/Debugger:
42
+ Description: Warn in debugger entries
43
+ Enabled: false
44
+ Lint/RescueWithoutErrorClass:
45
+ Description: Avoid rescuing without specifying an error class.
46
+ Enabled: false
47
+ Style/SymbolArray:
48
+ Description: Use %i or %I for arrays of symbols.
49
+ Enabled: false
50
+ Style/RegexpLiteral:
51
+ Description: Enforces using / or %r around regular expressions.
52
+ EnforcedStyle: percent_r
53
+ Style/AsciiComments:
54
+ # Disabling this so we can use non-breaking spaces (' ') in documentation comments, preventing browsers from collapsing multiple spaces in code blocks.
55
+ Description: This cop checks for non-ascii (non-English) characters in comments.
56
+ Enabled: false
57
+ Style/NumericLiterals:
58
+ Description: This cop checks for big numeric literals without _ between groups of digits in them.
59
+ Enabled: false
60
+ Style/Documentation:
61
+ Description: Document classes and non-namespace modules.
62
+ Enabled: false
63
+ Style/ClassAndModuleChildren:
64
+ Description: Use nested modules/class definitions instead of compact style.
65
+ Enabled: false
66
+ Style/FrozenStringLiteralComment:
67
+ Enabled: false
68
+ Style/EmptyMethod:
69
+ Enabled: false
70
+ Style/StderrPuts:
71
+ Enabled: true
72
+ Exclude:
73
+ - 'bin/**/*'
74
+ Style/BlockDelimiters:
75
+ Description: Check for uses of braces or do/end around single line or multi-line blocks.
76
+ Enabled: true
77
+ Exclude:
78
+ - 'spec/**/*.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.2
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.0
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --output-dir=./docs --no-private --markup=markdown --format=html
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sakimorix@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
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 env_parser.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ env_parser (0.1.0)
5
+ activesupport (>= 5.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.1.4)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (~> 0.7)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ concurrent-ruby (1.0.5)
16
+ diff-lcs (1.3)
17
+ i18n (0.9.1)
18
+ concurrent-ruby (~> 1.0)
19
+ minitest (5.10.1)
20
+ rake (10.5.0)
21
+ rspec (3.7.0)
22
+ rspec-core (~> 3.7.0)
23
+ rspec-expectations (~> 3.7.0)
24
+ rspec-mocks (~> 3.7.0)
25
+ rspec-core (3.7.0)
26
+ rspec-support (~> 3.7.0)
27
+ rspec-expectations (3.7.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.7.0)
30
+ rspec-mocks (3.7.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.7.0)
33
+ rspec-support (3.7.0)
34
+ thread_safe (0.3.6)
35
+ tzinfo (1.2.4)
36
+ thread_safe (~> 0.1)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 1.16)
43
+ env_parser!
44
+ rake (~> 10.0)
45
+ rspec (~> 3.0)
46
+
47
+ BUNDLED WITH
48
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Nestor Custodio
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.
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # EnvParser
2
+
3
+ If your code uses environment variables, you know that `ENV` will always surface these as strings. Interpreting these strings as the value you *actually* want to see/use takes some additional effort, however.
4
+
5
+ If you want a number, you need to cast: `#to_i`/`#to_f`. If you want a boolean, you need to check for a specific value: `ENV['SOME_VAR'] == 'true'`. Maybe you want to set non-trivial defaults (something other than `0` or `''`)? Maybe you only want to allow values from a limited set.
6
+
7
+ Things can get out of control pretty fast, especially as the number of environment variables in play grows. EnvParser aims to help keep things simple.
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'env_parser'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install env_parser
25
+
26
+
27
+ ## Usage
28
+
29
+ Basic EnvParser usage:
30
+ ```ruby
31
+ ## Returns ENV['TIMEOUT_MS'] as an Integer.
32
+ ## Yields 0 if ENV['TIMEOUT_MS'] is unset or nil.
33
+ ##
34
+ timeout_ms = EnvParser.parse ENV['TIMEOUT_MS'], as: :integer
35
+
36
+ ## LESS TYPING, PLZ! :(
37
+ ## If you pass in a Symbol instead of a String, EnvParser
38
+ ## will use the value behind the matching String key in ENV.
39
+ ## (i.e. passing in `ENV['X']` is equivalent to passing in `:X`)
40
+ ##
41
+ timeout_ms = EnvParser.parse :TIMEOUT_MS, as: :integer
42
+ ```
43
+
44
+ ---
45
+
46
+ The named `:as` value is required. Allowed values are:
47
+
48
+ | `:as` value | type returned |
49
+ |-----------------------------|---------------------------------|
50
+ | :string | String |
51
+ | :symbol | Symbol |
52
+ | :boolean | TrueValue / FalseValue |
53
+ | :int / :integer | Integer |
54
+ | :float / :decimal / :number | Float |
55
+ | :json | &lt; depends on JSON given &gt; |
56
+ | :array | Array |
57
+ | :hash | Hash |
58
+
59
+ Note JSON is parsed using *quirks-mode* (meaning 'true', '25', and 'null' are all considered valid, parseable JSON).
60
+
61
+ ---
62
+
63
+ [Consult the repo docs](https://github.com/nestor-custodio/env_parser/blob/master/docs/index.html) for the full EnvParser documentation.
64
+
65
+
66
+ ## Feature Roadmap / Future Development
67
+
68
+ Additional features/options coming in the future:
69
+ - An `:if_unset` option to more easily set default values.
70
+ - A `:from_set` option to restrict acceptable values to those on a given list.
71
+ - An `EnvParser.load` method that will not only parse the given value, but will set a constant, easily converting environment variables into constants in your code.
72
+ - An `EnvParser.load_all` method to shortcut multiple `.load` calls.
73
+ - A means to **optionally** bind `#parse`, `#load`, and `#load_all` methods onto `ENV` itself (not all hashes!). Because `ENV.parse ...` reads better than `EnvParser.parse ...`.
74
+ - ... ?
75
+
76
+
77
+ ## Contribution / Development
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nestor-custodio/env_parser.
80
+
81
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
82
+
83
+ Linting is courtesy of [Rubocop](https://github.com/bbatsov/rubocop) and documentation is built using [Yard](https://yardoc.org/). Neither is included in the Gemspec; you'll need to install these locally to take advantage.
84
+
85
+ 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).
86
+
87
+
88
+ ## License
89
+
90
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'env_parser'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
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
7
+
8
+ # Do any other automated setup that you need to do here