global 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d82e24b3a7c94f65e370d1b16142e028d3acf1ce3fe8064e9e9fcb9e4683d46e
4
- data.tar.gz: 809e1b6ac4e2f0ada443202b1d80ec7d663488515f682079cd07bc02335983c4
3
+ metadata.gz: 0da470ddbf97c73984898898bbada287d1fef733da1059016dbe7021a6b4e55a
4
+ data.tar.gz: b5cf15fb7e5a9e4e9cb7b30a0bf1265a374693d6f1423b95940976c9beeca3f0
5
5
  SHA512:
6
- metadata.gz: b290b4951da9d199d64ec8a27bdf630be5691ec1af0829d31e01872c1260893e2a3626fcc55a70f9ac816192279fbf04a4a2823dd770127808bd63b62ad8016d
7
- data.tar.gz: afa4586a51919a0d483dbcd01e5fd027cd6a79aebaea070c544c53f4838ccbbece9312536d40ed475adf1cc207ef7864937639baa60de7bab1918de3a081944a
6
+ metadata.gz: cbd030fd6ced5e6e3f0d47d75d14f59e16a69411814b1432f0bf66fb03444950006a87b86eed155f758c4a5535eb6e8d9d870edbecdc26c9a66b2a9230384e82
7
+ data.tar.gz: b99c7b6c92c33324834ad7fd92c75606a9abddbe7d8fe0fbe22b344013000a49073ece171b8063713b370d2c6526c6c0eee928584c90317e5592034506bc3790
@@ -0,0 +1,24 @@
1
+ name: Runs linter and tests
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ linters_and_tests:
7
+ runs-on: ${{ matrix.os }}-latest
8
+ continue-on-error: ${{ matrix.experimental == true }}
9
+ name: Linter and tests on ${{ matrix.os }}-ruby-${{ matrix.ruby-version }}
10
+ strategy:
11
+ matrix:
12
+ os: [ubuntu, macos]
13
+ ruby-version: ['3.1', '3.0', '2.7', '2.6', '2.5']
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby-version }}
21
+ bundler-cache: true
22
+
23
+ - name: Runs linter and tests
24
+ run: bundle exec rake
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Global [![Build Status](https://travis-ci.org/railsware/global.png)](https://travis-ci.org/railsware/global) [![Code Climate](https://codeclimate.com/github/railsware/global.png)](https://codeclimate.com/github/railsware/global)
1
+ # Global [![Runs linter and tests](https://github.com/railsware/global/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/railsware/global/actions/workflows/tests.yml) [![Code Climate](https://codeclimate.com/github/railsware/global.png)](https://codeclimate.com/github/railsware/global)
2
2
 
3
3
  The 'global' gem provides accessor methods for your configuration data and share configuration across backend and frontend.
4
4
 
@@ -19,14 +19,14 @@ Refer to the documentation on your chosen backend class for other dependencies.
19
19
  Refer to the documentation on your chosen backend class for configuration options.
20
20
 
21
21
  ```ruby
22
- > Global.backend(:filesystem, environment: "YOUR_ENV_HERE", directory: "PATH_TO_DIRECTORY_WITH_FILES")
22
+ > Global.backend(:filesystem, environment: "YOUR_ENV_HERE", path: "PATH_TO_DIRECTORY_WITH_FILES")
23
23
  ```
24
24
 
25
25
  Or you can use `configure` block:
26
26
 
27
27
  ```ruby
28
28
  Global.configure do |config|
29
- config.backend :filesystem, environment: "YOUR_ENV_HERE", directory: "PATH_TO_DIRECTORY_WITH_FILES"
29
+ config.backend :filesystem, environment: "YOUR_ENV_HERE", path: "PATH_TO_DIRECTORY_WITH_FILES"
30
30
  # set up multiple backends and have them merged together:
31
31
  config.backend :aws_parameter_store, prefix: '/prod/MyApp/'
32
32
  config.backend :gcp_secret_manager, prefix: 'prod-myapp-', project_id: 'example'
@@ -252,6 +252,12 @@ Some steps you will need to follow:
252
252
  - If you will use encrypted parameters: create a KMS key and allow the role to decrypt using the key.
253
253
  - Create parameters in Parameter Store. Use encryption for sensitive data like private keys and API credentials.
254
254
 
255
+ #### Usage with Go
256
+
257
+ You can reuse the same configuration in your Go services. For this, we developed a Go module that loads the same configuration tree into Go structs.
258
+
259
+ See [github.com/railsware/go-global](https://github.com/railsware/go-global) for further instructions.
260
+
255
261
  #### Configuration examples
256
262
 
257
263
  Backend setup:
@@ -5,12 +5,12 @@ module Global
5
5
  # Loads Global configuration from the filesystem
6
6
  #
7
7
  # Available options:
8
- # - `directory` (required): the directory with config files
8
+ # - `path` (required): the directory with config files
9
9
  # - `environment` (required): the environment to load
10
10
  # - `yaml_whitelist_classes`: the set of classes that are permitted to unmarshal from the configuration files
11
11
  #
12
12
  # For Rails:
13
- # - the `directory` is optional and defaults to `config/global`
13
+ # - the `path` is optional and defaults to `config/global`
14
14
  # - the `environment` is optional and defaults to the current Rails environment
15
15
  class Filesystem
16
16
 
@@ -60,11 +60,14 @@ module Global
60
60
  end
61
61
 
62
62
  def load_yml_file(file)
63
- YAML.safe_load(
64
- ERB.new(IO.read(file)).result,
65
- [Date, Time, DateTime, Symbol].concat(@yaml_whitelist_classes),
66
- [], true
67
- )
63
+ file_contents = ERB.new(IO.read(file)).result
64
+ permitted_classes = [Date, Time, DateTime, Symbol].concat(@yaml_whitelist_classes)
65
+
66
+ if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('4')
67
+ YAML.safe_load(file_contents, permitted_classes: permitted_classes, aliases: true)
68
+ else
69
+ YAML.safe_load(file_contents, permitted_classes, [], true)
70
+ end
68
71
  end
69
72
 
70
73
  def load_from_directory(path)
data/lib/global/base.rb CHANGED
@@ -34,7 +34,7 @@ module Global
34
34
  # and the configuration hashes will be merged.
35
35
  #
36
36
  # Configure with either:
37
- # Global.backend :filesystem, directory: 'config', environment: Rails.env
37
+ # Global.backend :filesystem, path: 'config', environment: Rails.env
38
38
  # or:
39
39
  # Global.backend YourConfigurationBackend.new
40
40
  #
@@ -45,7 +45,7 @@ module Global
45
45
 
46
46
  def respond_to_missing?(method_name, include_private = false)
47
47
  method = normalize_key_by_method(method_name)
48
- key?(method) || super
48
+ key?(method) || boolean_method?(method) || super
49
49
  end
50
50
 
51
51
  def method_missing(method, *args, &block)
@@ -57,8 +57,12 @@ module Global
57
57
  end
58
58
  end
59
59
 
60
+ def boolean_method?(method)
61
+ '?' == method.to_s[-1]
62
+ end
63
+
60
64
  def normalize_key_by_method(method)
61
- '?' == method.to_s[-1] ? method.to_s[0..-2] : method
65
+ boolean_method?(method) ? method.to_s[0..-2].to_sym : method
62
66
  end
63
67
 
64
68
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Global
4
4
 
5
- VERSION = '2.0.0'
5
+ VERSION = '2.1.0'
6
6
 
7
7
  end
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Global::Configuration do
6
- let(:hash) { { 'key' => 'value', 'nested' => { 'key' => 'value' }} }
6
+ let(:hash) { { 'key' => 'value', 'boolean_key' => true, 'nested' => { 'key' => 'value' }} }
7
7
  let(:configuration) { described_class.new hash }
8
8
 
9
9
  describe '#hash' do
@@ -68,7 +68,7 @@ RSpec.describe Global::Configuration do
68
68
  context 'when include all' do
69
69
  let(:filter_options) { { only: :all } }
70
70
 
71
- it { should == { 'key' => 'value', 'nested' => { 'key' => 'value' }} }
71
+ it { should == { 'key' => 'value', 'boolean_key' => true, 'nested' => { 'key' => 'value' }} }
72
72
  end
73
73
 
74
74
  context 'when except all' do
@@ -80,7 +80,7 @@ RSpec.describe Global::Configuration do
80
80
  context 'when except present' do
81
81
  let(:filter_options) { { except: %w[key] } }
82
82
 
83
- it { should == { 'nested' => { 'key' => 'value' }} }
83
+ it { should == { 'boolean_key' => true, 'nested' => { 'key' => 'value' }} }
84
84
  end
85
85
 
86
86
  context 'when include present' do
@@ -97,18 +97,30 @@ RSpec.describe Global::Configuration do
97
97
  end
98
98
 
99
99
  describe '#method_missing' do
100
- context 'when key exist' do
100
+ context 'when key exists' do
101
101
  subject { configuration.key }
102
102
 
103
103
  it { is_expected.to eq('value') }
104
104
  end
105
105
 
106
+ context 'when boolean key exists' do
107
+ subject { configuration.boolean_key? }
108
+
109
+ it { is_expected.to eq(true) }
110
+ end
111
+
106
112
  context 'when key does not exist' do
107
113
  subject { configuration.some_key }
108
114
 
109
115
  it { expect { subject }.to raise_error(NoMethodError) }
110
116
  end
111
117
 
118
+ context 'when boolean key does not exist' do
119
+ subject { configuration.some_boolean_key? }
120
+
121
+ it { expect { subject }.to raise_error(NoMethodError) }
122
+ end
123
+
112
124
  context 'with nested hash' do
113
125
  subject { configuration.nested.key }
114
126
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Railsware LLC
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-16 00:00:00.000000000 Z
11
+ date: 2022-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-ssm
@@ -115,11 +115,11 @@ executables:
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".github/workflows/tests.yml"
118
119
  - ".gitignore"
119
120
  - ".rspec"
120
121
  - ".rubocop.yml"
121
122
  - ".ruby-version"
122
- - ".travis.yml"
123
123
  - CODE_OF_CONDUCT.md
124
124
  - Gemfile
125
125
  - LICENSE.txt
@@ -150,7 +150,7 @@ homepage: https://github.com/railsware/global
150
150
  licenses:
151
151
  - MIT
152
152
  metadata: {}
153
- post_install_message:
153
+ post_install_message:
154
154
  rdoc_options: []
155
155
  require_paths:
156
156
  - lib
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  version: '0'
167
167
  requirements: []
168
168
  rubygems_version: 3.0.3
169
- signing_key:
169
+ signing_key:
170
170
  specification_version: 4
171
171
  summary: Simple way to load your configs from yaml/aws/gcp
172
172
  test_files:
data/.travis.yml DELETED
@@ -1,22 +0,0 @@
1
- language: ruby
2
- os: linux
3
- dist: bionic
4
-
5
- cache:
6
- bundler: true
7
-
8
- rvm:
9
- - 2.4
10
- - 2.5
11
- - 2.6
12
- - 2.7
13
- - ruby-head
14
- - jruby-head
15
-
16
- notifications:
17
- email: false
18
-
19
- matrix:
20
- allow_failures:
21
- - rvm: ruby-head
22
- - rvm: jruby-head