tiny_config 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 +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/lib/tiny_config/version.rb +3 -0
- data/lib/tiny_config.rb +35 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/tiny_config_spec.rb +38 -0
- data/tiny_config.gemspec +24 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 794a5639b058bc929497bb1ba97ba2f31289e48a
|
4
|
+
data.tar.gz: ea0c7c8aa1a2725b458bf5f7872d5ed7bb6aa27d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a6cedc44981cfb24c3b5a11b7fb24ad3beac6586ae3e1e3dfdfb0ad8268ae4eb2bdcaf03e7dec4689ad13103aa3a6a33d56c13f6ff37742042f141aaaff63bd
|
7
|
+
data.tar.gz: 53fdf1e63fa519ba05b83ae6231a85ca555d4b54833b82f95f14330b15bc1f1704ba4ac3d9da897d5ea1ad667a8eecd7aa97562137e6bf85942271ec5370bec5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 gong023
|
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,36 @@
|
|
1
|
+
# TinyConfig
|
2
|
+
|
3
|
+
simple and tiny config class.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tiny_config'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tiny_config
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
TinyConfig.register(:twitter, [:access_token, :access_secret]);
|
23
|
+
TinyConfig.twitter.access_token = 'abcd'
|
24
|
+
TinyConfig.twitter.access_token
|
25
|
+
=> 'abcd'
|
26
|
+
TinyConfig.twitter.access_secret
|
27
|
+
=> Throws Exception
|
28
|
+
```
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/tiny_config.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "tiny_config/version"
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
class TinyConfig
|
5
|
+
def self.register(namespace, config_keys)
|
6
|
+
const_set namespace.capitalize, Class.new {
|
7
|
+
include ::Singleton
|
8
|
+
|
9
|
+
config_keys = [config_keys] unless config_keys.instance_of?(Array)
|
10
|
+
|
11
|
+
config_keys.each do |config_key|
|
12
|
+
attr_writer config_key
|
13
|
+
|
14
|
+
define_method config_key do
|
15
|
+
v = instance_variable_get("@#{config_key}")
|
16
|
+
v.nil? ? raise(TinyConfig::ConfigKeyNillError, message) : v
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def message
|
21
|
+
namespace = self.class.to_s.split('::').last.downcase
|
22
|
+
required_key = caller()[1].match(/`.*'?/).to_s.delete('`\'')
|
23
|
+
"#{namespace} #{required_key} is requried."
|
24
|
+
end
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.method_missing namespace
|
29
|
+
raise UndefinedNamespaceError, namespace unless self.constants.include? namespace.capitalize
|
30
|
+
const_get(namespace.capitalize).instance
|
31
|
+
end
|
32
|
+
|
33
|
+
class ConfigKeyNillError < StandardError; end
|
34
|
+
class UndefinedNamespaceError < StandardError; end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TinyConfig, order: :defined do
|
4
|
+
it 'should have a version number' do
|
5
|
+
expect(TinyConfig::VERSION).not_to be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'register' do
|
9
|
+
context 'normal case' do
|
10
|
+
context 'multiple keys' do
|
11
|
+
subject { TinyConfig.register(:config_a, [:key1, :key2]) }
|
12
|
+
it { is_expected.to be TinyConfig::Config_a }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'single key' do
|
16
|
+
subject { TinyConfig.register(:config_b, :key1) }
|
17
|
+
it { is_expected.to be TinyConfig::Config_b }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'accessing keys' do
|
23
|
+
before(:context) do
|
24
|
+
TinyConfig.register(:config_c, [:key1, :key2])
|
25
|
+
TinyConfig.config_c.key1 = 'abcd'
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'normal case' do
|
29
|
+
subject { TinyConfig.config_c.key1 }
|
30
|
+
it { is_expected.to eq 'abcd' }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'abnormal case' do
|
34
|
+
it { expect { TinyConfig.config_c.key2 }.to raise_error TinyConfig::ConfigKeyNillError }
|
35
|
+
it { expect { TinyConfig.unregistered.key }.to raise_error TinyConfig::UndefinedNamespaceError }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/tiny_config.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 'tiny_config/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tiny_config"
|
8
|
+
spec.version = TinyConfig::VERSION
|
9
|
+
spec.authors = ["gong023"]
|
10
|
+
spec.email = ["gon.gong.gone@gmail.com"]
|
11
|
+
spec.description = %q{simple and tiny config class for casual use}
|
12
|
+
spec.summary = %q{simple and tiny config class}
|
13
|
+
spec.homepage = "https://gong023.com/gong023/tiny_config"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tiny_config
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- gong023
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-24 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
55
|
+
description: simple and tiny config class for casual use
|
56
|
+
email:
|
57
|
+
- gon.gong.gone@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/tiny_config.rb
|
70
|
+
- lib/tiny_config/version.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
- spec/tiny_config_spec.rb
|
73
|
+
- tiny_config.gemspec
|
74
|
+
homepage: https://gong023.com/gong023/tiny_config
|
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.0.3
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: simple and tiny config class
|
98
|
+
test_files:
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
- spec/tiny_config_spec.rb
|
101
|
+
has_rdoc:
|