courtier 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.ruby +63 -0
- data/.yardopts +8 -0
- data/Config.rb +82 -0
- data/HISTORY.md +20 -0
- data/LICENSE.txt +27 -0
- data/NOTES.md +38 -0
- data/README.md +185 -0
- data/lib/c.rb +7 -0
- data/lib/courtier.rb +8 -0
- data/lib/courtier/config.rb +249 -0
- data/lib/courtier/config_filter.rb +104 -0
- data/lib/courtier/configuration.rb +335 -0
- data/lib/courtier/core_ext.rb +78 -0
- data/lib/courtier/interface.rb +353 -0
- data/lib/courtier/properties.rb +44 -0
- data/lib/courtier/setup.rb +46 -0
- data/lib/courtier/tweaks/rake.rb +31 -0
- data/lib/rc.rb +2 -0
- data/spec/00_concept.md +23 -0
- data/spec/01_config.md +14 -0
- data/spec/02_configuration.md +51 -0
- data/spec/03_import.md +49 -0
- data/spec/06_interface.md +39 -0
- data/spec/applique/ae.rb +1 -0
- data/spec/applique/file.rb +8 -0
- data/spec/applique/fixture.rb +10 -0
- data/spec/applique/fixture/config.rb +16 -0
- data/spec/cov.rb +7 -0
- metadata +135 -0
data/.ruby
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
source:
|
3
|
+
- var
|
4
|
+
- var/
|
5
|
+
authors:
|
6
|
+
- name: Trans
|
7
|
+
email: transfire@gmail.com
|
8
|
+
copyrights:
|
9
|
+
- holder: Rubyworks
|
10
|
+
year: '2011'
|
11
|
+
license: BSD-2-Clause
|
12
|
+
requirements:
|
13
|
+
- name: finder
|
14
|
+
- name: loaded
|
15
|
+
- name: detroit
|
16
|
+
groups:
|
17
|
+
- build
|
18
|
+
development: true
|
19
|
+
- name: qed
|
20
|
+
groups:
|
21
|
+
- test
|
22
|
+
development: true
|
23
|
+
- name: ae
|
24
|
+
groups:
|
25
|
+
- test
|
26
|
+
development: true
|
27
|
+
dependencies: []
|
28
|
+
alternatives: []
|
29
|
+
conflicts: []
|
30
|
+
repositories:
|
31
|
+
- uri: git://github.com/rubyworks/courtier.git
|
32
|
+
scm: git
|
33
|
+
name: upstream
|
34
|
+
resources:
|
35
|
+
- uri: http://rubyworks.github.com/courtier
|
36
|
+
name: home
|
37
|
+
type: home
|
38
|
+
- uri: http://rubydoc.info/gems/courtier/frames
|
39
|
+
name: docs
|
40
|
+
type: doc
|
41
|
+
- uri: http://github.com/rubyworks/courtier
|
42
|
+
name: code
|
43
|
+
type: code
|
44
|
+
- uri: http://groups.google.com/group/rubyworks-mailinglist
|
45
|
+
name: mail
|
46
|
+
type: mail
|
47
|
+
- uri: http://chat.us.freenode.net/rubyworks
|
48
|
+
name: chat
|
49
|
+
type: chat
|
50
|
+
extra: {}
|
51
|
+
load_path:
|
52
|
+
- lib
|
53
|
+
revision: 0
|
54
|
+
created: '2011-11-06'
|
55
|
+
summary: The best way to manage your application's configuration.
|
56
|
+
title: Courtier
|
57
|
+
version: 0.2.0
|
58
|
+
name: courtier
|
59
|
+
description: ! 'Courtier is a multi-tenant configuration system for Ruby projects.
|
60
|
+
|
61
|
+
Courtier can configure almost any Ruby tool or library.'
|
62
|
+
organization: Rubyworks
|
63
|
+
date: '2012-04-28'
|
data/.yardopts
ADDED
data/Config.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
config 'pry' do
|
4
|
+
puts "RC on Pry!"
|
5
|
+
$LOAD_PATH.unshift('lib')
|
6
|
+
end
|
7
|
+
|
8
|
+
#
|
9
|
+
# Detroit assembly.
|
10
|
+
#
|
11
|
+
config 'detroit' do
|
12
|
+
service :email do |s|
|
13
|
+
s.mailto = ['ruby-talk@ruby-lang.org',
|
14
|
+
'rubyworks-mailinglist@googlegroups.com']
|
15
|
+
end
|
16
|
+
|
17
|
+
service :gem do |s|
|
18
|
+
s.gemspec = 'pkg/courtier.gemspec'
|
19
|
+
end
|
20
|
+
|
21
|
+
service :github do |s|
|
22
|
+
s.folder = 'web'
|
23
|
+
end
|
24
|
+
|
25
|
+
service :dnote do |s|
|
26
|
+
s.title = 'Source Notes'
|
27
|
+
s.output = 'log/notes.html'
|
28
|
+
end
|
29
|
+
|
30
|
+
service :locat do |s|
|
31
|
+
s.output = 'log/locat.html'
|
32
|
+
end
|
33
|
+
|
34
|
+
service :vclog do |s|
|
35
|
+
s.output = ['log/history.html',
|
36
|
+
'log/changes.html']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# QED test coverage report using SimpleCov.
|
42
|
+
#
|
43
|
+
# Use `$properties.coverage_folder` to set directory in which to store
|
44
|
+
# coverage report this defaults to `log/coverage`.
|
45
|
+
#
|
46
|
+
# IMPORTANT! Unfortunately this will not give us a reliable report
|
47
|
+
# b/c QED uses the RC gem, so SimpleCov can't differentiate the two.
|
48
|
+
#
|
49
|
+
config 'qed', profile: 'cov' do
|
50
|
+
puts "QED w/coverage!"
|
51
|
+
|
52
|
+
require 'simplecov'
|
53
|
+
|
54
|
+
dir = $properties.coverage_folder
|
55
|
+
|
56
|
+
SimpleCov.start do
|
57
|
+
coverage_dir(dir || 'log/coverage')
|
58
|
+
#add_group "Label", "lib/qed/directory"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
config 'qed' do
|
63
|
+
puts "QED!"
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Rake tasks
|
68
|
+
#
|
69
|
+
config 'rake' do
|
70
|
+
desc 'run unit tests'
|
71
|
+
task 'test' do
|
72
|
+
puts "Rake Boo!"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Example configuration.
|
78
|
+
#
|
79
|
+
config 'example' do
|
80
|
+
puts "Configuration Example!"
|
81
|
+
end
|
82
|
+
|
data/HISTORY.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# RELEASE HISTORY
|
2
|
+
|
3
|
+
## 0.2.0 | 2012-04-16
|
4
|
+
|
5
|
+
Continued improvements to design and API. Basically,
|
6
|
+
just read the README to see what is new.
|
7
|
+
|
8
|
+
Changes:
|
9
|
+
|
10
|
+
*
|
11
|
+
|
12
|
+
|
13
|
+
## 0.1.1 | 2012-04-09
|
14
|
+
|
15
|
+
Initial release of RC.
|
16
|
+
|
17
|
+
Changes:
|
18
|
+
|
19
|
+
* Happy first release.
|
20
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
(BSD-2-Clause license)
|
2
|
+
|
3
|
+
Ruby Confection (http://rubyworks.github.com/rc)
|
4
|
+
|
5
|
+
Copyright (c) 2011 Rubyworks. All rights reserved.
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
8
|
+
modification, are permitted provided that the following conditions are met:
|
9
|
+
|
10
|
+
1. Redistributions of source code must retain the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer.
|
12
|
+
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer in the
|
15
|
+
documentation and/or other materials provided with the distribution.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
18
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
19
|
+
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
20
|
+
COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
22
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
24
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
26
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
data/NOTES.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Developer Notes
|
2
|
+
|
3
|
+
|
4
|
+
## 2012-04-07 | Toplevel DSLs
|
5
|
+
|
6
|
+
If it were not for Ruby's mixing toplevel definitions into all
|
7
|
+
objects, I likely would have used the simpler design of
|
8
|
+
just loading the config files directly (via `#load`).
|
9
|
+
|
10
|
+
It's dissapointing that Ruby continues to insist on mixing toplevel
|
11
|
+
methods into all objects. It would be much easier to write script
|
12
|
+
DSLs if it did not, saving a good bit of code. In this case, for
|
13
|
+
instance, I probably could have shaved off 20% to 40% of the
|
14
|
+
current code --neither the Config or the Configuration class
|
15
|
+
would be needed, and the parser could be stripped down to just
|
16
|
+
enough code to collect a list of profiles since that is all it
|
17
|
+
would really be useful for then.
|
18
|
+
|
19
|
+
|
20
|
+
## 2012-04-05 | Multiple Configurations
|
21
|
+
|
22
|
+
Should multiple definitions for the same tool and profile be
|
23
|
+
allowed?
|
24
|
+
|
25
|
+
config :qed, :cov do
|
26
|
+
...
|
27
|
+
end
|
28
|
+
|
29
|
+
config :qed, :cov do
|
30
|
+
...
|
31
|
+
end
|
32
|
+
|
33
|
+
configuration.invoke(:qed, :cov)
|
34
|
+
|
35
|
+
Should both definitions be called, or just the later? I have decide
|
36
|
+
that both will be called. If this becomes a concern, I may add a `#reconfig`
|
37
|
+
method which would first clear the list of matching configurations.
|
38
|
+
|
data/README.md
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
# Ruby Courtier
|
2
|
+
|
3
|
+
[Homepage](http://rubyworks.github.com/courtier) /
|
4
|
+
[Source Code](http://github.com/rubyworks/courtier) /
|
5
|
+
[Report Issue](http://github.com/rubyworks/courtier/issues) /
|
6
|
+
[Mailing List](http://googlegroups.com/group/rubyworks-mailinglist) /
|
7
|
+
[IRC Channel](http://chat.us.freenode.net/rubyworks)
|
8
|
+
|
9
|
+
[](http://travis-ci.org/rubyworks/courtier)
|
10
|
+
|
11
|
+
|
12
|
+
## About
|
13
|
+
|
14
|
+
*Ruby Courtier*, RC for short, is a is multi-tenant runtime configuration system
|
15
|
+
for Ruby tools. If was designed to facilitate Ruby-based configuration for
|
16
|
+
multiple tools in a single file. It is extremely simple, and univerally applicable
|
17
|
+
which makes it easy to understand and flexible in use.
|
18
|
+
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
To use RC via tools that support RC directly, there is nothing you need to
|
23
|
+
install. Installing the said tool should install `courtier` via a dependency and
|
24
|
+
load `courtier` when the tool is used.
|
25
|
+
|
26
|
+
To use RC with tools that don't provide direct support, first install RC
|
27
|
+
in the usual manner via RubyGems.
|
28
|
+
|
29
|
+
$ gem install courtier
|
30
|
+
|
31
|
+
Then add `-rc` to your system's `RUBYOPT` environment variable.
|
32
|
+
|
33
|
+
$ export RUBYOPT='-rc'
|
34
|
+
|
35
|
+
You will want to add that to your `.bashrc`, `.profile` or equivalent configuration
|
36
|
+
script.
|
37
|
+
|
38
|
+
|
39
|
+
## Instruction
|
40
|
+
|
41
|
+
To use RC in a project create a master configuration file for the project called
|
42
|
+
`Config.rb`. The file can have any name that matches `.config.rb`, `Config.rb`
|
43
|
+
or `config.rb`, in that order of precedence. In this file add configuration
|
44
|
+
blocks by name of the commandline tool. For example, let's demonstrate how we could
|
45
|
+
use this to configure Rake tasks.
|
46
|
+
|
47
|
+
$ cat Config.rb
|
48
|
+
config :rake do
|
49
|
+
desc 'generate yard docs'
|
50
|
+
task :yard do
|
51
|
+
sh 'yard'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Now when `rake` is run the tasks defined in this configuration will be available.
|
56
|
+
|
57
|
+
You might wonder why anyone would do this. That's where the *multi-tenancy*
|
58
|
+
comes into play. Let's add another configuration.
|
59
|
+
|
60
|
+
$ cat Config.rb
|
61
|
+
title = "MyApp"
|
62
|
+
|
63
|
+
config :rake do
|
64
|
+
desc 'generate yard docs'
|
65
|
+
task :yard do
|
66
|
+
sh "yard doc --title #{title}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
config :qedoc do |doc|
|
71
|
+
doc.title = "#{title} Demos"
|
72
|
+
end
|
73
|
+
|
74
|
+
Now we have configuration for both the rake tool and the qedoc tool in
|
75
|
+
a single file. Thus we gain the advantage of reducing the file count of our
|
76
|
+
project while pulling our tool configurations together into one place.
|
77
|
+
Moreover, these configurations can potentially share settings as demonstrated
|
78
|
+
here via the `title` local variable.
|
79
|
+
|
80
|
+
RC also supports profiles, either via a `profile` block:
|
81
|
+
|
82
|
+
profile :cov
|
83
|
+
config :qed do
|
84
|
+
require 'simplecov'
|
85
|
+
...
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
Or via a second config argument:
|
90
|
+
|
91
|
+
config :qed, :cov do
|
92
|
+
require 'simplecov'
|
93
|
+
...
|
94
|
+
end
|
95
|
+
|
96
|
+
When utilizing the tool, set the profile via an environment variable.
|
97
|
+
|
98
|
+
$ profile='cov' qed
|
99
|
+
|
100
|
+
Some tools that support RC out-of-the-box, may support a profile command
|
101
|
+
line option for specifying the profile.
|
102
|
+
|
103
|
+
$ qed -p cov
|
104
|
+
|
105
|
+
Still other tools might utilize profiles to a more specific purpose of
|
106
|
+
the tool at hand. Consult the tool's documentation for details.
|
107
|
+
|
108
|
+
|
109
|
+
## Qualifications
|
110
|
+
|
111
|
+
RC can be used with any Ruby-based commandline tool and there exists some
|
112
|
+
means of configuring the tool via a toplevel/global interface, or the tool
|
113
|
+
has been desinged to directly support RC.
|
114
|
+
|
115
|
+
|
116
|
+
## Customization
|
117
|
+
|
118
|
+
A tool can provide dedicated support for RC by loading `rc` or `courtier`
|
119
|
+
and using the `court` method to define a configuration procedure. For example,
|
120
|
+
the `detroit` project defines:
|
121
|
+
|
122
|
+
require 'rc'
|
123
|
+
|
124
|
+
court 'detroit' do |config|
|
125
|
+
if config.command?
|
126
|
+
Detroit.rc_config << config
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
In our example, `detroit` is required this configuration will be proccessed.
|
131
|
+
The `if config.command?` condition ensures that it only happens if the config's
|
132
|
+
`command` property matches the current command, i.e. `$0 == 'detroit'`. We can
|
133
|
+
see that Detroit stores the configuration for later us. When Detroit gets
|
134
|
+
around to loading a project's build assemblies, it will check this `rc_config`
|
135
|
+
setting and evaluate the configurations found there via Detroit's own DSL.
|
136
|
+
|
137
|
+
It is important that Courtier be required first, ideally before anything else. This
|
138
|
+
ensures it will pick up all configured features.
|
139
|
+
|
140
|
+
Some tools will want to support a command line option for selecting a
|
141
|
+
configuration profile. RC has a convenience method to make this very
|
142
|
+
easy to do.
|
143
|
+
|
144
|
+
Courtier.profile_switch('qed', '-p', '--profile')
|
145
|
+
|
146
|
+
It does not remove the argument from `ARGV`, so the tool's command line option
|
147
|
+
parser should still account for it. This simply ensures RC will know what the
|
148
|
+
profile is by setting `ENV['profile']` to the entry following the switch.
|
149
|
+
|
150
|
+
|
151
|
+
## Dependencies
|
152
|
+
|
153
|
+
### Libraries
|
154
|
+
|
155
|
+
RC depends on the [Finder](http://rubyworks.github.com/finder) library
|
156
|
+
to provide reliable load path and Gem searching. This is used when importing
|
157
|
+
configurations from other projects.
|
158
|
+
|
159
|
+
### Core Extensions
|
160
|
+
|
161
|
+
RC uses two core extensions, `#to_h`, which applies to a few different
|
162
|
+
classes, and `String#tabto`. These are *copied* from
|
163
|
+
[Ruby Facets](http://rubyworks.github.com/facets) to ensure a high
|
164
|
+
standard of interoperability.
|
165
|
+
|
166
|
+
Both of these methods have been suggested for inclusion in Ruby proper.
|
167
|
+
Please head over to Ruby Issue Tracker and add your support.
|
168
|
+
|
169
|
+
* http://bugs.ruby-lang.org/issues/749
|
170
|
+
* http://bugs.ruby-lang.org/issues/6056
|
171
|
+
|
172
|
+
|
173
|
+
## Release Notes
|
174
|
+
|
175
|
+
Please see HISTORY.rdoc file.
|
176
|
+
|
177
|
+
|
178
|
+
## Copyrights
|
179
|
+
|
180
|
+
Copyright (c) 2011 Rubyworks
|
181
|
+
|
182
|
+
Confection is distributable in accordance with the **BSD-2-Clause** license.
|
183
|
+
|
184
|
+
See LICENSE.txt file for details.
|
185
|
+
|
data/lib/c.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This script is for use in the RUBYOPT, e.g. RUBYOPT="-rc".
|
2
|
+
#
|
3
|
+
# My apologies to the author of the `c` gem, but honestly
|
4
|
+
# I think it would be much better off that functionality
|
5
|
+
# were provided via some other gems, e.g. the `github` gem.
|
6
|
+
|
7
|
+
require 'courtier'
|