configureasy 0.0.2 → 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 +4 -4
- data/.coveralls.yml +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +14 -0
- data/README.md +70 -24
- data/Rakefile +3 -0
- data/configureasy.gemspec +3 -11
- data/lib/configureasy.rb +2 -1
- data/lib/configureasy/config.rb +46 -8
- data/lib/configureasy/config_parser.rb +58 -0
- data/lib/configureasy/configurable.rb +55 -40
- data/lib/configureasy/version.rb +1 -1
- data/spec/lib/configureasy/config_parser_spec.rb +60 -0
- data/spec/lib/configureasy/config_spec.rb +15 -4
- data/spec/lib/configureasy/configurable_spec.rb +48 -57
- data/spec/spec_helper.rb +3 -0
- metadata +11 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53ec1f1f03b188c3ef934d0bf5e5d980a313825c
|
4
|
+
data.tar.gz: 082aa5e705f4488e4a65033df3e4d63a92731249
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8225a7f3d3c5c06eed1a38570699e119e74e905df538f8c6ce0dd9b3d0c840a5f53f00cada86987bb8e5476e9e6e0ce4934a26a5a951ccd2af1572878e21f6d0
|
7
|
+
data.tar.gz: b4cb540efa45c89b5955a06a37fc85b0e2c685b519843fb3b65ea36bfc1b6c15d8cb1da57e04700b914dfe635e01897e7c43185b46614a0a19656ca831c31c99
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: ysw4PXa6VEK0TrzqD7rO26tiSCcBF2Vkv
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -2,3 +2,17 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in configureasy.gemspec
|
4
4
|
gemspec
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem 'terminal-notifier'
|
8
|
+
gem 'terminal-notifier-guard'
|
9
|
+
gem 'pry'
|
10
|
+
gem 'pry-nav'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem 'rake'
|
15
|
+
gem 'rspec'
|
16
|
+
gem 'guard-rspec'
|
17
|
+
gem 'coveralls', require: false
|
18
|
+
end
|
data/README.md
CHANGED
@@ -1,68 +1,114 @@
|
|
1
1
|
Configureasy
|
2
2
|
=============
|
3
3
|
|
4
|
-
|
4
|
+
[](https://travis-ci.org/alexandreprates/configureasy) [](https://coveralls.io/r/alexandreprates/configureasy) [](http://inch-ci.org/github/alexandreprates/configureasy)
|
5
5
|
|
6
|
-
|
6
|
+
Configureasy is a library for load configs quickly and easily.
|
7
7
|
|
8
|
-
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
9
11
|
|
10
12
|
```ruby
|
11
13
|
gem 'configureasy'
|
12
14
|
```
|
13
15
|
|
14
|
-
|
16
|
+
And then execute:
|
15
17
|
|
16
18
|
$ bundle
|
17
19
|
|
18
|
-
|
20
|
+
Or install it yourself as:
|
19
21
|
|
20
22
|
$ gem install configureasy
|
21
23
|
|
22
|
-
##
|
24
|
+
## Usage
|
23
25
|
|
24
|
-
|
26
|
+
Load content of <i>config/database.yml</i>
|
25
27
|
|
26
28
|
```ruby
|
27
|
-
|
29
|
+
# in ./config/database.yml
|
30
|
+
# host: localhost
|
31
|
+
# port: 1234
|
32
|
+
|
33
|
+
class DBConfig
|
28
34
|
include Configureasy
|
35
|
+
load_config :database
|
29
36
|
end
|
30
37
|
|
31
|
-
|
32
|
-
# => '
|
38
|
+
# You can access config values
|
39
|
+
DBConfig.database.host # => 'localhost'
|
40
|
+
DBConfig.database.port # => 1234
|
33
41
|
```
|
34
42
|
|
35
|
-
|
43
|
+
Setting different method name
|
36
44
|
|
37
45
|
```ruby
|
38
|
-
|
46
|
+
# in ./config/user_keys.yml
|
47
|
+
# name: secret_key
|
48
|
+
# value: secret_key_value
|
49
|
+
|
50
|
+
class User
|
39
51
|
include Configureasy
|
40
|
-
|
41
|
-
config_name :foo_config
|
52
|
+
load_config :user_keys, as: :keys
|
42
53
|
end
|
54
|
+
|
55
|
+
User.keys.name # => 'secret_key'
|
56
|
+
User.keys.value # => 'secret_key_value'
|
43
57
|
```
|
44
58
|
|
45
|
-
|
59
|
+
Setting different folder
|
46
60
|
|
47
61
|
```ruby
|
48
|
-
class
|
62
|
+
class Censor
|
49
63
|
include Configureasy
|
50
|
-
|
51
|
-
|
64
|
+
load_config :forbidden_words, path: './blacklist'
|
65
|
+
# load './blacklist/forbidden_words.yml'
|
52
66
|
end
|
53
67
|
```
|
54
68
|
|
55
|
-
|
69
|
+
Configureasy detect per environment configs
|
56
70
|
|
57
71
|
```ruby
|
58
|
-
|
72
|
+
# in ./config/aws.yml
|
73
|
+
# development:
|
74
|
+
# access: development_access
|
75
|
+
# secret: development_secret
|
76
|
+
# production:
|
77
|
+
# access: production_access
|
78
|
+
# secret: production_secret
|
79
|
+
|
80
|
+
class S3Storage
|
59
81
|
include Configureasy
|
82
|
+
load_config :aws
|
83
|
+
end
|
84
|
+
|
85
|
+
# in development
|
86
|
+
S3Storage.aws.access # => 'development_access'
|
87
|
+
|
88
|
+
# in production
|
89
|
+
S3Storage.aws.access # => 'production_access'
|
90
|
+
```
|
91
|
+
|
92
|
+
You can access config data as Hash
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
# in ./config/access.yml
|
96
|
+
# admin_group: 1
|
97
|
+
# user_group: 2
|
98
|
+
|
99
|
+
class User
|
100
|
+
require Configureasy
|
101
|
+
load_config :access
|
60
102
|
end
|
61
103
|
|
62
|
-
|
63
|
-
# => {'
|
104
|
+
User.access.as_hash
|
105
|
+
# => {'admin_group' => '1', 'user_group' => '2'}
|
64
106
|
```
|
65
107
|
|
66
|
-
##
|
108
|
+
## Contributing
|
67
109
|
|
68
|
-
|
110
|
+
1. Fork it ( https://github.com/alexandreprates/configureasy/fork )
|
111
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
112
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
113
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
114
|
+
5. Create a new Pull Request
|
data/Rakefile
CHANGED
data/configureasy.gemspec
CHANGED
@@ -8,20 +8,12 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Configureasy::VERSION
|
9
9
|
spec.authors = ["Alexandre Prates"]
|
10
10
|
spec.email = ["ajfprates@gmail.com"]
|
11
|
-
spec.summary = %q{A Simple way to get configs
|
12
|
-
spec.description = %q{A Simple way to get configs
|
13
|
-
spec.homepage = "https://
|
11
|
+
spec.summary = %q{A Simple way to get configs.}
|
12
|
+
spec.description = %q{A Simple way to get configs.}
|
13
|
+
spec.homepage = "https://github.com/alexandreprates/configureasy"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
17
|
spec.test_files = spec.files.grep(%r{^(spec|features)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
-
|
24
|
-
spec.add_development_dependency "rspec", "~> 3.1"
|
25
|
-
spec.add_development_dependency "guard", "~> 2.10"
|
26
|
-
spec.add_development_dependency "guard-rspec", "~> 4.5"
|
27
19
|
end
|
data/lib/configureasy.rb
CHANGED
@@ -29,10 +29,11 @@ module Configureasy
|
|
29
29
|
# Class to raise error on invalid config file
|
30
30
|
class ConfigInvalid < Exception; end
|
31
31
|
|
32
|
-
def self.included(receiver)
|
32
|
+
def self.included(receiver) # :nodoc:
|
33
33
|
receiver.extend Configurable
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
require 'configureasy/config'
|
38
|
+
require 'configureasy/config_parser'
|
38
39
|
require 'configureasy/configurable'
|
data/lib/configureasy/config.rb
CHANGED
@@ -1,15 +1,53 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
|
3
|
-
|
4
|
-
# Class for store and retrive config values
|
3
|
+
# Store data structure (Hash) and allow access values using method calling.
|
5
4
|
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# => 'foo'
|
5
|
+
# Confugureasy::Config.new(foo: 'foo').foo
|
6
|
+
# # => 'foo'
|
9
7
|
#
|
8
|
+
# Configureasy::Config.new(:foo => {:bar => :value}).foo.bar
|
9
|
+
# # => :value
|
10
|
+
#
|
11
|
+
# You can access values using [] too
|
12
|
+
#
|
13
|
+
# Configureasy::Config.new(foo: 'bar')[:foo]
|
14
|
+
# # => 'bar'
|
15
|
+
#
|
16
|
+
# Beside you retrive data as hash
|
17
|
+
#
|
18
|
+
# Configureasy::Config(foo: 'bar').as_hash
|
19
|
+
# # => {:foo => 'bar'}
|
10
20
|
class Configureasy::Config < OpenStruct
|
11
|
-
|
12
|
-
|
13
|
-
|
21
|
+
|
22
|
+
# Convert a hash data into methods recursively.
|
23
|
+
# Params:
|
24
|
+
# [+params+]:: Hash with data do convert
|
25
|
+
#
|
26
|
+
# Returns new instance of [Configureasy::Config].
|
27
|
+
def initialize(params = {})
|
28
|
+
@hash = params
|
29
|
+
params = params.inject({}) do |hash, data|
|
30
|
+
key, value = data
|
31
|
+
value = self.class.new(value) if value.is_a? Hash
|
32
|
+
hash.merge key.to_sym => value
|
33
|
+
end
|
34
|
+
super params
|
35
|
+
end
|
36
|
+
|
37
|
+
# Retrive some config value.
|
38
|
+
# Params:
|
39
|
+
# [+key+]:: name of config
|
40
|
+
#
|
41
|
+
# Configureasy::Config.new(foo: 'bar')[:foo]
|
42
|
+
# # => 'bar'
|
43
|
+
#
|
44
|
+
# Returns config value, or nil if can't reach config value.
|
45
|
+
def [](key)
|
46
|
+
self.send key
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns config as hash.
|
50
|
+
def as_hash
|
51
|
+
@hash
|
14
52
|
end
|
15
53
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
# Load and parse content of config (YAML).
|
4
|
+
# Raise exception if config file not found
|
5
|
+
#
|
6
|
+
# parser = Configureasy::ConfigParser.new('./config/config.yml')
|
7
|
+
# # => <# Configureasy::ConfigParser ... >
|
8
|
+
# parser.parse
|
9
|
+
# # => {:hash => :content}
|
10
|
+
#
|
11
|
+
# Set environment to load specific part of config
|
12
|
+
#
|
13
|
+
# parser = Configureasy::ConfigParser.new('./config/environments.yml', 'development')
|
14
|
+
# # => <# Configureasy::ConfigParser ... >
|
15
|
+
# parser.parse
|
16
|
+
# # => {:development => :content}
|
17
|
+
class Configureasy::ConfigParser
|
18
|
+
# Get config filename
|
19
|
+
attr_reader :filename
|
20
|
+
# Get environment to load data
|
21
|
+
attr_reader :environment
|
22
|
+
|
23
|
+
# Initialize ConfigParser instance.
|
24
|
+
# Params:
|
25
|
+
# [+filename+]:: name of config file.
|
26
|
+
# [+environment+]:: load specific environment config (*optional*).
|
27
|
+
#
|
28
|
+
# <b>If config file not found raise an exeception.</b>
|
29
|
+
#
|
30
|
+
# Returns instance of [Configureasy::ConfigParser]
|
31
|
+
def initialize(filename, environment = nil)
|
32
|
+
raise "Config #{filename} not found" unless File.exist? filename
|
33
|
+
@filename = filename
|
34
|
+
@environment = environment || current_environment
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns config content
|
38
|
+
def parse
|
39
|
+
content = YAML.load_file(filename)
|
40
|
+
content.has_key?(self.environment) ? content[self.environment] : content
|
41
|
+
rescue
|
42
|
+
raise "Invalid config content for #{filename}"
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns config content as [Configureasy::Config]
|
46
|
+
def as_config
|
47
|
+
Configureasy::Config.new self.parse
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# Gets the current environment.
|
53
|
+
# Returns current environment as string. If environment is not set returns 'development'
|
54
|
+
def current_environment
|
55
|
+
ENV['RUBY_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -1,57 +1,72 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
|
+
# Allows loading of different configuration files.
|
4
|
+
#
|
5
|
+
# class Dumb
|
6
|
+
# include Configureasy
|
7
|
+
#
|
8
|
+
# # create class method _config_ with content of config/config.yml
|
9
|
+
# load_config :config
|
10
|
+
#
|
11
|
+
# # create class method _secrets_ with content for config/session_secrets.yml
|
12
|
+
# load_config :session_secrets, as: :secrets
|
13
|
+
#
|
14
|
+
# # create class method _aws_keys_ with content for './aws/keys.yml'
|
15
|
+
# load_config :keys, as: :aws_keys, path: './aws'
|
16
|
+
# end
|
3
17
|
module Configureasy::Configurable
|
4
|
-
|
5
|
-
#
|
6
|
-
# Example
|
7
|
-
# config_name :foo
|
8
|
-
# => APP_ROOT/config/foo.yml
|
9
|
-
#
|
10
|
-
# config_name :bar
|
11
|
-
# => APP_ROOT/config/bar.yml
|
12
|
-
#
|
13
|
-
def config_name(name = nil)
|
14
|
-
@config_name = name if name
|
15
|
-
@config_name || self.name.downcase
|
16
|
-
end
|
17
|
-
|
18
|
-
def config_filename(filename = nil)
|
19
|
-
@config_filename = File.expand_path filename if filename
|
20
|
-
@config_filename || File.expand_path("./config/#{config_name}.yml")
|
21
|
-
end
|
18
|
+
@@configurables = {}
|
22
19
|
|
23
|
-
#
|
24
|
-
|
25
|
-
|
20
|
+
# dinamically create method for access config data.
|
21
|
+
# Params:
|
22
|
+
# [+file_basename+]:: config file name (by default in *config* directory)
|
23
|
+
# [+as+]:: generated method name (by default same as file_basename)
|
24
|
+
# [+path+]:: config path (by default './config')
|
25
|
+
def load_config(file_basename, options = {})
|
26
|
+
name = options[:as] || file_basename
|
27
|
+
path = options[:path] || './config'
|
28
|
+
filename = File.join path, "#{file_basename}.yml"
|
29
|
+
self.class.send(:define_method, name) { _configurable_for(filename) }
|
30
|
+
self.class.send(:define_method, "#{name}_reload!") { _configurable_reload(filename) }
|
26
31
|
end
|
27
32
|
|
28
|
-
#
|
29
|
-
|
30
|
-
|
33
|
+
# @deprecated Please use {#load_config} instead.
|
34
|
+
# Setting config source filename.
|
35
|
+
# Params:
|
36
|
+
# [+name+]:: the name of config file
|
37
|
+
#
|
38
|
+
# # load contents for ./config/foo.yml
|
39
|
+
# config_name :foo
|
40
|
+
#
|
41
|
+
# # load contents for ./config/bar.yml
|
42
|
+
# config_name :bar
|
43
|
+
def config_name(name = nil)
|
44
|
+
warn "[DEPRECATION] `config_name` is deprecated. Please use `load_config` instead."
|
45
|
+
load_config name, as: 'config'
|
31
46
|
end
|
32
47
|
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
48
|
+
# @deprecated Please use {#load_config} instead.
|
49
|
+
# Load config in specific location.
|
50
|
+
# Params
|
51
|
+
# [+filename+]:: config filename
|
52
|
+
#
|
53
|
+
# # load contents for /etc/my_configs.yml
|
54
|
+
# config_filename '/etc/my_configs.yml'
|
55
|
+
def config_filename(filename = nil)
|
56
|
+
warn "[DEPRECATION] `config_filename` is deprecated. Please use `load_config` instead."
|
57
|
+
basename = File.basename(filename, '.yml')
|
58
|
+
path = File.dirname(filename)
|
59
|
+
load_config basename, as: 'config', path: path
|
37
60
|
end
|
38
61
|
|
39
62
|
private
|
40
63
|
|
41
|
-
def
|
42
|
-
|
43
|
-
raise Configureasy::ConfigInvalid, "invalid config file '#{config_filename}'", caller unless configs_hash.is_a? Hash
|
44
|
-
|
45
|
-
Configureasy::Config.new configs_hash[_current_env] || configs_hash
|
46
|
-
end
|
47
|
-
|
48
|
-
def parse_configs
|
49
|
-
raise Configureasy::ConfigNotFound, "file not found '#{config_filename}'", caller unless have_config?
|
50
|
-
YAML.load_file config_filename
|
64
|
+
def _configurable_for(filename) # :nodoc:
|
65
|
+
@@configurables[filename.to_sym] || _configurable_reload(filename)
|
51
66
|
end
|
52
67
|
|
53
|
-
def
|
54
|
-
|
68
|
+
def _configurable_reload(filename) # :nodoc:
|
69
|
+
@@configurables[filename.to_sym] = Configureasy::ConfigParser.new(filename).as_config
|
55
70
|
end
|
56
71
|
|
57
72
|
end
|
data/lib/configureasy/version.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Configureasy::ConfigParser do
|
4
|
+
describe '.new' do
|
5
|
+
before(:each) do
|
6
|
+
allow(File).to receive(:exist?) { true }
|
7
|
+
allow(ENV).to receive(:[]) { nil }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "check if filename exists" do
|
11
|
+
expect(File).to receive(:exist?).with('missing_config.yml') { false }
|
12
|
+
expect { described_class.new('missing_config.yml') }.to raise_error "Config missing_config.yml not found"
|
13
|
+
expect(File).to receive(:exist?).with('missing_config.yml') { true }
|
14
|
+
expect(described_class.new 'missing_config.yml').to be_instance_of described_class
|
15
|
+
end
|
16
|
+
|
17
|
+
it "set environment to load data" do
|
18
|
+
allow(File).to receive(:exist?) { true }
|
19
|
+
expect(described_class.new('config.yml', 'stage').environment).to eq 'stage'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "get RUBY_ENV" do
|
23
|
+
allow(ENV).to receive(:[]).with('RUBY_ENV') { 'ruby_env' }
|
24
|
+
expect(described_class.new('config.yml').environment).to eq 'ruby_env'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "get RAILS_ENV" do
|
28
|
+
allow(ENV).to receive(:[]).with('RAILS_ENV') { 'rails_env' }
|
29
|
+
expect(described_class.new('config.yml').environment).to eq 'rails_env'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "get RACK_ENV" do
|
33
|
+
allow(ENV).to receive(:[]).with('RACK_ENV') { 'rack_env' }
|
34
|
+
expect(described_class.new('config.yml').environment).to eq 'rack_env'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#parse' do
|
39
|
+
it "return content of yml" do
|
40
|
+
allow(File).to receive(:exist?) { true }
|
41
|
+
allow(YAML).to receive(:load_file) { {'yaml' => 'content'} }
|
42
|
+
expect(described_class.new('config.yml').parse).to eq({'yaml' => 'content'})
|
43
|
+
end
|
44
|
+
it 'return config for environment' do
|
45
|
+
allow(File).to receive(:exist?) { true }
|
46
|
+
allow(YAML).to receive(:load_file) { {'development' => 'wrong', 'test' => 'wrong', 'stage' => 'correct'} }
|
47
|
+
allow(ENV).to receive(:[]).with('RUBY_ENV') { 'stage' }
|
48
|
+
expect(described_class.new('config.yml').parse).to eq('correct')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#as_config' do
|
53
|
+
it 'return config as Configureasy::Config' do
|
54
|
+
allow(File).to receive(:exist?) { true }
|
55
|
+
allow(YAML).to receive(:load_file) { {'yaml' => 'content'} }
|
56
|
+
expect(described_class.new('config.yml').as_config).to be_instance_of Configureasy::Config
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -1,13 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Configureasy::Config do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
let(:values) { {'first_level' => {'second_level' => 'second_level_value'}, 'single_level' => 'single_level_value'} }
|
5
|
+
let(:config) { described_class.new(values) }
|
6
|
+
describe '.new' do
|
7
|
+
it 'convert multi level hash' do
|
8
|
+
expect(config.first_level.second_level).to eq 'second_level_value'
|
7
9
|
end
|
8
10
|
end
|
9
11
|
|
10
|
-
describe
|
12
|
+
describe '#[]' do
|
13
|
+
it 'return value for a key' do
|
14
|
+
expect(config[:single_level]).to eq 'single_level_value'
|
15
|
+
end
|
16
|
+
end
|
11
17
|
|
18
|
+
describe '#.as_hash' do
|
19
|
+
it "return raw content" do
|
20
|
+
expect(config.as_hash).to eq values
|
21
|
+
end
|
12
22
|
end
|
23
|
+
|
13
24
|
end
|
@@ -1,81 +1,72 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class Foo
|
4
|
-
extend Configureasy::Configurable
|
5
|
-
end
|
6
|
-
|
7
3
|
describe Configureasy::Configurable do
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
before(:each) do
|
5
|
+
allow(File).to receive(:exist?) { true }
|
6
|
+
allow(YAML).to receive(:load_file) { {'works' => 'true'} }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '.load_config' do
|
10
|
+
let(:dumb_class) do
|
11
|
+
Class.new do
|
12
|
+
extend Configureasy::Configurable
|
13
|
+
load_config :dumb_config
|
14
|
+
load_config :another_config
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
|
-
it
|
14
|
-
expect(
|
15
|
-
Foo.config_name "bar"
|
16
|
-
expect(Foo.config_name).to eq('bar')
|
18
|
+
it 'dynamically generate methods' do
|
19
|
+
expect(dumb_class).to respond_to :dumb_config
|
17
20
|
end
|
18
21
|
|
19
|
-
it
|
20
|
-
|
21
|
-
expect(Foo.send :config_filename).to match(/other_conf\.yml$/)
|
22
|
+
it 'support more than one config' do
|
23
|
+
expect(dumb_class).to respond_to :another_config
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
Foo.config_filename '.hidedir/secret_config.yml'
|
28
|
-
expect(Foo.config_filename).to end_with('.hidedir/secret_config.yml')
|
26
|
+
it 'return ConfigParser content' do
|
27
|
+
expect(dumb_class.dumb_config.works).to eq 'true'
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
describe '
|
33
|
-
let(:
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
describe '.config_reload!' do
|
32
|
+
let(:dumb_class) do
|
33
|
+
Class.new do
|
34
|
+
extend Configureasy::Configurable
|
35
|
+
load_config :config
|
36
|
+
end
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
40
|
-
|
41
|
-
allow(File).to receive(:exist?).and_return(true)
|
42
|
-
|
43
|
-
expect { Foo.config }.to raise_exception Configureasy::ConfigInvalid
|
39
|
+
it 'reloading config file content' do
|
40
|
+
expect(dumb_class.config).not_to be dumb_class.config_reload!
|
44
41
|
end
|
42
|
+
end
|
45
43
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
describe '.config_name' do
|
45
|
+
let(:dumb_class) do
|
46
|
+
Class.new do
|
47
|
+
extend Configureasy::Configurable
|
48
|
+
config_name :deprecated
|
49
|
+
end
|
52
50
|
end
|
53
51
|
|
54
|
-
it "load
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
ENV['RUBY_ENV'] = 'development'
|
59
|
-
expect(Foo.reset_config!.foo).to eq('bar')
|
60
|
-
|
61
|
-
ENV['RUBY_ENV'] = 'test'
|
62
|
-
expect(Foo.reset_config!.foo).to eq('test')
|
63
|
-
|
64
|
-
ENV['RUBY_ENV'] = nil
|
65
|
-
|
66
|
-
ENV['RACK_ENV'] = 'development'
|
67
|
-
expect(Foo.reset_config!.foo).to eq('bar')
|
68
|
-
ENV['RACK_ENV'] = nil
|
69
|
-
|
70
|
-
ENV['RAILS_ENV'] = 'test'
|
71
|
-
expect(Foo.reset_config!.foo).to eq('test')
|
52
|
+
it "load config content into config method" do
|
53
|
+
expect(dumb_class).to respond_to :config
|
54
|
+
expect(dumb_class.config.works).to eq('true')
|
72
55
|
end
|
56
|
+
end
|
73
57
|
|
74
|
-
|
75
|
-
|
76
|
-
|
58
|
+
describe '.config_filename' do
|
59
|
+
let(:dumb_class) do
|
60
|
+
Class.new do
|
61
|
+
extend Configureasy::Configurable
|
62
|
+
config_filename './deprecated/feature.yml'
|
63
|
+
end
|
64
|
+
end
|
77
65
|
|
78
|
-
|
66
|
+
it "load config with filename into config method" do
|
67
|
+
expect(dumb_class).to respond_to :config
|
68
|
+
expect(dumb_class.config.works).to eq('true')
|
79
69
|
end
|
80
70
|
end
|
71
|
+
|
81
72
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,93 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configureasy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Prates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
12
|
-
dependencies:
|
13
|
-
|
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.1'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '3.1'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: guard
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.10'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '2.10'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: guard-rspec
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '4.5'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '4.5'
|
83
|
-
description: A Simple way to get configs in your Classes/Modules.
|
11
|
+
date: 2015-03-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Simple way to get configs.
|
84
14
|
email:
|
85
15
|
- ajfprates@gmail.com
|
86
16
|
executables: []
|
87
17
|
extensions: []
|
88
18
|
extra_rdoc_files: []
|
89
19
|
files:
|
20
|
+
- ".coveralls.yml"
|
90
21
|
- ".gitignore"
|
22
|
+
- ".travis.yml"
|
91
23
|
- Gemfile
|
92
24
|
- Guardfile
|
93
25
|
- LICENSE.txt
|
@@ -96,13 +28,15 @@ files:
|
|
96
28
|
- configureasy.gemspec
|
97
29
|
- lib/configureasy.rb
|
98
30
|
- lib/configureasy/config.rb
|
31
|
+
- lib/configureasy/config_parser.rb
|
99
32
|
- lib/configureasy/configurable.rb
|
100
33
|
- lib/configureasy/version.rb
|
34
|
+
- spec/lib/configureasy/config_parser_spec.rb
|
101
35
|
- spec/lib/configureasy/config_spec.rb
|
102
36
|
- spec/lib/configureasy/configurable_spec.rb
|
103
37
|
- spec/lib/configureasy_spec.rb
|
104
38
|
- spec/spec_helper.rb
|
105
|
-
homepage: https://
|
39
|
+
homepage: https://github.com/alexandreprates/configureasy
|
106
40
|
licenses:
|
107
41
|
- MIT
|
108
42
|
metadata: {}
|
@@ -125,8 +59,9 @@ rubyforge_project:
|
|
125
59
|
rubygems_version: 2.4.5
|
126
60
|
signing_key:
|
127
61
|
specification_version: 4
|
128
|
-
summary: A Simple way to get configs
|
62
|
+
summary: A Simple way to get configs.
|
129
63
|
test_files:
|
64
|
+
- spec/lib/configureasy/config_parser_spec.rb
|
130
65
|
- spec/lib/configureasy/config_spec.rb
|
131
66
|
- spec/lib/configureasy/configurable_spec.rb
|
132
67
|
- spec/lib/configureasy_spec.rb
|