mine_setting 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/lib/mine_setting/version.rb +3 -0
- data/lib/mine_setting.rb +57 -0
- data/mine_setting.gemspec +25 -0
- data/spec/examples.txt +6 -0
- data/spec/gem_helper.rb +7 -0
- data/spec/lib/mine_setting_spec.rb +56 -0
- data/spec/settings/.secrets.yml.swp +0 -0
- data/spec/settings/base.yml +12 -0
- data/spec/settings/secrets.yml +9 -0
- data/spec/spec_helper.rb +92 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c0f79bd1f3a729797e8296f641279710a1bdd37
|
4
|
+
data.tar.gz: 667019653939c85934b0d23fb63d1c6d5cffe266
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8d1f3cb05b61ebd531406b3c8e2571387a81f185f6b770bd3b2a71343db0234b667524704e16ed216cd9eabae60ef871b33ab6a9cea5e7d539360e083f8a1d5
|
7
|
+
data.tar.gz: 27c860b1896f4216273f6f39326fc3d13900183fbbf1f1ffc8b4ce6124de6e885e9e074734061235a1719e023f3effcc519509eced93c74bfb58832b354331e9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 jiangzhi.xie
|
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,46 @@
|
|
1
|
+
# MineSetting
|
2
|
+
|
3
|
+
Simple load setting files
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'mine_setting'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install mine_setting
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
config/settings/base.yml
|
24
|
+
```
|
25
|
+
development:
|
26
|
+
name: base
|
27
|
+
env: dev
|
28
|
+
```
|
29
|
+
|
30
|
+
```
|
31
|
+
class MySetting
|
32
|
+
extend MineSetting
|
33
|
+
|
34
|
+
load_dir File.expand_path('../config/settings'), :development
|
35
|
+
end
|
36
|
+
|
37
|
+
MySetting.base # => {'name' => 'base', 'env' => 'dev'}
|
38
|
+
```
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it ( https://github.com/[my-github-username]/mine_setting/fork )
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/mine_setting.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "mine_setting/version"
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
# Files:
|
7
|
+
# config/settings/base.yml
|
8
|
+
# config/settings/secrets.yml
|
9
|
+
# config/settings/other_config.yml
|
10
|
+
#
|
11
|
+
# File Content:
|
12
|
+
# development:
|
13
|
+
# foo: bar
|
14
|
+
# test:
|
15
|
+
# xxx: yyy
|
16
|
+
#
|
17
|
+
#
|
18
|
+
# Code:
|
19
|
+
# class MySettings
|
20
|
+
# extend MineSetting
|
21
|
+
#
|
22
|
+
# load_dir Rails.root.join('config/settings'), 'development'
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# MySettings.base # {foo: bar}
|
26
|
+
# MySettings.secrets
|
27
|
+
# MySettings.other_config
|
28
|
+
#
|
29
|
+
|
30
|
+
module MineSetting
|
31
|
+
def self.included(cls)
|
32
|
+
raise "Cannot include SimpleSettings, please use extend"
|
33
|
+
end
|
34
|
+
|
35
|
+
def load_dir(dir_path, env)
|
36
|
+
Dir[File.join(dir_path, '*')].each do |filepath|
|
37
|
+
filename = File.basename filepath
|
38
|
+
next unless filename =~ /^\w+\.ya?ml$/
|
39
|
+
puts "Load config '#{filename}'"
|
40
|
+
|
41
|
+
setting_name = filename.gsub(/\.ya?ml/, '')
|
42
|
+
eval(%Q{
|
43
|
+
def self.#{setting_name}
|
44
|
+
@#{setting_name} ||= load_setting('#{filepath}', '#{env}')
|
45
|
+
end
|
46
|
+
})
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def load_setting(filepath, env)
|
54
|
+
str = File.read(filepath)
|
55
|
+
YAML.load(ERB.new(str).result)[env]
|
56
|
+
end
|
57
|
+
end
|
@@ -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 'mine_setting/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mine_setting"
|
8
|
+
spec.version = MineSetting::VERSION
|
9
|
+
spec.authors = ["jiangzhi.xie"]
|
10
|
+
spec.email = ["xiejiangzhi@gmail.com"]
|
11
|
+
spec.summary = %q{Sample load setting files}
|
12
|
+
spec.description = %q{Sample load setting files}
|
13
|
+
spec.homepage = ""
|
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.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
24
|
+
spec.add_development_dependency "pry", '~> 0'
|
25
|
+
end
|
data/spec/examples.txt
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
example_id | status | run_time |
|
2
|
+
-------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/lib/mine_setting_spec.rb[1:1] | passed | 0.00105 seconds |
|
4
|
+
./spec/lib/mine_setting_spec.rb[1:2:1] | passed | 0.00195 seconds |
|
5
|
+
./spec/lib/mine_setting_spec.rb[1:3:1] | passed | 0.00132 seconds |
|
6
|
+
./spec/lib/mine_setting_spec.rb[1:3:2] | passed | 0.00492 seconds |
|
data/spec/gem_helper.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
RSpec.describe MineSetting do
|
2
|
+
let(:cls) do
|
3
|
+
Class.new { extend MineSetting }
|
4
|
+
end
|
5
|
+
let(:config_dir) { File.expand_path('../../settings', __FILE__) }
|
6
|
+
|
7
|
+
|
8
|
+
it 'include should raise error' do
|
9
|
+
expect {
|
10
|
+
Class.new { include MineSetting }
|
11
|
+
}.to raise_error(/\ACannot include SimpleSettings/)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe '.load_dir' do
|
16
|
+
it 'should define config methods' do
|
17
|
+
expect {
|
18
|
+
cls.load_dir(config_dir, :development)
|
19
|
+
}.to change { cls.respond_to?(:base) && cls.respond_to?(:secrets) }.to(true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
describe 'config_methods' do
|
25
|
+
it 'should retrun config' do
|
26
|
+
cls.load_dir(config_dir, :development)
|
27
|
+
|
28
|
+
expect(cls.base).to eq({
|
29
|
+
'name' => 'base',
|
30
|
+
'number' => 333,
|
31
|
+
'env' => 'development'
|
32
|
+
})
|
33
|
+
|
34
|
+
expect(cls.secrets).to eq({
|
35
|
+
'name' => 'secrets',
|
36
|
+
'key' => 'this my key'
|
37
|
+
})
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'load with env should correct' do
|
41
|
+
cls.load_dir(config_dir, :test)
|
42
|
+
|
43
|
+
expect(cls.base).to eq({
|
44
|
+
'name' => 'base',
|
45
|
+
'number' => 123,
|
46
|
+
'env' => 'test'
|
47
|
+
})
|
48
|
+
|
49
|
+
expect(cls.secrets).to eq({
|
50
|
+
'name' => 'secrets',
|
51
|
+
'key' => 'what my key?'
|
52
|
+
})
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# These two settings work together to allow you to limit a spec run
|
44
|
+
# to individual examples or groups you care about by tagging them with
|
45
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
46
|
+
# get run.
|
47
|
+
config.filter_run :focus
|
48
|
+
config.run_all_when_everything_filtered = true
|
49
|
+
|
50
|
+
# Allows RSpec to persist some state between runs in order to support
|
51
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
52
|
+
# you configure your source control system to ignore this file.
|
53
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
54
|
+
|
55
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
56
|
+
# recommended. For more details, see:
|
57
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
58
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
59
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
60
|
+
config.disable_monkey_patching!
|
61
|
+
|
62
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
63
|
+
# be too noisy due to issues in dependencies.
|
64
|
+
config.warnings = true
|
65
|
+
|
66
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
67
|
+
# file, and it's useful to allow more verbose output when running an
|
68
|
+
# individual spec file.
|
69
|
+
if config.files_to_run.one?
|
70
|
+
# Use the documentation formatter for detailed output,
|
71
|
+
# unless a formatter has already been configured
|
72
|
+
# (e.g. via a command-line flag).
|
73
|
+
config.default_formatter = 'doc'
|
74
|
+
end
|
75
|
+
|
76
|
+
# Print the 10 slowest examples and example groups at the
|
77
|
+
# end of the spec run, to help surface which specs are running
|
78
|
+
# particularly slow.
|
79
|
+
config.profile_examples = 10
|
80
|
+
|
81
|
+
# Run specs in random order to surface order dependencies. If you find an
|
82
|
+
# order dependency and want to debug it, you can fix the order by providing
|
83
|
+
# the seed, which is printed after each run.
|
84
|
+
# --seed 1234
|
85
|
+
config.order = :random
|
86
|
+
|
87
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
88
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
89
|
+
# test failures related to randomization by passing the same `--seed` value
|
90
|
+
# as the one that triggered the failure.
|
91
|
+
Kernel.srand config.seed
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mine_setting
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jiangzhi.xie
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-29 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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Sample load setting files
|
70
|
+
email:
|
71
|
+
- xiejiangzhi@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/mine_setting.rb
|
83
|
+
- lib/mine_setting/version.rb
|
84
|
+
- mine_setting.gemspec
|
85
|
+
- spec/examples.txt
|
86
|
+
- spec/gem_helper.rb
|
87
|
+
- spec/lib/mine_setting_spec.rb
|
88
|
+
- spec/settings/.secrets.yml.swp
|
89
|
+
- spec/settings/base.yml
|
90
|
+
- spec/settings/secrets.yml
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
homepage: ''
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.2.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Sample load setting files
|
116
|
+
test_files:
|
117
|
+
- spec/examples.txt
|
118
|
+
- spec/gem_helper.rb
|
119
|
+
- spec/lib/mine_setting_spec.rb
|
120
|
+
- spec/settings/.secrets.yml.swp
|
121
|
+
- spec/settings/base.yml
|
122
|
+
- spec/settings/secrets.yml
|
123
|
+
- spec/spec_helper.rb
|