tepee 0.0.1

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: a9e0ccf99d106a61407b6f7d076165f60e30f24d
4
+ data.tar.gz: 217bc76c1c6558b4092f44480f25b90f15159ddc
5
+ SHA512:
6
+ metadata.gz: fca3087eb54625901d20528e79de769e243753bf4e14ad1d0b5cc80ecbf6c3f4bae4d7f5aeaf82cc1218a36795f4f7d1db33931ad16d3babd9dea9ae87643c43
7
+ data.tar.gz: 0f1d3eb8de91be2b0668d996f9bba6a4b9cb9aecae692b21004a14ce3955608feedf0b1b04bd70236d2fe2b21badae261efab3f2a8d02a347829aa7318ad06c4
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ before_install:
2
+ - gem install bundler
3
+ language: ruby
4
+ rvm:
5
+ - 2.3.0
6
+ script: bundle exec rspec spec
data/Gemfile.lock ADDED
@@ -0,0 +1,29 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.5)
5
+ rspec (3.4.0)
6
+ rspec-core (~> 3.4.0)
7
+ rspec-expectations (~> 3.4.0)
8
+ rspec-mocks (~> 3.4.0)
9
+ rspec-core (3.4.4)
10
+ rspec-support (~> 3.4.0)
11
+ rspec-expectations (3.4.0)
12
+ diff-lcs (>= 1.2.0, < 2.0)
13
+ rspec-support (~> 3.4.0)
14
+ rspec-mocks (3.4.1)
15
+ diff-lcs (>= 1.2.0, < 2.0)
16
+ rspec-support (~> 3.4.0)
17
+ rspec-support (3.4.1)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ rspec
24
+
25
+ RUBY VERSION
26
+ ruby 2.3.0p0
27
+
28
+ BUNDLED WITH
29
+ 1.12.5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Appaloosa.io
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,123 @@
1
+ # Tepee: A configuration helper for the braves
2
+
3
+ [![Build Status](https://travis-ci.org/appaloosa-store/tepee.svg)](https://travis-ci.org/appaloosa-store/tepee)
4
+
5
+ ## Purpose
6
+
7
+ This gem aims to make your rails app (or lib, script, ...) by making your environment variables more maintainable by nesting them, allowing you to use your own naming conventions for them.
8
+
9
+ ## Usage
10
+
11
+ ### Setup
12
+
13
+ Your conf class must inherit from Tepee.
14
+
15
+ ```ruby
16
+ class MyApp::Configuration < Tepee
17
+ # ...
18
+ end
19
+ ```
20
+
21
+ ### Setting a value
22
+
23
+ ```ruby
24
+ class MyApp::Configuration < Tepee
25
+ add(:my_value, 42)
26
+ ## Defines the configuration value 'my_value', with 42 as default value.
27
+ ## If the MY_VALUE environment variable is set, it overrides 42.
28
+
29
+ add(:my_value, 13, env_var: 'FOOBAR')
30
+ ## Defines the configuration value 'my_value', with 13 as default value.
31
+ ## If the FOOBAR environment variable is set, it overrides 13.
32
+ ## You can use this for mapping purposes!
33
+ end
34
+ ```
35
+
36
+ ### Fetching a value
37
+
38
+ `MyApp::Configuration.my_value`
39
+
40
+ ### Using sub sections
41
+
42
+ #### Adding a section
43
+
44
+ ```ruby
45
+ class MyApp::Configuration < Tepee
46
+ section(:billing) do
47
+ add :domain, 'my_domain'
48
+ add :api_key, 'qwerty12345'
49
+ add :public_key, 'my-public-key'
50
+ add :webhook_token, '12345azerty'
51
+ end
52
+ end
53
+ ```
54
+
55
+ Those values could be accessed through: `MyApp::Configuration.billing.domain`.
56
+ That value is either:
57
+ The content of the environment variable `BILLING_DOMAIN` if it exists, or `'my_domain'` if it does not.
58
+
59
+ #### Nesting sections
60
+
61
+ ```ruby
62
+ class MyApp::Configuration < Tepee
63
+ section(:foo) do
64
+ # Can be overrided by the FOO_VALUE environment variable.
65
+ # Accessible via MyApp::Configuration.foo.value
66
+ add :value, "I'm a foo value"
67
+ section(:bar) do
68
+ # Can be overrided by the FOO_BAR_VALUE environment variable.
69
+ # Accessible via Appaloosa::Configuration.foo.bar.value
70
+ add :value, "I'm a bar value"
71
+ end
72
+ end
73
+ end
74
+ ```
75
+
76
+ Now, you are able to retrieve the values of your configuration tokens like follow:
77
+ * `MyApp::Configuration.foo.value # => "I'm a foo value"`
78
+ * `MyApp::Configuration.foo.bar.value # => "I'm a bar value"`
79
+ * `MyApp::Configuration.bar.value # => Undefined method bar for <Configuration #...`
80
+
81
+ ### Overriding values with environment variables
82
+
83
+ Assuming that your configuration is:
84
+
85
+ ```ruby
86
+ class MyApp::Configuration
87
+ ...
88
+ add :top_domain_name, (Rails.env.test? ? 'example.com' : 'lvh.me')
89
+ section :mobile do
90
+ add :api_key, 'dvorak98765', env_var: 'GC2M_API_KEY'
91
+ section :notification do
92
+ add :user, 'bob@alice.com'
93
+ end
94
+ end
95
+ end
96
+ ```
97
+
98
+ If you want to configure (for the heroku application 'my-app') any of those configuration values, please proceed as following:
99
+
100
+ ```ruby
101
+ # MyApp::Configuration.top_domain_name:
102
+ heroku config:set TOP_DOMAIN_NAME='www.alice.bob' -a my-app
103
+
104
+ # MyApp::Configuration.mobile.api_key:
105
+ heroku config:set MOBILE_API_KEY='bepo13579' -a my-app
106
+
107
+ # MyApp::Configuration.mobile.notification.user:
108
+ heroku config:set MOBILE_NOTIFICATION_USER='alice@bob.com' -a my-app
109
+ ```
110
+
111
+ But do not use the `env_var` keyword which allows to override the used environment variable name.
112
+
113
+ ## Contributing
114
+
115
+ 1. Fork it ( https://github.com/appaloosa-store/tepee/fork )
116
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
117
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
118
+ 4. Push to the branch (`git push origin my-new-feature`)
119
+ 5. Create a new Pull Request
120
+
121
+ ## Licence
122
+
123
+ See the included LICENSE file for details.
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ class Tepee
5
+ # This module holds the Tepee version information.
6
+ module Version
7
+ STRING = '0.0.1'.freeze
8
+
9
+ module_function
10
+
11
+ def version(*_args)
12
+ STRING
13
+ end
14
+ end
15
+ end
data/lib/tepee.rb ADDED
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'tepee/version'
5
+
6
+ # Tepee configuration helper for the braves
7
+ class Tepee
8
+ class << self
9
+ attr_accessor :env_var_prefix
10
+
11
+ protected
12
+
13
+ def add(name, default, env_var: "#{env_var_prefix}#{name}")
14
+ value = ENV[String(env_var).upcase] || default
15
+ const_set(String(name).upcase, value)
16
+ define_singleton_method(name) { value }
17
+ self
18
+ end
19
+
20
+ SEP = '_'.freeze
21
+ MISSING_BLOCK = 'Missing block'.freeze
22
+
23
+ def section(name, &block)
24
+ raise MISSING_BLOCK unless block_given?
25
+ new_env_var_prefix = "#{String(name)}#{SEP}"
26
+ unless env_var_prefix.nil?
27
+ new_env_var_prefix = "#{env_var_prefix}#{new_env_var_prefix}"
28
+ end
29
+ klass = Class.new(self)
30
+ klass.env_var_prefix = new_env_var_prefix.upcase
31
+ klass.instance_exec(&block)
32
+ const_set(String(name).upcase, klass)
33
+ define_singleton_method(name) { klass }
34
+ end
35
+ self
36
+ end
37
+ end
data/tepee.gemspec ADDED
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
+ require 'tepee/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'tepee'
8
+ s.version = Tepee::Version::STRING
9
+ s.platform = Gem::Platform::RUBY
10
+ s.required_ruby_version = '>= 1.9.3'
11
+ s.authors = ['Alexandre Ignjatovic', 'Robin Sfez', 'Benoit Tigeot', 'Christophe Valentin']
12
+ s.description = <<-EOF
13
+ A ruby configuration helper for the braves.
14
+
15
+ Organize your configuration into sections.
16
+
17
+ Easily override your configuration value by updating your enviroment variables (heroku friendly).
18
+
19
+ Self contained, and with a very light memory footprint.
20
+ EOF
21
+
22
+ s.email = 'alexandre.ignjatovic@gmail.com'
23
+ s.files = `git ls-files`.split($RS).reject do |file|
24
+ file =~ %r{^(?:
25
+ spec/.*
26
+ |Gemfile
27
+ |Rakefile
28
+ |\.rspec
29
+ |\.gitignore
30
+ |\.rubocop.yml
31
+ |\.rubocop_todo.yml
32
+ |.*\.eps
33
+ )$}x
34
+ end
35
+ s.test_files = []
36
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
37
+ s.extra_rdoc_files = ['LICENSE', 'README.md']
38
+ s.homepage = 'http://github.com/appaloosa-store/tepee'
39
+ s.licenses = ['MIT']
40
+ s.require_paths = ['lib']
41
+ s.rubygems_version = '1.8.23'
42
+
43
+ s.summary = 'A ruby configuration helper for the braves'
44
+
45
+ s.add_development_dependency('rspec', '~> 3.4')
46
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tepee
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexandre Ignjatovic
8
+ - Robin Sfez
9
+ - Benoit Tigeot
10
+ - Christophe Valentin
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2016-06-22 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.4'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.4'
30
+ description: |2
31
+ A ruby configuration helper for the braves.
32
+
33
+ Organize your configuration into sections.
34
+
35
+ Easily override your configuration value by updating your enviroment variables (heroku friendly).
36
+
37
+ Self contained, and with a very light memory footprint.
38
+ email: alexandre.ignjatovic@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.md
44
+ files:
45
+ - ".travis.yml"
46
+ - Gemfile.lock
47
+ - LICENSE
48
+ - README.md
49
+ - lib/tepee.rb
50
+ - lib/tepee/version.rb
51
+ - tepee.gemspec
52
+ homepage: http://github.com/appaloosa-store/tepee
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.9.3
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.6.5
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: A ruby configuration helper for the braves
76
+ test_files: []