conferrable 1.0.2 → 1.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
  SHA1:
3
- metadata.gz: cca938558ae02f3ddcbb70d0a27bbad49f0fde54
4
- data.tar.gz: 357db2e7fc8a1ef810f785a98efa48c31f28c5a5
3
+ metadata.gz: 540aa0627fba5b489ce2f93d6da830021ed7c9c3
4
+ data.tar.gz: 8e1e82140cb2e202fae3ee82fad21650c50049db
5
5
  SHA512:
6
- metadata.gz: 26012d1c811df974b41083bff49090f3f1a845344367b053395a4a694c79aadc82a4d00b6402d5f25b63c4e2cdd154e3c12c9bc349748b5b869b58f8aa2e4bfe
7
- data.tar.gz: 30f7070c56bd45879d32b7c9f3db5280366ba7300ceafb49d89567675941b5cf6a3ac16d1eb35c754dd991f0cd33b998f116c4a2699506df71992bf0b77291a4
6
+ metadata.gz: aa9e2aff2d7a5304d4b422f79389e13f382f1b307987074f4b5f5fa481e4e24c3d1f68f5c82aa76566246a031b0d2b370f96c90cb56c233abd087a492e67e1df
7
+ data.tar.gz: 6b1efa372cfcbdbc409a9ceafeb4cb23be9a7cdb2266e524283f2657dc94abf0127025bcbdb4e3a7b18e35bf5052fa8e4c1c0a4ce970c657e0d83250baf3a207
@@ -0,0 +1,4 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Metrics/LineLength:
4
+ Max: 100
@@ -0,0 +1,22 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-09-28 08:27:14 -0500 using RuboCop version 0.59.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Metrics/AbcSize:
11
+ Max: 17
12
+
13
+ # Offense count: 2
14
+ # Configuration parameters: CountComments, ExcludedMethods.
15
+ # ExcludedMethods: refine
16
+ Metrics/BlockLength:
17
+ Max: 45
18
+
19
+ # Offense count: 1
20
+ # Configuration parameters: CountComments, ExcludedMethods.
21
+ Metrics/MethodLength:
22
+ Max: 11
@@ -4,4 +4,5 @@ rvm:
4
4
  - 2.3.7
5
5
  cache: bundler
6
6
  script:
7
+ - bundle exec rubocop
7
8
  - bundle exec rspec
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
@@ -1,12 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- conferrable (1.0.2)
4
+ conferrable (1.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ast (2.4.0)
9
10
  diff-lcs (1.3)
11
+ jaro_winkler (1.5.1)
12
+ parallel (1.12.1)
13
+ parser (2.5.1.2)
14
+ ast (~> 2.4.0)
15
+ powerpack (0.1.2)
16
+ rainbow (3.0.0)
10
17
  rspec (3.8.0)
11
18
  rspec-core (~> 3.8.0)
12
19
  rspec-expectations (~> 3.8.0)
@@ -20,6 +27,16 @@ GEM
20
27
  diff-lcs (>= 1.2.0, < 2.0)
21
28
  rspec-support (~> 3.8.0)
22
29
  rspec-support (3.8.0)
30
+ rubocop (0.59.2)
31
+ jaro_winkler (~> 1.5.1)
32
+ parallel (~> 1.10)
33
+ parser (>= 2.5, != 2.5.1.1)
34
+ powerpack (~> 0.1)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ ruby-progressbar (~> 1.7)
37
+ unicode-display_width (~> 1.0, >= 1.0.1)
38
+ ruby-progressbar (1.10.0)
39
+ unicode-display_width (1.4.0)
23
40
 
24
41
  PLATFORMS
25
42
  ruby
@@ -27,6 +44,7 @@ PLATFORMS
27
44
  DEPENDENCIES
28
45
  conferrable!
29
46
  rspec
47
+ rubocop (~> 0.59.2)
30
48
 
31
49
  BUNDLED WITH
32
50
  1.16.3
@@ -1,25 +1,28 @@
1
- require "./lib/conferrable/version"
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/conferrable/version'
2
4
 
3
5
  Gem::Specification.new do |s|
4
6
  s.name = 'conferrable'
5
7
  s.version = Conferrable::VERSION
6
- s.summary = "Simple YAML file-based configuration management"
8
+ s.summary = 'Simple YAML file-based configuration management'
7
9
 
8
- s.description = <<-EOS
10
+ s.description = <<-DESCRIPTION
9
11
  We have seen our applications gain more and more static configuration files over time.
10
12
  A common library we use on a daily basis is these configuration file loaders.
11
13
  Conferrable standardizes how we interact with these static YAML configuration files.
12
- EOS
14
+ DESCRIPTION
13
15
 
14
- s.authors = [ 'Matthew Ruggio' ]
15
- s.email = [ 'mruggio@bluemarblepayroll.com' ]
16
+ s.authors = ['Matthew Ruggio']
17
+ s.email = ['mruggio@bluemarblepayroll.com']
16
18
  s.files = `git ls-files`.split("\n")
17
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
21
  s.homepage = 'https://github.com/bluemarblepayroll/conferrable'
20
22
  s.license = 'MIT'
21
23
 
22
24
  s.required_ruby_version = '>= 2.3.1'
23
25
 
24
26
  s.add_development_dependency('rspec')
27
+ s.add_development_dependency('rubocop', '~> 0.59.2')
25
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -13,13 +15,12 @@ require_relative 'configuration'
13
15
  require_relative 'file_based_configuration'
14
16
  require_relative 'entry'
15
17
 
18
+ # This is the main module that contains the class-level methods that define the main API.
16
19
  module Conferrable
17
-
18
20
  GET_PREFIX_MATCHER_REGEX = /^get_(.+)$/
19
21
  GET_PREFIX_REGEX = /^get_/
20
22
 
21
23
  class << self
22
-
23
24
  def clear!
24
25
  @entries = {}
25
26
 
@@ -63,6 +64,5 @@ module Conferrable
63
64
  def keyify(val)
64
65
  val.to_s.sub(GET_PREFIX_REGEX, '')
65
66
  end
66
-
67
67
  end
68
68
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -6,29 +8,20 @@
6
8
  #
7
9
 
8
10
  module Conferrable
11
+ # Base class that defines main hash-based implementation.
9
12
  class Configuration
13
+ attr_reader :all
10
14
 
11
15
  def initialize(*configs)
12
- load!(configs)
13
- end
16
+ @all = {}
14
17
 
15
- def all
16
- @all || {}
18
+ overlay(configs)
17
19
  end
18
20
 
19
- def load!(*configs)
20
- configs.flatten.compact.each { |c| overlay(c) }
21
+ def overlay(*configs)
22
+ configs.flatten.compact.each { |config| @all.merge!(config || {}) }
21
23
 
22
24
  nil
23
25
  end
24
-
25
- private
26
-
27
- def overlay(config)
28
- @all = {} unless @all
29
-
30
- @all.merge!(config || {})
31
- end
32
-
33
26
  end
34
27
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -6,30 +8,25 @@
6
8
  #
7
9
 
8
10
  module Conferrable
11
+ # This class builds on the basic concepts of Configuration and FileBasedConfiguration.
12
+ # It allows the ability to define a "configuration store".
9
13
  class Entry
10
-
11
14
  class << self
15
+ attr_writer :default_folder
12
16
 
13
17
  def default_folder
14
18
  @default_folder || File.join('.', 'config')
15
19
  end
16
20
 
17
- def default_folder=(path)
18
- @default_folder = path
19
- end
20
-
21
21
  def default_file(name)
22
22
  File.join(default_folder, "#{name}.yml.erb")
23
23
  end
24
-
25
24
  end
26
25
 
27
- attr_reader :key
28
-
29
- attr_accessor :filenames
26
+ attr_reader :key, :filenames
30
27
 
31
28
  def initialize(key, filenames: nil)
32
- raise ArgumentError, 'key is required' unless key && key.to_s.length > 0
29
+ raise ArgumentError, 'key is required' unless key && key.to_s.length.positive?
33
30
 
34
31
  @key = key.to_s
35
32
  @filenames = filenames
@@ -58,7 +55,7 @@ module Conferrable
58
55
  private
59
56
 
60
57
  def protected!
61
- raise ArgumentError, "[Illegal] #{key} config store has been re-configured after it was loaded." if loaded?
58
+ raise ArgumentError, "#{key} config store has been re-configured after load." if loaded?
62
59
  end
63
60
 
64
61
  def loaded!
@@ -73,12 +70,11 @@ module Conferrable
73
70
 
74
71
  names = Array(filenames).flatten
75
72
 
76
- names = [ self.class.default_file(key) ] if names.length == 0
73
+ names = [self.class.default_file(key)] if names.length.zero?
77
74
 
78
75
  @configuration = FileBasedConfiguration.new(names)
79
76
 
80
77
  loaded!
81
78
  end
82
-
83
79
  end
84
80
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -6,11 +8,14 @@
6
8
  #
7
9
 
8
10
  module Conferrable
11
+ # This class extends the Configuration class by introducing the concept of
12
+ # loading from a file.
9
13
  class FileBasedConfiguration < Configuration
10
-
11
14
  attr_reader :filenames, :loaded_filenames
12
15
 
13
16
  def initialize(*filenames)
17
+ super() # explicit () because we do not want to send in filenames
18
+
14
19
  @filenames = filenames.flatten
15
20
  @loaded_filenames = FileUtilities.resolve(@filenames)
16
21
 
@@ -20,8 +25,7 @@ module Conferrable
20
25
  def load!
21
26
  configs = @loaded_filenames.map { |f| FileUtilities.read(f) }
22
27
 
23
- super(configs)
28
+ overlay(configs)
24
29
  end
25
-
26
30
  end
27
31
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -6,15 +8,16 @@
6
8
  #
7
9
 
8
10
  module Conferrable
11
+ # Extra utilities that help, but do not define the domain.
9
12
  class FileUtilities
10
13
  class << self
11
-
12
14
  def resolve(filenames)
13
15
  Array(filenames).flatten.map do |filename|
14
- next unless filename && filename.to_s.length > 0
16
+ next unless filename && filename.to_s.length.positive?
15
17
 
16
18
  if File.exist?(filename) && File.directory?(filename)
17
- Dir.glob(File.join(filename, '**', '*.yml.erb')).select { |f| !File.directory?(f) }
19
+ dir_name = File.join(filename, '**', '*.yml.erb')
20
+ Dir.glob(dir_name).reject { |f| File.directory?(f) }
18
21
  elsif File.exist?(filename)
19
22
  filename
20
23
  else
@@ -24,9 +27,8 @@ module Conferrable
24
27
  end
25
28
 
26
29
  def read(filename)
27
- YAML.load(ERB.new(IO.read(filename)).result)
30
+ YAML.safe_load(ERB.new(IO.read(filename)).result)
28
31
  end
29
-
30
32
  end
31
33
  end
32
34
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -6,5 +8,5 @@
6
8
  #
7
9
 
8
10
  module Conferrable
9
- VERSION = "1.0.2"
11
+ VERSION = '1.0.3'
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -8,14 +10,14 @@
8
10
  require './lib/conferrable'
9
11
 
10
12
  describe Conferrable do
11
-
12
13
  let(:default_file_path) { './config/file1.yml.erb' }
13
14
  let(:default_abs_file_path) { File.expand_path(default_file_path) }
14
15
 
15
- let(:default_file) { "admin: true" }
16
+ let(:default_file) { 'admin: true' }
16
17
 
17
18
  before(:each) do
18
- allow(::Conferrable::FileUtilities).to receive(:resolve).with([default_file_path]).and_return([default_abs_file_path])
19
+ allow(::Conferrable::FileUtilities).to receive(:resolve).with([default_file_path])
20
+ .and_return([default_abs_file_path])
19
21
 
20
22
  allow(IO).to receive(:read).with(default_abs_file_path).and_return(default_file)
21
23
  end
@@ -58,5 +60,4 @@ describe Conferrable do
58
60
  Conferrable.set_filenames(:file1, 'something_else.yml.erb')
59
61
  end.to raise_error(ArgumentError)
60
62
  end
61
-
62
63
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -8,7 +10,6 @@
8
10
  require './lib/conferrable'
9
11
 
10
12
  describe Conferrable::Configuration do
11
-
12
13
  it 'should accept no initialization arguments' do
13
14
  config = Conferrable::Configuration.new
14
15
 
@@ -38,5 +39,4 @@ describe Conferrable::Configuration do
38
39
 
39
40
  expect(config.all.dig('options', 'admin')).to be false
40
41
  end
41
-
42
42
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -8,14 +10,13 @@
8
10
  require './lib/conferrable'
9
11
 
10
12
  describe Conferrable::Entry do
11
-
12
13
  let(:default_file_path) { './config/file1.yml.erb' }
13
14
  let(:default_abs_file_path) { File.expand_path(default_file_path) }
14
-
15
- let(:default_file) { "admin: true" }
15
+ let(:default_file) { 'admin: true' }
16
16
 
17
17
  before(:each) do
18
- allow(::Conferrable::FileUtilities).to receive(:resolve).with([default_file_path]).and_return([default_abs_file_path])
18
+ allow(::Conferrable::FileUtilities).to receive(:resolve).with([default_file_path])
19
+ .and_return([default_abs_file_path])
19
20
 
20
21
  allow(IO).to receive(:read).with(default_abs_file_path).and_return(default_file)
21
22
  end
@@ -27,5 +28,4 @@ describe Conferrable::Entry do
27
28
 
28
29
  expect(admin_value).to be true
29
30
  end
30
-
31
31
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -8,24 +10,30 @@
8
10
  require './lib/conferrable'
9
11
 
10
12
  describe Conferrable::FileBasedConfiguration do
11
-
12
13
  let(:file1_path) { File.expand_path('spec/files/file1.yml.erb') }
13
14
  let(:file2_path) { File.expand_path('spec/files/file2.yml.erb') }
14
15
  let(:files_path) { File.expand_path('spec/files') }
15
- let(:files) { [ file1_path, file2_path ]}
16
-
17
- let(:file1) { "admin: true" }
18
- let(:file2) { "admin: false" }
16
+ let(:files) { [file1_path, file2_path] }
17
+ let(:file1) { 'admin: true' }
18
+ let(:file2) { 'admin: false' }
19
19
 
20
20
  before(:each) do
21
21
  allow(::Conferrable::FileUtilities).to receive(:resolve).with([]).and_return([])
22
- allow(::Conferrable::FileUtilities).to receive(:resolve).with([file1_path]).and_return([file1_path])
23
- allow(::Conferrable::FileUtilities).to receive(:resolve).with([file2_path]).and_return([file2_path])
22
+
23
+ allow(::Conferrable::FileUtilities).to receive(:resolve).with([file1_path])
24
+ .and_return([file1_path])
25
+
26
+ allow(::Conferrable::FileUtilities).to receive(:resolve).with([file2_path])
27
+ .and_return([file2_path])
28
+
24
29
  allow(::Conferrable::FileUtilities).to receive(:resolve).with([files_path]).and_return(files)
30
+
25
31
  allow(::Conferrable::FileUtilities).to receive(:resolve).with([files]).and_return(files)
32
+
26
33
  allow(::Conferrable::FileUtilities).to receive(:resolve).with(files).and_return(files)
27
34
 
28
35
  allow(IO).to receive(:read).with(file1_path).and_return(file1)
36
+
29
37
  allow(IO).to receive(:read).with(file2_path).and_return(file2)
30
38
  end
31
39
 
@@ -57,7 +65,7 @@ describe Conferrable::FileBasedConfiguration do
57
65
  expect(admin_value).to be false
58
66
 
59
67
  # Test passing in an nested arrays
60
- config = Conferrable::FileBasedConfiguration.new([ [ files ] ])
68
+ config = Conferrable::FileBasedConfiguration.new([[files]])
61
69
  admin_value = config.all['admin']
62
70
  expect(admin_value).to be false
63
71
  end
@@ -69,5 +77,4 @@ describe Conferrable::FileBasedConfiguration do
69
77
  expect(admin_value).to be false
70
78
  expect(config.loaded_filenames).to eq(files)
71
79
  end
72
-
73
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conferrable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-27 00:00:00.000000000 Z
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.59.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.59.2
27
41
  description: |2
28
42
  We have seen our applications gain more and more static configuration files over time.
29
43
  A common library we use on a daily basis is these configuration file loaders.
@@ -36,6 +50,8 @@ extra_rdoc_files: []
36
50
  files:
37
51
  - ".editorconfig"
38
52
  - ".gitignore"
53
+ - ".rubocop.yml"
54
+ - ".rubocop_todo.yml"
39
55
  - ".ruby-version"
40
56
  - ".travis.yml"
41
57
  - Gemfile