configify-rb 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 +7 -0
- data/.gitignore +36 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +80 -0
- data/Rakefile +2 -0
- data/configify.gemspec +25 -0
- data/lib/configify.rb +25 -0
- data/lib/configify/base.rb +36 -0
- data/lib/configify/version.rb +3 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d801d49720de0faae6fc1f2da71e67902269dea
|
4
|
+
data.tar.gz: 97d08fecc8b651ef72ea7bc5138dd6ac69c09b47
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46c660469d9a2b087380e39b1a70461b44855096d8e5200a3f9e0476c3c5aab41a5addfdd20acd202ab59583f0f53d820febe2c7de604225269afa243412a243
|
7
|
+
data.tar.gz: 4e7e109aa1ecac30e16016b17fff67bd86a8746394c9b70481b988e5bdfd31a4d73427d2a02d0e0815abc24aab657a1977ecdd7f14c06387bbf7a76a3d5d4032
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
35
|
+
|
36
|
+
.ruby-version
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 soloman
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Configify
|
2
|
+
|
3
|
+
Configify captures a simple pattern for setting up configuration properties, as well as enable loading configurations from environment variables.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'configify'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install configify
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The following shows how to `Configify` a service class:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class TestService
|
27
|
+
include Configify
|
28
|
+
|
29
|
+
configuration do
|
30
|
+
env_variable_prefix 'TEST'
|
31
|
+
|
32
|
+
property :base_url, default: 'localhost:8080'
|
33
|
+
property :init_count
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize config: config
|
37
|
+
@base_url = config.base_url
|
38
|
+
@init_count = config.init_count
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
With configified service class above, `TestService.configuration` can be used to access the configuration class for the `TestService`. For example:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
config = TestService.configuration.new
|
47
|
+
config.init_count = 100
|
48
|
+
|
49
|
+
servcie = TestService.new config: config
|
50
|
+
```
|
51
|
+
|
52
|
+
`Configify` also supports loading properties from environment variables:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
# Assume the following environment variables
|
56
|
+
# TEST_INIT_COUNT = 100
|
57
|
+
# TEST_BASE_URL = 127.0.0.1:1234
|
58
|
+
|
59
|
+
config = TestService.configuration.new
|
60
|
+
config.load_from_env
|
61
|
+
|
62
|
+
servcie = TestService.new config: config
|
63
|
+
```
|
64
|
+
|
65
|
+
The preferred way to initialise a instance is to utilize the `with_config`:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
service = TestService.with_config do |config|
|
69
|
+
config.load_from_env
|
70
|
+
config.init_count = 100
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
1. Fork it ( https://github.com/everydayhero/configify/fork )
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
80
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/configify.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'configify/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "configify-rb"
|
8
|
+
spec.version = Configify::VERSION
|
9
|
+
spec.authors = ["soloman"]
|
10
|
+
spec.email = ["soloman1124@gmail.com"]
|
11
|
+
spec.summary = %q{Simple utility to set config properties}
|
12
|
+
spec.description = %q{Simple utility to set config properties}
|
13
|
+
spec.homepage = 'https://github.com/everydayhero/configify'
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.required_ruby_version = '~> 2.1'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
data/lib/configify.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'configify/version'
|
2
|
+
require 'configify/base'
|
3
|
+
|
4
|
+
module Configify
|
5
|
+
def self.included base
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def configuration &block
|
11
|
+
@configuration_class = Class.new Base, &block if block_given?
|
12
|
+
|
13
|
+
@configuration_class
|
14
|
+
end
|
15
|
+
|
16
|
+
def with_config
|
17
|
+
return unless configuration
|
18
|
+
|
19
|
+
new_config = configuration.new
|
20
|
+
yield new_config if block_given?
|
21
|
+
|
22
|
+
new config: new_config
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Configify
|
2
|
+
class Base
|
3
|
+
def initialize
|
4
|
+
self.class.properties.each do |key, value|
|
5
|
+
send "#{key}=", value
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def load_from_env prefix: self.class.env_variable_prefix
|
10
|
+
self.class.properties.each do |key, _|
|
11
|
+
env_var_name = "#{prefix}_#{key.upcase}"
|
12
|
+
self.send "#{key}=", ENV[env_var_name] if ENV.has_key? env_var_name
|
13
|
+
end
|
14
|
+
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def env_variable_prefix prefix = nil
|
20
|
+
@env_variable_prefix = prefix if prefix
|
21
|
+
|
22
|
+
@env_variable_prefix
|
23
|
+
end
|
24
|
+
|
25
|
+
def property key, default: nil
|
26
|
+
attr_accessor key.to_sym
|
27
|
+
|
28
|
+
properties[key.to_sym] = default
|
29
|
+
end
|
30
|
+
|
31
|
+
def properties
|
32
|
+
@properties ||= Hash.new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: configify-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- soloman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-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: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Simple utility to set config properties
|
42
|
+
email:
|
43
|
+
- soloman1124@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- configify.gemspec
|
55
|
+
- lib/configify.rb
|
56
|
+
- lib/configify/base.rb
|
57
|
+
- lib/configify/version.rb
|
58
|
+
homepage: https://github.com/everydayhero/configify
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '2.1'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.2.2
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Simple utility to set config properties
|
82
|
+
test_files: []
|