qonfig 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -86
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -2
- data/README.md +13 -0
- data/Rakefile +1 -1
- data/bin/console +1 -0
- data/lib/qonfig.rb +8 -0
- data/lib/qonfig/error.rb +12 -0
- data/lib/qonfig/plugins.rb +62 -0
- data/lib/qonfig/plugins/abstract.rb +17 -0
- data/lib/qonfig/plugins/access_mixin.rb +30 -0
- data/lib/qonfig/plugins/registry.rb +129 -0
- data/lib/qonfig/settings.rb +2 -0
- data/lib/qonfig/version.rb +2 -2
- data/qonfig.gemspec +8 -8
- metadata +9 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afe6dc7a96eec7d6f1e45a84d88fe5d4d7188547c6f55fb6aff65f7e46b92620
|
4
|
+
data.tar.gz: c045b73600ef8b751229a81ca8030cdbd45b6955f47a1c8e1d0cff48b1229a67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0933d09ee590ab14c764373e66a90adce051cad88e3edcb8fb72ea75c39616797d263621f99f3ffe53645a652a6a8f8d566762a4b12d165168c0196ca4c87579'
|
7
|
+
data.tar.gz: 5dbcfedecf3a20906e00adb5f0ffec49f240bff0402e2db75690c29cb4b0bb8a394ccf9f1531723ff46c97a51d230c4e2484aa0eae122479189fa57882b41df8
|
data/.rubocop.yml
CHANGED
@@ -1,95 +1,14 @@
|
|
1
|
-
|
1
|
+
inherit_gem:
|
2
|
+
armitage-rubocop:
|
3
|
+
- lib/rubocop.general.yml
|
4
|
+
- lib/rubocop.rspec.yml
|
2
5
|
|
3
6
|
AllCops:
|
4
|
-
DisplayCopNames: true
|
5
|
-
DisplayStyleGuide: true
|
6
7
|
TargetRubyVersion: 2.5.1
|
7
8
|
Include:
|
8
9
|
- lib/**/*.rb
|
9
10
|
- spec/**/*.rb
|
10
|
-
Exclude:
|
11
|
-
- bin/**/*
|
12
11
|
- Gemfile
|
13
12
|
- Rakefile
|
14
13
|
- qonfig.gemspec
|
15
|
-
|
16
|
-
Style/SingleLineMethods:
|
17
|
-
Exclude:
|
18
|
-
- spec/**/*
|
19
|
-
|
20
|
-
Style/RescueModifier:
|
21
|
-
Exclude:
|
22
|
-
- spec/**/*
|
23
|
-
|
24
|
-
Style/IfUnlessModifier:
|
25
|
-
Enabled: false
|
26
|
-
|
27
|
-
Metrics/BlockLength:
|
28
|
-
Exclude:
|
29
|
-
- spec/**/*
|
30
|
-
|
31
|
-
Naming/VariableNumber:
|
32
|
-
EnforcedStyle: snake_case
|
33
|
-
|
34
|
-
Style/AsciiComments:
|
35
|
-
Enabled: false
|
36
|
-
|
37
|
-
Layout/IndentArray:
|
38
|
-
Enabled: false
|
39
|
-
|
40
|
-
Style/Documentation:
|
41
|
-
Enabled: false
|
42
|
-
|
43
|
-
RSpec/DescribeClass:
|
44
|
-
Enabled: false
|
45
|
-
|
46
|
-
Style/ConditionalAssignment:
|
47
|
-
Enabled: false
|
48
|
-
|
49
|
-
Metrics/LineLength:
|
50
|
-
Max: 100
|
51
|
-
|
52
|
-
Style/Alias:
|
53
|
-
EnforcedStyle: prefer_alias_method
|
54
|
-
|
55
|
-
Style/MultilineIfModifier:
|
56
|
-
Enabled: false
|
57
|
-
|
58
|
-
Lint/HandleExceptions:
|
59
|
-
Enabled: false
|
60
|
-
|
61
|
-
Metrics/MethodLength:
|
62
|
-
Max: 20
|
63
|
-
|
64
|
-
Style/DoubleNegation:
|
65
|
-
Enabled: false
|
66
|
-
|
67
|
-
Style/EmptyCaseCondition:
|
68
|
-
Enabled: false
|
69
|
-
|
70
|
-
RSpec/ExampleLength:
|
71
|
-
Enabled: false
|
72
|
-
|
73
|
-
RSpec/MultipleExpectations:
|
74
|
-
Enabled: false
|
75
|
-
|
76
|
-
Style/MultilineBlockChain:
|
77
|
-
Enabled: false
|
78
|
-
|
79
|
-
Metrics/AbcSize:
|
80
|
-
Max: 19
|
81
|
-
|
82
|
-
Metrics/CyclomaticComplexity:
|
83
|
-
Max: 10
|
84
|
-
|
85
|
-
Metrics/PerceivedComplexity:
|
86
|
-
Max: 10
|
87
|
-
|
88
|
-
Style/ClassAndModuleChildren:
|
89
|
-
Enabled: false
|
90
|
-
|
91
|
-
Lint/UnderscorePrefixedVariableName:
|
92
|
-
Enabled: false
|
93
|
-
|
94
|
-
Security/YAMLLoad:
|
95
|
-
Enabled: false
|
14
|
+
- bin/console
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.4.0] - 2018-06-24
|
5
|
+
- Introduce Plugin Ecosystem (`Qonfig::Plugins`):
|
6
|
+
- load plugin: `Qonfig.plugin('plugin_name')` or `Qonfig.plugin(:plugin_name)`;
|
7
|
+
- get registered plugins: `Qonfig.plugins #=> array of strings`
|
8
|
+
|
4
9
|
## [0.3.0] - 2018-06-13
|
5
10
|
### Added
|
6
11
|
- Improved configuration process: `#configure` can take a hash as a configuration `[option key => option]`
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in qonfig.gemspec
|
6
8
|
gemspec
|
data/README.md
CHANGED
@@ -34,6 +34,7 @@ require 'qonfig'
|
|
34
34
|
- [Load from ENV](#load-from-env)
|
35
35
|
- [Load from \_\_END\_\_](#load-from-__end__) (aka `load_from_self`)
|
36
36
|
- [Smart Mixin](#smart-mixin) (`Qonfig::Configurable`)
|
37
|
+
- [Plugins](#plugins)
|
37
38
|
|
38
39
|
---
|
39
40
|
|
@@ -691,6 +692,18 @@ GeneralApplication.config.to_h
|
|
691
692
|
|
692
693
|
---
|
693
694
|
|
695
|
+
### Plugins
|
696
|
+
|
697
|
+
```ruby
|
698
|
+
# --- show names of registered plugins ---
|
699
|
+
Qonfig.plugins # => array of strings
|
700
|
+
|
701
|
+
# --- load specific plugin ---
|
702
|
+
Qonfig.plugin(:plugin_name) # or Qonfig.plugin('plugin_name')
|
703
|
+
```
|
704
|
+
|
705
|
+
---
|
706
|
+
|
694
707
|
## Contributing
|
695
708
|
|
696
709
|
- Fork it ( https://github.com/0exp/qonfig/fork )
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/lib/qonfig.rb
CHANGED
@@ -23,4 +23,12 @@ module Qonfig
|
|
23
23
|
require_relative 'qonfig/data_set'
|
24
24
|
require_relative 'qonfig/data_set/class_builder'
|
25
25
|
require_relative 'qonfig/configurable'
|
26
|
+
require_relative 'qonfig/plugins/registry'
|
27
|
+
require_relative 'qonfig/plugins'
|
28
|
+
require_relative 'qonfig/plugins/access_mixin'
|
29
|
+
require_relative 'qonfig/plugins/abstract'
|
30
|
+
|
31
|
+
# @api public
|
32
|
+
# @since 0.4.0
|
33
|
+
extend Plugins::AccessMixin
|
26
34
|
end
|
data/lib/qonfig/error.rb
CHANGED
@@ -62,4 +62,16 @@ module Qonfig
|
|
62
62
|
# @api public
|
63
63
|
# @since 0.2.0
|
64
64
|
SelfDataNotFoundError = Class.new(Error)
|
65
|
+
|
66
|
+
# @see Qonfig::Plugins::Regsitry
|
67
|
+
#
|
68
|
+
# @api private
|
69
|
+
# @since 0.4.0
|
70
|
+
AlreadyRegisteredPluginError = Class.new(Error)
|
71
|
+
|
72
|
+
# @see Qonfig::Plugins::Registry
|
73
|
+
#
|
74
|
+
# @api public
|
75
|
+
# @since 0.4.0
|
76
|
+
UnregisteredPluginError = Class.new(Error)
|
65
77
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Qonfig
|
4
|
+
# @api public
|
5
|
+
# @since 0.4.0
|
6
|
+
module Plugins
|
7
|
+
# @since 0.4.0
|
8
|
+
@plugin_registry = Registry.new
|
9
|
+
# @since 0.4.0
|
10
|
+
@access_lock = Mutex.new
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# @param plugin_name [Symbol, String]
|
14
|
+
# @return [void]
|
15
|
+
#
|
16
|
+
# @api public
|
17
|
+
# @since 0.4.0
|
18
|
+
def load(plugin_name)
|
19
|
+
thread_safe { plugin_registry[plugin_name].load! }
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Array<String>]
|
23
|
+
#
|
24
|
+
# @api public
|
25
|
+
# @since 0.4.0
|
26
|
+
def names
|
27
|
+
thread_safe { plugin_registry.names }
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param plugin_name [Symbol, String]
|
31
|
+
# @return [void]
|
32
|
+
#
|
33
|
+
# @api private
|
34
|
+
# @since 0.4.0
|
35
|
+
def register_plugin(plugin_name, plugin_module)
|
36
|
+
thread_safe { plugin_registry[plugin_name] = plugin_module }
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# @return [Qonfig::Plugins::Registry]
|
42
|
+
#
|
43
|
+
# @api private
|
44
|
+
# @since 0.4.0
|
45
|
+
attr_reader :plugin_registry
|
46
|
+
|
47
|
+
# @return [Mutex]
|
48
|
+
#
|
49
|
+
# @api private
|
50
|
+
# @since 0.4.0
|
51
|
+
attr_reader :access_lock
|
52
|
+
|
53
|
+
# @return [void]
|
54
|
+
#
|
55
|
+
# @api private
|
56
|
+
# @since 0.4.0
|
57
|
+
def thread_safe
|
58
|
+
access_lock.synchronize { yield if block_given? }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Qonfig
|
4
|
+
module Plugins
|
5
|
+
# @api private
|
6
|
+
# @since 0.4.0
|
7
|
+
module AccessMixin
|
8
|
+
# @param plugin_name [Symbol, String]
|
9
|
+
# @return [void]
|
10
|
+
#
|
11
|
+
# @see Qonfig::Plugins
|
12
|
+
#
|
13
|
+
# @api public
|
14
|
+
# @since 0.4.0
|
15
|
+
def plugin(plugin_name)
|
16
|
+
Qonfig::Plugins.load(plugin_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Array<String>]
|
20
|
+
#
|
21
|
+
# @see Qonfig::Plugins
|
22
|
+
#
|
23
|
+
# @api public
|
24
|
+
# @since 0.4.0
|
25
|
+
def plugins
|
26
|
+
Qonfig::Plugins.names
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Qonfig
|
4
|
+
module Plugins
|
5
|
+
# @api private
|
6
|
+
# @since 0.4.0
|
7
|
+
class Registry
|
8
|
+
# @return [void]
|
9
|
+
#
|
10
|
+
# @api private
|
11
|
+
# @since 0.4.0
|
12
|
+
def initialize
|
13
|
+
@plugin_set = {}
|
14
|
+
@access_lock = Mutex.new
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param plugin_name [Symbol, String]
|
18
|
+
# @return [Qonfig::Plugins::Abstract]
|
19
|
+
#
|
20
|
+
# @api private
|
21
|
+
# @since 0.4.0
|
22
|
+
def [](plugin_name)
|
23
|
+
thread_safe { fetch(plugin_name) }
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param plugin_name [Symbol, String]
|
27
|
+
# @param plugin_module [Qonfig::Plugins::Abstract]
|
28
|
+
# @return [void]
|
29
|
+
#
|
30
|
+
# @api private
|
31
|
+
# @since 0.4.0
|
32
|
+
def register(plugin_name, plugin_module)
|
33
|
+
thread_safe { apply(plugin_name, plugin_module) }
|
34
|
+
end
|
35
|
+
alias_method :[]=, :register
|
36
|
+
|
37
|
+
# @return [Array<String>]
|
38
|
+
#
|
39
|
+
# @api private
|
40
|
+
# @since 0.4.0
|
41
|
+
def names
|
42
|
+
thread_safe { plugin_names }
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# @return [Hash]
|
48
|
+
#
|
49
|
+
# @api private
|
50
|
+
# @since 0.4.0
|
51
|
+
attr_reader :plugin_set
|
52
|
+
|
53
|
+
# @return [Mutex]
|
54
|
+
#
|
55
|
+
# @api private
|
56
|
+
# @since 0.4.0
|
57
|
+
attr_reader :access_lock
|
58
|
+
|
59
|
+
# @return [void]
|
60
|
+
#
|
61
|
+
# @api private
|
62
|
+
# @since 0.4.0
|
63
|
+
def thread_safe
|
64
|
+
access_lock.synchronize { yield if block_given? }
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Array<String>]
|
68
|
+
#
|
69
|
+
# @api private
|
70
|
+
# @since 0.4.0
|
71
|
+
def plugin_names
|
72
|
+
plugin_set.keys
|
73
|
+
end
|
74
|
+
|
75
|
+
# @param plugin_name [String]
|
76
|
+
# @return [Boolean]
|
77
|
+
#
|
78
|
+
# @api private
|
79
|
+
# @since 0.4.0
|
80
|
+
def registered?(plugin_name)
|
81
|
+
plugin_set.key?(plugin_name)
|
82
|
+
end
|
83
|
+
|
84
|
+
# @param plugin_name [Symbol, String]
|
85
|
+
# @param plugin_module [Qonfig::Plugins::Abstract]
|
86
|
+
# @return [void]
|
87
|
+
#
|
88
|
+
# @raise [Qonfig::AlreadyRegisteredPluginError]
|
89
|
+
#
|
90
|
+
# @api private
|
91
|
+
# @since 0.4.0
|
92
|
+
def apply(plugin_name, plugin_module)
|
93
|
+
plugin_name = indifferently_accessable_plugin_name(plugin_name)
|
94
|
+
|
95
|
+
if registered?(plugin_name)
|
96
|
+
raise Qonfig::AlreadyRegisteredPluginError, "#{plugin_name} plugin already exist"
|
97
|
+
end
|
98
|
+
|
99
|
+
plugin_set[plugin_name] = plugin_module
|
100
|
+
end
|
101
|
+
|
102
|
+
# @param plugin_name [Symbol, String]
|
103
|
+
# @return [Qonfig::Plugins::Abstract]
|
104
|
+
#
|
105
|
+
# @raise [Qonfig::UnregisteredPluginError]
|
106
|
+
#
|
107
|
+
# @api private
|
108
|
+
# @since 0.4.0
|
109
|
+
def fetch(plugin_name)
|
110
|
+
plugin_name = indifferently_accessable_plugin_name(plugin_name)
|
111
|
+
|
112
|
+
unless registered?(plugin_name)
|
113
|
+
raise Qonfig::UnregisteredPluginError, "#{plugin_name} plugin is not registered"
|
114
|
+
end
|
115
|
+
|
116
|
+
plugin_set[plugin_name]
|
117
|
+
end
|
118
|
+
|
119
|
+
# @param key [Symbol, String]
|
120
|
+
# @return [String]
|
121
|
+
#
|
122
|
+
# @api private
|
123
|
+
# @since 0.4.0
|
124
|
+
def indifferently_accessable_plugin_name(plugin_name)
|
125
|
+
plugin_name.to_s
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/lib/qonfig/settings.rb
CHANGED
@@ -355,6 +355,7 @@ module Qonfig
|
|
355
355
|
KeyGuard.new(key).prevent_core_method_intersection!
|
356
356
|
end
|
357
357
|
|
358
|
+
# rubocop:disable Layout/ClassStructure
|
358
359
|
# @return [Array<String>]
|
359
360
|
#
|
360
361
|
# @api private
|
@@ -364,6 +365,7 @@ module Qonfig
|
|
364
365
|
private_instance_methods(false) |
|
365
366
|
%i[super define_singleton_method self]
|
366
367
|
).map(&:to_s).freeze
|
368
|
+
# rubocop:enable Layout/ClassStructure
|
367
369
|
end
|
368
370
|
|
369
371
|
# rubocop:enable Metrics/ClassLength
|
data/lib/qonfig/version.rb
CHANGED
data/qonfig.gemspec
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# codning: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
lib = File.expand_path('
|
4
|
+
lib = File.expand_path('lib', __dir__)
|
4
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
6
|
require 'qonfig/version'
|
6
7
|
|
@@ -23,16 +24,15 @@ Gem::Specification.new do |spec|
|
|
23
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
25
|
spec.require_paths = ['lib']
|
25
26
|
|
26
|
-
spec.files
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
28
|
f.match(%r{^(test|spec|features)/})
|
28
29
|
end
|
29
30
|
|
30
|
-
spec.add_development_dependency 'coveralls',
|
31
|
-
spec.add_development_dependency 'simplecov',
|
32
|
-
spec.add_development_dependency 'simplecov-json',
|
33
|
-
spec.add_development_dependency '
|
34
|
-
spec.add_development_dependency '
|
35
|
-
spec.add_development_dependency 'rubocop-rspec', '~> 1.26'
|
31
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
32
|
+
spec.add_development_dependency 'simplecov', '~> 0.14'
|
33
|
+
spec.add_development_dependency 'simplecov-json', '~> 0.2'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.7'
|
35
|
+
spec.add_development_dependency 'armitage-rubocop', '~> 0.3'
|
36
36
|
|
37
37
|
spec.add_development_dependency 'bundler'
|
38
38
|
spec.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qonfig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Ibragimov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.2'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.57'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.57'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rspec
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,19 +67,19 @@ dependencies:
|
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '3.7'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop
|
70
|
+
name: armitage-rubocop
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
75
|
+
version: '0.3'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
82
|
+
version: '0.3'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: bundler
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,6 +160,10 @@ files:
|
|
174
160
|
- lib/qonfig/dsl.rb
|
175
161
|
- lib/qonfig/error.rb
|
176
162
|
- lib/qonfig/loaders/yaml.rb
|
163
|
+
- lib/qonfig/plugins.rb
|
164
|
+
- lib/qonfig/plugins/abstract.rb
|
165
|
+
- lib/qonfig/plugins/access_mixin.rb
|
166
|
+
- lib/qonfig/plugins/registry.rb
|
177
167
|
- lib/qonfig/settings.rb
|
178
168
|
- lib/qonfig/settings/builder.rb
|
179
169
|
- lib/qonfig/settings/key_guard.rb
|