topping 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/README.md +44 -10
- data/lib/topping/configurable/branch.rb +1 -34
- data/lib/topping/configurable/hq.rb +39 -30
- data/lib/topping/configuration_builder.rb +6 -4
- data/lib/topping/version.rb +1 -1
- data/lib/topping.rb +28 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1147486fdb5ceb1e12f992681b5d6e86745d332
|
4
|
+
data.tar.gz: e622771370993c6881fd67b8b94a72685617cd54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5c089fa4a81fdfeee5e6dbef54c7006669c96941c999ee28e856a7002882b1db9275983501ac22983a3fae4761d610d417af19452a57dd79d31acfdbd37bb10
|
7
|
+
data.tar.gz: 342d2a23a9bdcb56c1a5d8ab092676616d7d69a7e6c2b9cfd823366e3ae138b007fb15be9b3002471185b381a2a3878039678bf9bce899cc4372d3916515db34
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
# Topping
|
2
|
-
|
1
|
+
# Topping [![Gem Version](https://badge.fury.io/rb/topping.svg)](https://badge.fury.io/rb/topping) [![Build Status](https://travis-ci.org/rike422/topping.svg?branch=master)](https://travis-ci.org/rike422/topping) [![Code Climate](https://codeclimate.com/github/rike422/topping/badges/gpa.svg)](https://codeclimate.com/github/rike422/topping) [![Coverage Status](https://coveralls.io/repos/github/rike422/topping/badge.svg?branch=master)](https://coveralls.io/github/rike422/topping?branch=master)
|
3
2
|
Configuration library for like a [Lita](https://github.com/litaio/lita) style application
|
4
3
|
|
5
4
|
## Installation
|
@@ -17,8 +16,19 @@ gem 'topping'
|
|
17
16
|
require 'topping'
|
18
17
|
|
19
18
|
module MockApplication
|
20
|
-
class
|
21
|
-
|
19
|
+
class BaseApplication
|
20
|
+
extend Topping::Configurable::HQ
|
21
|
+
config :store, default: :memory
|
22
|
+
config :name, default: 'myapp'
|
23
|
+
config :dir, type: String
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module MockApplication
|
28
|
+
class Application < MockApplication::BaseApplication
|
29
|
+
config.store = :redis
|
30
|
+
config.name = 'topping_app'
|
31
|
+
config.dir = 'work'
|
22
32
|
end
|
23
33
|
end
|
24
34
|
|
@@ -40,7 +50,7 @@ module MockApplication
|
|
40
50
|
end
|
41
51
|
end
|
42
52
|
|
43
|
-
|
53
|
+
Topping.build
|
44
54
|
|
45
55
|
MockApplication::Application.configure do |c|
|
46
56
|
c.features.net.host = 'github.com'
|
@@ -51,13 +61,19 @@ MockApplication::Application.configure do |c|
|
|
51
61
|
end
|
52
62
|
|
53
63
|
net = MockApplication::Features::Net.new
|
54
|
-
user = MockApplication::Features::User.new
|
64
|
+
user = MockApplication::Features::User.new
|
65
|
+
|
66
|
+
p MockApplication::Application.config.name
|
67
|
+
# => 'topping_app'
|
68
|
+
p MockApplication::Application.config.store
|
69
|
+
# => :redis
|
70
|
+
p MockApplication::Application.config.dir
|
71
|
+
# => 'work'
|
55
72
|
|
56
73
|
p net.config.host
|
57
74
|
# => 'github.com'
|
58
75
|
p net.config.port
|
59
76
|
# => 89
|
60
|
-
|
61
77
|
p user.config.username
|
62
78
|
# => 'akira takahashi'
|
63
79
|
p user.config.password
|
@@ -68,11 +84,20 @@ p user.config.password
|
|
68
84
|
or
|
69
85
|
|
70
86
|
```ruby
|
87
|
+
|
71
88
|
require 'topping'
|
72
89
|
|
73
90
|
module MockApplication
|
74
|
-
class
|
75
|
-
|
91
|
+
class BaseApplication
|
92
|
+
extend Topping::Configurable::HQ
|
93
|
+
config :store, default: :memory
|
94
|
+
config :name, default: 'myapp'
|
95
|
+
config :dir, type: String
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
module MockApplication
|
100
|
+
class Application < MockApplication::BaseApplication
|
76
101
|
end
|
77
102
|
end
|
78
103
|
|
@@ -94,7 +119,7 @@ module MockApplication
|
|
94
119
|
end
|
95
120
|
end
|
96
121
|
|
97
|
-
|
122
|
+
Topping.build
|
98
123
|
|
99
124
|
MockApplication::Features::Net.configure do |c|
|
100
125
|
c.host = 'github.com'
|
@@ -106,6 +131,15 @@ MockApplication::Features::User.configure do |c|
|
|
106
131
|
c.password = 'password'
|
107
132
|
end
|
108
133
|
|
134
|
+
p MockApplication::Application.config.name
|
135
|
+
# => 'topping_app'
|
136
|
+
|
137
|
+
p MockApplication::Application.config.store
|
138
|
+
# => :redis
|
139
|
+
|
140
|
+
p MockApplication::Application.config.dir
|
141
|
+
# => 'work'
|
142
|
+
|
109
143
|
p MockApplication::Application.config.features.net.host
|
110
144
|
# => 'github.com'
|
111
145
|
p MockApplication::Application.config.features.net.port
|
@@ -25,41 +25,8 @@ module Topping
|
|
25
25
|
end
|
26
26
|
|
27
27
|
module ChildClassMethods
|
28
|
-
|
29
|
-
# @return [#call, nil] The block.
|
30
|
-
# @since 0.0.1
|
31
|
-
# @api private
|
32
|
-
attr_accessor :after_config_block
|
28
|
+
include Topping::Configurable
|
33
29
|
|
34
|
-
# The plugins's {ConfigurationBuilder} object.
|
35
|
-
# @return [ConfigurationBuilder] The configuration builder.
|
36
|
-
# @since 0.0.1
|
37
|
-
# @api public
|
38
|
-
attr_accessor :configuration_builder
|
39
|
-
# Registers a block to be executed after configuration is finalized.
|
40
|
-
# @yieldparam config [Configuration] The handler's configuration object.
|
41
|
-
# @return [void]
|
42
|
-
# @since 0.0.1
|
43
|
-
def after_config(&block)
|
44
|
-
self.after_config_block = block
|
45
|
-
end
|
46
|
-
|
47
|
-
# Sets a configuration attribute on the plugin.
|
48
|
-
# @return [void]
|
49
|
-
# @since 0.0.1
|
50
|
-
# @see ConfigurationBuilder#config
|
51
|
-
def config(*args, **kwargs, &block)
|
52
|
-
if block
|
53
|
-
configuration_builder.config(*args, **kwargs, &block)
|
54
|
-
else
|
55
|
-
configuration_builder.config(*args, **kwargs)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Yields the configuration object
|
60
|
-
# @yieldparam [Configuration] config The configuration object.
|
61
|
-
# @since 0.0.1
|
62
|
-
# @see ConfigurationBuilder#config
|
63
30
|
def configure(&block)
|
64
31
|
configuration_builder.configure(&block)
|
65
32
|
end
|
@@ -11,29 +11,29 @@ module Topping
|
|
11
11
|
# @api private
|
12
12
|
attr_accessor :name_space
|
13
13
|
|
14
|
-
#
|
15
|
-
# @
|
14
|
+
# Sets a configuration attribute on the application.
|
15
|
+
# @return [void]
|
16
16
|
# @since 0.0.1
|
17
17
|
# @see ConfigurationBuilder#config
|
18
|
-
def
|
19
|
-
|
18
|
+
def config(*args, **kwargs, &block)
|
19
|
+
if block
|
20
|
+
root.config(*args, **kwargs, &block)
|
21
|
+
else
|
22
|
+
root.config(*args, **kwargs)
|
23
|
+
end
|
24
|
+
build
|
20
25
|
end
|
21
26
|
|
22
|
-
#
|
23
|
-
# @return [
|
27
|
+
# Sets a configuration attribute on the application.
|
28
|
+
# @return [void]
|
24
29
|
# @since 0.0.1
|
25
|
-
def config
|
26
|
-
root.configuration.send(name_space.first.to_sym)
|
27
|
-
end
|
28
|
-
|
29
30
|
def build
|
30
|
-
|
31
|
+
root.build
|
31
32
|
end
|
32
33
|
|
33
34
|
# @api private
|
34
35
|
def mapping(klass)
|
35
|
-
keys = Topping
|
36
|
-
keys.delete(name_space)
|
36
|
+
keys = Topping.underscore_namespace(klass) - name_space
|
37
37
|
klass_name = keys.pop
|
38
38
|
|
39
39
|
parent = keys.reduce(root) do |memo, key|
|
@@ -44,16 +44,17 @@ module Topping
|
|
44
44
|
parent.combine(klass_name, klass.configuration_builder)
|
45
45
|
end
|
46
46
|
|
47
|
+
def inherited(klass)
|
48
|
+
klass.extend(Topping::Configurable::HQ::ChildClassMethods)
|
49
|
+
klass.root = root
|
50
|
+
end
|
51
|
+
|
47
52
|
class << self
|
48
53
|
# The top-level Configurable Class
|
49
54
|
# @api private
|
50
55
|
# @return [Configuration] The root attribute.
|
51
56
|
attr_accessor :hq_class
|
52
57
|
|
53
|
-
def included(klass)
|
54
|
-
klass.extend(Topping::Configurable::HQ)
|
55
|
-
end
|
56
|
-
|
57
58
|
def mapping(klass)
|
58
59
|
hq_class.mapping(klass)
|
59
60
|
end
|
@@ -61,23 +62,31 @@ module Topping
|
|
61
62
|
def extended(klass)
|
62
63
|
super
|
63
64
|
self.hq_class = klass
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
klass.name_space = Topping.underscore_namespace(klass)
|
66
|
+
|
67
|
+
config = Topping.root.config(klass.name_space.first)
|
68
|
+
klass.root = config
|
67
69
|
end
|
70
|
+
end
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
72
|
+
module ChildClassMethods
|
73
|
+
# The top-level {ConfigurationBuilder} attribute.
|
74
|
+
# @return [Configuration] The root attribute.
|
75
|
+
attr_accessor :root
|
76
|
+
|
77
|
+
# Yields the configuration object
|
78
|
+
# @yieldparam [Configuration] config The configuration object.
|
79
|
+
# @since 0.0.1
|
80
|
+
# @see ConfigurationBuilder#config
|
81
|
+
def configure
|
82
|
+
yield root.configuration
|
73
83
|
end
|
74
84
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
downcase
|
85
|
+
# User configuration store
|
86
|
+
# @return [Configuration] The root attribute.
|
87
|
+
# @since 0.0.1
|
88
|
+
def config
|
89
|
+
root.configuration
|
81
90
|
end
|
82
91
|
end
|
83
92
|
end
|
@@ -59,6 +59,12 @@ module Topping
|
|
59
59
|
@name = :root
|
60
60
|
end
|
61
61
|
|
62
|
+
# Merges two configuration builders by making one an attribute on the other.
|
63
|
+
# @yield The configuration object
|
64
|
+
def configure
|
65
|
+
yield configuration
|
66
|
+
end
|
67
|
+
|
62
68
|
# Builds a {Configuration} object from the attributes defined on the builder.
|
63
69
|
# @param object [Configuration] The empty configuration object that will be extended to
|
64
70
|
# create the final form.
|
@@ -93,10 +99,6 @@ module Topping
|
|
93
99
|
children << attribute
|
94
100
|
end
|
95
101
|
|
96
|
-
def configure
|
97
|
-
yield configuration
|
98
|
-
end
|
99
|
-
|
100
102
|
# rubocop:disable Metrics1/ParameterLists
|
101
103
|
# Declares a configuration attribute.
|
102
104
|
# @param name [String, Symbol] The attribute's name.
|
data/lib/topping/version.rb
CHANGED
data/lib/topping.rb
CHANGED
@@ -1,9 +1,35 @@
|
|
1
1
|
require 'topping/version'
|
2
|
+
require 'topping/configuration_builder'
|
3
|
+
require 'topping/errors'
|
2
4
|
|
3
5
|
module Topping
|
4
6
|
# Your code goes here...
|
7
|
+
class << self
|
8
|
+
# rubocop:disable Style/ClassVars
|
9
|
+
@@root = ConfigurationBuilder.new
|
10
|
+
|
11
|
+
def root
|
12
|
+
@@root
|
13
|
+
end
|
14
|
+
|
15
|
+
def build
|
16
|
+
root.build
|
17
|
+
end
|
18
|
+
|
19
|
+
def underscore_namespace(klass)
|
20
|
+
klass.name.split('::').map do |key|
|
21
|
+
Topping.underscore(key)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def underscore(str)
|
26
|
+
str.gsub(/::/, '/').
|
27
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
28
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
29
|
+
tr('-', '_').
|
30
|
+
downcase
|
31
|
+
end
|
32
|
+
end
|
5
33
|
end
|
6
34
|
|
7
35
|
require 'topping/configurable'
|
8
|
-
require 'topping/configuration_builder'
|
9
|
-
require 'topping/errors'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: topping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Takahashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|