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
@@ -0,0 +1,46 @@
|
|
1
|
+
module Courtier
|
2
|
+
|
3
|
+
# Tool configuration setup is used to customize how a tool handles
|
4
|
+
# configuration.
|
5
|
+
#
|
6
|
+
class Setup
|
7
|
+
|
8
|
+
#
|
9
|
+
# Intialize new configuration setup.
|
10
|
+
#
|
11
|
+
def initialize(feature, options={}, &block)
|
12
|
+
@feature = feature.to_s
|
13
|
+
|
14
|
+
@command = @feature
|
15
|
+
@command = options[:command] || options[:tool] if options.key?(:command) || options.key?(:tool)
|
16
|
+
|
17
|
+
@profile = options[:profile] if options.key?(:profile)
|
18
|
+
|
19
|
+
@block = block
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Feature for which this is the configuration setup.
|
24
|
+
#
|
25
|
+
attr :feature
|
26
|
+
|
27
|
+
#
|
28
|
+
#
|
29
|
+
#
|
30
|
+
def call(config)
|
31
|
+
return unless config.command == @command.to_s if @command
|
32
|
+
return unless config.profile == @profile.to_s if @profile
|
33
|
+
|
34
|
+
@block.call(config)
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
#
|
39
|
+
#
|
40
|
+
def to_proc
|
41
|
+
@block
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
court 'rake' do |config|
|
4
|
+
Module.new do
|
5
|
+
extend Rake::DSL
|
6
|
+
module_eval(&config)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Rake
|
11
|
+
RC_FILES = '.config.rb', 'config.rb', 'Config.rb'
|
12
|
+
|
13
|
+
class Application
|
14
|
+
remove_const(:DEFAULT_RAKEFILES)
|
15
|
+
DEFAULT_RAKEFILES = [
|
16
|
+
'rakefile', 'Rakefile', 'rakefile.rb', 'Rakefile.rb',
|
17
|
+
] + RC_FILES
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.load_rakefile(path)
|
21
|
+
case File.basename(path)
|
22
|
+
when *RC_FILES
|
23
|
+
# do nothing, RC will do it
|
24
|
+
else
|
25
|
+
load(path)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Must manually configure tweaked libraries.
|
31
|
+
RC.configure('rake')
|
data/lib/rc.rb
ADDED
data/spec/00_concept.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Ruby Courtier
|
2
|
+
|
3
|
+
The purpose of Courtier is to provide unified configuration management
|
4
|
+
for Ruby tools.
|
5
|
+
|
6
|
+
Courtier 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
|
+
|
data/spec/01_config.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Config Class
|
2
|
+
|
3
|
+
The Config class encapsulates a single config entry. It has a tool, profile
|
4
|
+
and procedure.
|
5
|
+
|
6
|
+
config = RC::Config.new('foo', :profile=>'bar') do
|
7
|
+
'example'
|
8
|
+
end
|
9
|
+
|
10
|
+
config.command #=> 'foo'
|
11
|
+
config.feature #=> 'foo'
|
12
|
+
config.profile #=> 'bar'
|
13
|
+
config.to_proc.call #=> 'example'
|
14
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Configuration
|
2
|
+
|
3
|
+
The Configuration class handle evaluation of a project configuration file.
|
4
|
+
|
5
|
+
rc = RC::Configuration.new
|
6
|
+
|
7
|
+
We can use the `#instance_eval` method to evaluate a configuration for our
|
8
|
+
demonstration.
|
9
|
+
|
10
|
+
rc.evaluate(<<-HERE)
|
11
|
+
config :sample1 do
|
12
|
+
"block code"
|
13
|
+
end
|
14
|
+
HERE
|
15
|
+
|
16
|
+
Evaluation of a configuration file, populate the Confection.config instance.
|
17
|
+
|
18
|
+
sample = rc.configurations.last
|
19
|
+
sample.tool #=> 'sample1'
|
20
|
+
sample.profile #=> 'default'
|
21
|
+
sample.class #=> RC::Config
|
22
|
+
|
23
|
+
A profile can be used as a means fo defining multiple configurations
|
24
|
+
for a single tool. This can be done by setting the second argument to
|
25
|
+
a Symbol.
|
26
|
+
|
27
|
+
rc.evaluate(<<-HERE)
|
28
|
+
config :sample2, profile: 'opt1' do
|
29
|
+
"block code"
|
30
|
+
end
|
31
|
+
HERE
|
32
|
+
|
33
|
+
sample = rc.configurations.last
|
34
|
+
sample.tool #=> 'sample2'
|
35
|
+
sample.profile #=> 'opt1'
|
36
|
+
|
37
|
+
Or it can be done by using a `profile` block.
|
38
|
+
|
39
|
+
rc.evaluate(<<-HERE)
|
40
|
+
profile :opt1 do
|
41
|
+
config :sample2 do
|
42
|
+
"block code"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
HERE
|
46
|
+
|
47
|
+
sample = rc.configurations.last
|
48
|
+
sample.tool #=> 'sample2'
|
49
|
+
sample.profile #=> 'opt1'
|
50
|
+
|
51
|
+
|
data/spec/03_import.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Importing
|
2
|
+
|
3
|
+
## Configuration Importing
|
4
|
+
|
5
|
+
Configurations can be imported from another project
|
6
|
+
using the `:from` option.
|
7
|
+
|
8
|
+
rc = RC::Configuration.new
|
9
|
+
|
10
|
+
rc.config :qed, :profile=>'example', :from=>'qed'
|
11
|
+
|
12
|
+
rc.to_a.size.assert == 1
|
13
|
+
|
14
|
+
The configuration can also be imported from a different profile.
|
15
|
+
|
16
|
+
rc.config :qed, :profile=>:coverage, :from=>['qed', :profile=>:simplecov]
|
17
|
+
|
18
|
+
rc.to_a.size.assert == 2
|
19
|
+
|
20
|
+
Although it will rarely be of use, it may also be imported from another
|
21
|
+
feature or commandline tool.
|
22
|
+
|
23
|
+
rc.config :example, :from=>['qed', :command=>:sample]
|
24
|
+
|
25
|
+
Imported configurations can also be augmented via a block.
|
26
|
+
|
27
|
+
rc = RC::Configuration.new
|
28
|
+
|
29
|
+
rc.config :qed, :from=>['qed', :profile=>:simplecov] do
|
30
|
+
# additional code here
|
31
|
+
end
|
32
|
+
|
33
|
+
rc.to_a.size.assert == 2
|
34
|
+
|
35
|
+
Technically this last form just creates two configurations for the same
|
36
|
+
tool and profile, but the ultimate effect is the same.
|
37
|
+
|
38
|
+
## Script Importing
|
39
|
+
|
40
|
+
Library files can be imported directly into configuration blocks via the
|
41
|
+
`#import` method.
|
42
|
+
|
43
|
+
rc.config :example do
|
44
|
+
import "fruitbasket/example.rb"
|
45
|
+
end
|
46
|
+
|
47
|
+
This looks up the file via the `finder` gem and then evals it in the context
|
48
|
+
of the config block.
|
49
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Interface
|
2
|
+
|
3
|
+
The main means of workin with RC's API are the RC class methods,
|
4
|
+
collectively called the Inteface.
|
5
|
+
|
6
|
+
Let's say we have a configuration file `config.rb` containing:
|
7
|
+
|
8
|
+
config :example do
|
9
|
+
"example config"
|
10
|
+
end
|
11
|
+
|
12
|
+
config :example, :profile=>:something do
|
13
|
+
"example config using profile"
|
14
|
+
end
|
15
|
+
|
16
|
+
To get the configuration of the current project --relative to the
|
17
|
+
current working directory, use the `configuration` method.
|
18
|
+
|
19
|
+
RC.configuration
|
20
|
+
|
21
|
+
The configuration properties of the current project can be
|
22
|
+
had via the `properties` method.
|
23
|
+
|
24
|
+
RC.properties
|
25
|
+
|
26
|
+
The profile names can be looked up for any given tool via the `profile_names`
|
27
|
+
method.
|
28
|
+
|
29
|
+
RC.profile_names(:example) #=> ['default', 'something']
|
30
|
+
|
31
|
+
The number of feature configurations in the current project can be
|
32
|
+
had via the `size` method.
|
33
|
+
|
34
|
+
RC.configuration.size #=> 1
|
35
|
+
|
36
|
+
A list of all configuration entries can be had by calling #to_a.
|
37
|
+
|
38
|
+
RC.configuration.to_a.size #=> 2
|
39
|
+
|
data/spec/applique/ae.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ae'
|
data/spec/cov.rb
ADDED
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: courtier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Trans
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: finder
|
16
|
+
requirement: &29133520 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *29133520
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: loaded
|
27
|
+
requirement: &29132980 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *29132980
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: detroit
|
38
|
+
requirement: &29132460 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *29132460
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: qed
|
49
|
+
requirement: &29131940 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *29131940
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: ae
|
60
|
+
requirement: &29131420 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *29131420
|
69
|
+
description: ! 'Courtier is a multi-tenant configuration system for Ruby projects.
|
70
|
+
|
71
|
+
Courtier can configure almost any Ruby tool or library.'
|
72
|
+
email:
|
73
|
+
- transfire@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files:
|
77
|
+
- LICENSE.txt
|
78
|
+
- NOTES.md
|
79
|
+
- HISTORY.md
|
80
|
+
- README.md
|
81
|
+
files:
|
82
|
+
- .ruby
|
83
|
+
- .yardopts
|
84
|
+
- lib/c.rb
|
85
|
+
- lib/courtier/config.rb
|
86
|
+
- lib/courtier/config_filter.rb
|
87
|
+
- lib/courtier/configuration.rb
|
88
|
+
- lib/courtier/core_ext.rb
|
89
|
+
- lib/courtier/interface.rb
|
90
|
+
- lib/courtier/properties.rb
|
91
|
+
- lib/courtier/setup.rb
|
92
|
+
- lib/courtier/tweaks/rake.rb
|
93
|
+
- lib/courtier.rb
|
94
|
+
- lib/rc.rb
|
95
|
+
- spec/00_concept.md
|
96
|
+
- spec/01_config.md
|
97
|
+
- spec/02_configuration.md
|
98
|
+
- spec/03_import.md
|
99
|
+
- spec/06_interface.md
|
100
|
+
- spec/applique/ae.rb
|
101
|
+
- spec/applique/file.rb
|
102
|
+
- spec/applique/fixture/config.rb
|
103
|
+
- spec/applique/fixture.rb
|
104
|
+
- spec/cov.rb
|
105
|
+
- NOTES.md
|
106
|
+
- LICENSE.txt
|
107
|
+
- HISTORY.md
|
108
|
+
- README.md
|
109
|
+
- Config.rb
|
110
|
+
homepage: http://rubyworks.github.com/courtier
|
111
|
+
licenses:
|
112
|
+
- BSD-2-Clause
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 1.8.11
|
132
|
+
signing_key:
|
133
|
+
specification_version: 3
|
134
|
+
summary: The best way to manage your application's configuration.
|
135
|
+
test_files: []
|