configureasy 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +15 -9
- data/README.md +1 -1
- data/lib/configureasy/configurable.rb +28 -7
- data/lib/configureasy/version.rb +1 -1
- data/spec/lib/configureasy/configurable_spec.rb +29 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc4e5cfa5599e0fd74ec1d47cc08ca74c5d51e96
|
4
|
+
data.tar.gz: 2fd4941231c93651f46af41a3512c92c68c30ac5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 285b80e511bd271d2295c1b208dc6c9da15e0365646b1250823d6e39d879bcda71da6f293d297d1fda973dad20927bfe00a5e93d21c0681c573b72406250a970
|
7
|
+
data.tar.gz: 61ff91a551470e6bb675c41549b37e1220a94e6d159cea4fc3e52bdf0953281283a20013de17f625e9da83c57fe947d4428f6ff03942c75ecfb699d6c90ba5ef
|
data/Gemfile
CHANGED
@@ -4,15 +4,21 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
group :development do
|
7
|
-
gem 'terminal-notifier'
|
8
|
-
gem 'terminal-notifier-guard'
|
9
|
-
gem 'pry'
|
10
|
-
gem 'pry-nav'
|
7
|
+
gem 'terminal-notifier', '1.6.2'
|
8
|
+
gem 'terminal-notifier-guard', '1.6.4'
|
9
|
+
gem 'pry', '0.10.1'
|
10
|
+
gem 'pry-nav', '0.2.4'
|
11
11
|
end
|
12
12
|
|
13
13
|
group :test do
|
14
|
-
gem 'rake'
|
15
|
-
gem 'rspec'
|
16
|
-
|
17
|
-
gem '
|
18
|
-
|
14
|
+
gem 'rake', '10.4.2'
|
15
|
+
gem 'rspec', '3.2.0'
|
16
|
+
|
17
|
+
gem 'tins', '1.3.5' # coveralls dependency
|
18
|
+
gem 'term-ansicolor', '1.3.0' # coveralls dependency
|
19
|
+
gem 'rb-fsevent', '0.9.4' # guard-rspec dependency
|
20
|
+
gem 'rb-inotify', '0.9.5' # guard-rspec dependency
|
21
|
+
|
22
|
+
gem 'guard-rspec', '4.5.0'
|
23
|
+
gem 'coveralls', '0.7.11', require: false
|
24
|
+
end
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Configureasy
|
2
2
|
=============
|
3
3
|
|
4
|
-
[![Build Status](https://travis-ci.org/alexandreprates/configureasy.svg?branch=master)](https://travis-ci.org/alexandreprates/configureasy) [![Coverage Status](https://coveralls.io/repos/alexandreprates/configureasy/badge.svg)](https://coveralls.io/r/alexandreprates/configureasy) [![Inline docs](http://inch-ci.org/github/alexandreprates/configureasy.svg?branch=master)](http://inch-ci.org/github/alexandreprates/configureasy)
|
4
|
+
[![Build Status](https://travis-ci.org/alexandreprates/configureasy.svg?branch=master)](https://travis-ci.org/alexandreprates/configureasy) [![Coverage Status](https://coveralls.io/repos/alexandreprates/configureasy/badge.svg)](https://coveralls.io/r/alexandreprates/configureasy) [![Inline docs](http://inch-ci.org/github/alexandreprates/configureasy.svg?branch=master)](http://inch-ci.org/github/alexandreprates/configureasy) [![Code Climate](https://codeclimate.com/github/alexandreprates/configureasy/badges/gpa.svg)](https://codeclimate.com/github/alexandreprates/configureasy)
|
5
5
|
|
6
6
|
Configureasy is a library for load configs quickly and easily.
|
7
7
|
|
@@ -26,8 +26,7 @@ module Configureasy::Configurable
|
|
26
26
|
name = options[:as] || file_basename
|
27
27
|
path = options[:path] || './config'
|
28
28
|
filename = File.join path, "#{file_basename}.yml"
|
29
|
-
|
30
|
-
self.class.send(:define_method, "#{name}_reload!") { _configurable_reload(filename) }
|
29
|
+
_configurable_init(name, filename)
|
31
30
|
end
|
32
31
|
|
33
32
|
# @deprecated Please use {#load_config} instead.
|
@@ -40,7 +39,7 @@ module Configureasy::Configurable
|
|
40
39
|
#
|
41
40
|
# # load contents for ./config/bar.yml
|
42
41
|
# config_name :bar
|
43
|
-
|
42
|
+
def config_name(name = nil)
|
44
43
|
warn "[DEPRECATION] `config_name` is deprecated. Please use `load_config` instead."
|
45
44
|
load_config name, as: 'config'
|
46
45
|
end
|
@@ -61,12 +60,34 @@ module Configureasy::Configurable
|
|
61
60
|
|
62
61
|
private
|
63
62
|
|
64
|
-
def
|
65
|
-
@@configurables[
|
63
|
+
def _configurable_init(method_name, filename)
|
64
|
+
@@configurables[_configurable_key(method_name)] = { filename: filename,
|
65
|
+
payload: nil }
|
66
|
+
return if self.class.respond_to? method_name
|
67
|
+
self.class.send(:define_method, method_name) do
|
68
|
+
_configurable_for(method_name)
|
69
|
+
end
|
70
|
+
self.class.send(:define_method, "#{method_name}_reload!") do
|
71
|
+
_configurable_reload(method_name)
|
72
|
+
end
|
66
73
|
end
|
67
74
|
|
68
|
-
def
|
69
|
-
|
75
|
+
def _configurable_key(method_name)
|
76
|
+
"#{self}.#{method_name}"
|
70
77
|
end
|
71
78
|
|
79
|
+
def _configurable_hash(method_name)
|
80
|
+
@@configurables[_configurable_key(method_name)]
|
81
|
+
end
|
82
|
+
|
83
|
+
def _configurable_for(method_name) # :nodoc:
|
84
|
+
_configurable_hash(method_name)[:payload] ||
|
85
|
+
_configurable_reload(method_name)
|
86
|
+
end
|
87
|
+
|
88
|
+
def _configurable_reload(method_name) # :nodoc:
|
89
|
+
filename = _configurable_hash(method_name)[:filename]
|
90
|
+
config = Configureasy::ConfigParser.new(filename).as_config
|
91
|
+
_configurable_hash(method_name)[:payload] = config
|
92
|
+
end
|
72
93
|
end
|
data/lib/configureasy/version.rb
CHANGED
@@ -1,9 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Configureasy::Configurable do
|
4
6
|
before(:each) do
|
5
7
|
allow(File).to receive(:exist?) { true }
|
6
|
-
allow(YAML).to receive(:load_file) { {'works' => 'true'} }
|
8
|
+
allow(YAML).to receive(:load_file) { { 'works' => 'true' } }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when I have two modules with same config name' do
|
12
|
+
before do
|
13
|
+
module Foo
|
14
|
+
include Configureasy
|
15
|
+
load_config :foo, as: :config
|
16
|
+
end
|
17
|
+
module Bar
|
18
|
+
include Configureasy
|
19
|
+
load_config :bar, as: :config
|
20
|
+
end
|
21
|
+
expect(YAML).to receive(:load_file).with('./config/foo.yml') do
|
22
|
+
{ 'name' => 'andré' }
|
23
|
+
end
|
24
|
+
expect(YAML).to receive(:load_file).with('./config/bar.yml') do
|
25
|
+
{ 'name' => 'rodrigo' }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'has different outputs' do
|
30
|
+
expect(Foo.config).not_to eq(Bar.config)
|
31
|
+
end
|
7
32
|
end
|
8
33
|
|
9
34
|
describe '.load_config' do
|
@@ -49,7 +74,7 @@ describe Configureasy::Configurable do
|
|
49
74
|
end
|
50
75
|
end
|
51
76
|
|
52
|
-
it
|
77
|
+
it 'load config content into config method' do
|
53
78
|
expect(dumb_class).to respond_to :config
|
54
79
|
expect(dumb_class.config.works).to eq('true')
|
55
80
|
end
|
@@ -63,10 +88,9 @@ describe Configureasy::Configurable do
|
|
63
88
|
end
|
64
89
|
end
|
65
90
|
|
66
|
-
it
|
91
|
+
it 'load config with filename into config method' do
|
67
92
|
expect(dumb_class).to respond_to :config
|
68
93
|
expect(dumb_class.config.works).to eq('true')
|
69
94
|
end
|
70
95
|
end
|
71
|
-
|
72
|
-
end
|
96
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configureasy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Prates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Simple way to get configs.
|
14
14
|
email:
|
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
58
|
rubyforge_project:
|
59
|
-
rubygems_version: 2.
|
59
|
+
rubygems_version: 2.6.11
|
60
60
|
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: A Simple way to get configs.
|