gonfic 0.5.0 → 0.6.2

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: cdf1477e7d76fc97fe5ee9a224079275e563e90c22d837346c0a6ba43f0a4841
4
- data.tar.gz: 8f8121dfac2bc667c067008352763f1a5a276a96d1817180d0f2c4ae6d3f1e36
3
+ metadata.gz: 7b8810655c20a36c4ae9220d82652bd740f7a9b108f62fa6c34400c39d8af4d0
4
+ data.tar.gz: 4202e4993d903c3fe560730ff88e798728617f2db71d92bc9f5de1127ca30888
5
5
  SHA512:
6
- metadata.gz: 564f42cc15d5a2a7055c8a9d58e960bdf3206b5f7b340c908c45ab1af243f02ccf8ab8444345d36901e998f83d9c7e22de418c24d099ce1ae0a4aef82ae19946
7
- data.tar.gz: 1910650dfe238d8d4e01db9dffc03e9f4edb0f7ac9385b460cee285dedc6fbcb8471621dd2417316f547a1bbc26030cf2c8435dbc2dae7b186d633f74f58a04b
6
+ metadata.gz: 4dd9ed806e8982e2be4103930ab51291b3c93c4163f044b5ebbdd63edc72b6bf369d4b2be8c597c5da66a8d83bce4e116171f1021c4238284e54cc6a3f36092b
7
+ data.tar.gz: 6828d7979ccc5589531c81d2f4f063fcf5d8511749f97445d58c6a8aff6ce2befa75a808d67f6f1e8db89d843a837cee237a5feb40a981146e9567b9a1473432
data/README.md CHANGED
@@ -58,6 +58,11 @@ The `Gonfic.new` call will peform file I/O and other operations, which can poten
58
58
  In this way you are lazily deferring the "dangerous" operations until first usage, then memoizing.
59
59
  Additionally, with access to your config via a method that's easy to stub, your test suite will be happy :)
60
60
 
61
+ ### Providing custom list of directories
62
+
63
+ By default, `Gonfic.new` will look for `filename:` in `~/` and `./` (merging them, if both are present).
64
+ If you want to load from other directories, just set the `directories:` parameter to your list.
65
+
61
66
  ### Loading configuration from ENV
62
67
 
63
68
  If you provide `filename:`, `Gonfic.new` will also check `ENV` for variables it considers relevant.
@@ -83,9 +88,7 @@ Your first steps should be:
83
88
 
84
89
  This will run tests (Minitest) and linter (Rubocop, custom config, see `.rubocop.yml`).
85
90
 
86
- Note: the repo does not force the bundle to be vendorized,
87
- but should work fine if you set `BUNDLE_PATH: "vendor"` in your `~/.bundle/config`.
88
- Hint, hint ;)
91
+ Note: the repo does not force the bundle to be vendorized, but should work fine if you set `BUNDLE_PATH: "vendor"` in your `~/.bundle/config`. Hint, hint ;)
89
92
 
90
93
  You can also run `bin/console` for an interactive prompt that will allow you to experiment.
91
94
 
data/gonfic.gemspec CHANGED
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'lib/gonfic/version'
4
2
 
5
3
  Gem::Specification.new do |spec|
@@ -25,7 +23,7 @@ Gem::Specification.new do |spec|
25
23
  spec.files = Dir.chdir(__dir__) do
26
24
  `git ls-files -z`.split("\x0").reject do |f|
27
25
  File.expand_path(f) == __FILE__ ||
28
- f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
26
+ f.start_with?(*%w[bin/ test/ .git .rubocop.yml Gemfile Rakefile])
29
27
  end
30
28
  end
31
29
  spec.bindir = 'exe'
@@ -0,0 +1,11 @@
1
+ module Gonfic
2
+ # provide convenient lists of directories
3
+ class Directories
4
+ HOME = '~'.freeze
5
+ HERE = '.'.freeze
6
+
7
+ def self.home_then_here
8
+ [HOME, HERE]
9
+ end
10
+ end
11
+ end
@@ -30,7 +30,7 @@ module Gonfic
30
30
 
31
31
  def self.extract_variable(prefix:, key_name:, into:)
32
32
  env_var_name = prefix + upcase_and_simplify(key_name)
33
- into[key_name] = env[env_var_name] if env.key?(env_var_name)
33
+ into[key_name] = env.fetch(env_var_name) if env.key?(env_var_name)
34
34
  end
35
35
 
36
36
  def self.env
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Gonfic
4
- VERSION = '0.5.0'
2
+ VERSION = '0.6.2'.freeze
5
3
  end
data/lib/gonfic.rb CHANGED
@@ -1,25 +1,38 @@
1
- # frozen_string_literal: true
1
+ require 'yaml'
2
2
 
3
3
  require_relative 'gonfic/version'
4
4
  require_relative 'gonfic/config'
5
5
  require_relative 'gonfic/env_extractor'
6
+ require_relative 'gonfic/directories'
6
7
 
7
8
  # external interface to creating a Config with data loaded from files
8
9
  module Gonfic
9
- FILE_LOADER = ->(filename){ YAML.safe_load(File.read(filename)) }
10
+ YAML_FILE_LOADER = ->(filename){ YAML.safe_load(File.read(filename)) }
10
11
 
11
12
  def self.new(
12
13
  defaults: {},
13
- filename: nil, file_loader: FILE_LOADER,
14
+ filename: nil, file_loader: YAML_FILE_LOADER, directories: Directories.home_then_here,
14
15
  env_variable_prefix: EnvExtractor.env_prefix_from_filename(filename)
15
16
  )
16
- config = Config.new(defaults)
17
- config.merge!(load_configuration_file("~/#{filename}", file_loader)) if filename
18
- config.merge!(load_configuration_file("./#{filename}", file_loader)) if filename
19
- if env_variable_prefix
20
- config.merge!(EnvExtractor.extract_variables_from_env(prefix: env_variable_prefix, defaults: defaults))
17
+ configs =
18
+ configs_from_defaults(defaults: defaults) +
19
+ configs_from_files(filename: filename, file_loader: file_loader, directories: directories) +
20
+ configs_from_env(env_variable_prefix: env_variable_prefix, defaults: defaults)
21
+
22
+ configs.reduce(:merge!)
23
+ end
24
+
25
+ def self.configs_from_defaults(defaults:)
26
+ [Config.new(defaults)]
27
+ end
28
+
29
+ def self.configs_from_files(filename:, file_loader:, directories:)
30
+ return [] unless filename
31
+
32
+ directories.map do |directory|
33
+ filepath = File.expand_path(File.join(directory, filename))
34
+ load_configuration_file(filepath, file_loader)
21
35
  end
22
- config
23
36
  end
24
37
 
25
38
  def self.load_configuration_file(filename, file_loader)
@@ -30,4 +43,10 @@ module Gonfic
30
43
  Hashie.logger.error(e)
31
44
  {}
32
45
  end
46
+
47
+ def self.configs_from_env(env_variable_prefix:, defaults:)
48
+ return [] unless env_variable_prefix
49
+
50
+ [EnvExtractor.extract_variables_from_env(prefix: env_variable_prefix, defaults: defaults)]
51
+ end
33
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gonfic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Chludziński
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-21 00:00:00.000000000 Z
11
+ date: 2023-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -34,13 +34,12 @@ executables: []
34
34
  extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
- - ".rubocop.yml"
38
37
  - LICENSE.txt
39
38
  - README.md
40
- - Rakefile
41
39
  - gonfic.gemspec
42
40
  - lib/gonfic.rb
43
41
  - lib/gonfic/config.rb
42
+ - lib/gonfic/directories.rb
44
43
  - lib/gonfic/env_extractor.rb
45
44
  - lib/gonfic/version.rb
46
45
  homepage: https://gitlab.com/tanstaafl/gonfic
data/.rubocop.yml DELETED
@@ -1,53 +0,0 @@
1
- ---
2
- AllCops:
3
- TargetRubyVersion: 2.6
4
- SuggestExtensions: false
5
- NewCops: enable
6
-
7
- Style/FrozenStringLiteralComment:
8
- Enabled: false
9
-
10
- Layout/EndOfLine:
11
- Enabled: true
12
- EnforcedStyle: lf
13
-
14
- # tab country begins
15
- Layout/IndentationStyle:
16
- Enabled: true
17
- EnforcedStyle: tabs
18
-
19
- Layout/IndentationWidth: # weird setting to enable other Layout cops to work with tabs
20
- Enabled: true
21
- Width: 1
22
- # tab country ends
23
-
24
- Layout/MultilineMethodCallIndentation:
25
- Enabled: true
26
- EnforcedStyle: indented
27
-
28
- Layout/SpaceBeforeBlockBraces:
29
- Enabled: true
30
- EnforcedStyle: no_space
31
-
32
- Layout/LineLength:
33
- Max: 120
34
-
35
- Style/StringLiterals:
36
- Enabled: true
37
- EnforcedStyle: single_quotes
38
-
39
- Style/StringLiteralsInInterpolation:
40
- Enabled: true
41
- EnforcedStyle: single_quotes
42
-
43
- Style/TrailingCommaInArrayLiteral:
44
- Enabled: true
45
- EnforcedStyleForMultiline: comma
46
-
47
- Style/TrailingCommaInHashLiteral:
48
- Enabled: true
49
- EnforcedStyleForMultiline: comma
50
-
51
- Layout/SpaceInsideHashLiteralBraces:
52
- Enabled: true
53
- EnforcedStyle: no_space
data/Rakefile DELETED
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rake/testtask'
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << 'test'
8
- t.libs << 'lib'
9
- t.test_files = FileList['test/**/test_*.rb']
10
- end
11
-
12
- require 'rubocop/rake_task'
13
-
14
- RuboCop::RakeTask.new
15
-
16
- task default: %i[rubocop test]