rc 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.index +66 -0
- data/.rubyrc +88 -0
- data/.yardopts +8 -0
- data/HISTORY.md +40 -0
- data/LICENSE.txt +27 -0
- data/README.md +194 -0
- data/demo/00_concept.md +23 -0
- data/demo/01_config.md +14 -0
- data/demo/02_configuration.md +51 -0
- data/demo/03_import.md +48 -0
- data/demo/06_interface.md +39 -0
- data/demo/applique/ae.rb +1 -0
- data/demo/applique/file.rb +8 -0
- data/demo/applique/fixture.rb +10 -0
- data/demo/applique/fixture/.ruby +11 -0
- data/demo/cov.rb +7 -0
- data/lib/c.rb +8 -0
- data/lib/rc.rb +10 -0
- data/lib/rc/api.rb +4 -0
- data/lib/rc/config.rb +305 -0
- data/lib/rc/config_filter.rb +110 -0
- data/lib/rc/configuration.rb +362 -0
- data/lib/rc/constants.rb +9 -0
- data/lib/rc/core_ext.rb +6 -0
- data/lib/rc/core_ext/argv.rb +22 -0
- data/lib/rc/core_ext/hash.rb +17 -0
- data/lib/rc/core_ext/kernel.rb +38 -0
- data/lib/rc/core_ext/string.rb +20 -0
- data/lib/rc/core_ext/symbol.rb +8 -0
- data/lib/rc/dsl.rb +72 -0
- data/lib/rc/interface.rb +338 -0
- data/lib/rc/properties.rb +108 -0
- data/lib/rc/required.rb +10 -0
- data/lib/rc/setup.rb +57 -0
- data/lib/rc/tweaks/rake.rb +31 -0
- metadata +118 -22
data/.index
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
---
|
2
|
+
type: ruby
|
3
|
+
revision: 2013
|
4
|
+
sources:
|
5
|
+
- var
|
6
|
+
authors:
|
7
|
+
- name: Trans
|
8
|
+
email: transfire@gmail.com
|
9
|
+
organizations: []
|
10
|
+
requirements:
|
11
|
+
- name: finder
|
12
|
+
- groups:
|
13
|
+
- build
|
14
|
+
development: true
|
15
|
+
name: detroit
|
16
|
+
- groups:
|
17
|
+
- test
|
18
|
+
development: true
|
19
|
+
name: qed
|
20
|
+
- groups:
|
21
|
+
- test
|
22
|
+
development: true
|
23
|
+
name: ae
|
24
|
+
- groups:
|
25
|
+
- test
|
26
|
+
development: true
|
27
|
+
name: test
|
28
|
+
conflicts: []
|
29
|
+
alternatives: []
|
30
|
+
resources:
|
31
|
+
- type: home
|
32
|
+
uri: http://rubyworks.github.com/rc
|
33
|
+
label: Homepage
|
34
|
+
- type: docs
|
35
|
+
uri: http://rubydoc.info/github/rubyworks/rc/master/frames
|
36
|
+
label: Documentation
|
37
|
+
- type: code
|
38
|
+
uri: http://github.com/rubyworks/rc
|
39
|
+
label: Source Code
|
40
|
+
- type: mail
|
41
|
+
uri: http://groups.google.com/group/rubyworks-mailinglist
|
42
|
+
label: Mailing List
|
43
|
+
- type: chat
|
44
|
+
uri: http://chat.us.freenode.net/rubyworks
|
45
|
+
label: IRC Channel
|
46
|
+
repositories:
|
47
|
+
- name: upstream
|
48
|
+
scm: git
|
49
|
+
uri: git://github.com/rubyworks/rc.git
|
50
|
+
categories: []
|
51
|
+
paths:
|
52
|
+
load:
|
53
|
+
- lib
|
54
|
+
copyrights:
|
55
|
+
- holder: Rubyworks
|
56
|
+
year: '2011'
|
57
|
+
license: BSD-2-Clause
|
58
|
+
created: '2011-11-06'
|
59
|
+
summary: The best way to manage your application's configuration.
|
60
|
+
title: RC
|
61
|
+
version: 0.3.0
|
62
|
+
name: rc
|
63
|
+
description: ! 'R.C. is a multi-tenant configuration system for Ruby projects.
|
64
|
+
|
65
|
+
R.C. can configure almost any Ruby tool or library.'
|
66
|
+
date: '2013-01-08'
|
data/.rubyrc
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# Configure QED demo tool.
|
5
|
+
#
|
6
|
+
config 'qed' do
|
7
|
+
puts "QED!"
|
8
|
+
end
|
9
|
+
|
10
|
+
#
|
11
|
+
# QED test coverage report using SimpleCov.
|
12
|
+
#
|
13
|
+
# Use `$properties.coverage_folder` to set directory in which to store
|
14
|
+
# coverage report this defaults to `log/coverage`.
|
15
|
+
#
|
16
|
+
# IMPORTANT! Unfortunately this will not give us a reliable report
|
17
|
+
# b/c QED uses the RC gem, so SimpleCov can't differentiate the two.
|
18
|
+
#
|
19
|
+
config 'qed', :profile=>'cov' do
|
20
|
+
puts "QED w/coverage!"
|
21
|
+
|
22
|
+
require 'simplecov'
|
23
|
+
|
24
|
+
dir = $properties.coverage_folder
|
25
|
+
|
26
|
+
SimpleCov.start do
|
27
|
+
coverage_dir(dir || 'log/coverage')
|
28
|
+
#add_group "Label", "lib/qed/directory"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
#
|
34
|
+
#
|
35
|
+
config 'pry' do
|
36
|
+
puts "Pry on RC!"
|
37
|
+
$LOAD_PATH.unshift('lib')
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Detroit assembly.
|
42
|
+
#
|
43
|
+
config 'detroit' do |asm|
|
44
|
+
asm.service :email do |s|
|
45
|
+
s.mailto = ['ruby-talk@ruby-lang.org',
|
46
|
+
'rubyworks-mailinglist@googlegroups.com']
|
47
|
+
end
|
48
|
+
|
49
|
+
asm.service :gem do |s|
|
50
|
+
s.gemspec = 'pkg/rc.gemspec'
|
51
|
+
end
|
52
|
+
|
53
|
+
asm.service :github do |s|
|
54
|
+
s.folder = 'web'
|
55
|
+
end
|
56
|
+
|
57
|
+
asm.service :dnote do |s|
|
58
|
+
s.title = 'Source Notes'
|
59
|
+
s.output = 'log/notes.html'
|
60
|
+
end
|
61
|
+
|
62
|
+
asm.service :locat do |s|
|
63
|
+
s.output = 'log/locat.html'
|
64
|
+
end
|
65
|
+
|
66
|
+
asm.service :vclog do |s|
|
67
|
+
s.output = ['log/history.html',
|
68
|
+
'log/changes.html']
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Rake tasks
|
74
|
+
#
|
75
|
+
config 'rake' do
|
76
|
+
desc 'run unit tests'
|
77
|
+
task 'test' do
|
78
|
+
puts "Rake Boo!"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Example configuration.
|
84
|
+
#
|
85
|
+
config 'example' do
|
86
|
+
puts "Configuration Example!"
|
87
|
+
end
|
88
|
+
|
data/.yardopts
ADDED
data/HISTORY.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# RELEASE HISTORY
|
2
|
+
|
3
|
+
## 0.3.0 / 2012-13-08
|
4
|
+
|
5
|
+
This release is of the project finally begins to settle down the API.
|
6
|
+
The most significant change since the last release is the use of `.rubyrc`,
|
7
|
+
or just `.ruby`, as the name for the standard configuration file. It was
|
8
|
+
changed from the previous `Config.rb` file name in order to avoid any
|
9
|
+
confusion with Rails `config` directory or any other use of the word.
|
10
|
+
If you still prefer the old name, simply add a `.rubyrc` file to your
|
11
|
+
project containing `import "Config.rb"` to get equivalent functionality.
|
12
|
+
Other than that the majority of changes have been to improve the library
|
13
|
+
internally.
|
14
|
+
|
15
|
+
Changes:
|
16
|
+
|
17
|
+
* Change default config file name to `.rubyrc`, or just `.ruby`.
|
18
|
+
* Improve configuration loading code.
|
19
|
+
* Remove dependency on Courtier.
|
20
|
+
|
21
|
+
|
22
|
+
## 0.2.0 / 2012-04-16
|
23
|
+
|
24
|
+
Major improvements and simplifications to design and API.
|
25
|
+
Basically, just read the README to see what is new.
|
26
|
+
|
27
|
+
Changes:
|
28
|
+
|
29
|
+
* Add support for require-based configuration setups.
|
30
|
+
* Overhaul and drastically simplify design.
|
31
|
+
|
32
|
+
|
33
|
+
## 0.1.1 . 2012-04-09
|
34
|
+
|
35
|
+
Initial release of RC.
|
36
|
+
|
37
|
+
Changes:
|
38
|
+
|
39
|
+
* Happy first release.
|
40
|
+
|
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/README.md
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
# RC - Runtime Configuration
|
2
|
+
|
3
|
+
[Homepage](http://rubyworks.github.com/rc) /
|
4
|
+
[Report Issue](http://github.com/rubyworks/rc/issues) /
|
5
|
+
[Source Code](http://github.com/rubyworks/rc)
|
6
|
+
( [![Build Status](https://secure.travis-ci.org/rubyworks/rc.png)](http://travis-ci.org/rubyworks/rc) )
|
7
|
+
|
8
|
+
|
9
|
+
## About
|
10
|
+
|
11
|
+
RC is a is multi-tenant runtime configuration system for Ruby tools.
|
12
|
+
It is designed to facilitate Ruby-based configuration for multiple
|
13
|
+
tools in a single file, and designed to work whether the tool
|
14
|
+
has built-in support for RC or not. The syntax is simple, universally
|
15
|
+
applicable, yet flexible.
|
16
|
+
|
17
|
+
RC can be used with any Ruby-based commandline tool or library utilized by
|
18
|
+
such tool, where there exists some means of configuring it via a toplevel/global
|
19
|
+
interface; or the tool has been designed to directly support RC, of course.
|
20
|
+
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
To use RC with tools that support RC directly, there is likely nothing to
|
25
|
+
install. Installing the tool should install `rc` via a dependency and
|
26
|
+
load runtime configurations when the tool is used.
|
27
|
+
|
28
|
+
To use RC with a tool that does not provide built-in support, first install
|
29
|
+
the RC library, typically via RubyGems:
|
30
|
+
|
31
|
+
gem install rc
|
32
|
+
|
33
|
+
Then add `-rc` to your system's `RUBYOPT` environment variable.
|
34
|
+
|
35
|
+
$ export RUBYOPT='-rc'
|
36
|
+
|
37
|
+
You will want to add that to your `.bashrc`, `.profile` or equivalent configuration
|
38
|
+
script, so it always available.
|
39
|
+
|
40
|
+
|
41
|
+
## Instruction
|
42
|
+
|
43
|
+
To use RC in a project create a configuration file called either `.rc` or `RC.rb`.
|
44
|
+
Technically the file can be any variation of `rc` with an optional `.rb` extension,
|
45
|
+
hidden or not and case-insensitive. Hidden file names have precedence if multiple
|
46
|
+
matches exist. In this file add configuration blocks by name of the commandline tool.
|
47
|
+
|
48
|
+
For example, let's demonstrate how we could use this to configure Rake tasks.
|
49
|
+
(Yes, Rake is not the most obvious choice, since most developers are just as happy
|
50
|
+
to keep using a Rakefile. But a Rake example serves to show that it can be done,
|
51
|
+
and also it makes a good tie-in with next example.)
|
52
|
+
|
53
|
+
$ cat Config.rb
|
54
|
+
config :rake do
|
55
|
+
desc 'generate yard docs'
|
56
|
+
task :yard do
|
57
|
+
sh 'yard'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
Now when `rake` is run the tasks defined in this configuration will be available.
|
62
|
+
|
63
|
+
You might wonder why anyone would do this. That's where the *multi-tenancy*
|
64
|
+
comes into play. Let's add another configuration.
|
65
|
+
|
66
|
+
$ cat Config.rb
|
67
|
+
title = "MyApp"
|
68
|
+
|
69
|
+
config :rake do
|
70
|
+
desc 'generate yard docs'
|
71
|
+
task :yard do
|
72
|
+
sh "yard doc --title #{title}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
config :qedoc do |doc|
|
77
|
+
doc.title = "#{title} Demos"
|
78
|
+
end
|
79
|
+
|
80
|
+
Now we have configuration for both the `rake` tool and the `qedoc` tool in
|
81
|
+
a single file. Thus we gain the advantage of reducing the file count of our
|
82
|
+
project while pulling our tool configurations together into one place.
|
83
|
+
Moreover, these configurations can potentially share settings as demonstrated
|
84
|
+
here via the `title` local variable.
|
85
|
+
|
86
|
+
Of course, if we want configurations stored in multiple files, that can be done
|
87
|
+
too. Simple use the `import` method to load them, e.g.
|
88
|
+
|
89
|
+
import 'rc/*.rb'
|
90
|
+
|
91
|
+
RC also supports profiles, either via a `profile` block:
|
92
|
+
|
93
|
+
profile :cov do
|
94
|
+
config :qed do
|
95
|
+
require 'simplecov'
|
96
|
+
...
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
Or via a keyword parameter:
|
101
|
+
|
102
|
+
config 'qed', profile: 'cov' do
|
103
|
+
require 'simplecov'
|
104
|
+
...
|
105
|
+
end
|
106
|
+
|
107
|
+
When utilizing the tool, set the profile via an environment variable.
|
108
|
+
|
109
|
+
$ profile=cov qed
|
110
|
+
|
111
|
+
RC also support just `p` as a convenient shortcut.
|
112
|
+
|
113
|
+
$ p=cov qed
|
114
|
+
|
115
|
+
Some tools that support RC out-of-the-box, may support a profile command
|
116
|
+
line option for specifying the profile.
|
117
|
+
|
118
|
+
$ qed -p cov
|
119
|
+
|
120
|
+
Beyond mere namespacing, some tools might utilize profiles for a more specific
|
121
|
+
purpose fitting the tool. Consult the tool's documentation for details.
|
122
|
+
|
123
|
+
|
124
|
+
## Customization
|
125
|
+
|
126
|
+
A tool can provide dedicated support for RC by loading `rc/api` and using the
|
127
|
+
`configure` method to define a configuration procedure. For example,
|
128
|
+
the `detroit` project defines:
|
129
|
+
|
130
|
+
require 'rc/api'
|
131
|
+
|
132
|
+
RC.configure 'detroit' do |config|
|
133
|
+
if config.command?
|
134
|
+
Detroit.rc_config << config
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
In our example, when `detroit` is required this configuration will be processed.
|
139
|
+
The `if config.command?` condition ensures that it only happens if the config's
|
140
|
+
`command` property matches the current command, i.e. `$0 == 'detroit'`. We see
|
141
|
+
here that Detroit stores the configuration for later use. When Detroit gets
|
142
|
+
around to doing it's thing, it checks this `rc_config` setting and evaluates
|
143
|
+
the configurations found there.
|
144
|
+
|
145
|
+
It is important that RC be required first, ideally before anything else. This
|
146
|
+
ensures it will pick up all configured features.
|
147
|
+
|
148
|
+
Some tools will want to support a command line option for selecting a
|
149
|
+
configuration profile. RC has a convenience method to make this very
|
150
|
+
easy to do. For example, `qed` uses it:
|
151
|
+
|
152
|
+
RC.profile_switch('qed', '-p', '--profile')
|
153
|
+
|
154
|
+
It does not remove the argument from `ARGV`, so the tool's command line option
|
155
|
+
parser should still account for it. This simply ensures RC will know what the
|
156
|
+
profile is by setting `ENV['profile']` to the entry following the switch.
|
157
|
+
|
158
|
+
|
159
|
+
## Dependencies
|
160
|
+
|
161
|
+
### Libraries
|
162
|
+
|
163
|
+
RC depends on the [Finder](http://rubyworks.github.com/finder) library
|
164
|
+
to provide reliable load path and Gem searching. This is used when importing
|
165
|
+
configurations from other projects. (It's very much a shame Ruby and RubyGems
|
166
|
+
does not have this kind of functionality built-in.)
|
167
|
+
|
168
|
+
### Core Extensions
|
169
|
+
|
170
|
+
RC uses two core extensions, `#to_h`, which applies to a few different
|
171
|
+
classes, and `String#tabto`. These are *copied* from
|
172
|
+
[Ruby Facets](http://rubyworks.github.com/facets) to ensure a high
|
173
|
+
standard of interoperability.
|
174
|
+
|
175
|
+
Both of these methods have been suggested for inclusion in Ruby proper.
|
176
|
+
Please head over to Ruby Issue Tracker and add your support.
|
177
|
+
|
178
|
+
* http://bugs.ruby-lang.org/issues/749
|
179
|
+
* http://bugs.ruby-lang.org/issues/6056
|
180
|
+
|
181
|
+
|
182
|
+
## Release Notes
|
183
|
+
|
184
|
+
Please see HISTORY.md file.
|
185
|
+
|
186
|
+
|
187
|
+
## Copyrights
|
188
|
+
|
189
|
+
Copyright (c) 2011 Rubyworks
|
190
|
+
|
191
|
+
Confection is distributable in accordance with the **BSD-2-Clause** license.
|
192
|
+
|
193
|
+
See LICENSE.txt file for details.
|
194
|
+
|
data/demo/00_concept.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# R.C.
|
2
|
+
|
3
|
+
The purpose of R.C. is to provide unified configuration management
|
4
|
+
for Ruby tools.
|
5
|
+
|
6
|
+
R.C. designates a single per-project configuration file, named
|
7
|
+
either `.config.rb`, `Config.rb` or `config.rb`, looked up in that
|
8
|
+
order. The structure of this configuration file is very simple.
|
9
|
+
It is a ruby script sectioned into named `config` and `onload`
|
10
|
+
blocks:
|
11
|
+
|
12
|
+
config 'rubytest' do
|
13
|
+
# ... configure rubytest command ...
|
14
|
+
end
|
15
|
+
|
16
|
+
onload 'rake' do
|
17
|
+
# ... when rake is required then ...
|
18
|
+
end
|
19
|
+
|
20
|
+
Utilization of the these configurations may be handled by the consuming
|
21
|
+
application, but can be used on any Ruby-based tool if `-rc` is added
|
22
|
+
to RUBYOPT.
|
23
|
+
|