config-factory 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -8
- data/.rubocop.yml +15 -11
- data/.ruby-version +1 -1
- data/CHANGES.md +5 -0
- data/Gemfile +2 -0
- data/LICENSE.md +1 -1
- data/Rakefile +5 -3
- data/config-factory.gemspec +5 -3
- data/example.rb +1 -0
- data/lib/config/factory.rb +2 -0
- data/lib/config/factory/abstract_factory.rb +7 -5
- data/lib/config/factory/environment.rb +5 -3
- data/lib/config/factory/environments.rb +4 -2
- data/lib/config/factory/log.rb +3 -2
- data/lib/config/factory/module_info.rb +4 -2
- data/spec/.rubocop.yml +3 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/config/factory/abstract_factory_spec.rb +2 -0
- data/spec/unit/config/factory/environment_spec.rb +4 -1
- data/spec/unit/config/factory/environments_spec.rb +4 -2
- data/spec/unit/config/factory/fixtures.rb +3 -1
- data/spec/unit/config/factory/log_spec.rb +4 -1
- metadata +13 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71ac5f68f30df9052485393cdcf146484a7acd37
|
4
|
+
data.tar.gz: e5d2743640833b9cbeb9c6ee3614b5ba6b6bfd28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f580ce87fbee29317fb3dd0445bd936b996054597309bf90b77bfeae576f76dc0db8f668b8ba649def5879c61f82e3038450694799739457e6dd2bd56e5451c0
|
7
|
+
data.tar.gz: fa49944fb3829497732cee5a131509db8a276264d9005b1c9dc9784e7de0db30d31206881f006b146311b59641c8709cc70f61a73fef00a96fe6bb874a2749d0
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
# Disable compact style check for example.rb
|
2
|
-
Style/ClassAndModuleChildren:
|
3
|
-
Exclude:
|
4
|
-
- 'example.rb'
|
5
|
-
|
6
1
|
# Disable line-length check; it's too easy for the cure to be worse than the disease
|
7
2
|
Metrics/LineLength:
|
8
3
|
Enabled: False
|
@@ -11,14 +6,23 @@ Metrics/LineLength:
|
|
11
6
|
Style/Documentation:
|
12
7
|
Enabled: false
|
13
8
|
|
14
|
-
# Allow one line around class body (
|
15
|
-
|
9
|
+
# Allow one line around class body (Layout/EmptyLines will still disallow two or more)
|
10
|
+
Layout/EmptyLinesAroundClassBody:
|
16
11
|
Enabled: false
|
17
12
|
|
18
|
-
# Allow one line around module body (
|
19
|
-
|
13
|
+
# Allow one line around module body (Layout/EmptyLines will still disallow two or more)
|
14
|
+
Layout/EmptyLinesAroundModuleBody:
|
20
15
|
Enabled: false
|
21
16
|
|
22
|
-
# Allow one line around block body (
|
23
|
-
|
17
|
+
# Allow one line around block body (Layout/EmptyLines will still disallow two or more)
|
18
|
+
Layout/EmptyLinesAroundBlockBody:
|
24
19
|
Enabled: false
|
20
|
+
|
21
|
+
# Disable some style checks for sample code
|
22
|
+
Style/ClassAndModuleChildren:
|
23
|
+
Exclude:
|
24
|
+
- 'example.rb'
|
25
|
+
|
26
|
+
Style/MixinUsage:
|
27
|
+
Exclude:
|
28
|
+
- 'example.rb'
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.1
|
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
data/LICENSE.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2018 The Regents of the University of California
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
6
6
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# ------------------------------------------------------------
|
2
4
|
# RSpec
|
3
5
|
|
@@ -8,7 +10,7 @@ namespace :spec do
|
|
8
10
|
|
9
11
|
desc 'Run all unit tests'
|
10
12
|
RSpec::Core::RakeTask.new(:unit) do |task|
|
11
|
-
task.rspec_opts = %w
|
13
|
+
task.rspec_opts = %w[--color --format documentation --order default]
|
12
14
|
task.pattern = 'unit/**/*_spec.rb'
|
13
15
|
end
|
14
16
|
|
@@ -38,7 +40,7 @@ RuboCop::RakeTask.new
|
|
38
40
|
|
39
41
|
desc 'List TODOs (from spec/todo.rb)'
|
40
42
|
RSpec::Core::RakeTask.new(:todo) do |task|
|
41
|
-
task.rspec_opts = %w
|
43
|
+
task.rspec_opts = %w[--color --format documentation --order default]
|
42
44
|
task.pattern = 'todo.rb'
|
43
45
|
end
|
44
46
|
|
@@ -46,4 +48,4 @@ end
|
|
46
48
|
# Defaults
|
47
49
|
|
48
50
|
desc 'Run unit tests, check test coverage, run acceptance tests, check code style'
|
49
|
-
task default: [
|
51
|
+
task default: %i[coverage rubocop]
|
data/config-factory.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
lib = File.expand_path('../lib', __FILE__)
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
6
|
|
@@ -15,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
15
17
|
spec.license = 'MIT'
|
16
18
|
|
17
19
|
origin = `git config --get remote.origin.url`.chomp
|
18
|
-
origin_uri = origin.start_with?('http') ? URI(origin) : URI(origin.
|
20
|
+
origin_uri = origin.start_with?('http') ? URI(origin) : URI(origin.gsub(%r{git@([^:]+)(.com|.org)[^\/]+}, 'http://\1\2'))
|
19
21
|
spec.homepage = URI::HTTP.build(host: origin_uri.host, path: origin_uri.path.chomp('.git')).to_s
|
20
22
|
|
21
23
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -27,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
27
29
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
28
30
|
spec.add_development_dependency 'rake', '~> 10.4'
|
29
31
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 0.52'
|
30
33
|
spec.add_development_dependency 'simplecov', '~> 0.9.2'
|
31
34
|
spec.add_development_dependency 'simplecov-console', '~> 0.2.0'
|
32
|
-
spec.add_development_dependency 'rubocop', '~> 0.35.1'
|
33
35
|
end
|
data/example.rb
CHANGED
data/lib/config/factory.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'config/factory/environments'
|
2
4
|
|
3
5
|
module Config
|
@@ -32,7 +34,7 @@ module Config
|
|
32
34
|
|
33
35
|
def for_environment(env, config_name)
|
34
36
|
arg_hash = env.args_for(config_name)
|
35
|
-
|
37
|
+
raise ArgumentError, "no #{self} arguments found for config #{config_name} in environment #{env}" unless arg_hash
|
36
38
|
build_from(arg_hash, nil, env.name)
|
37
39
|
end
|
38
40
|
|
@@ -42,13 +44,13 @@ module Config
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def build_from(arg_hash, section_name = nil, env_name = nil)
|
45
|
-
|
47
|
+
raise ArgumentError, "nil argument hash passed to #{self}.build_from" unless arg_hash
|
46
48
|
args = deep_symbolize_keys(arg_hash)
|
47
49
|
args = args[section_name] if section_name
|
48
50
|
impl_class = find_impl_class(args)
|
49
51
|
begin
|
50
52
|
return create_impl(impl_class, args, env_name)
|
51
|
-
rescue => e
|
53
|
+
rescue StandardError => e
|
52
54
|
raise ArgumentError, "Error instantiating #{impl_class} with arguments #{args}: #{e}"
|
53
55
|
end
|
54
56
|
end
|
@@ -65,10 +67,10 @@ module Config
|
|
65
67
|
end
|
66
68
|
|
67
69
|
def impl_for_key(key_sym, args)
|
68
|
-
|
70
|
+
raise ArgumentError, "implementation key #{key_sym} not found in argument hash #{args || 'nil'}" unless args&.key?(key_sym)
|
69
71
|
key_value = args.delete(key_sym)
|
70
72
|
impl_class = impls_by_key[key_value]
|
71
|
-
|
73
|
+
raise ArgumentError, "No #{name} implementation found for #{key_sym}: #{key_value}" unless impl_class
|
72
74
|
impl_class
|
73
75
|
end
|
74
76
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Config
|
2
4
|
module Factory
|
3
5
|
class Environment
|
@@ -17,7 +19,7 @@ module Config
|
|
17
19
|
|
18
20
|
def self.load_file(path)
|
19
21
|
hash = YAML.load_file(path)
|
20
|
-
|
22
|
+
raise IOError, "Unable to load YAML file #{path}" unless hash && hash.is_a?(Hash)
|
21
23
|
load_hash(hash)
|
22
24
|
end
|
23
25
|
|
@@ -32,12 +34,12 @@ module Config
|
|
32
34
|
private
|
33
35
|
|
34
36
|
def name=(v)
|
35
|
-
|
37
|
+
raise ArgumentError, "Environment name #{v} must be a symbol" unless v && v.is_a?(Symbol)
|
36
38
|
@name = v
|
37
39
|
end
|
38
40
|
|
39
41
|
def configs=(v)
|
40
|
-
|
42
|
+
raise ArgumentError, "Environment configs #{v} must be a hash" unless v && v.is_a?(Hash)
|
41
43
|
@configs = v
|
42
44
|
end
|
43
45
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'yaml'
|
2
4
|
require 'config/factory/environment'
|
3
5
|
|
@@ -5,12 +7,12 @@ module Config
|
|
5
7
|
module Factory
|
6
8
|
module Environments
|
7
9
|
DEFAULT_ENVIRONMENT = :production
|
8
|
-
STANDARD_ENVIRONMENTS = [
|
10
|
+
STANDARD_ENVIRONMENTS = %i[defaults development test stage staging production].freeze
|
9
11
|
STANDARD_ENVIRONMENTS_NOT_FOUND = "No standard environment tags (#{STANDARD_ENVIRONMENTS.join(', ')}) found; is this really a multiple-environment configuration?"
|
10
12
|
|
11
13
|
def self.load_file(path)
|
12
14
|
hash = YAML.load_file(path)
|
13
|
-
|
15
|
+
raise IOError, "Unable to load YAML file #{path}" unless hash && hash.is_a?(Hash)
|
14
16
|
load_hash(hash)
|
15
17
|
end
|
16
18
|
|
data/lib/config/factory/log.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'logger'
|
2
4
|
|
3
5
|
module Config
|
@@ -20,8 +22,6 @@ module Config
|
|
20
22
|
@log = new_logger(logdev: value)
|
21
23
|
end
|
22
24
|
|
23
|
-
private
|
24
|
-
|
25
25
|
def self.new_logger(logdev:, level: Logger::DEBUG, shift_age: 10, shift_size: 1024 * 1024)
|
26
26
|
logger = Logger.new(logdev, shift_age, shift_size)
|
27
27
|
logger.level = level
|
@@ -30,6 +30,7 @@ module Config
|
|
30
30
|
end
|
31
31
|
logger
|
32
32
|
end
|
33
|
+
private_class_method :new_logger
|
33
34
|
|
34
35
|
end
|
35
36
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Config
|
2
4
|
module Factory
|
3
5
|
# The name of this gem
|
4
6
|
NAME = 'config-factory'
|
5
7
|
|
6
8
|
# The version of this gem
|
7
|
-
VERSION = '0.0
|
9
|
+
VERSION = '0.1.0'
|
8
10
|
|
9
11
|
# The copyright notice for this gem
|
10
|
-
COPYRIGHT = 'Copyright (c)
|
12
|
+
COPYRIGHT = 'Copyright (c) 2018 The Regents of the University of California'
|
11
13
|
end
|
12
14
|
end
|
data/spec/.rubocop.yml
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
4
|
+
require 'tmpdir'
|
2
5
|
require_relative 'fixtures'
|
3
6
|
|
4
7
|
module Config
|
@@ -18,7 +21,7 @@ module Config
|
|
18
21
|
it 'registers the configurations' do
|
19
22
|
yaml_hash = YAML.load_file('spec/data/single-environment.yml')
|
20
23
|
env = Environment.new(name: :test, configs: yaml_hash)
|
21
|
-
%w
|
24
|
+
%w[db source index].each do |key|
|
22
25
|
expect(env.args_for(key)).to eq(yaml_hash[key])
|
23
26
|
end
|
24
27
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require_relative 'fixtures'
|
3
5
|
|
@@ -8,7 +10,7 @@ module Config
|
|
8
10
|
it 'loads a multi-environment config file' do
|
9
11
|
envs = Environments.load_file('spec/data/multiple-environments.yml')
|
10
12
|
expect(envs).to be_a(Hash)
|
11
|
-
expected = [
|
13
|
+
expected = %i[defaults development test production]
|
12
14
|
expect(envs.size).to eq(expected.size)
|
13
15
|
expected.each do |env_name|
|
14
16
|
env = envs[env_name]
|
@@ -67,7 +69,7 @@ module Config
|
|
67
69
|
it 'reads a standard ActiveRecord DB config' do
|
68
70
|
envs = Environments.load_file('spec/data/db-config.yml')
|
69
71
|
expect(envs).to be_a(Hash)
|
70
|
-
expected = [
|
72
|
+
expected = %i[development test production]
|
71
73
|
expect(envs.size).to eq(expected.size)
|
72
74
|
expected.each do |env_name|
|
73
75
|
env = envs[env_name]
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'config/factory'
|
2
4
|
require 'uri'
|
3
5
|
|
@@ -61,7 +63,7 @@ class XMLConfig < PersistenceConfig
|
|
61
63
|
attr_reader :connection_info
|
62
64
|
|
63
65
|
can_build_if do |config|
|
64
|
-
config[:path]
|
66
|
+
config[:path]&.end_with?('.xml')
|
65
67
|
end
|
66
68
|
|
67
69
|
def initialize(connection_info)
|
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
4
|
+
require 'time'
|
2
5
|
|
3
6
|
module Config
|
4
7
|
module Factory
|
@@ -12,7 +15,7 @@ module Config
|
|
12
15
|
logged = out.string
|
13
16
|
expect(logged).to include(msg)
|
14
17
|
timestamp_str = logged.split[0]
|
15
|
-
timestamp =
|
18
|
+
timestamp = Time.parse(timestamp_str)
|
16
19
|
expect(timestamp.to_date).to eq(Time.now.utc.to_date)
|
17
20
|
ensure
|
18
21
|
Factory.log_device = $stdout
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config-factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Moles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,47 +53,47 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: '0.52'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: '0.52'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: simplecov
|
70
|
+
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.2
|
75
|
+
version: 0.9.2
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.2
|
82
|
+
version: 0.9.2
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: simplecov-console
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.2.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.2.0
|
97
97
|
description: A gem for creating configuration classes using the Abstract Factory pattern,
|
98
98
|
with run-time configuration provided by hashes or YAML files.
|
99
99
|
email:
|
@@ -130,7 +130,7 @@ files:
|
|
130
130
|
- spec/unit/config/factory/environments_spec.rb
|
131
131
|
- spec/unit/config/factory/fixtures.rb
|
132
132
|
- spec/unit/config/factory/log_spec.rb
|
133
|
-
homepage: http://github.com/
|
133
|
+
homepage: http://github.com/config-factory
|
134
134
|
licenses:
|
135
135
|
- MIT
|
136
136
|
metadata: {}
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.6.12
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: A gem for creating configuration classes using the Abstract Factory pattern.
|
@@ -166,4 +166,3 @@ test_files:
|
|
166
166
|
- spec/unit/config/factory/environments_spec.rb
|
167
167
|
- spec/unit/config/factory/fixtures.rb
|
168
168
|
- spec/unit/config/factory/log_spec.rb
|
169
|
-
has_rdoc:
|