confection 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby +43 -0
- data/COPYING.rdoc +31 -0
- data/HISTORY.rdoc +10 -0
- data/README.rdoc +80 -0
- data/lib/confection.rb +139 -0
- metadata +76 -0
data/.ruby
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
source:
|
3
|
+
- profile
|
4
|
+
authors:
|
5
|
+
- name: Trans
|
6
|
+
email: transfire@gmail.com
|
7
|
+
copyrights:
|
8
|
+
- holder: Rubyworks
|
9
|
+
year: '2011'
|
10
|
+
license: BSD-2-Clause
|
11
|
+
replacements: []
|
12
|
+
alternatives: []
|
13
|
+
requirements:
|
14
|
+
- name: detroit
|
15
|
+
groups:
|
16
|
+
- build
|
17
|
+
development: true
|
18
|
+
- name: qed
|
19
|
+
groups:
|
20
|
+
- test
|
21
|
+
development: true
|
22
|
+
dependencies: []
|
23
|
+
conflicts: []
|
24
|
+
repositories:
|
25
|
+
- uri: git://github.com/rubyworks/confection.git
|
26
|
+
scm: git
|
27
|
+
name: upstream
|
28
|
+
resources:
|
29
|
+
home: http://rubyworks.github.com/confection
|
30
|
+
code: http://github.com/rubyworks/confection
|
31
|
+
mail: http://groups.google.com/group/rubyworks-mailinglist
|
32
|
+
extra: {}
|
33
|
+
load_path:
|
34
|
+
- lib
|
35
|
+
revision: 0
|
36
|
+
created: '2011-11-06'
|
37
|
+
summary: Multi-tenant configuration for Ruby
|
38
|
+
title: Confection
|
39
|
+
version: 0.0.1
|
40
|
+
name: confection
|
41
|
+
description: Confection is a multi-tenant configuration system for Ruby projects.
|
42
|
+
organization: Rubyworks
|
43
|
+
date: '2011-11-07'
|
data/COPYING.rdoc
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= COPYRIGHT NOTICES
|
2
|
+
|
3
|
+
== Confection
|
4
|
+
|
5
|
+
Copyright:: (c) 2011 Rubyworks
|
6
|
+
License:: BSD-2-Clause
|
7
|
+
Website:: http://rubyworks.github.com/tapout
|
8
|
+
|
9
|
+
Copyright 2011 Rubyworks. All rights reserved.
|
10
|
+
|
11
|
+
Redistribution and use in source and binary forms, with or without
|
12
|
+
modification, are permitted provided that the following conditions are met:
|
13
|
+
|
14
|
+
1. Redistributions of source code must retain the above copyright notice,
|
15
|
+
this list of conditions and the following disclaimer.
|
16
|
+
|
17
|
+
2. Redistributions in binary form must reproduce the above copyright
|
18
|
+
notice, this list of conditions and the following disclaimer in the
|
19
|
+
documentation and/or other materials provided with the distribution.
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
+
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
+
COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
25
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
26
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
28
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
29
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
30
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
|
data/HISTORY.rdoc
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
= Confection
|
2
|
+
|
3
|
+
{Homepage}[http://rubyworks.github.com/confection] |
|
4
|
+
{Source Code}[http://github.com/rubyworks/confection] |
|
5
|
+
{Mailing List}[http://googlegroups.com/group/rubyworks-mailinglist]
|
6
|
+
|
7
|
+
{<img src="http://travis-ci.org/rubyworks/confection.png" />}[http://travis-ci.org/rubyworks/confection]
|
8
|
+
|
9
|
+
|
10
|
+
== Description
|
11
|
+
|
12
|
+
Confection is multi-tenant configuration system for Ruby projects. If was
|
13
|
+
designed to faciliate Ruby-based configuration for multiple tools in a
|
14
|
+
single file. If is extremely simple, which makes it easy to understand
|
15
|
+
and flexible in use.
|
16
|
+
|
17
|
+
|
18
|
+
== Synopsis
|
19
|
+
|
20
|
+
Create a file in you project called `.co.rb`. In it, add configuration blocks
|
21
|
+
by name. As an example let's demonstrate how we could use this for Rake tasks.
|
22
|
+
|
23
|
+
$ cat .co.rb
|
24
|
+
rake do
|
25
|
+
desc 'generate yard docs'
|
26
|
+
task :yard do
|
27
|
+
sh 'yard'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
In our Rakefile:
|
32
|
+
|
33
|
+
$ cat Rakefile
|
34
|
+
require 'confection'
|
35
|
+
confection(:rake).call
|
36
|
+
|
37
|
+
Now you might wonder why the heck you would do this. That's where the
|
38
|
+
*multi-tenancy* comes into play. Let's add another configuration. This time
|
39
|
+
for a tool that has native support for Confection.
|
40
|
+
|
41
|
+
$ cat .confection
|
42
|
+
title = "myapp"
|
43
|
+
|
44
|
+
rake do
|
45
|
+
desc 'generate yard docs'
|
46
|
+
task :yard do
|
47
|
+
sh "yard doc --title #{title}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
qed do |config|
|
52
|
+
config.title = "#{title} Demonstrandum"
|
53
|
+
end
|
54
|
+
|
55
|
+
Now we have configuration for both the rake tool and the qed test tool in
|
56
|
+
a single file. Thus we gain the advantage of reducing the file count of our
|
57
|
+
project while pulling our project configuration together into one place.
|
58
|
+
Moreover, these configurations can potentially share settings as demonstrated
|
59
|
+
here via the `TITLE` constant.
|
60
|
+
|
61
|
+
Using Confection in your libraries is very simele. As you can see from our
|
62
|
+
example Rakefile the #confection method is used to get a handle on a name
|
63
|
+
configuration. With it you have two options, `#call` or `#exec`. The first
|
64
|
+
evaluates the configuration block at the toplevel, while the later evaluates
|
65
|
+
the block in the context of the caller.
|
66
|
+
|
67
|
+
|
68
|
+
== Release Notes
|
69
|
+
|
70
|
+
Please see HISTORY.rdoc file.
|
71
|
+
|
72
|
+
|
73
|
+
== Copyrights
|
74
|
+
|
75
|
+
Copyright (c) 2011 Rubyworks
|
76
|
+
|
77
|
+
Confection is distributable in accordance with the terms of the BSD-2-Clause license.
|
78
|
+
|
79
|
+
See COPYING.rdoc for detiails.
|
80
|
+
|
data/lib/confection.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
# Welcome to Confection. Your easy means to tool configuration.
|
2
|
+
#
|
3
|
+
module Confection
|
4
|
+
|
5
|
+
#
|
6
|
+
FILENAMES = ['.config.rb', 'config.rb']
|
7
|
+
|
8
|
+
# Bootstrap the system, loading current configurations.
|
9
|
+
#
|
10
|
+
def self.bootstrap
|
11
|
+
begin
|
12
|
+
::Kernel.eval(read, Evaluator.binding, file)
|
13
|
+
rescue => e
|
14
|
+
raise e if $DEBUG
|
15
|
+
abort e.message
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Stores the configuration blocks.
|
20
|
+
#
|
21
|
+
# @return [Hash] configuration store
|
22
|
+
def self.config
|
23
|
+
@config ||= {}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Look-up configuration block.
|
27
|
+
#
|
28
|
+
# @param name [Symbol,String]
|
29
|
+
# The identifying name for the config block.
|
30
|
+
#
|
31
|
+
def self.[](name)
|
32
|
+
config[name.to_sym]
|
33
|
+
end
|
34
|
+
|
35
|
+
# Set configuration block.
|
36
|
+
#
|
37
|
+
# @param name [Symbol,String]
|
38
|
+
# The identifying name for the config block.
|
39
|
+
#
|
40
|
+
# @param block [Proc]
|
41
|
+
# Code block for configuration.
|
42
|
+
#
|
43
|
+
# @return [Proc] code block
|
44
|
+
def self.[]=(name, block)
|
45
|
+
config[name.to_sym] = block.to_proc
|
46
|
+
end
|
47
|
+
|
48
|
+
# Read config file.
|
49
|
+
#
|
50
|
+
# @return [String] contents of the `.co.rb` file
|
51
|
+
def self.read
|
52
|
+
File.read(file)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Find config file by looking up the '.co.rb' file.
|
56
|
+
#
|
57
|
+
# @param dir [String]
|
58
|
+
# Optional directory to begin search.
|
59
|
+
#
|
60
|
+
# @return [String] file path
|
61
|
+
def self.file(dir=nil)
|
62
|
+
@file ||= (
|
63
|
+
file = nil
|
64
|
+
dir = dir || Dir.pwd
|
65
|
+
while dir != '/'
|
66
|
+
FILENAMES.each do |fname|
|
67
|
+
f = File.join(dir, fname)
|
68
|
+
break(file = f) if File.exist?(f)
|
69
|
+
end
|
70
|
+
dir = File.dirname(dir)
|
71
|
+
end
|
72
|
+
file
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Root directory, where config file is located.
|
77
|
+
#
|
78
|
+
# @param dir [String]
|
79
|
+
# Optional directory to begin search.
|
80
|
+
#
|
81
|
+
# @return [String] directory path
|
82
|
+
def self.root(dir=nil)
|
83
|
+
f = file(dir)
|
84
|
+
f ? File.dirname(f) : nil
|
85
|
+
end
|
86
|
+
|
87
|
+
# The Evaluator class is used to evaluate the `.co.rb` file.
|
88
|
+
#
|
89
|
+
class Evaluator < Module #BasicObject
|
90
|
+
def self.binding
|
91
|
+
new.__binding__
|
92
|
+
end
|
93
|
+
def __binding__
|
94
|
+
::Kernel.binding
|
95
|
+
end
|
96
|
+
def method_missing(sym, *args, &block)
|
97
|
+
#def block.call
|
98
|
+
# ::Kernel.eval('self',::TOPLEVEL_BINDING).instance_exec(&self)
|
99
|
+
#end
|
100
|
+
::Confection[sym] = block
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# The Controller class is used to encapsulate the two types of invocation
|
105
|
+
# that are posible on configuration blocks.
|
106
|
+
#
|
107
|
+
class Controller
|
108
|
+
def initialize(block, &exec_block)
|
109
|
+
@block = block
|
110
|
+
@exec_block = exec_block
|
111
|
+
end
|
112
|
+
def exec(*args)
|
113
|
+
@exec_block.call(*args)
|
114
|
+
end
|
115
|
+
def call(*args)
|
116
|
+
::Kernel.eval('self',::TOPLEVEL_BINDING).instance_exec(*args, &@block)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
# Confection's primary use method.
|
123
|
+
#
|
124
|
+
# @return [Confection::Controller] config controller
|
125
|
+
def confection(name, *args)
|
126
|
+
config_block = Confection[name.to_sym]
|
127
|
+
if config_block
|
128
|
+
Confection::Controller.new(config_block) do |*args|
|
129
|
+
instance_exec *args, &config_block
|
130
|
+
end
|
131
|
+
else
|
132
|
+
warn "no configuration -- `#{name}'"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# Load configuration.
|
137
|
+
Confection.bootstrap #(self)
|
138
|
+
|
139
|
+
# Copyright (c) 2011 Rubyworks (BSD-2-Clause)
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: confection
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Trans
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: detroit
|
16
|
+
requirement: &26027680 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *26027680
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: qed
|
27
|
+
requirement: &26026820 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *26026820
|
36
|
+
description: Confection is a multi-tenant configuration system for Ruby projects.
|
37
|
+
email:
|
38
|
+
- transfire@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files:
|
42
|
+
- HISTORY.rdoc
|
43
|
+
- README.rdoc
|
44
|
+
- COPYING.rdoc
|
45
|
+
files:
|
46
|
+
- .ruby
|
47
|
+
- lib/confection.rb
|
48
|
+
- HISTORY.rdoc
|
49
|
+
- README.rdoc
|
50
|
+
- COPYING.rdoc
|
51
|
+
homepage: http://rubyworks.github.com/confection
|
52
|
+
licenses:
|
53
|
+
- BSD-2-Clause
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.10
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Multi-tenant configuration for Ruby
|
76
|
+
test_files: []
|