quandl-config 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/lib/quandl/config.rb +14 -3
- data/lib/quandl/project_root.rb +34 -0
- data/spec/fixtures/{dummy_app.rb → dummy_rails_app/application.rb} +0 -0
- data/spec/fixtures/{config → dummy_rails_app/config}/fake.yml +0 -0
- data/spec/fixtures/{dummy_app → dummy_rails_app}/fake.rb +0 -0
- data/spec/spec_helper.rb +1 -1
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3c242cb6777c5f912d2158e0d84f9cdee14523e
|
4
|
+
data.tar.gz: 9219e301bd41527772c10d3c95b8c92707724997
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8cb23bffe218861a9c9fff371fb117d7ab7fd3865c0957e2e4b7ac49160aec4c63f1cea72d5b2cf0c781e87a1a8b6a849735f69c6beb0f819326a0b1b4af566
|
7
|
+
data.tar.gz: 7325ce38a989e6e7bd98fdee4b8a4dc12b55c65234fdbf0db2c8f3568a9a59a96b65bab15d6db050eb59b952589cb794118c0819514556f286f837a20fddfd0f
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ class: A::B::C
|
|
24
24
|
file name: config/a/b/c.yml
|
25
25
|
```
|
26
26
|
|
27
|
-
2. Extend the Quandl::Configurable class. This adds a configuration class method.
|
27
|
+
2. Extend the `Quandl::Configurable` class. This adds a configuration class method.
|
28
28
|
```ruby
|
29
29
|
class A::B::C
|
30
30
|
extend Quandl::Configurable
|
@@ -56,6 +56,12 @@ class A::B::C
|
|
56
56
|
end
|
57
57
|
```
|
58
58
|
|
59
|
+
### What if my project is not a Rails app?
|
60
|
+
|
61
|
+
That's ok. `Quandl::Config` will find your config file if it's in a `config` folder in the root of your app.
|
62
|
+
|
63
|
+
If you want to provide the environment, use `ENV['RAILS_ENV']` or `ENV['RAKE_ENV']`. If you don't, the `default` environment will be assumed.
|
64
|
+
|
59
65
|
## Contributing
|
60
66
|
|
61
67
|
1. Fork it ( https://github.com/[my-github-username]/quandl-config/fork )
|
data/lib/quandl/config.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
require 'yaml'
|
3
|
+
require 'quandl/project_root'
|
3
4
|
|
4
5
|
module Quandl
|
5
6
|
class Config < ::OpenStruct
|
6
|
-
VERSION = '0.0.
|
7
|
+
VERSION = '0.0.2'
|
7
8
|
|
8
9
|
def initialize(file_name)
|
9
|
-
raw_config = File.read(
|
10
|
+
raw_config = File.read(project_root.join('config', "#{file_name}.yml"))
|
10
11
|
erb_config = ERB.new(raw_config).result
|
11
|
-
config = YAML.load(erb_config)[
|
12
|
+
config = YAML.load(erb_config)[project_environment]
|
12
13
|
|
13
14
|
super(config)
|
14
15
|
end
|
@@ -18,6 +19,16 @@ module Quandl
|
|
18
19
|
getters = setters_and_getters.reject { |method| method =~ /=$/ }
|
19
20
|
getters
|
20
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def project_root
|
26
|
+
defined?(Rails) ? ::Rails.root : Pathname.new(ProjectRoot.root)
|
27
|
+
end
|
28
|
+
|
29
|
+
def project_environment
|
30
|
+
defined?(Rails) ? ::Rails.env : (ENV['RAILS_ENV'] || ENV('RAKE_ENV') || 'default')
|
31
|
+
end
|
21
32
|
end
|
22
33
|
end
|
23
34
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Quandl
|
2
|
+
module ProjectRoot
|
3
|
+
# Borrowed from https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/ruby_project.rb
|
4
|
+
|
5
|
+
def self.root
|
6
|
+
@project_root ||= determine_root
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.determine_root
|
10
|
+
find_first_parent_containing('lib') || '.'
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.find_first_parent_containing(dir)
|
14
|
+
ascend_until { |path| File.exist?(File.join(path, dir)) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.ascend_until
|
18
|
+
fs = File::SEPARATOR
|
19
|
+
escaped_slash = "\\#{fs}"
|
20
|
+
special = "_ESCAPED_SLASH_"
|
21
|
+
project_path = File.expand_path(".")
|
22
|
+
parts = project_path.gsub(escaped_slash, special).squeeze(fs).split(fs).map do |x|
|
23
|
+
x.gsub(special, escaped_slash)
|
24
|
+
end
|
25
|
+
|
26
|
+
until parts.empty?
|
27
|
+
path = parts.join(fs)
|
28
|
+
path = fs if path == ""
|
29
|
+
return path if yield(path)
|
30
|
+
parts.pop
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Najwa Azer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -166,10 +166,11 @@ files:
|
|
166
166
|
- Rakefile
|
167
167
|
- lib/quandl/config.rb
|
168
168
|
- lib/quandl/configurable.rb
|
169
|
+
- lib/quandl/project_root.rb
|
169
170
|
- quandl-config.gemspec
|
170
|
-
- spec/fixtures/
|
171
|
-
- spec/fixtures/
|
172
|
-
- spec/fixtures/
|
171
|
+
- spec/fixtures/dummy_rails_app/application.rb
|
172
|
+
- spec/fixtures/dummy_rails_app/config/fake.yml
|
173
|
+
- spec/fixtures/dummy_rails_app/fake.rb
|
173
174
|
- spec/quandl/quandl-config_spec.rb
|
174
175
|
- spec/quandl/quandl-configurable_spec.rb
|
175
176
|
- spec/spec_helper.rb
|
@@ -198,9 +199,9 @@ signing_key:
|
|
198
199
|
specification_version: 4
|
199
200
|
summary: Openstruct-based per-class configuration.
|
200
201
|
test_files:
|
201
|
-
- spec/fixtures/
|
202
|
-
- spec/fixtures/
|
203
|
-
- spec/fixtures/
|
202
|
+
- spec/fixtures/dummy_rails_app/application.rb
|
203
|
+
- spec/fixtures/dummy_rails_app/config/fake.yml
|
204
|
+
- spec/fixtures/dummy_rails_app/fake.rb
|
204
205
|
- spec/quandl/quandl-config_spec.rb
|
205
206
|
- spec/quandl/quandl-configurable_spec.rb
|
206
207
|
- spec/spec_helper.rb
|