config_module 1.2.3 → 1.2.4

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: 04d4f6c816e394924d4d3e833ef2d3c8be39cc6048a1167dca507761c6f965db
4
- data.tar.gz: b782426dd752d18ed5ca2a8a6ec2f8c98998156d6fd2b5807cea0f7eebf629fd
3
+ metadata.gz: 701a829eca82ba1d43a19d1bd2b75193f023251871313acc51482ca29fa4f66e
4
+ data.tar.gz: 05f819d5bf5b604edae092a8a42ea52b3f384cf6c2c53c1922cf04a2769f4c14
5
5
  SHA512:
6
- metadata.gz: b12be1b132e0e47a3a80f1bde3ae177e1f8ad7f73edd9228ad3c2830e706189571104ae0768b0c5fa53b986f444894dde2b9a6e34a8b1a93b1ddf0ddcd68f32f
7
- data.tar.gz: 53678ce655a23c423bad46535a774075a8ecb5483ef9237677d3e0484a5a500884391a11beab622c0d2e1915205cd7530379581d1e5428ed61c23bd14e0bf437
6
+ metadata.gz: 01ed4412fab19c1b3c7809f5e8d89fb7885c3ce3fcf51907bde289fc088986db1731471b37f409badd50aafec97af9f27aabdbcbafcc09777755cf2dea6737e8
7
+ data.tar.gz: 656d3401a0dd788025efeae0c09d200dfaededfdffe3872ab2da6f40255c7999a9047455877ec1a017e5499fc742e4e66c0ea653354ae8e6bce65b7e6d50955c
@@ -8,6 +8,8 @@ engines:
8
8
  rubocop:
9
9
  enabled: true
10
10
  channel: rubocop-0-50
11
+ config:
12
+ file: .rubocop.yml
11
13
  reek:
12
14
  enabled: true
13
15
  ratings:
@@ -0,0 +1,12 @@
1
+
2
+ # EditorConfig is awesome: https://EditorConfig.org
3
+
4
+ root = true
5
+
6
+ [*]
7
+ end_of_line = lf
8
+ insert_final_newline = true
9
+ indent_style = space
10
+ indent_size = 2
11
+ charset = utf-8
12
+ trim_trailing_whitespace = true
@@ -1 +1 @@
1
- 2.3.7
1
+ 2.3.7
@@ -0,0 +1 @@
1
+ # [The official Code of Conduct can be found in the Project Standards repository.](https://github.com/acook/project_standards/blob/master/community/coc.markdown)
@@ -0,0 +1,70 @@
1
+ # How to Contribute
2
+
3
+ Hi, and thanks for your interest in this project! We look forward to your contributions!
4
+
5
+ # Getting Started
6
+
7
+ To contribute to this project you'll need...
8
+
9
+ - Git
10
+ - A GitHub/Gitlab account
11
+ - A compiler/interpreter for the language you're using
12
+ - The latest project repo
13
+ - Sent me an email just to say hi and that you agree to the Contributor's Agreement (at the bottom)
14
+
15
+ # If You Want to Assist
16
+
17
+ - Check out the Trello Board and GitHub/Gitlab Issues to see what there is to do
18
+ - Pick out a task from the Ready list on Trello or a Bug tag from Issues
19
+ - Fork the repo and start getting familiar with the codebase
20
+ - Make your changes (see Git Commit Messages and Code Standards sections later in this document)
21
+ - Run the examples to make sure you didn't break anything
22
+ - Open a Pull Request
23
+ - Also, feel free to email me through GitHub (people do it all the time) or post an issue if you need help
24
+
25
+ # If You Have An Idea
26
+
27
+ - As above, check the Trello Board and GitHub Issues
28
+ - See if there's an existing or similar idea
29
+ - If so, feel free to start working on a solution (see above section), or wait for someone else to pick it up
30
+ - If not, submit it as a GitHub issue
31
+
32
+ # To Report a Bug
33
+
34
+ Please use GitHub/Gitlab Issues and provide as much as possible of the following...
35
+
36
+ - The version or git SHA1 of the project that you're using
37
+ - An example to reproduce the problem
38
+ - A clear description of what you expected to happen
39
+ - Detailed information about what happened instead
40
+ - Include the full text of any error messages
41
+ - Your OS and its release info (eg Debian Jesse or Windows 8.1)
42
+
43
+ # Git Commit Messages
44
+
45
+ - Stick to GitHub's suggested commit message length
46
+ - Keep commits small, don't squash commits, but do clean up WIPs
47
+ - Write informative summary of why your made your changes
48
+ - Try to keep each commit in a working state whenever possible
49
+ - Use git add -p to chunk up your changes into logical units if you make several unrelated changes
50
+
51
+ # Code Standards
52
+
53
+ Please use idiomatic formatting for the language, there are plugins for many editors which do this automatically. Each project may specify additional formatting guidelines.
54
+
55
+ - Use [EditorConfig](https://editorconfig.org/)
56
+ - Correct errors or new warnings that the CI and status checks report
57
+
58
+ # Contributor Agreement
59
+
60
+ You must agree to this contributor agreement when contributing.
61
+
62
+ You grant me (Anthony M. Cook) a non-exclusive unlimited license to use your contributions. As well as granting a non-exclusive unlimited license to any patents you hold that you utilize in your contribution. You promise to not include patents or code that you don't have the permissions to grant these rights. You continue to own your copyright and patents for your contributions, you're just letting me use them.
63
+
64
+ You also grant permission for me (Anthony M. Cook) to change the license(s) of this project, since we never know what the futer may hold! Even if released under a new license, the existing code will remain under the existing license. This allows persons and organizations to contribute to the development of this project financially without being bound by the terms of the standard agreement. This is called a dual-licensing model and you can find out more about how it benefits open source projects [on the OSS Watch page](http://oss-watch.ac.uk/resources/duallicence2).
65
+
66
+ Thanks so much for your contributions!
67
+
68
+ # Official Version of this Document
69
+ The contents of the official version supercede the above, in case they get out of sync!
70
+ https://github.com/acook/project_standards/edit/master/Contributing/CONTRIBUTING.markdown
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Anthony M. Cook
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -5,12 +5,11 @@ Load important configuration files into their own modules!
5
5
 
6
6
  Reference documentation for the [Latest Released](http://rubydoc.info/gems/config_module/file/README.markdown) and [Edge Version](https://github.com/acook/config_module#readme) is available.
7
7
 
8
- [![Gem Version](https://img.shields.io/gem/v/config_module.svg)](https://rubygems.org/gems/config_module)
9
- [![Gem Downloads](https://img.shields.io/gem/dt/config_module.svg?maxAge=2592000)](https://rubygems.org/gems/config_module)
10
- [![Build Status](https://travis-ci.org/acook/config_module.svg?branch=master)](https://travis-ci.org/acook/config_module)
8
+ [![Gem Version](https://img.shields.io/gem/v/config_module.svg?style=for-the-badge)](https://rubygems.org/gems/config_module)
9
+ [![Gem Downloads](https://img.shields.io/gem/dt/config_module.svg?style=for-the-badge)](https://rubygems.org/gems/config_module)
10
+ [![Build Status](https://img.shields.io/travis/acook/config_module.svg?style=for-the-badge)](https://travis-ci.org/acook/config_module)
11
+ [![Maintainability](https://api.codeclimate.com/v1/badges/14d47ea9d0e90d40154d/maintainability)](https://codeclimate.com/github/acook/config_module/maintainability)
11
12
  [![CircleCI](https://circleci.com/gh/acook/config_module.svg?style=svg)](https://circleci.com/gh/acook/config_module)
12
- [![Code Climate](https://codeclimate.com/github/acook/config_module/badges/gpa.svg)](https://codeclimate.com/github/acook/config_module)
13
- [![Test Coverage](https://codeclimate.com/github/acook/config_module/badges/coverage.svg)](https://codeclimate.com/github/acook/config_module/coverage)
14
13
 
15
14
  Installation
16
15
  ------------
@@ -102,13 +101,7 @@ end
102
101
 
103
102
  ### Check for Presence of Configuration Keys with `has_key?`
104
103
 
105
- There are times you want to provde defaults for values, and in typical Ruby fashion you would probably do this:
106
-
107
- ```ruby
108
- MyConfig.some_option || 'my default value'
109
- ```
110
-
111
- Occassionally though, that won't be good enough because the value could intentionally be `false` or even `nil`. In those situations, you might want to check to see if the key exists (especially useful along with namespaces). Much like a Hash, you can use the `has_key?` method and do something like:
104
+ You might want to check to see if the key exists (especially useful along with namespaces) before calling the method. Much like a Hash, you can use the `has_key?` method and do something like:
112
105
 
113
106
  ```ruby
114
107
  if MyConfig.has_key? :some_option then
@@ -133,13 +126,15 @@ You can access config options like a hash too, if you want:
133
126
  MyConfig.nonexistant_key #=> raises ConfigModule::ConfigOption::NotFoundError
134
127
  ```
135
128
 
136
- It'll also avoid any naming conflicts that might arise between methods defined on ConfigModule or ConfigOption and your key names. You can use it in concert with the above `config` method instead of `self` to enhance readability:
129
+ It'll also avoid any naming conflicts that might arise between methods names and key names. You can use it in concert with the above `config` method instead of `self` to enhance readability:
137
130
 
138
131
  ```ruby
139
132
  def bar
140
- config[:namespace]
133
+ config[:my_key]
141
134
  end
142
135
  ```
136
+
137
+ Lastly, it also doesn't wrap the returned value in a `ConfigOption`, it will return the underlying value such as a `Hash` directly.
143
138
 
144
139
 
145
140
  ### Enumerable
@@ -211,7 +206,6 @@ Caveats
211
206
  Who made this anyway?
212
207
  ---------------------
213
208
 
214
- I'm glad you asked!
215
-
216
- Anthony M. Cook 2016
209
+ © 2016-2019 Anthony M. Cook
210
+ Contributors: Brian Hawley
217
211
 
@@ -9,8 +9,10 @@ Gem::Specification.new do |gem|
9
9
  gem.version = ConfigModule::VERSION
10
10
  gem.authors = ["Anthony M. Cook"]
11
11
  gem.email = ["github@anthonymcook.com"]
12
- gem.description =
13
- "Wrap a configuration file in a module for easy use throughout your application. Inspired by Rails."
12
+ gem.description = <<-DESC.chomp.gsub(/^ */, "")
13
+ ConfigModule loads a YAML file into a module to make it easy to access and maintain your configurations.
14
+ It provides helpers for namespaces (like environments), hash-like square-bracket access, helpful custom exceptions, and optimized repeat access.
15
+ DESC
14
16
  gem.summary = "Load important configuration files into their own modules!"
15
17
  gem.homepage = "http://github.com/acook/config_module"
16
18
  gem.licenses = %w[MIT LGPL-3.0]
@@ -13,14 +13,12 @@ module ConfigModule
13
13
  def method_missing_handler name, source, *args, &block
14
14
  ConfigOption.wrap config.send(name, *args, &block)
15
15
  rescue NoMethodError => error
16
- if error.name == name
17
- raise(
18
- ConfigOption::NotFoundError.new(name, self, error),
19
- error.message, source
20
- )
21
- else
22
- raise
23
- end
16
+ raise unless error.name == name
17
+
18
+ raise(
19
+ ConfigOption::NotFoundError.new(name, self, error),
20
+ error.message, source
21
+ )
24
22
  end
25
23
 
26
24
  def respond_to_missing_handler name, include_all
@@ -32,8 +30,10 @@ module ConfigModule
32
30
  end
33
31
 
34
32
  def load_config
35
- @raw_config = YAML.load_file config_file
33
+ raise ConfigModule::ConfigFileNotSpecified, config_file unless config_file
34
+ raise ConfigModule::ConfigFileNotFound, config_file unless File.exist? config_file
36
35
 
36
+ yaml_load
37
37
  load_namespaces_from raw_config
38
38
  end
39
39
 
@@ -58,5 +58,18 @@ module ConfigModule
58
58
  def namespaces
59
59
  @namespaces ||= []
60
60
  end
61
+
62
+ private
63
+
64
+ def yaml_load
65
+ @raw_config =
66
+ if YAML::VERSION >= "3.0.2"
67
+ YAML.load_file config_file, fallback: {}
68
+ elsif YAML::VERSION >= "2.1.0"
69
+ YAML.load_file config_file, {}
70
+ else
71
+ YAML.load_file(config_file) || {} # ambiguous with false or nil value
72
+ end
73
+ end
61
74
  end
62
75
  end
@@ -14,6 +14,7 @@ module ConfigModule
14
14
 
15
15
  def each_pair
16
16
  return to_enum(__method__) { @table.size } unless block_given?
17
+
17
18
  @table.each_pair { |pair| yield pair }
18
19
  self
19
20
  end
@@ -21,12 +22,14 @@ module ConfigModule
21
22
 
22
23
  def each_key
23
24
  return to_enum(__method__) { @table.size } unless block_given?
25
+
24
26
  @table.each_key { |key| yield key }
25
27
  self
26
28
  end
27
29
 
28
30
  def each_value
29
31
  return to_enum(__method__) { @table.size } unless block_given?
32
+
30
33
  @table.each_value { |value| yield value }
31
34
  self
32
35
  end
@@ -1,20 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ConfigModule
4
+ # for when a config setting error occurs
4
5
  class ConfigError < NoMethodError
5
6
  def initialize name, object, details = nil
6
7
  @name, @object, @details = name, object, details
7
- @custom_message = "invalid #{identifier} `#{name}' for #{object_info}"
8
8
  end
9
9
  attr_reader :name, :object, :details
10
10
 
11
- def custom_message
12
- @custom_message + "\n#{super_message}"
11
+ def message
12
+ "invalid #{identifier} `#{name}' for #{object_info}"
13
13
  end
14
14
 
15
- alias_method :super_message, :message
16
- alias_method :message, :custom_message
17
-
18
15
  def object_info
19
16
  if object.is_a?(Class)
20
17
  object.name
@@ -27,4 +24,30 @@ module ConfigModule
27
24
  class InvalidNamespaceError < ConfigError
28
25
  def identifier; :namespace; end
29
26
  end
27
+
28
+ # for when config_file path isn't found
29
+ class ConfigFileNotFound < EOFError
30
+ def initialize config_file
31
+ @config_file = config_file
32
+ end
33
+ attr_reader :config_file
34
+
35
+ def message
36
+ "config_file `#{config_file}` not found."\
37
+ "Make sure it exists in the location specified."
38
+ end
39
+ end
40
+
41
+ # for when config_file was not set
42
+ class ConfigFileNotSpecified < TypeError
43
+ def initialize config_file
44
+ @config_file = config_file
45
+ end
46
+ attr_reader :config_file
47
+
48
+ def message
49
+ "config_file location is #{config_file.inspect}."\
50
+ "Set your config's location with the `config_file` method."
51
+ end
52
+ end
30
53
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ConfigModule
4
- VERSION = "1.2.3".freeze
4
+ VERSION = "1.2.4".freeze
5
5
  end
File without changes
@@ -12,3 +12,22 @@ spec "method_missing_handler traces back to the caller" do
12
12
  error.backtrace.to_s.include?("spec/config_helper_spec.rb:8:in") || error.backtrace
13
13
  end
14
14
  end
15
+
16
+ spec "is helpful when the config_file is not set" do
17
+ begin
18
+ configless_helper = ConfigModule::ConfigHelper.new
19
+ configless_helper.load_config
20
+ rescue ConfigModule::ConfigFileNotSpecified => error
21
+ error.message.include?("config_file") || error
22
+ end
23
+ end
24
+
25
+ spec "is helpful when the config_file is missing" do
26
+ begin
27
+ missing_helper = ConfigModule::ConfigHelper.new
28
+ missing_helper.config_file = "god"
29
+ missing_helper.load_config
30
+ rescue ConfigModule::ConfigFileNotFound => error
31
+ error.message.include?("config_file") || error
32
+ end
33
+ end
@@ -103,3 +103,13 @@ spec "incorrect namespaces raise informative errors" do
103
103
  true
104
104
  end
105
105
  end
106
+
107
+ module EmptyExample
108
+ extend ConfigModule
109
+ config_file "./config/empty.yml"
110
+ end
111
+
112
+ spec "empty config file becomes empty config" do
113
+ EmptyExample.config.class == ConfigModule::ConfigOption &&
114
+ EmptyExample.config.each.to_a == []
115
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_module
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony M. Cook
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-14 00:00:00.000000000 Z
11
+ date: 2019-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uspec
@@ -24,8 +24,9 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.1.0
27
- description: Wrap a configuration file in a module for easy use throughout your application.
28
- Inspired by Rails.
27
+ description: |-
28
+ ConfigModule loads a YAML file into a module to make it easy to access and maintain your configurations.
29
+ It provides helpers for namespaces (like environments), hash-like square-bracket access, helpful custom exceptions, and optimized repeat access.
29
30
  email:
30
31
  - github@anthonymcook.com
31
32
  executables: []
@@ -34,13 +35,17 @@ extra_rdoc_files: []
34
35
  files:
35
36
  - ".circleci/config.yml"
36
37
  - ".codeclimate.yml"
38
+ - ".editorconfig"
37
39
  - ".gitignore"
38
40
  - ".gitlab-ci.yml"
39
41
  - ".rubocop.yml"
40
42
  - ".ruby-gemset"
41
43
  - ".ruby-version"
42
44
  - ".travis.yml"
45
+ - CODE_OF_CONDUCT.md
46
+ - CONTRIBUTING.md
43
47
  - Gemfile
48
+ - LICENSE
44
49
  - README.markdown
45
50
  - Rakefile
46
51
  - config_module.gemspec
@@ -49,6 +54,7 @@ files:
49
54
  - lib/config_module/config_option.rb
50
55
  - lib/config_module/exceptions.rb
51
56
  - lib/config_module/version.rb
57
+ - uspec/config/empty.yml
52
58
  - uspec/config/example.yml
53
59
  - uspec/config/false_nil.yml
54
60
  - uspec/config_helper_spec.rb