config_reader 2.0.2 → 2.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d62b191e4d30a81325a11a994d3d663eb2f528bc02307731baae267f2fa08948
4
- data.tar.gz: ad668aaecbf1670c81f11d277caa7567630d241b0ee6f94cef5d76c2121001b0
3
+ metadata.gz: 78fbec26257c57d41e0e8969f2ec3ffb6ae73736134d6f3d885a4f44af401041
4
+ data.tar.gz: 5b224c74ab1a851277239b562d45b9411b94f5c40b56208303e0b62b73897448
5
5
  SHA512:
6
- metadata.gz: 06e2530d3e104ecc1251283aa2e85b9d0a26b4f42eaf8478c8ec34d6d85e2c9a65ba1f0c3da7dec5b75e276591f7dde37fd19ee1aae0a9c8e866fe0852066c71
7
- data.tar.gz: 63cbd8684f90f35a78c42b91ddb6f88872704b8c5468d5f0d485672c601d73105b2fb11c9083458112030101d5a854cda1f4d2d43723f785ca6d119bd7051560
6
+ metadata.gz: ebd13bac5a7341da8fa7cc8f367aa4bbbaf66a705e9c54f18ab76f5cfa85c93448bb99883372033d98b63f8bc7da6b0d92cb70d60bd5b2dbf17302de62cb4855
7
+ data.tar.gz: 36e99fa9848a53c5d10f640801f60ddb865ac4ab1aa6b84bd239a7abf8dd04e144e2334740d906ea0b056694654e1d2c668206352685eb6d7ee0845810fd255e
data/.deepsource.toml ADDED
@@ -0,0 +1,4 @@
1
+ version = 1
2
+
3
+ [[analyzers]]
4
+ name = "ruby"
@@ -0,0 +1,31 @@
1
+ name: Specs
2
+
3
+ on:
4
+ push:
5
+ branches: [ "main" ]
6
+ pull_request:
7
+ branches: [ "main" ]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ test:
14
+
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ ruby-version: ['3.0', '3.1', '3.2']
19
+
20
+ steps:
21
+ - uses: actions/checkout@v3
22
+ - name: Set up Ruby
23
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
24
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
25
+ # uses: ruby/setup-ruby@v1
26
+ uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: ${{ matrix.ruby-version }}
29
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
30
+ - name: Run tests
31
+ run: bundle exec rspec
data/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ lts/Hydrogen
data/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "plugins": ["@prettier/plugin-ruby"],
3
+ "editor.tabSize": 2,
4
+ "editor.useTabStops": true,
5
+ "files.trimTrailingWhitespace": true
6
+ }
data/.rubocop.yml ADDED
@@ -0,0 +1,64 @@
1
+ # https://docs.rubocop.org/en/latest/cops_layout/
2
+
3
+ require: rubocop-rspec
4
+
5
+ AllCops:
6
+ Exclude:
7
+ - "app/controllers/graphql_controller.rb"
8
+ - "app/graphql/vivo_point_schema.rb"
9
+ - "bin/**/*"
10
+ - "config/**/*"
11
+ - "db/**/*"
12
+ - "lib/util.rb"
13
+ - "node_modules/**/*"
14
+ - "script/**/*"
15
+ - "spec/**/*"
16
+ TargetRubyVersion: 2.6
17
+
18
+ Rails/UnknownEnv:
19
+ Environments:
20
+ - development
21
+ - test
22
+ - staging
23
+ - uat
24
+ - production
25
+
26
+ Layout/MultilineMethodCallIndentation:
27
+ EnforcedStyle: indented
28
+
29
+ Metrics/AbcSize:
30
+ Max: 20
31
+
32
+ Metrics/BlockLength:
33
+ ExcludedMethods:
34
+ - "generate_jwt!"
35
+ - "guard"
36
+ - "included"
37
+ - "namespace"
38
+
39
+ Metrics/MethodLength:
40
+ ExcludedMethods:
41
+ - "generate_jwt!"
42
+ - "add_resource_roles_to_user"
43
+ Max: 15
44
+
45
+ Style/StringLiterals:
46
+ EnforcedStyle: double_quotes
47
+
48
+ Style/AndOr:
49
+ Enabled: false
50
+
51
+ Style/Documentation:
52
+ Enabled: false
53
+
54
+ Style/MultilineMemoization:
55
+ EnforcedStyle: braces
56
+
57
+ Style/StringLiteralsInInterpolation:
58
+ EnforcedStyle: double_quotes
59
+
60
+ Style/FrozenStringLiteralComment:
61
+ Enabled: false
62
+
63
+ Style/YodaCondition:
64
+ EnforcedStyle: require_for_equality_operators_only
data/.standard.yml ADDED
@@ -0,0 +1,23 @@
1
+ default_ignores: false
2
+ fix: true
3
+ format: progress
4
+ parallel: true
5
+
6
+ ignore:
7
+ - "db/schema.rb"
8
+ - "vendor/**/*"
9
+ - "test/**/*":
10
+ - Layout/AlignHash
11
+ - "**/*":
12
+ - Layout/ArgumentAlignment
13
+ - Layout/ArrayAlignment
14
+ - Layout/BlockAlignment
15
+ - Layout/ClosingHeredocIndentation
16
+ - Layout/FirstArgumentIndentation
17
+ - Layout/MultilineMethodCallIndentation
18
+ - Layout/MultilineOperationIndentation
19
+ - Layout/SpaceInsideHashLiteralBraces
20
+ - Lint/AssignmentInCondition
21
+ - Lint/ShadowedException
22
+ - Style/MultilineMemoization
23
+ - Style/RescueStandardError
@@ -0,0 +1,3 @@
1
+ {
2
+ "cSpell.words": ["sekrets"]
3
+ }
data/Gemfile CHANGED
@@ -1,4 +1,13 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
4
+
3
5
  # Specify your gem's dependencies in config_reader.gemspec
4
6
  gemspec
7
+
8
+ gem "sekrets", github: "UnderpantsGnome/sekrets", branch: "ruby-3-2-support"
9
+
10
+ group :development do
11
+ gem "prettier", "~> 4.0"
12
+ gem "standard", "~> 1.29"
13
+ end
data/Gemfile.lock CHANGED
@@ -1,19 +1,40 @@
1
+ GIT
2
+ remote: https://github.com/UnderpantsGnome/sekrets.git
3
+ revision: 9f939c7789e2ed03902db9534b9df5cc8030c365
4
+ branch: ruby-3-2-support
5
+ specs:
6
+ sekrets (1.13.0)
7
+ coerce (~> 0.0.3)
8
+ fattr (~> 2.2)
9
+ highline (~> 1.6)
10
+ main (~> 6.1)
11
+ map (~> 6.3)
12
+
1
13
  PATH
2
14
  remote: .
3
15
  specs:
4
- config_reader (2.0.2)
16
+ config_reader (2.0.3)
5
17
 
6
18
  GEM
7
19
  remote: http://rubygems.org/
8
20
  specs:
21
+ abbrev (0.1.2)
9
22
  arrayfields (4.9.2)
23
+ ast (2.4.2)
10
24
  chronic (0.10.2)
11
25
  coderay (1.1.3)
12
26
  coerce (0.0.8)
13
27
  chronic (>= 0.6.2)
14
28
  diff-lcs (1.5.0)
15
29
  fattr (2.4.0)
30
+ haml (6.3.0)
31
+ temple (>= 0.8.2)
32
+ thor
33
+ tilt
16
34
  highline (1.7.10)
35
+ json (2.7.2)
36
+ language_server-protocol (3.17.0.3)
37
+ lint_roller (1.1.0)
17
38
  main (6.3.0)
18
39
  arrayfields (~> 4.9, >= 4.9.2)
19
40
  chronic (~> 0.10, >= 0.10.2)
@@ -21,10 +42,25 @@ GEM
21
42
  map (~> 6.6, >= 6.6.0)
22
43
  map (6.6.0)
23
44
  method_source (1.0.0)
45
+ parallel (1.24.0)
46
+ parser (3.3.1.0)
47
+ ast (~> 2.4.1)
48
+ racc
49
+ prettier (4.0.4)
50
+ syntax_tree (>= 4.0.1)
51
+ syntax_tree-haml (>= 2.0.0)
52
+ syntax_tree-rbs (>= 0.2.0)
53
+ prettier_print (1.2.1)
24
54
  pry (0.14.2)
25
55
  coderay (~> 1.1)
26
56
  method_source (~> 1.0)
57
+ racc (1.7.3)
58
+ rainbow (3.1.1)
27
59
  rake (13.0.6)
60
+ rbs (3.4.4)
61
+ abbrev
62
+ regexp_parser (2.9.0)
63
+ rexml (3.2.6)
28
64
  rspec (3.12.0)
29
65
  rspec-core (~> 3.12.0)
30
66
  rspec-expectations (~> 3.12.0)
@@ -38,22 +74,61 @@ GEM
38
74
  diff-lcs (>= 1.2.0, < 2.0)
39
75
  rspec-support (~> 3.12.0)
40
76
  rspec-support (3.12.0)
41
- sekrets (1.13.0)
42
- coerce (~> 0.0.3)
43
- fattr (~> 2.2)
44
- highline (~> 1.6)
45
- main (~> 6.1)
46
- map (~> 6.3)
77
+ rubocop (1.62.1)
78
+ json (~> 2.3)
79
+ language_server-protocol (>= 3.17.0)
80
+ parallel (~> 1.10)
81
+ parser (>= 3.3.0.2)
82
+ rainbow (>= 2.2.2, < 4.0)
83
+ regexp_parser (>= 1.8, < 3.0)
84
+ rexml (>= 3.2.5, < 4.0)
85
+ rubocop-ast (>= 1.31.1, < 2.0)
86
+ ruby-progressbar (~> 1.7)
87
+ unicode-display_width (>= 2.4.0, < 3.0)
88
+ rubocop-ast (1.31.3)
89
+ parser (>= 3.3.1.0)
90
+ rubocop-performance (1.20.2)
91
+ rubocop (>= 1.48.1, < 2.0)
92
+ rubocop-ast (>= 1.30.0, < 2.0)
93
+ ruby-progressbar (1.13.0)
94
+ standard (1.35.1)
95
+ language_server-protocol (~> 3.17.0.2)
96
+ lint_roller (~> 1.0)
97
+ rubocop (~> 1.62.0)
98
+ standard-custom (~> 1.0.0)
99
+ standard-performance (~> 1.3)
100
+ standard-custom (1.0.2)
101
+ lint_roller (~> 1.0)
102
+ rubocop (~> 1.50)
103
+ standard-performance (1.3.1)
104
+ lint_roller (~> 1.1)
105
+ rubocop-performance (~> 1.20.2)
106
+ syntax_tree (6.2.0)
107
+ prettier_print (>= 1.2.0)
108
+ syntax_tree-haml (4.0.3)
109
+ haml (>= 5.2)
110
+ prettier_print (>= 1.2.1)
111
+ syntax_tree (>= 6.0.0)
112
+ syntax_tree-rbs (1.0.0)
113
+ prettier_print
114
+ rbs
115
+ syntax_tree (>= 2.0.1)
116
+ temple (0.10.3)
117
+ thor (1.3.1)
118
+ tilt (2.3.0)
119
+ unicode-display_width (2.5.0)
47
120
 
48
121
  PLATFORMS
49
122
  ruby
50
123
 
51
124
  DEPENDENCIES
52
125
  config_reader!
126
+ prettier (~> 4.0)
53
127
  pry
54
128
  rake
55
129
  rspec (~> 3.9)
56
- sekrets (~> 1)
130
+ sekrets!
131
+ standard (~> 1.29)
57
132
 
58
133
  BUNDLED WITH
59
134
  2.3.13
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # ConfigReader
2
+
3
+ [![Maintainability](https://codeclimate.com/github/UnderpantsGnome/config_reader-gem.png)](https://codeclimate.com/github/UnderpantsGnome/config_reader-gem)
4
+ ![Specs](https://github.com/UnderpantsGnome/config_reader-gem/actions/workflows/ruby.yml/badge.svg)
5
+ ![Ruby 3.0+](https://img.shields.io/badge/Ruby-%3E%3D%203.0-success)
6
+
7
+ Provides a way to manage environment specific configuration settings. It will
8
+ use the defaults for any environment and override any values you specify for
9
+ an environment.
10
+
11
+ Example config file:
12
+
13
+ defaults:
14
+ site_url: http://localhost:3000
15
+ host_name: example.com
16
+ mail_from: noreply@example.com
17
+ site_name: example
18
+ admin_email: admin@example.com
19
+
20
+ production:
21
+ site_url: http://example.com
22
+
23
+ ## Ruby 3.1 and 3.2
24
+
25
+ If you want to use Sekrets with these versions of Ruby you need to use this version until upstream gets updated.
26
+
27
+ ```ruby
28
+ gem "sekrets",
29
+ github: "UnderpantsGnome/sekrets",
30
+ branch: "ruby-3-2-support"
31
+ ```
32
+
33
+ ## Sekrets
34
+
35
+ Includes Sekrets integration. See <https://github.com/ahoward/sekrets> for more
36
+ information.
37
+
38
+ The format of the sekrets file is the same as the regular file.
39
+
40
+ ## Setup
41
+
42
+ class MyConfig < ConfigReader
43
+ configure do |config|
44
+ config.environment = Rails.env # (set this however you access the env in your app)
45
+ config.config_file = 'config/my_config.yml'
46
+ config.sekrets_file = 'config/my_config.yml.enc' # (default nil)
47
+ config.ignore_missing_keys = true # (default false, raises KeyError)
48
+ end
49
+ end
50
+
51
+ ## Usage
52
+
53
+ MyConfig.mail_from #=> noreply@example.com
54
+ MyConfig[:mail_from] #=> noreply@example.com
55
+ MyConfig['mail_from'] #=> noreply@example.com
56
+
57
+ ## Note on Patches/Pull Requests
58
+
59
+ * Fork the project.
60
+ * Make your feature addition or bug fix.
61
+ * Add tests for it. This is important so I don't break it in a future
62
+ version unintentionally.
63
+ * Commit, do not mess with rakefile, version, or history. (if you want to
64
+ have your own version, that is fine but bump version in a commit by itself
65
+ I can ignore when I pull)
66
+ * Send me a pull request. Bonus points for topic branches.
67
+
68
+ ## Copyright
69
+
70
+ Copyright (c) Michael Moen. See LICENSE for details.
@@ -2,15 +2,15 @@ class ConfigReader
2
2
  class MagicHash < Hash
3
3
  attr_accessor :ignore_missing_keys
4
4
 
5
- def self.convert_hash(hash, ignore_missing_keys=false)
5
+ def self.convert_hash(hash, ignore_missing_keys = false)
6
6
  magic_hash = new
7
7
  magic_hash.ignore_missing_keys = ignore_missing_keys
8
8
 
9
9
  hash.each_pair do |key, value|
10
- if value.is_a?(Hash)
11
- magic_hash[key.to_sym] = convert_hash(value, ignore_missing_keys)
10
+ magic_hash[key.to_sym] = if value.is_a?(Hash)
11
+ convert_hash(value, ignore_missing_keys)
12
12
  else
13
- magic_hash[key.to_sym] = value
13
+ value
14
14
  end
15
15
  end
16
16
 
@@ -18,22 +18,19 @@ class ConfigReader
18
18
  end
19
19
 
20
20
  def [](key)
21
- begin
22
- fetch(key.to_sym)
23
- rescue KeyError => e
24
- raise e unless ignore_missing_keys
25
- end
21
+ fetch(key.to_sym)
22
+ rescue KeyError => e
23
+ raise e unless ignore_missing_keys
26
24
  end
27
25
 
28
26
  def method_missing(key, *args, &block)
29
- begin
30
- has_key?(key) ?
31
- fetch(key) :
32
- super
33
- rescue KeyError, NoMethodError => e
34
- raise e unless ignore_missing_keys
35
- end
27
+ key?(key) ? fetch(key) : super
28
+ rescue KeyError, NoMethodError => e
29
+ raise e unless ignore_missing_keys
36
30
  end
37
31
 
32
+ def respond_to_missing?(m, *)
33
+ config.key?(m)
34
+ end
38
35
  end
39
36
  end
@@ -1,3 +1,3 @@
1
1
  class ConfigReader
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
data/lib/config_reader.rb CHANGED
@@ -1,22 +1,28 @@
1
- require 'config_reader/version'
2
- require 'config_reader/magic_hash'
3
- require 'yaml'
1
+ require "config_reader/version"
2
+ require "config_reader/magic_hash"
3
+ require "yaml"
4
4
 
5
5
  begin
6
- require 'erb'
6
+ require "erb"
7
7
  rescue LoadError
8
8
  puts "ERB not found, you won't be able to use ERB in your config"
9
9
  end
10
10
 
11
11
  class ConfigReader
12
12
  class << self
13
- attr_accessor :configuration
13
+ attr_reader :configuration
14
14
 
15
15
  def config
16
16
  @config = nil unless defined?(@config)
17
17
  @config ||= reload
18
18
  end
19
19
 
20
+ def dig(*args)
21
+ args.map!(&:to_sym) if args.respond_to?(:map!)
22
+
23
+ config.dig(*args)
24
+ end
25
+
20
26
  def reload
21
27
  merge_configs(load_config, load_sekrets)
22
28
  end
@@ -28,7 +34,7 @@ class ConfigReader
28
34
  def find_config
29
35
  return configuration.config_file if File.exist?(configuration.config_file)
30
36
 
31
- %w( . config ).each do |dir|
37
+ %w[. config].each do |dir|
32
38
  config_file = File.join(dir, configuration.config_file)
33
39
  return config_file if File.exist?(config_file)
34
40
  end
@@ -37,27 +43,32 @@ class ConfigReader
37
43
  end
38
44
 
39
45
  def method_missing(key, *args, &block)
40
- if key.to_s.end_with?('=')
41
- raise ArgumentError.new('ConfigReader is immutable')
46
+ if key.to_s.end_with?("=")
47
+ raise ArgumentError.new("ConfigReader is immutable")
42
48
  end
43
49
 
44
50
  config[key] || nil
45
51
  end
46
52
 
53
+ def respond_to_missing?(m, *)
54
+ config.key?(m)
55
+ end
56
+
47
57
  def inspect
48
58
  puts config.inspect
49
59
  end
50
60
 
51
61
  def load_config
52
- raise 'No config file set' unless find_config
62
+ raise "No config file set" unless find_config
53
63
 
54
- if defined?(ERB)
55
- conf = YAML.load(ERB.new(File.open(find_config).read).result)
56
- else
57
- conf = YAML.load(File.open(find_config).read)
58
- end
64
+ conf =
65
+ if defined?(ERB)
66
+ YAML.load(ERB.new(File.read(find_config)).result)
67
+ else
68
+ YAML.load_file(File.read(find_config))
69
+ end
59
70
 
60
- raise 'No config found' unless conf
71
+ raise "No config found" unless conf
61
72
 
62
73
  conf
63
74
  end
@@ -67,11 +78,11 @@ class ConfigReader
67
78
 
68
79
  if configuration.sekrets_file
69
80
  begin
70
- require 'sekrets'
81
+ require "sekrets"
71
82
  sekrets = ::Sekrets.settings_for(configuration.sekrets_file)
72
- raise 'No sekrets found' unless sekrets
83
+ raise "No sekrets found" unless sekrets
73
84
  rescue LoadError
74
- $stderr.puts "You specified a sekrets_file, but the sekrets gem isn't available."
85
+ warn "You specified a sekrets_file, but the sekrets gem isn't available."
75
86
  end
76
87
  end
77
88
 
@@ -81,12 +92,16 @@ class ConfigReader
81
92
  def merge_configs(conf, sekrets)
82
93
  env = configuration.environment
83
94
 
84
- _conf = conf['defaults']
85
- deep_merge!(_conf, sekrets['defaults']) if sekrets && sekrets['defaults']
86
- deep_merge!(_conf, conf[env]) if conf[env]
87
- deep_merge!(_conf, sekrets[env]) if sekrets && sekrets[env]
95
+ defaults = conf["defaults"]
96
+
97
+ if sekrets && sekrets["defaults"]
98
+ deep_merge!(defaults, sekrets["defaults"])
99
+ end
100
+
101
+ deep_merge!(defaults, conf[env]) if conf[env]
102
+ deep_merge!(defaults, sekrets[env]) if sekrets && sekrets[env]
88
103
 
89
- MagicHash.convert_hash(_conf, configuration.ignore_missing_keys)
104
+ MagicHash.convert_hash(defaults, configuration.ignore_missing_keys)
90
105
  end
91
106
 
92
107
  def configure
@@ -110,7 +125,10 @@ class ConfigReader
110
125
  end
111
126
 
112
127
  class Configuration
113
- attr_accessor :config_file, :sekrets_file, :ignore_missing_keys, :environment
128
+ attr_accessor :config_file,
129
+ :sekrets_file,
130
+ :ignore_missing_keys,
131
+ :environment
114
132
 
115
133
  def initialize
116
134
  @config_file = nil
@@ -119,5 +137,4 @@ class ConfigReader
119
137
  @environment = nil
120
138
  end
121
139
  end
122
-
123
140
  end
data/package.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "devDependencies": {
3
+ "@prettier/plugin-ruby": "^4.0.4",
4
+ "prettier": "^3.2.5"
5
+ }
6
+ }
@@ -1,96 +1,97 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe "ConfigReader" do
4
4
  describe "setting values" do
5
-
6
5
  it "should fail with []=" do
7
- expect {
8
- TestConfig[:app_name] = 'test_app'
9
- }.to raise_error(ArgumentError)
6
+ expect { TestConfig[:app_name] = "test_app" }.to raise_error(
7
+ ArgumentError
8
+ )
10
9
  end
11
10
 
12
11
  it "should fail with #key =" do
13
- expect {
14
- TestConfig.app_name = 'test_app'
15
- }.to raise_error(ArgumentError)
12
+ expect { TestConfig.app_name = "test_app" }.to raise_error(ArgumentError)
16
13
  end
17
14
  end
18
15
 
19
16
  describe "default KeyNotFound behavior" do
20
17
  it "should raise on missing key with [] accessor" do
21
- expect {
22
- TestConfig[:no_key]
23
- }.to raise_error(KeyError)
18
+ expect { TestConfig[:no_key] }.to raise_error(KeyError)
24
19
  end
25
20
 
26
21
  it "should raise on missing key with #key accessor" do
27
- expect {
28
- TestConfig.no_key
29
- }.to raise_error(KeyError)
22
+ expect { TestConfig.no_key }.to raise_error(KeyError)
30
23
  end
31
24
 
32
25
  it "should raise on missing nested key with [] accessor" do
33
- expect {
34
- TestConfig[:nested_key][:missing]
35
- }.to raise_error(KeyError)
26
+ expect { TestConfig[:nested_key][:missing] }.to raise_error(KeyError)
36
27
  end
37
28
 
38
29
  it "should raise on missing nested key with #key accessor" do
39
- expect {
40
- TestConfig.nested_key.missing
41
- }.to raise_error(NoMethodError)
30
+ expect { TestConfig.nested_key.missing }.to raise_error(NoMethodError)
31
+ end
32
+ end
33
+
34
+ describe "#dig" do
35
+ it "finds values as symbols" do
36
+ expect(TestConfig.dig(*%i[nested_key value])).to eq("test")
37
+ end
38
+
39
+ it "finds values as strings" do
40
+ expect(TestConfig.dig(*%w[nested_key value])).to eq("test")
42
41
  end
43
42
  end
44
43
 
45
44
  describe "ignoring KeyNotFound" do
46
45
  it "should not raise on missing key with [] accessor" do
47
- expect {
48
- NoKeyNoErrorConfig[:no_key]
49
- }.to_not raise_error
46
+ expect { NoKeyNoErrorConfig[:no_key] }.to_not raise_error
50
47
  end
51
48
 
52
49
  it "should not raise on missing key with #key accessor" do
53
- expect {
54
- NoKeyNoErrorConfig.no_key
55
- }.to_not raise_error
50
+ expect { NoKeyNoErrorConfig.no_key }.to_not raise_error
56
51
  end
57
52
 
58
53
  it "should not raise on missing nested key with [] accessor" do
59
- expect {
60
- NoKeyNoErrorConfig[:nested_key][:missing]
61
- }.to_not raise_error
54
+ expect { NoKeyNoErrorConfig[:nested_key][:missing] }.to_not raise_error
62
55
  end
63
56
 
64
57
  it "should not raise on missing nested key with #key accessor" do
65
- expect {
66
- NoKeyNoErrorConfig.nested_key.missing
67
- }.to_not raise_error
58
+ expect { NoKeyNoErrorConfig.nested_key.missing }.to_not raise_error
59
+ end
60
+ end
61
+
62
+ describe "method_missing" do
63
+ it "handles respond_to?" do
64
+ expect(TestConfig.respond_to?(:not_a_key)).to be_falsey
65
+ end
66
+
67
+ it "handles respond_to_missing?" do
68
+ expect(TestConfig.respond_to_missing?(:not_a_key)).to be_falsey
68
69
  end
69
70
  end
70
71
 
71
72
  describe "parsing a YAML file" do
72
73
  it "should find values with method_missing" do
73
- expect(TestConfig.app_name).to eq('test_app')
74
+ expect(TestConfig.app_name).to eq("test_app")
74
75
  end
75
76
 
76
77
  it "should find values using [] and a string" do
77
- expect(TestConfig['app_name']).to eq('test_app')
78
+ expect(TestConfig["app_name"]).to eq("test_app")
78
79
  end
79
80
 
80
81
  it "should find values using [] and a symbol" do
81
- expect(TestConfig[:app_name]).to eq('test_app')
82
+ expect(TestConfig[:app_name]).to eq("test_app")
82
83
  end
83
84
 
84
85
  it "should find nested values using method_missing" do
85
- expect(TestConfig.nested_key.value).to eq('test')
86
+ expect(TestConfig.nested_key.value).to eq("test")
86
87
  end
87
88
 
88
89
  it "should find nested values using [] and a symbol" do
89
- expect(TestConfig[:nested_key][:value]).to eq('test')
90
+ expect(TestConfig[:nested_key][:value]).to eq("test")
90
91
  end
91
92
 
92
93
  it "should find nested values using [] and a string" do
93
- expect(TestConfig['nested_key']['value']).to eq('test')
94
+ expect(TestConfig["nested_key"]["value"]).to eq("test")
94
95
  end
95
96
 
96
97
  it "should not find sekrets only nested values using method_missing" do
@@ -102,47 +103,46 @@ describe "ConfigReader" do
102
103
  end
103
104
 
104
105
  it "should not find sekrets only nested values using [] and a string" do
105
- expect { TestConfig['sekrets_only']['value'] }.to raise_error(KeyError)
106
+ expect { TestConfig["sekrets_only"]["value"] }.to raise_error(KeyError)
106
107
  end
107
-
108
108
  end
109
109
 
110
- context 'using sekrets' do
110
+ context "using sekrets" do
111
111
  describe "parsing a YAML file" do
112
112
  it "should find values with method_missing" do
113
- expect(SekretsConfig.app_name).to eq('test_app_sekret')
113
+ expect(SekretsConfig.app_name).to eq("test_app_sekret")
114
114
  end
115
115
 
116
116
  it "should find values using [] and a string" do
117
- expect(SekretsConfig['app_name']).to eq('test_app_sekret')
117
+ expect(SekretsConfig["app_name"]).to eq("test_app_sekret")
118
118
  end
119
119
 
120
120
  it "should find values using [] and a symbol" do
121
- expect(SekretsConfig[:app_name]).to eq('test_app_sekret')
121
+ expect(SekretsConfig[:app_name]).to eq("test_app_sekret")
122
122
  end
123
123
 
124
124
  it "should find nested values using method_missing" do
125
- expect(SekretsConfig.nested_key.value).to eq('test_sekret')
125
+ expect(SekretsConfig.nested_key.value).to eq("test_sekret")
126
126
  end
127
127
 
128
128
  it "should find nested values using [] and a symbol" do
129
- expect(SekretsConfig[:nested_key][:value]).to eq('test_sekret')
129
+ expect(SekretsConfig[:nested_key][:value]).to eq("test_sekret")
130
130
  end
131
131
 
132
132
  it "should find nested values using [] and a string" do
133
- expect(SekretsConfig['nested_key']['value']).to eq('test_sekret')
133
+ expect(SekretsConfig["nested_key"]["value"]).to eq("test_sekret")
134
134
  end
135
135
 
136
136
  it "should find sekrets only nested values using method_missing" do
137
- expect(SekretsConfig.nested_key.value).to eq('test_sekret')
137
+ expect(SekretsConfig.nested_key.value).to eq("test_sekret")
138
138
  end
139
139
 
140
140
  it "should find sekrets only nested values using [] and a symbol" do
141
- expect(SekretsConfig[:nested_key][:value]).to eq('test_sekret')
141
+ expect(SekretsConfig[:nested_key][:value]).to eq("test_sekret")
142
142
  end
143
143
 
144
144
  it "should find sekrets only nested values using [] and a string" do
145
- expect(SekretsConfig['nested_key']['value']).to eq('test_sekret')
145
+ expect(SekretsConfig["nested_key"]["value"]).to eq("test_sekret")
146
146
  end
147
147
 
148
148
  it "shouldn't need to have all keys duplicated in the environment section" do
@@ -1,7 +1,7 @@
1
1
  class NoKeyNoErrorConfig < ConfigReader
2
2
  configure do |config|
3
- config.environment = 'test'
4
- config.config_file = 'spec/test_config.yml'
3
+ config.environment = "test"
4
+ config.config_file = "spec/test_config.yml"
5
5
  config.ignore_missing_keys = true
6
6
  end
7
7
  end
@@ -1,7 +1,14 @@
1
1
  class SekretsConfig < ConfigReader
2
+ secret_file =
3
+ if RUBY_VERSION > "3.0"
4
+ "spec/sekrets_ruby_3_2.yml.enc"
5
+ else
6
+ "spec/sekrets_config.yml.enc"
7
+ end
8
+
2
9
  configure do |config|
3
- config.environment = 'test'
4
- config.config_file = 'spec/test_config.yml'
5
- config.sekrets_file = 'spec/sekrets_config.yml.enc'
10
+ config.environment = "test"
11
+ config.config_file = "spec/test_config.yml"
12
+ config.sekrets_file = secret_file
6
13
  end
7
14
  end
@@ -0,0 +1,9 @@
1
+ ---
2
+ defaults:
3
+ app_name: default_app_sekret
4
+ sekret_only: yup
5
+ nested_key:
6
+ value: test_sekret
7
+
8
+ test:
9
+ app_name: test_app_sekret
@@ -0,0 +1,2 @@
1
+ Ϧ3W|dvd�؂�����Q�Div�ň5p2vr3,��֛��mLC:Ϣ��F�M��Wn�c׿j+�<�%�]��hg�`4�� �ޣ�K%������)8�%Pee>�g���~
2
+ %�U\�(���+THDx�͇�2�
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
3
 
4
- require 'config_reader'
5
- require 'test_config'
6
- require 'sekrets_config'
7
- require 'no_key_no_error_config'
4
+ require "config_reader"
5
+ require "test_config"
6
+ require "sekrets_config"
7
+ require "no_key_no_error_config"
8
8
 
9
- ENV['RACK_ENV'] = 'test'
10
- ENV['SEKRETS_KEY'] = 'ruby2.4_needs_longer_keys'
9
+ ENV["RACK_ENV"] = "test"
10
+ ENV["SEKRETS_KEY"] = "ruby2.4_needs_longer_keys"
data/spec/test_config.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  class TestConfig < ConfigReader
2
2
  configure do |config|
3
- config.environment = 'test'
4
- config.config_file = 'spec/test_config.yml'
3
+ config.environment = "test"
4
+ config.config_file = "spec/test_config.yml"
5
5
  end
6
6
  end
data/yarn.lock ADDED
@@ -0,0 +1,13 @@
1
+ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ # yarn lockfile v1
3
+
4
+
5
+ "@prettier/plugin-ruby@^4.0.4":
6
+ version "4.0.4"
7
+ resolved "https://registry.yarnpkg.com/@prettier/plugin-ruby/-/plugin-ruby-4.0.4.tgz#73d85fc2a1731a3f62b57ac3116cf1c234027cb6"
8
+ integrity sha512-lCpvfS/dQU5WrwN3AQ5vR8qrvj2h5gE41X08NNzAAXvHdM4zwwGRcP2sHSxfu6n6No+ljWCVx95NvJPFTTjCTg==
9
+
10
+ prettier@^3.2.5:
11
+ version "3.2.5"
12
+ resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.2.5.tgz#e52bc3090586e824964a8813b09aba6233b28368"
13
+ integrity sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Moen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-11 00:00:00.000000000 Z
11
+ date: 2024-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -73,26 +73,37 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".deepsource.toml"
77
+ - ".github/workflows/ruby.yml"
76
78
  - ".gitignore"
79
+ - ".nvmrc"
80
+ - ".prettierrc"
81
+ - ".rubocop.yml"
82
+ - ".standard.yml"
77
83
  - ".travis.yml"
84
+ - ".vscode/settings.json"
78
85
  - CHANGELOG.md
79
86
  - Gemfile
80
87
  - Gemfile.lock
81
88
  - License.txt
82
- - README.rdoc
89
+ - README.md
83
90
  - Rakefile
84
91
  - checksums/config_reader-2.0.2.gem.sha512
85
92
  - config_reader.gemspec
86
93
  - lib/config_reader.rb
87
94
  - lib/config_reader/magic_hash.rb
88
95
  - lib/config_reader/version.rb
96
+ - package.json
89
97
  - spec/config_reader_spec.rb
90
98
  - spec/no_key_no_error_config.rb
91
99
  - spec/sekrets_config.rb
92
100
  - spec/sekrets_config.yml.enc
101
+ - spec/sekrets_ruby_3_2.yml
102
+ - spec/sekrets_ruby_3_2.yml.enc
93
103
  - spec/spec_helper.rb
94
104
  - spec/test_config.rb
95
105
  - spec/test_config.yml
106
+ - yarn.lock
96
107
  homepage: https://github.com/UnderpantsGnome/config_reader-gem
97
108
  licenses: []
98
109
  metadata: {}
@@ -112,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
123
  - !ruby/object:Gem::Version
113
124
  version: '0'
114
125
  requirements: []
115
- rubygems_version: 3.2.33
126
+ rubygems_version: 3.3.26
116
127
  signing_key:
117
128
  specification_version: 4
118
129
  summary: Provides a way to manage environment specific configuration settings.
@@ -121,6 +132,8 @@ test_files:
121
132
  - spec/no_key_no_error_config.rb
122
133
  - spec/sekrets_config.rb
123
134
  - spec/sekrets_config.yml.enc
135
+ - spec/sekrets_ruby_3_2.yml
136
+ - spec/sekrets_ruby_3_2.yml.enc
124
137
  - spec/spec_helper.rb
125
138
  - spec/test_config.rb
126
139
  - spec/test_config.yml
data/README.rdoc DELETED
@@ -1,59 +0,0 @@
1
- = ConfigReader
2
-
3
- {<img src="https://codeclimate.com/github/UnderpantsGnome/config_reader-gem.png" />}[https://codeclimate.com/github/UnderpantsGnome/config_reader-gem] {<img src="https://travis-ci.org/UnderpantsGnome/config_reader-gem.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/UnderpantsGnome/config_reader-gem]
4
-
5
- Provides a way to manage environment specific configuration settings. It will use the defaults for any environment and override any values you specify for an environment.
6
-
7
- Example config file:
8
-
9
- defaults:
10
- site_url: http://localhost:3000
11
- host_name: example.com
12
- mail_from: noreply@example.com
13
- site_name: example
14
- admin_email: admin@example.com
15
- blackbird: true
16
-
17
- production:
18
- site_url: http://example.com
19
- blackbird: false
20
-
21
- test:
22
- blackbird: false
23
-
24
- == Sekrets
25
-
26
- Includes Sekrets integration. See https://github.com/ahoward/sekrets for more information.
27
-
28
- The format of the sekrets file is the same as the regular file.
29
-
30
- == Setup
31
-
32
- class MyConfig < ConfigReader
33
- configure do |config|
34
- config.environment = Rails.env # (set this however you access the env in your app)
35
- config.config_file = 'config/my_config.yml'
36
- config.sekrets_file = 'config/my_config.yml.enc' # (default nil)
37
- config.ignore_missing_keys = true # (default false, raises KeyError)
38
- end
39
- end
40
-
41
- == Usage
42
-
43
- MyConfig.mail_from #=> noreply@example.com
44
- MyConfig[:mail_from] #=> noreply@example.com
45
- MyConfig['mail_from'] #=> noreply@example.com
46
-
47
- == Note on Patches/Pull Requests
48
-
49
- * Fork the project.
50
- * Make your feature addition or bug fix.
51
- * Add tests for it. This is important so I don't break it in a
52
- future version unintentionally.
53
- * Commit, do not mess with rakefile, version, or history.
54
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
55
- * Send me a pull request. Bonus points for topic branches.
56
-
57
- == Copyright
58
-
59
- Copyright (c) 2008-2018 Michael Moen. See LICENSE for details.