persey 0.0.10 → 0.0.11
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/.travis.yml +2 -1
- data/Dockerfile +1 -1
- data/Gemfile +3 -4
- data/README.md +2 -2
- data/Rakefile +0 -9
- data/docker-compose.yml +1 -1
- data/lib/persey.rb +10 -10
- data/lib/persey/adapters/yaml.rb +9 -2
- data/lib/persey/inspector.rb +6 -2
- data/lib/persey/version.rb +1 -1
- data/persey.gemspec +5 -3
- data/spec/fixtures/broken_yaml_config.yml +5 -0
- data/{test → spec}/fixtures/ini_config.ini +0 -0
- data/{test → spec}/fixtures/json_config.json +0 -0
- data/{test → spec}/fixtures/toml_config.toml +0 -0
- data/{test → spec}/fixtures/yaml_config.yml +0 -0
- data/{test → spec}/fixtures/yaml_config_with_envs.yml +0 -0
- data/spec/lib/persey_spec.rb +75 -0
- data/spec/spec_helper.rb +29 -0
- metadata +32 -16
- data/test/lib/persey_test.rb +0 -47
- data/test/test_helper.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b2133ecea516e37fec41f835ff20f23e1f9a071
|
4
|
+
data.tar.gz: dffc911ff91650efc41f037de58551e941b9d69c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b3d757c399a4d9d81d587b1623126400bed5d2094f8af44542cc4e9155bce0a043a03450fa1de9ec26fe142bc93fbe90c9e28b1926a931dba318c80c86a79e3
|
7
|
+
data.tar.gz: c490136c10bdcc155db2f66cf90028bed006e47245219dcf7ff3dcd51686d4a7543e8734331d0d41218987011350a20bafe56ee39a6f51265c1af023df8a3f46
|
data/.travis.yml
CHANGED
data/Dockerfile
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Persey [](https://travis-ci.org/zzet/persey) [](http://badge.fury.io/rb/persey) [](https://gemnasium.com/zzet/persey) [](https://codeclimate.com/github/zzet/persey) [](https://img.shields.io/gem/dt/persey.svg)
|
2
2
|
|
3
3
|
|
4
4
|
## Summary
|
@@ -25,7 +25,7 @@ This solution allows to **accumulate** different configs in one, with the **poss
|
|
25
25
|
Add this to your `Gemfile`:
|
26
26
|
|
27
27
|
``` ruby
|
28
|
-
gem "persey", '>= 0.0.
|
28
|
+
gem "persey", '>= 0.0.11'
|
29
29
|
```
|
30
30
|
|
31
31
|
Generate default config file
|
data/Rakefile
CHANGED
data/docker-compose.yml
CHANGED
data/lib/persey.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
1
|
+
require 'persey/version'
|
2
|
+
require 'persey/builder'
|
3
|
+
require 'persey/inspector'
|
4
|
+
require 'persey/loader'
|
5
|
+
require 'persey/adapters/base'
|
6
|
+
require 'persey/adapters/yaml'
|
7
|
+
require 'persey/adapters/json'
|
8
|
+
require 'persey/adapters/toml'
|
9
|
+
require 'persey/adapters/ini'
|
10
|
+
require 'persey/configus_patch'
|
11
11
|
|
12
12
|
module Persey
|
13
13
|
class << self
|
data/lib/persey/adapters/yaml.rb
CHANGED
@@ -2,6 +2,8 @@ require 'yaml'
|
|
2
2
|
require 'erb'
|
3
3
|
|
4
4
|
module Persey
|
5
|
+
class MissingEnvVariable < RuntimeError; end
|
6
|
+
|
5
7
|
module Adapters
|
6
8
|
class Yaml < Persey::Adapters::Base
|
7
9
|
class << self
|
@@ -9,8 +11,13 @@ module Persey
|
|
9
11
|
begin
|
10
12
|
raw_hash = YAML.load(ERB.new(File.read(file)).result)
|
11
13
|
symbolize_keys(raw_hash)
|
12
|
-
rescue
|
13
|
-
|
14
|
+
rescue KeyError => e
|
15
|
+
_, line, method = /\(erb\):(\d+):in `(.*)'/.match(e.backtrace[0]).to_a
|
16
|
+
if method == 'fetch'
|
17
|
+
raise MissingEnvVariable.new("Check line ##{line} in #{file}")
|
18
|
+
else
|
19
|
+
raise e
|
20
|
+
end
|
14
21
|
end
|
15
22
|
end
|
16
23
|
end
|
data/lib/persey/inspector.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
2
|
|
3
3
|
module Persey
|
4
|
+
class MissingConfigFile < RuntimeError; end
|
5
|
+
|
4
6
|
class Inspector
|
5
7
|
class << self
|
6
8
|
def analize(&block)
|
@@ -10,10 +12,12 @@ module Persey
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def source(source_type, config_file, namespace = nil)
|
13
|
-
|
15
|
+
raise MissingConfigFile.new("Can't find #{source_type} config: #{config_file}") unless File.exist?(config_file)
|
14
16
|
|
15
17
|
klass = "persey/adapters/#{source_type}".camelize.constantize
|
16
|
-
@sources << { class: klass, file: config_file, namespace: namespace }
|
18
|
+
@sources << { class: klass, file: config_file, namespace: namespace }
|
19
|
+
|
20
|
+
override_config_file = config_file + '.override'
|
17
21
|
@sources << { class: klass, file: override_config_file, namespace: namespace } if File.exist?(override_config_file)
|
18
22
|
end
|
19
23
|
|
data/lib/persey/version.rb
CHANGED
data/persey.gemspec
CHANGED
@@ -18,9 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency
|
21
|
+
spec.add_runtime_dependency 'activesupport'
|
22
22
|
spec.add_runtime_dependency 'configus', '>= 0.0.5'
|
23
23
|
spec.add_runtime_dependency 'yajl-ruby'
|
24
|
-
spec.add_runtime_dependency
|
25
|
-
spec.add_runtime_dependency
|
24
|
+
spec.add_runtime_dependency 'toml', '~> 0.1.0'
|
25
|
+
spec.add_runtime_dependency 'inifile'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'simplecov'
|
26
28
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Persey do
|
4
|
+
context 'true-flow input data' do
|
5
|
+
before do
|
6
|
+
plain_config = File.join(fixtures_path, 'yaml_config.yml')
|
7
|
+
env_config = File.join(fixtures_path, 'yaml_config_with_envs.yml')
|
8
|
+
plain_json_config = File.join(fixtures_path, 'json_config.json')
|
9
|
+
plain_toml_config = File.join(fixtures_path, 'toml_config.toml')
|
10
|
+
plain_ini_config = File.join(fixtures_path, 'ini_config.ini')
|
11
|
+
|
12
|
+
Persey.init :production do
|
13
|
+
source :yaml, plain_config
|
14
|
+
source :yaml, env_config, :namespace
|
15
|
+
source :json, plain_json_config, :json_config
|
16
|
+
source :toml, plain_toml_config, :toml_config
|
17
|
+
source :ini, plain_ini_config, :ini_config
|
18
|
+
|
19
|
+
env :production do
|
20
|
+
option do
|
21
|
+
first "first value"
|
22
|
+
second "second value"
|
23
|
+
end
|
24
|
+
|
25
|
+
first do
|
26
|
+
testss -> { second }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it '#config' do
|
33
|
+
expect { Persey.config }.not_to raise_exception
|
34
|
+
end
|
35
|
+
|
36
|
+
it '#config.methods' do
|
37
|
+
@config = Persey.config
|
38
|
+
expect(@config.option.first).to eq('first value')
|
39
|
+
expect(@config.first.testss).to eq('foo value')
|
40
|
+
expect(@config.first.second).to eq('foo value')
|
41
|
+
expect(@config.namespace.another_key).to eq('another key value')
|
42
|
+
expect(@config.namespace.another_key).to eq('another key value')
|
43
|
+
expect(@config.key).to eq('key value')
|
44
|
+
expect(@config.json_config.owner.name).to eq('John Doe')
|
45
|
+
expect(@config.toml_config.owner.name).to eq('Tom Preston-Werner')
|
46
|
+
expect(@config.ini_config.section1.var1).to eq('foo')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'false-flow data' do
|
51
|
+
it 'missing config' do
|
52
|
+
missing_config = File.join(fixtures_path, 'missing_yaml_config.yml')
|
53
|
+
|
54
|
+
expect do
|
55
|
+
Persey.init :production do
|
56
|
+
source :yaml, missing_config
|
57
|
+
|
58
|
+
env :production
|
59
|
+
end
|
60
|
+
end.to raise_error(Persey::MissingConfigFile)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'missing ENV.fetch' do
|
64
|
+
broken_yaml_config = File.join(fixtures_path, 'broken_yaml_config.yml')
|
65
|
+
|
66
|
+
expect do
|
67
|
+
Persey.init :production do
|
68
|
+
source :yaml, broken_yaml_config
|
69
|
+
|
70
|
+
env :production
|
71
|
+
end
|
72
|
+
end.to raise_error(Persey::MissingEnvVariable)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter '/spec/'
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'pry'
|
9
|
+
require 'persey'
|
10
|
+
|
11
|
+
PROJECT_ROOT = File.join(Dir.pwd)
|
12
|
+
|
13
|
+
Dir[File.expand_path('..', __FILE__) + '/support/**/*.rb'].each { |f| require f }
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
def fixtures_path
|
17
|
+
@path ||= File.expand_path(File.join(__FILE__, "../fixtures"))
|
18
|
+
end
|
19
|
+
|
20
|
+
config.expect_with :rspec do |expectations|
|
21
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
22
|
+
end
|
23
|
+
|
24
|
+
config.mock_with :rspec do |mocks|
|
25
|
+
mocks.verify_partial_doubles = true
|
26
|
+
end
|
27
|
+
|
28
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: persey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Kumanyaev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Persey helps you easily load configs from different files and use them
|
84
98
|
from one variable. Based on Configus.
|
85
99
|
email:
|
@@ -110,13 +124,14 @@ files:
|
|
110
124
|
- lib/persey/loader.rb
|
111
125
|
- lib/persey/version.rb
|
112
126
|
- persey.gemspec
|
113
|
-
-
|
114
|
-
-
|
115
|
-
-
|
116
|
-
-
|
117
|
-
-
|
118
|
-
-
|
119
|
-
-
|
127
|
+
- spec/fixtures/broken_yaml_config.yml
|
128
|
+
- spec/fixtures/ini_config.ini
|
129
|
+
- spec/fixtures/json_config.json
|
130
|
+
- spec/fixtures/toml_config.toml
|
131
|
+
- spec/fixtures/yaml_config.yml
|
132
|
+
- spec/fixtures/yaml_config_with_envs.yml
|
133
|
+
- spec/lib/persey_spec.rb
|
134
|
+
- spec/spec_helper.rb
|
120
135
|
homepage: https://github.com/zzet/persey
|
121
136
|
licenses:
|
122
137
|
- MIT
|
@@ -142,10 +157,11 @@ signing_key:
|
|
142
157
|
specification_version: 4
|
143
158
|
summary: Helps you easily manage environment specific settings
|
144
159
|
test_files:
|
145
|
-
-
|
146
|
-
-
|
147
|
-
-
|
148
|
-
-
|
149
|
-
-
|
150
|
-
-
|
151
|
-
-
|
160
|
+
- spec/fixtures/broken_yaml_config.yml
|
161
|
+
- spec/fixtures/ini_config.ini
|
162
|
+
- spec/fixtures/json_config.json
|
163
|
+
- spec/fixtures/toml_config.toml
|
164
|
+
- spec/fixtures/yaml_config.yml
|
165
|
+
- spec/fixtures/yaml_config_with_envs.yml
|
166
|
+
- spec/lib/persey_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
data/test/lib/persey_test.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class PerseyTest < TestCase
|
4
|
-
def setup
|
5
|
-
plain_config = File.join(fixtures_path, 'yaml_config.yml')
|
6
|
-
env_config = File.join(fixtures_path, 'yaml_config_with_envs.yml')
|
7
|
-
plain_json_config = File.join(fixtures_path, 'json_config.json')
|
8
|
-
plain_toml_config = File.join(fixtures_path, 'toml_config.toml')
|
9
|
-
plain_ini_config = File.join(fixtures_path, 'ini_config.ini')
|
10
|
-
|
11
|
-
Persey.init :production do
|
12
|
-
source :yaml, plain_config
|
13
|
-
source :yaml, env_config, :namespace
|
14
|
-
source :json, plain_json_config, :json_config
|
15
|
-
source :toml, plain_toml_config, :toml_config
|
16
|
-
source :ini, plain_ini_config, :ini_config
|
17
|
-
|
18
|
-
env :production do
|
19
|
-
option do
|
20
|
-
first "first value"
|
21
|
-
second "second value"
|
22
|
-
end
|
23
|
-
|
24
|
-
first do
|
25
|
-
testss -> { second }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_load_config
|
32
|
-
assert { Persey.config }
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_correct_config
|
36
|
-
@config = Persey.config
|
37
|
-
assert { @config.option.first == "first value" }
|
38
|
-
assert { @config.first.testss == "foo value" }
|
39
|
-
assert { @config.first.second == "foo value" }
|
40
|
-
assert { @config.namespace.another_key == "another key value" }
|
41
|
-
assert { @config.namespace.another_key == "another key value" }
|
42
|
-
assert { @config.key == "key value" }
|
43
|
-
assert { @config.json_config.owner.name == "John Doe" }
|
44
|
-
assert { @config.toml_config.owner.name == "Tom Preston-Werner" }
|
45
|
-
assert { @config.ini_config.section1.var1 == "foo" }
|
46
|
-
end
|
47
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require 'bundler/setup'
|
3
|
-
require 'pry'
|
4
|
-
|
5
|
-
Bundler.require
|
6
|
-
|
7
|
-
require 'wrong/adapters/minitest'
|
8
|
-
|
9
|
-
PROJECT_ROOT = File.join(Dir.pwd)
|
10
|
-
|
11
|
-
Wrong.config.color
|
12
|
-
|
13
|
-
Minitest.autorun
|
14
|
-
|
15
|
-
class TestCase < Minitest::Test
|
16
|
-
include Wrong
|
17
|
-
|
18
|
-
def fixtures_path
|
19
|
-
@path ||= File.expand_path(File.join(__FILE__, "../fixtures"))
|
20
|
-
end
|
21
|
-
end
|