quandl-config 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/quandl/config.rb +1 -49
- data/lib/quandl/config/config.rb +48 -0
- data/lib/quandl/config/configurable.rb +3 -1
- data/lib/quandl/config/version.rb +1 -1
- data/spec/quandl/quandl-config_spec.rb +12 -4
- data/spec/spec_helper.rb +1 -0
- metadata +7 -90
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2da0e09d1f79ff22ae924363dd6217c0d1acc022
|
4
|
+
data.tar.gz: f0a48598abc63ff78a302876f9ce78026b55293f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07f8ef1cd37e9f57a3271e048f437a2b89b96d48cdaeefdd4fff7fbddcd6ffc8f69ebec67b1e554c2102a9250fcd57ac50acf869039c8bf9c7561a231b8635b4
|
7
|
+
data.tar.gz: ad5d13efd7344d4a662feb064850d3631257d1d33c889659eec1ef4a931cb6b293a4a54f089001fa2d0919eb7f52073073c84b553095cf150efd782596e4e6d9
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Quandl::Config
|
1
|
+
# Quandl::Config [![Build Status](https://travis-ci.org/quandl/quandl-config.svg?branch=master)](https://travis-ci.org/quandl/quandl-config)
|
2
2
|
|
3
3
|
This gem allows you to quickly convert YML files into a `Config` object where the attributes can be accessed using dot, hash symbol or hash string notation.
|
4
4
|
|
data/lib/quandl/config.rb
CHANGED
@@ -1,51 +1,3 @@
|
|
1
|
-
|
2
|
-
require 'yaml'
|
3
|
-
require 'active_support/inflector'
|
4
|
-
require 'pathname'
|
5
|
-
|
1
|
+
require_relative 'config/config'
|
6
2
|
require_relative 'config/project_root'
|
7
3
|
require_relative 'config/configurable'
|
8
|
-
|
9
|
-
module Quandl
|
10
|
-
class Config < ::OpenStruct
|
11
|
-
# Optimize loading of configs multiple times by keeping a hash of already loaded configs.
|
12
|
-
def self.new(filename, options = {})
|
13
|
-
@_registered_configs ||= {}
|
14
|
-
return @_registered_configs[filename] if @_registered_configs.key?(filename)
|
15
|
-
@_registered_configs[filename] = super
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.clear_internal_cache
|
19
|
-
@_registered_configs = {}
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize(file_name, options = {})
|
23
|
-
@_root = options.delete(:root_path)
|
24
|
-
@_environment = options.delete(:environment)
|
25
|
-
|
26
|
-
super(read_config(file_name))
|
27
|
-
end
|
28
|
-
|
29
|
-
def configurable_attributes
|
30
|
-
setters_and_getters = methods - self.class.instance_methods
|
31
|
-
getters = setters_and_getters.reject { |method| method =~ /=$/ }
|
32
|
-
getters
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def read_config(file_name)
|
38
|
-
raw_config = File.read(Pathname.new(project_root).join('config', "#{file_name}.yml"))
|
39
|
-
erb_config = ERB.new(raw_config).result
|
40
|
-
YAML.load(erb_config)[project_environment]
|
41
|
-
end
|
42
|
-
|
43
|
-
def project_root
|
44
|
-
@_root ||= defined?(Rails) ? ::Rails.root : ProjectRoot.root
|
45
|
-
end
|
46
|
-
|
47
|
-
def project_environment
|
48
|
-
@_environment ||= defined?(Rails) ? ::Rails.env : (ENV['RAILS_ENV'] || ENV['RAKE_ENV'] || ENV['QUANDL_ENV'] || 'default')
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'yaml'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module Quandl
|
6
|
+
class Config < ::OpenStruct
|
7
|
+
# Optimize loading of configs multiple times by keeping a hash of already loaded configs.
|
8
|
+
def self.new(filename, options = {})
|
9
|
+
@_registered_configs ||= {}
|
10
|
+
return @_registered_configs[filename] if @_registered_configs.key?(filename)
|
11
|
+
@_registered_configs[filename] = super
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.clear_internal_cache
|
15
|
+
@_registered_configs = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(file_name, options = {})
|
19
|
+
@_root = options.delete(:root_path)
|
20
|
+
@_environment = options.delete(:environment)
|
21
|
+
|
22
|
+
super(read_config(file_name))
|
23
|
+
end
|
24
|
+
|
25
|
+
def configurable_attributes
|
26
|
+
setters_and_getters = methods - self.class.instance_methods
|
27
|
+
setters_and_getters += self.table.keys
|
28
|
+
getters = setters_and_getters.reject { |method| method =~ /=$/ }
|
29
|
+
getters.uniq
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def read_config(file_name)
|
35
|
+
raw_config = File.read(Pathname.new(project_root).join('config', "#{file_name}.yml"))
|
36
|
+
erb_config = ERB.new(raw_config).result
|
37
|
+
YAML.load(erb_config)[project_environment]
|
38
|
+
end
|
39
|
+
|
40
|
+
def project_root
|
41
|
+
@_root ||= defined?(Rails) ? ::Rails.root : ProjectRoot.root
|
42
|
+
end
|
43
|
+
|
44
|
+
def project_environment
|
45
|
+
@_environment ||= defined?(Rails) ? ::Rails.env : (ENV['RAILS_ENV'] || ENV['RAKE_ENV'] || ENV['QUANDL_ENV'] || 'default')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,19 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Quandl::Config do
|
4
|
+
subject(:configuration) { Quandl::Config.new('fake') }
|
5
|
+
|
4
6
|
describe '.initialize' do
|
5
7
|
it 'generates a Config class, evaluating ERB' do
|
6
|
-
configuration
|
8
|
+
expect(configuration['notifiers']['ci']['channel']).to eq('#development')
|
9
|
+
end
|
10
|
+
end
|
7
11
|
|
12
|
+
describe 'accessing values' do
|
13
|
+
it 'can access values as methods' do
|
8
14
|
expect(configuration['notifiers']['ci']['channel']).to eq('#development')
|
9
15
|
end
|
16
|
+
|
17
|
+
it 'can access values as hash table' do
|
18
|
+
expect(configuration.notifiers['ci']['channel']).to eq('#development')
|
19
|
+
end
|
10
20
|
end
|
11
21
|
|
12
22
|
describe '#configurable_attributes' do
|
13
23
|
it 'provides a list of configurable attributes' do
|
14
|
-
configuration
|
15
|
-
|
16
|
-
expect(configuration.configurable_attributes).to eq([:webhook_url, :notifiers])
|
24
|
+
expect(configuration.configurable_attributes).to match_array([:webhook_url, :notifiers])
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Matthew Basset
|
7
8
|
- Najwa Azer
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2017-03-24 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: activesupport
|
@@ -26,62 +27,6 @@ dependencies:
|
|
26
27
|
version: '0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.6'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.6'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
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
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec-nc
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: guard
|
85
30
|
requirement: !ruby/object:Gem::Requirement
|
86
31
|
requirements:
|
87
32
|
- - ">="
|
@@ -95,35 +40,7 @@ dependencies:
|
|
95
40
|
- !ruby/object:Gem::Version
|
96
41
|
version: '0'
|
97
42
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: pry
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: pry-remote
|
43
|
+
name: rake
|
127
44
|
requirement: !ruby/object:Gem::Requirement
|
128
45
|
requirements:
|
129
46
|
- - ">="
|
@@ -137,7 +54,7 @@ dependencies:
|
|
137
54
|
- !ruby/object:Gem::Version
|
138
55
|
version: '0'
|
139
56
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
57
|
+
name: rspec
|
141
58
|
requirement: !ruby/object:Gem::Requirement
|
142
59
|
requirements:
|
143
60
|
- - ">="
|
@@ -160,6 +77,7 @@ files:
|
|
160
77
|
- LICENSE.txt
|
161
78
|
- README.md
|
162
79
|
- lib/quandl/config.rb
|
80
|
+
- lib/quandl/config/config.rb
|
163
81
|
- lib/quandl/config/configurable.rb
|
164
82
|
- lib/quandl/config/project_root.rb
|
165
83
|
- lib/quandl/config/version.rb
|
@@ -189,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
107
|
version: '0'
|
190
108
|
requirements: []
|
191
109
|
rubyforge_project:
|
192
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.6.10
|
193
111
|
signing_key:
|
194
112
|
specification_version: 4
|
195
113
|
summary: OpenStruct-based per-class configuration.
|
@@ -200,4 +118,3 @@ test_files:
|
|
200
118
|
- spec/quandl/quandl-config_spec.rb
|
201
119
|
- spec/quandl/quandl-configurable_spec.rb
|
202
120
|
- spec/spec_helper.rb
|
203
|
-
has_rdoc:
|