environ 1.0.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: 9065b8dcd8d89051b05d62bb500afa9f7c31976f
4
+ data.tar.gz: 7540825d1ecf5a0d0d7ae98c2e65e58b2ea31590
5
+ SHA512:
6
+ metadata.gz: 8cf005fbc2dffab23763f4599dd6cbaa7b787526dc2a9abda559af7b7fbea17b943b121ac033907492fe097823add71bec833553e8ceee6ac7baeee6db656beb
7
+ data.tar.gz: 5b476c1933bcf831e58c660aac851221e139e7e80237a3a472e95d6bbda69c5c9517cb179310c7d55baf5440eced90e86069a16dc39b90b17d74100f8952706e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
4
+ - "2.1.0"
5
+ - "2.2.0"
6
+ - "jruby-9.0.0.0.pre1"
7
+ branches:
8
+ only:
9
+ - master
10
+ notifications:
11
+ email: false
12
+ script: bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Matt Mondok
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,60 @@
1
+ [![Build Status](https://travis-ci.org/mondok/environ.svg?branch=master)](https://travis-ci.org/mondok/environ)
2
+ # Environ
3
+
4
+ Environ is a Ruby gem that lets you access environment variables in an object oriented manner. Instead of using `ENV['VARIABLE']`, Environ lets you do `Environ.env_variable`.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'environ'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install environ
21
+
22
+ ## Usage
23
+
24
+ Let's say you want to access the PATH variable. You could do:
25
+
26
+ ENV['PATH']
27
+
28
+ With Environ, you can access it OOP style with:
29
+
30
+ Environ.env_path
31
+
32
+ You can also set values if you need to:
33
+
34
+ Environ.env_path = 'new_path'
35
+
36
+ If you set a variable and need to reset everything, you can call:
37
+
38
+ Environ.reset!
39
+
40
+ You can also access all the keys in the environment with:
41
+
42
+ Environ.all
43
+
44
+ This will return a hash of all the environment variables.
45
+
46
+ Finally, Environ respects accessing variables that may not be set. If you call something like `Environ.env_doesnt_exist` it will return nil rather than throw an exception.
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it ( https://github.com/mondok/environ/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "lib"
8
+ t.libs << "test"
9
+ t.test_files = FileList['test/*_test.rb']
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "environ"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/environ.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'environ/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "environ"
8
+ spec.version = Environ::VERSION
9
+ spec.authors = ["Matt Mondok"]
10
+ spec.email = ["mattm@edentech.net"]
11
+
12
+ spec.summary = %q{A gem to access environment variables in a OOP way.}
13
+ spec.description = %q{A gem to access environment variables in a OOP way. Rather than relying on ENV and strings, Environ lets you access the variables as objects.}
14
+ spec.homepage = "https://github.com/mondok/environ"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "minitest"
23
+ spec.add_development_dependency "rake"
24
+ end
data/lib/environ.rb ADDED
@@ -0,0 +1,75 @@
1
+ require_relative "environ/version"
2
+
3
+ # Public: Main handler for accessing variables
4
+ module Environ
5
+ module_function
6
+ @_data = {}
7
+
8
+ # Public: Returns all environment variables as hash
9
+ #
10
+ # Examples
11
+ #
12
+ # Environ.all => {"PATH"=>"/Users/someone/.rvm/gems/ruby-2.2.0/bin", "RUBY_VERSION"=>"ruby-2.2.0", "_"=>"/Users/someone/.rvm/rubies/ruby-2.2.0/bin/irb"}
13
+ #
14
+ # returns hash of all variables
15
+ def all
16
+ ENV
17
+ end
18
+
19
+ # Public: Resets all environment variables back to their original values
20
+ #
21
+ # Examples
22
+ #
23
+ # Environ.reset!
24
+ #
25
+ # returns nothing
26
+ def reset!
27
+ @_data.clear
28
+ create_methods
29
+ end
30
+
31
+ def method_missing(method, *args, &block)
32
+ if (method.to_s =~ /env_/)
33
+ create_method(method.to_s, nil)
34
+ nil
35
+ else
36
+ super.method_missing(method, *args, &block)
37
+ end
38
+ end
39
+
40
+ # Public: Dynamically defines singleton methods from ENV
41
+ #
42
+ # Examples
43
+ #
44
+ # Environ.create_methods
45
+ #
46
+ # returns nothing
47
+ def create_methods
48
+ ENV.each do |key, val|
49
+ create_method(key, val)
50
+ end
51
+ end
52
+
53
+ # Public: Dynamically defines a singleton method
54
+ #
55
+ # Examples
56
+ #
57
+ # Environ.create_method('path', 'something')
58
+ #
59
+ # returns nothing
60
+ def create_method(name, val)
61
+ var_name = "env_#{name.strip.downcase}"
62
+ @_data[var_name] = val
63
+ define_singleton_method(var_name) do
64
+ @_data[var_name]
65
+ end
66
+
67
+ define_singleton_method(:"#{var_name}=") do |value|
68
+ @_data[var_name] = value
69
+ end
70
+ end
71
+
72
+ # initialize methods
73
+ self.create_methods
74
+
75
+ end
@@ -0,0 +1,3 @@
1
+ module Environ
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: environ
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Mondok
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-08 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ description: A gem to access environment variables in a OOP way. Rather than relying
56
+ on ENV and strings, Environ lets you access the variables as objects.
57
+ email:
58
+ - mattm@edentech.net
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - environ.gemspec
72
+ - lib/environ.rb
73
+ - lib/environ/version.rb
74
+ homepage: https://github.com/mondok/environ
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.5
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: A gem to access environment variables in a OOP way.
98
+ test_files: []