Skip to content

Commit f64a790

Browse files
committedJun 13, 2019
Test against 2.6, and development mode fixes
Also added some sensible rubocop defaults.
1 parent f1d1be5 commit f64a790

20 files changed

+232
-136
lines changed
 

‎.codeclimate.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ engines:
77
- ruby
88
rubocop:
99
enabled: true
10+
channel: rubocop-0-50
1011
reek:
1112
enabled: true
1213
ratings:

‎.rubocop.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Rubocop override settings
2+
3+
AllCops:
4+
TargetRubyVersion: 2.0
5+
6+
Metrics/LineLength:
7+
Max: 120
8+
Exclude:
9+
- config_module.gemspec
10+
- "uspec/**/*"
11+
12+
Naming/PredicateName:
13+
Enabled: false
14+
15+
Style/PreferredHashMethods:
16+
Exclude:
17+
- "**/*"
18+
19+
Style/Documentation:
20+
Enabled: false
21+
22+
# FIXME: See issue #5
23+
Style/MethodMissing:
24+
Enabled: false
25+
26+
Style/MethodDefParentheses:
27+
Enabled: false
28+
29+
Style/ParallelAssignment:
30+
Enabled: false
31+
32+
Style/SingleLineMethods:
33+
Enabled: false
34+
35+
Style/Alias:
36+
Enabled: false
37+
38+
Style/CaseEquality:
39+
Enabled: false
40+
41+
Style/SymbolArray:
42+
Enabled: false
43+
44+
Bundler/OrderedGems:
45+
Enabled: false
46+
47+
Style/StringLiterals:
48+
EnforcedStyle: double_quotes
49+
50+
Style/StringLiteralsInInterpolation:
51+
EnforcedStyle: double_quotes
52+
53+
Layout/AccessModifierIndentation:
54+
EnforcedStyle: outdent

‎.ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ruby-2.3.3
1+
ruby-2.3.7

‎.travis.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: ruby
22
rvm:
3+
- 2.6
34
- 2.5
45
- 2.4
56
- 2.3
@@ -8,19 +9,19 @@ rvm:
89
- 2.0
910

1011
- ruby-head
11-
- jruby-9.1.6.0
12+
- jruby-9.2.7.0
1213
- jruby-21mode
1314

1415
matrix:
1516
allow_failures:
1617
- rvm: ruby-head
17-
- rvm: jruby-9.1.6.0
18+
- rvm: jruby-9.2.7.0
1819
- rvm: jruby-21mode
1920

2021
sudo: false
2122

2223
before_install:
23-
- gem update bundler
24+
- which bundle || gem install bundler
2425
before_script:
2526
- bundle exec gem list
2627
script: bundle exec uspec

‎Gemfile

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
source 'https://rubygems.org'
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
24

35
# Specify your gem's dependencies in config_module.gemspec
46
gemspec
57

6-
if ENV['CI'] == 'true' then
8+
if ENV["CI"] == "true"
79
group :test do
8-
gem 'simplecov'
9-
gem 'codeclimate-test-reporter', '~> 1.0.0'
10+
gem "simplecov"
11+
gem "codeclimate-test-reporter", "~> 1.0.0"
1012
end
1113
else
1214
group :development do
13-
gem 'travis'
15+
gem "travis"
16+
17+
if RUBY_VERSION.to_f < 2.2
18+
byebug_version = "~> 9.0.6"
19+
elsif RUBY_VERSION.to_f < 2.3
20+
byebug_version = "~> 10.0.2"
21+
elsif RUBY_VERSION.to_f < 2.4
22+
byebug_version = "< 12"
23+
end
24+
gem "byebug", byebug_version
1425

15-
gem 'pry'
16-
gem 'pry-doc'
17-
gem 'pry-theme'
18-
gem 'pry-rescue'
19-
gem 'pry-byebug'
20-
gem 'pry-coolline'
21-
gem 'pry-stack_explorer'
26+
gem "pry"
27+
gem "pry-doc"
28+
gem "pry-theme"
29+
gem "pry-rescue"
30+
gem "pry-byebug"
31+
gem "pry-coolline"
2232
end
2333
end

‎Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
# frozen_string_literal: true
2+
13
require "bundler/gem_tasks"

‎config_module.gemspec

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
# -*- encoding: utf-8 -*-
2-
lib = File.expand_path('../lib', __FILE__)
1+
# frozen_string_literal: true
2+
3+
lib = File.expand_path("../lib", __FILE__)
34
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4-
require 'config_module/version'
5+
require "config_module/version"
56

67
Gem::Specification.new do |gem|
7-
gem.name = 'config_module'
8-
gem.version = ConfigModule::VERSION
9-
gem.authors = ['Anthony M. Cook']
10-
gem.email = ['github@anthonymcook.com']
11-
gem.description = %q{Wrap a configuration file in a module for easy use throughout your application. Inspired by Rails.}
12-
gem.summary = %q{Load important configuration files into their own modules!}
13-
gem.homepage = 'http://github.com/acook/config_module'
14-
gem.licenses = %w{MIT LGPL-3}
8+
gem.name = "config_module"
9+
gem.version = ConfigModule::VERSION
10+
gem.authors = ["Anthony M. Cook"]
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."
14+
gem.summary = "Load important configuration files into their own modules!"
15+
gem.homepage = "http://github.com/acook/config_module"
16+
gem.licenses = %w[MIT LGPL-3]
1517

16-
gem.files = `git ls-files`.split($/)
17-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19-
gem.require_paths = ['lib']
18+
gem.files = `git ls-files`.split($/)
19+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
20+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21+
gem.require_paths = ["lib"]
2022

21-
gem.add_development_dependency 'uspec'
23+
gem.add_development_dependency "uspec"
2224
end

‎lib/config_module.rb

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
require 'ostruct'
2-
require 'yaml'
1+
# frozen_string_literal: true
32

4-
require_relative 'config_module/version'
5-
require_relative 'config_module/exceptions'
6-
require_relative 'config_module/config_option'
7-
require_relative 'config_module/config_helper'
3+
require "ostruct"
4+
require "yaml"
5+
6+
require_relative "config_module/version"
7+
require_relative "config_module/exceptions"
8+
require_relative "config_module/config_option"
9+
require_relative "config_module/config_helper"
810

911
module ConfigModule
1012
def [] key, *args
@@ -36,6 +38,6 @@ def __config_module_helper
3638
end
3739

3840
def method_missing name, *args, &block
39-
__config_module_helper.method_missing_handler name, caller(1), *args
41+
__config_module_helper.method_missing_handler name, caller(1), *args, &block
4042
end
4143
end

‎lib/config_module/config_helper.rb

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
# frozen_string_literal: true
2+
13
module ConfigModule
24
class ConfigHelper
3-
attr :raw_config
4-
attr_accessor :config_file, :namespaces
5+
attr_reader :raw_config
6+
attr_accessor :config_file
7+
attr_writer :namespaces
58

69
def config
710
@config ||= ConfigOption.wrap load_config
@@ -10,7 +13,7 @@ def config
1013
def method_missing_handler name, source, *args, &block
1114
ConfigOption.wrap config.send(name, *args, &block)
1215
rescue NoMethodError => error
13-
if error.name == name then
16+
if error.name == name
1417
raise(
1518
ConfigOption::NotFoundError.new(name, self, error),
1619
error.message, source
@@ -20,7 +23,7 @@ def method_missing_handler name, source, *args, &block
2023
end
2124
end
2225

23-
def field_lookup_handler name, source, *args, &block
26+
def field_lookup_handler name, _source, *_args, &_block
2427
config[name]
2528
end
2629

@@ -31,7 +34,7 @@ def load_config
3134
end
3235

3336
def load_namespaces_from tree
34-
namespaces.inject(ConfigOption.wrap tree) do |subtree, ns|
37+
namespaces.inject(ConfigOption.wrap(tree)) do |subtree, ns|
3538
if ConfigOption === subtree && ns.respond_to?(:to_sym) && subtree.has_key?(ns)
3639
ConfigOption.wrap subtree[ns]
3740
else
@@ -41,15 +44,15 @@ def load_namespaces_from tree
4144
)
4245
end
4346
end
44-
rescue TypeError => error
47+
rescue TypeError
4548
raise(
4649
InvalidNamespaceError.new(namespaces.first, self, caller),
4750
"Namespace must be a string or symbol, instead it was: #{namespaces.first.class}", caller(6)
4851
)
4952
end
5053

5154
def namespaces
52-
@namespaces ||= Array.new
55+
@namespaces ||= []
5356
end
5457
end
5558
end

‎lib/config_module/config_option.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
# frozen_string_literal: true
2+
13
module ConfigModule
24
class ConfigOption < OpenStruct
35
include Enumerable
46

57
def self.wrap data
6-
if data.is_a? Hash then
8+
if data.is_a? Hash
79
ConfigOption.new data
810
else
911
data
@@ -12,7 +14,7 @@ def self.wrap data
1214

1315
def each
1416
return to_enum __method__ unless block_given?
15-
@table.each_pair{|p| yield p}
17+
@table.each_pair { |p| yield p }
1618
end
1719

1820
def [] name
@@ -26,7 +28,7 @@ def has_key? key
2628
def method_missing name, *args, &block
2729
result = super
2830

29-
if result || @table.has_key?(name) then
31+
if result || @table.has_key?(name)
3032
self.class.wrap result
3133
else
3234
raise(

‎lib/config_module/exceptions.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# frozen_string_literal: true
2+
13
module ConfigModule
24
class ConfigError < NoMethodError
35
def initialize name, object, details = nil
46
@name, @object, @details = name, object, details
57
@custom_message = "invalid #{identifier} `#{name}' for #{object_info}"
68
end
7-
attr :name, :object, :details
9+
attr_reader :name, :object, :details
810

911
def custom_message
1012
@custom_message + "\n#{super_message}"
@@ -14,7 +16,7 @@ def custom_message
1416
alias_method :message, :custom_message
1517

1618
def object_info
17-
if object.is_a?(Class) then
19+
if object.is_a?(Class)
1820
object.name
1921
else
2022
"instance of `#{object.class} < #{object.class.superclass}'"

‎lib/config_module/version.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ConfigModule
2-
VERSION = '1.2.2'
4+
VERSION = "1.2.2".freeze
35
end

‎uspec/config_helper_spec.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
require_relative 'spec_helper'
1+
# frozen_string_literal: true
2+
3+
require_relative "spec_helper"
24

35
helper = ConfigModule::ConfigHelper.new
4-
helper.config_file = './config/example.yml'
6+
helper.config_file = "./config/example.yml"
57

6-
spec 'method_missing_handler traces back to the caller' do
8+
spec "method_missing_handler traces back to the caller" do
79
begin
810
helper.method_missing_handler :nonexistant, caller(1)
911
rescue NoMethodError => error
10-
error.backtrace.to_s.include? "spec/config_helper_spec.rb:6:in"
12+
error.backtrace.to_s.include? "spec/config_helper_spec.rb:8:in"
1113
end
1214
end

0 commit comments

Comments
 (0)