api-config 0.4.8 → 0.5.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/README.md +3 -13
- data/lib/api-config/version.rb +5 -0
- data/lib/api-config.rb +33 -38
- data/lib/api_config.rb +3 -1
- metadata +10 -54
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/ruby.yml +0 -41
- data/.gitignore +0 -14
- data/.rspec +0 -2
- data/Gemfile +0 -9
- data/Rakefile +0 -15
- data/api-config.gemspec +0 -25
- data/config/api.yml +0 -12
- data/spec/api_config_spec.rb +0 -97
- data/spec/config/api.yml +0 -12
- data/spec/config/foo.yml +0 -5
- data/spec/deep_strucure_spec.rb +0 -36
- data/spec/spec_helper.rb +0 -93
- /data/{LICENSE.txt → LICENSE} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 45c4501fac89421b7cbb3052abe9a93c4886d2dbccf8fd1021750ed2eaecb2b9
|
|
4
|
+
data.tar.gz: 8422c09fef720146c518e24ae7194a6698f7ea9bc2c5f4c583c61e549ebf4c84
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e3c89ab970f1e276522d2177f72b26cc380e56fc284d7ef6448143ca8355fc36ca8e66db74bc5792dded91186c59136961e756dffb1f0812d3a3b06b50fc80d9
|
|
7
|
+
data.tar.gz: c1333cad42d553fa9e9bad25524b5db5624751d1161f6259854cbac2fdbf3e812526f64fb243bfb7ba2a1878a8580b217eb635751a9c13e821d69086099fab2c
|
data/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
[](https://github.com/ifad/api-config/actions)
|
|
3
|
+
[](https://github.com/ifad/api-config/actions/workflows/rubocop.yml)
|
|
3
4
|
|
|
4
5
|
# Api::Config
|
|
5
6
|
|
|
@@ -24,19 +25,8 @@ Or install it yourself as:
|
|
|
24
25
|
## Usage
|
|
25
26
|
|
|
26
27
|
```Ruby
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Ruby 3.0.x
|
|
32
|
-
|
|
33
|
-
An issue with the `ostruct` version shipped with Ruby 3.0.x does not allow
|
|
34
|
-
`Api::Config` to work properly.
|
|
35
|
-
|
|
36
|
-
If you are using Ruby 3.0.x, please add to your Gemfile
|
|
37
|
-
|
|
38
|
-
```rb
|
|
39
|
-
gem 'ostruct', '> 0.3.1'
|
|
28
|
+
ApiConfig.foo
|
|
29
|
+
ApiConfig.bar.goo
|
|
40
30
|
```
|
|
41
31
|
|
|
42
32
|
## Contributing
|
data/lib/api-config.rb
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'erb'
|
|
2
4
|
require 'ostruct'
|
|
3
5
|
require 'yaml'
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
VERSION = '0.4.8'
|
|
7
|
+
require_relative 'api-config/version'
|
|
8
8
|
|
|
9
|
+
module APIConfig
|
|
9
10
|
class << self
|
|
10
11
|
def env
|
|
11
12
|
environment || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
|
@@ -47,38 +48,33 @@ module APIConfig
|
|
|
47
48
|
end
|
|
48
49
|
|
|
49
50
|
protected
|
|
50
|
-
def environment
|
|
51
|
-
@@env ||= nil
|
|
52
|
-
end
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
def environment
|
|
53
|
+
@@env ||= nil
|
|
54
|
+
end
|
|
57
55
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
def configuration
|
|
57
|
+
@configuration ||= {}
|
|
58
|
+
end
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
configuration[which] = parse(source)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
60
|
+
def files
|
|
61
|
+
@files ||= { default: 'config/api.yml' }
|
|
62
|
+
end
|
|
68
63
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
YAML.safe_load(erb_result, aliases: true).fetch(APIConfig.env)
|
|
74
|
-
else
|
|
75
|
-
YAML.load(erb_result).fetch(APIConfig.env)
|
|
76
|
-
end
|
|
77
|
-
DeepStruct.new(config, source)
|
|
78
|
-
|
|
79
|
-
rescue => e
|
|
80
|
-
raise Error, "#{source}: #{e.message}"
|
|
64
|
+
def configuration_for(which)
|
|
65
|
+
configuration.fetch(which) do
|
|
66
|
+
source = files.fetch(which)
|
|
67
|
+
configuration[which] = parse(source)
|
|
81
68
|
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def parse(source)
|
|
72
|
+
erb_result = ERB.new(File.read(source)).result
|
|
73
|
+
config = YAML.safe_load(erb_result, aliases: true).fetch(APIConfig.env)
|
|
74
|
+
DeepStruct.new(config, source)
|
|
75
|
+
rescue StandardError => e
|
|
76
|
+
raise Error, "#{source}: #{e.message}"
|
|
77
|
+
end
|
|
82
78
|
end
|
|
83
79
|
|
|
84
80
|
class Error < StandardError
|
|
@@ -92,18 +88,18 @@ module APIConfig
|
|
|
92
88
|
@parent = parent
|
|
93
89
|
@branch = branch
|
|
94
90
|
|
|
95
|
-
(hash || []).each do |k,v|
|
|
91
|
+
(hash || []).each do |k, v|
|
|
96
92
|
@table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v, file, self, k) : v)
|
|
97
93
|
@hash_table[k.to_sym] = v
|
|
98
94
|
end
|
|
99
95
|
end
|
|
100
96
|
|
|
101
|
-
def each(&
|
|
102
|
-
@table.each(&
|
|
97
|
+
def each(&)
|
|
98
|
+
@table.each(&)
|
|
103
99
|
end
|
|
104
100
|
|
|
105
|
-
def map(&
|
|
106
|
-
@table.map(&
|
|
101
|
+
def map(&)
|
|
102
|
+
@table.map(&)
|
|
107
103
|
end
|
|
108
104
|
|
|
109
105
|
def to_h
|
|
@@ -114,15 +110,14 @@ module APIConfig
|
|
|
114
110
|
[(@parent ? @parent.path_for(@branch) : APIConfig.env), key].compact.join('.')
|
|
115
111
|
end
|
|
116
112
|
|
|
117
|
-
def method_missing(meth, *args, &
|
|
113
|
+
def method_missing(meth, *args, &)
|
|
118
114
|
if meth.to_s =~ /\A(.+)!\Z/
|
|
119
|
-
setting =
|
|
115
|
+
setting = ::Regexp.last_match(1).intern
|
|
120
116
|
|
|
121
117
|
@table.fetch(setting) { raise Error, "API Setting `#{path_for(setting)}' not found in #{@file}" }
|
|
122
118
|
else
|
|
123
119
|
super
|
|
124
120
|
end
|
|
125
121
|
end
|
|
126
|
-
|
|
127
122
|
end
|
|
128
123
|
end
|
data/lib/api_config.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: api-config
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lleir Borras Metje
|
|
@@ -11,7 +11,7 @@ cert_chain: []
|
|
|
11
11
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: ostruct
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
@@ -24,34 +24,6 @@ dependencies:
|
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: rake
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :runtime
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '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: '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
27
|
description: A nice way to configure api url's and configuratios for a ruby app.
|
|
56
28
|
email:
|
|
57
29
|
- l.borrasmetje@ifad.org
|
|
@@ -60,27 +32,16 @@ executables: []
|
|
|
60
32
|
extensions: []
|
|
61
33
|
extra_rdoc_files: []
|
|
62
34
|
files:
|
|
63
|
-
-
|
|
64
|
-
- ".github/workflows/ruby.yml"
|
|
65
|
-
- ".gitignore"
|
|
66
|
-
- ".rspec"
|
|
67
|
-
- Gemfile
|
|
68
|
-
- LICENSE.txt
|
|
35
|
+
- LICENSE
|
|
69
36
|
- README.md
|
|
70
|
-
- Rakefile
|
|
71
|
-
- api-config.gemspec
|
|
72
|
-
- config/api.yml
|
|
73
37
|
- lib/api-config.rb
|
|
38
|
+
- lib/api-config/version.rb
|
|
74
39
|
- lib/api_config.rb
|
|
75
|
-
|
|
76
|
-
- spec/config/api.yml
|
|
77
|
-
- spec/config/foo.yml
|
|
78
|
-
- spec/deep_strucure_spec.rb
|
|
79
|
-
- spec/spec_helper.rb
|
|
80
|
-
homepage: http://code.ifad.org/api-config
|
|
40
|
+
homepage: https://github.com/ifad/api-config
|
|
81
41
|
licenses:
|
|
82
42
|
- MIT
|
|
83
|
-
metadata:
|
|
43
|
+
metadata:
|
|
44
|
+
rubygems_mfa_required: 'true'
|
|
84
45
|
rdoc_options: []
|
|
85
46
|
require_paths:
|
|
86
47
|
- lib
|
|
@@ -88,19 +49,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
88
49
|
requirements:
|
|
89
50
|
- - ">="
|
|
90
51
|
- !ruby/object:Gem::Version
|
|
91
|
-
version: '
|
|
52
|
+
version: '3.1'
|
|
92
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
54
|
requirements:
|
|
94
55
|
- - ">="
|
|
95
56
|
- !ruby/object:Gem::Version
|
|
96
57
|
version: '0'
|
|
97
58
|
requirements: []
|
|
98
|
-
rubygems_version:
|
|
59
|
+
rubygems_version: 4.0.3
|
|
99
60
|
specification_version: 4
|
|
100
61
|
summary: A nice way to configure api url's and configuratios for a ruby app.
|
|
101
|
-
test_files:
|
|
102
|
-
- spec/api_config_spec.rb
|
|
103
|
-
- spec/config/api.yml
|
|
104
|
-
- spec/config/foo.yml
|
|
105
|
-
- spec/deep_strucure_spec.rb
|
|
106
|
-
- spec/spec_helper.rb
|
|
62
|
+
test_files: []
|
data/.github/dependabot.yml
DELETED
data/.github/workflows/ruby.yml
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
name: Ruby specs
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [ master ]
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [ master ]
|
|
8
|
-
|
|
9
|
-
permissions:
|
|
10
|
-
contents: read
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
test:
|
|
14
|
-
name: Specs
|
|
15
|
-
runs-on: ${{ matrix.os }}
|
|
16
|
-
strategy:
|
|
17
|
-
matrix:
|
|
18
|
-
ruby-version: ['2.0', '2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4']
|
|
19
|
-
channel: ['stable']
|
|
20
|
-
os: ['ubuntu-latest']
|
|
21
|
-
|
|
22
|
-
include:
|
|
23
|
-
- ruby-version: 'head'
|
|
24
|
-
channel: 'experimental'
|
|
25
|
-
os: 'ubuntu-latest'
|
|
26
|
-
|
|
27
|
-
- ruby-version: '1.9.3'
|
|
28
|
-
channel: 'stable'
|
|
29
|
-
os: 'ubuntu-22.04'
|
|
30
|
-
|
|
31
|
-
continue-on-error: ${{ matrix.channel != 'stable' }}
|
|
32
|
-
|
|
33
|
-
steps:
|
|
34
|
-
- uses: actions/checkout@v6
|
|
35
|
-
- name: Set up Ruby
|
|
36
|
-
uses: ruby/setup-ruby@v1
|
|
37
|
-
with:
|
|
38
|
-
ruby-version: ${{ matrix.ruby-version }}
|
|
39
|
-
bundler-cache: true
|
|
40
|
-
- name: Run specs
|
|
41
|
-
run: bundle exec rake
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require "bundler"
|
|
2
|
-
Bundler::GemHelper.install_tasks
|
|
3
|
-
|
|
4
|
-
# RSpec
|
|
5
|
-
require 'rspec/core'
|
|
6
|
-
require 'rspec/core/rake_task'
|
|
7
|
-
|
|
8
|
-
task :default => :rspec
|
|
9
|
-
RSpec::Core::RakeTask.new(:rspec)
|
|
10
|
-
|
|
11
|
-
# YARD
|
|
12
|
-
# require 'yard'
|
|
13
|
-
# require 'yard/rake/yardoc_task'
|
|
14
|
-
# YARD::Rake::YardocTask.new
|
|
15
|
-
|
data/api-config.gemspec
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
|
|
5
|
-
require 'api-config'
|
|
6
|
-
|
|
7
|
-
Gem::Specification.new do |spec|
|
|
8
|
-
spec.name = 'api-config'
|
|
9
|
-
spec.version = APIConfig::VERSION
|
|
10
|
-
spec.authors = ['Lleir Borras Metje', 'Marcello Barnaba']
|
|
11
|
-
spec.email = ['l.borrasmetje@ifad.org', 'm.barnaba@ifad.org']
|
|
12
|
-
spec.summary = %q{A nice way to configure api url's and configuratios for a ruby app.}
|
|
13
|
-
spec.description = %q{A nice way to configure api url's and configuratios for a ruby app.}
|
|
14
|
-
spec.homepage = 'http://code.ifad.org/api-config'
|
|
15
|
-
spec.license = 'MIT'
|
|
16
|
-
|
|
17
|
-
spec.files = `git ls-files -z`.split("\x0")
|
|
18
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
20
|
-
spec.require_paths = ['lib']
|
|
21
|
-
|
|
22
|
-
spec.add_dependency 'bundler'
|
|
23
|
-
spec.add_dependency 'rake'
|
|
24
|
-
spec.add_development_dependency 'rspec'
|
|
25
|
-
end
|
data/config/api.yml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
development: &development
|
|
2
|
-
mycalls: 'http://mine.ifad.org/mycalls/'
|
|
3
|
-
quasar: 'http://mine.ifad.org/quasar/'
|
|
4
|
-
people_soft: 'http://mine.ifad.org/ps/'
|
|
5
|
-
people: 'http://people.staging.ifad.org/'
|
|
6
|
-
ciao:
|
|
7
|
-
url: 'http://ciao.staging.ifad.org/'
|
|
8
|
-
token: 'c028418c171d339d644b2097f493044443495e6676bb721110cf2f64f9193af1'
|
|
9
|
-
|
|
10
|
-
test: *development
|
|
11
|
-
production: *development
|
|
12
|
-
staging: *development
|
data/spec/api_config_spec.rb
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe APIConfig do
|
|
4
|
-
before do
|
|
5
|
-
described_class.set_file(:default, 'spec/config/api.yml')
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
describe '.env' do
|
|
9
|
-
it 'uses RAILS_ENV' do
|
|
10
|
-
expect(ENV).to receive(:[]).with('RAILS_ENV').and_return('foo')
|
|
11
|
-
|
|
12
|
-
expect(described_class.env).to eq('foo')
|
|
13
|
-
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it 'uses RACK_ENV' do
|
|
17
|
-
expect(ENV).to receive(:[]).with('RAILS_ENV').and_return(nil)
|
|
18
|
-
expect(ENV).to receive(:[]).with('RACK_ENV').and_return('bars')
|
|
19
|
-
|
|
20
|
-
expect(described_class.env).to eq('bars')
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'defaults to development' do
|
|
24
|
-
expect(ENV).to receive(:[]).with('RAILS_ENV').and_return(nil)
|
|
25
|
-
expect(ENV).to receive(:[]).with('RACK_ENV').and_return(nil)
|
|
26
|
-
|
|
27
|
-
expect(described_class.env).to eq('development')
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe '.env=' do
|
|
32
|
-
before do
|
|
33
|
-
described_class.env = 'foobarbaz'
|
|
34
|
-
@old_rails_env = ENV['RAILS_ENV']
|
|
35
|
-
@old_rack_env = ENV['RACK_ENV']
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
after do
|
|
39
|
-
described_class.env = nil
|
|
40
|
-
ENV['RAILS_ENV'] = @old_rails_env
|
|
41
|
-
ENV['RACK_ENV'] = @old_rack_env
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'uses defined environment value' do
|
|
45
|
-
expect(described_class.env).to eq('foobarbaz')
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'uses defined environment value even if RAILS_ENV is set' do
|
|
49
|
-
ENV['RAILS_ENV'] = 'foo'
|
|
50
|
-
|
|
51
|
-
expect(described_class.env).to eq('foobarbaz')
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
it 'uses defined environment value even if RACK_ENV is set' do
|
|
56
|
-
ENV['RAILS_ENV'] = nil
|
|
57
|
-
ENV['RACK_ENV'] = 'bar'
|
|
58
|
-
|
|
59
|
-
expect(described_class.env).to eq('foobarbaz')
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
describe '.method_missing' do
|
|
64
|
-
it 'works' do
|
|
65
|
-
expect(described_class.foo).to eq('foo')
|
|
66
|
-
expect(described_class.bar).to eq('bar')
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it 'gets the correct root key' do
|
|
70
|
-
expect(described_class).to receive(:env).and_return('foobarbaz')
|
|
71
|
-
described_class.reload!
|
|
72
|
-
|
|
73
|
-
expect(described_class.foo).to eq('bar')
|
|
74
|
-
expect(described_class.bar).to eq(APIConfig::DeepStruct.new(baz: 'barbaz'))
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
describe '.reload!' do
|
|
79
|
-
it 'works' do
|
|
80
|
-
foo = described_class.foo
|
|
81
|
-
|
|
82
|
-
described_class.set_file :default, 'spec/config/foo.yml'
|
|
83
|
-
|
|
84
|
-
expect(foo).not_to eq(described_class.foo)
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
describe '.set_file' do
|
|
89
|
-
it 'works' do
|
|
90
|
-
file = described_class.get_file(:default)
|
|
91
|
-
|
|
92
|
-
described_class.set_file :default, 'spec/config/foo.yml'
|
|
93
|
-
|
|
94
|
-
expect(file).not_to eq(described_class.get_file(:default))
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
data/spec/config/api.yml
DELETED
data/spec/config/foo.yml
DELETED
data/spec/deep_strucure_spec.rb
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe APIConfig::DeepStruct do
|
|
4
|
-
let!(:hash) { { a: :a, b: { c: { d: :e }}} }
|
|
5
|
-
|
|
6
|
-
subject { APIConfig::DeepStruct.new(hash, 'src') }
|
|
7
|
-
|
|
8
|
-
describe '#to_h' do
|
|
9
|
-
it 'works' do
|
|
10
|
-
expect(subject.to_h).to eq(hash)
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe '#path_for' do
|
|
15
|
-
it 'works' do
|
|
16
|
-
expect(subject.path_for(:a)).to eq("#{APIConfig.env}.a")
|
|
17
|
-
expect(subject.b.c.path_for(:d)).to eq("#{APIConfig.env}.b.c.d")
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe '#method_missing' do
|
|
22
|
-
it 'works' do
|
|
23
|
-
expect(subject.a).to eq(:a)
|
|
24
|
-
expect(subject.b.c.d).to eq(:e)
|
|
25
|
-
expect(subject.b.c).to eq(described_class.new(d: :e))
|
|
26
|
-
expect(subject.c).to eq(nil)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it 'works with !' do
|
|
30
|
-
expect(subject.a!).to eq(:a)
|
|
31
|
-
expect(subject.b!.c!.d!).to eq(:e)
|
|
32
|
-
expect(subject.b!.c!).to eq(described_class.new(d: :e))
|
|
33
|
-
expect{subject.c!}.to raise_error("API Setting `test.c' not found in src")
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
ENV["RACK_ENV"] = 'test'
|
|
2
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
3
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
4
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
|
5
|
-
# file to always be loaded, without a need to explicitly require it in any 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 it.
|
|
13
|
-
#
|
|
14
|
-
# The `.rspec` file also contains a few flags that are not defaults but that
|
|
15
|
-
# users commonly want.
|
|
16
|
-
#
|
|
17
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
18
|
-
require 'bundler/setup'
|
|
19
|
-
Bundler.setup
|
|
20
|
-
|
|
21
|
-
require 'api-config'
|
|
22
|
-
|
|
23
|
-
RSpec.configure do |config|
|
|
24
|
-
config.expose_dsl_globally = true
|
|
25
|
-
|
|
26
|
-
# rspec-expectations config goes here. You can use an alternate
|
|
27
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
28
|
-
# assertions if you prefer.
|
|
29
|
-
config.expect_with :rspec do |expectations|
|
|
30
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
31
|
-
# and `failure_message` of custom matchers include text for helper methods
|
|
32
|
-
# defined using `chain`, e.g.:
|
|
33
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
|
34
|
-
# # => "be bigger than 2 and smaller than 4"
|
|
35
|
-
# ...rather than:
|
|
36
|
-
# # => "be bigger than 2"
|
|
37
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
|
41
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
42
|
-
config.mock_with :rspec do |mocks|
|
|
43
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
|
44
|
-
# a real object. This is generally recommended, and will default to
|
|
45
|
-
# `true` in RSpec 4.
|
|
46
|
-
mocks.verify_partial_doubles = true
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# These two settings work together to allow you to limit a spec run
|
|
50
|
-
# to individual examples or groups you care about by tagging them with
|
|
51
|
-
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
|
52
|
-
# get run.
|
|
53
|
-
config.filter_run :focus
|
|
54
|
-
config.run_all_when_everything_filtered = true
|
|
55
|
-
|
|
56
|
-
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
|
57
|
-
# For more details, see:
|
|
58
|
-
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
|
59
|
-
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
|
60
|
-
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
|
61
|
-
config.disable_monkey_patching!
|
|
62
|
-
|
|
63
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
|
64
|
-
# be too noisy due to issues in dependencies.
|
|
65
|
-
config.warnings = true
|
|
66
|
-
|
|
67
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
|
68
|
-
# file, and it's useful to allow more verbose output when running an
|
|
69
|
-
# individual spec file.
|
|
70
|
-
if config.files_to_run.one?
|
|
71
|
-
# Use the documentation formatter for detailed output,
|
|
72
|
-
# unless a formatter has already been configured
|
|
73
|
-
# (e.g. via a command-line flag).
|
|
74
|
-
config.default_formatter = 'doc'
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# Print the 10 slowest examples and example groups at the
|
|
78
|
-
# end of the spec run, to help surface which specs are running
|
|
79
|
-
# particularly slow.
|
|
80
|
-
config.profile_examples = 10
|
|
81
|
-
|
|
82
|
-
# Run specs in random order to surface order dependencies. If you find an
|
|
83
|
-
# order dependency and want to debug it, you can fix the order by providing
|
|
84
|
-
# the seed, which is printed after each run.
|
|
85
|
-
# --seed 1234
|
|
86
|
-
config.order = :random
|
|
87
|
-
|
|
88
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
|
89
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
|
90
|
-
# test failures related to randomization by passing the same `--seed` value
|
|
91
|
-
# as the one that triggered the failure.
|
|
92
|
-
Kernel.srand config.seed
|
|
93
|
-
end
|
/data/{LICENSE.txt → LICENSE}
RENAMED
|
File without changes
|