confection 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby +3 -3
- data/HISTORY.rdoc +19 -2
- data/README.rdoc +18 -15
- data/lib/confection.rb +53 -35
- data/lib/confection/basic_object.rb +2 -2
- metadata +8 -8
data/.ruby
CHANGED
@@ -28,7 +28,7 @@ repositories:
|
|
28
28
|
name: upstream
|
29
29
|
resources:
|
30
30
|
home: http://rubyworks.github.com/confection
|
31
|
-
docs: http://rubydoc.info/gems/confection
|
31
|
+
docs: http://rubydoc.info/gems/confection/frames
|
32
32
|
code: http://github.com/rubyworks/confection
|
33
33
|
mail: http://groups.google.com/group/rubyworks-mailinglist
|
34
34
|
extra: {}
|
@@ -38,8 +38,8 @@ revision: 0
|
|
38
38
|
created: '2011-11-06'
|
39
39
|
summary: Multi-tenant configuration for Ruby
|
40
40
|
title: Confection
|
41
|
-
version: 0.0
|
41
|
+
version: 0.1.0
|
42
42
|
name: confection
|
43
43
|
description: Confection is a multi-tenant configuration system for Ruby projects.
|
44
44
|
organization: Rubyworks
|
45
|
-
date: '2011-11-
|
45
|
+
date: '2011-11-17'
|
data/HISTORY.rdoc
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
= RELEASE HISTORY
|
2
2
|
|
3
|
-
== 0.0
|
3
|
+
== 0.1.0 | 2011-11-17
|
4
|
+
|
5
|
+
This major release, probably the first truly usable release,
|
6
|
+
adds support for multiple configration files by storing them
|
7
|
+
on a per working directory basis, renames the default config
|
8
|
+
file name to `.confile` or `confile` with or without an optional
|
9
|
+
`.rb` extension, and adds a class method for changing the file
|
10
|
+
name (though using the global variable still works if needed).
|
11
|
+
|
12
|
+
Changes:
|
13
|
+
|
14
|
+
* Configuration file default is '{.,}confile{.rb,}'.
|
15
|
+
* Default can be changed via class method or global.
|
16
|
+
* Configrations are stored per-working directory, to
|
17
|
+
support multiple configurations at once.
|
18
|
+
|
19
|
+
|
20
|
+
== 0.0.2 | 2011-11-07
|
4
21
|
|
5
22
|
You can now use $CONFIG_FILE to change the default config file.
|
6
23
|
Just set the variable prior to using confection. Confection
|
@@ -13,7 +30,7 @@ Changes:
|
|
13
30
|
* Add $CONFIG_FILE to allow default config file to be adjusted.
|
14
31
|
|
15
32
|
|
16
|
-
== 0.0.1
|
33
|
+
== 0.0.1 | 2011-11-06
|
17
34
|
|
18
35
|
This is the initial release of Confection.
|
19
36
|
|
data/README.rdoc
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
{Homepage}[http://rubyworks.github.com/confection] |
|
4
4
|
{Source Code}[http://github.com/rubyworks/confection] |
|
5
|
+
{Report Issue}[http://github.com/rubyworks/confection/issues] |
|
5
6
|
{Mailing List}[http://googlegroups.com/group/rubyworks-mailinglist]
|
6
7
|
|
7
8
|
{<img src="http://travis-ci.org/rubyworks/confection.png" />}[http://travis-ci.org/rubyworks/confection]
|
@@ -10,17 +11,19 @@
|
|
10
11
|
== Description
|
11
12
|
|
12
13
|
Confection is multi-tenant configuration system for Ruby projects. If was
|
13
|
-
designed to
|
14
|
-
single file.
|
14
|
+
designed to facilitate Ruby-based configuration for multiple tools in a
|
15
|
+
single file. It is extremely simple, which makes it easy to understand
|
15
16
|
and flexible in use.
|
16
17
|
|
17
18
|
|
18
19
|
== Synopsis
|
19
20
|
|
20
|
-
Create a file in you project called `
|
21
|
-
|
21
|
+
Create a file in you project called `Confile`. By default the file can have any
|
22
|
+
name tha matches the glob `{.,}confile{.rb,}` case insensitive. In this file
|
23
|
+
add configuration blocks by name. For example, let's demonstrate how we could
|
24
|
+
use this to configure Rake tasks.
|
22
25
|
|
23
|
-
$ cat
|
26
|
+
$ cat Confile
|
24
27
|
rake do
|
25
28
|
desc 'generate yard docs'
|
26
29
|
task :yard do
|
@@ -34,11 +37,11 @@ In our Rakefile:
|
|
34
37
|
require 'confection'
|
35
38
|
confection(:rake).call
|
36
39
|
|
37
|
-
Now you might wonder why the heck you would do this. That's where the
|
38
|
-
|
39
|
-
|
40
|
+
Now you might wonder why the heck you would do this. That's where the *multi-tenancy*
|
41
|
+
comes into play. Let's add another configuration, and this time for a tool that has
|
42
|
+
native support for Confection.
|
40
43
|
|
41
|
-
$ cat
|
44
|
+
$ cat Confile
|
42
45
|
title = "myapp"
|
43
46
|
|
44
47
|
rake do
|
@@ -54,12 +57,12 @@ for a tool that has native support for Confection.
|
|
54
57
|
|
55
58
|
Now we have configuration for both the rake tool and the qed test tool in
|
56
59
|
a single file. Thus we gain the advantage of reducing the file count of our
|
57
|
-
project while pulling our
|
60
|
+
project while pulling our tool configurations together into one place.
|
58
61
|
Moreover, these configurations can potentially share settings as demonstrated
|
59
|
-
here via the `
|
62
|
+
here via the `title` variable.
|
60
63
|
|
61
|
-
Using Confection in your libraries is very
|
62
|
-
example Rakefile
|
64
|
+
Using Confection in your libraries is very simple. As you can see from our
|
65
|
+
example Rakefile. The `#confection` method is used to get a handle on a named
|
63
66
|
configuration. With it you have two options, `#call` or `#exec`. The first
|
64
67
|
evaluates the configuration block at the toplevel, while the later evaluates
|
65
68
|
the block in the context of the caller.
|
@@ -74,7 +77,7 @@ Please see HISTORY.rdoc file.
|
|
74
77
|
|
75
78
|
Copyright (c) 2011 Rubyworks
|
76
79
|
|
77
|
-
Confection is distributable in accordance with the terms of the BSD-2-Clause license.
|
80
|
+
Confection is distributable in accordance with the terms of the *BSD-2-Clause* license.
|
78
81
|
|
79
|
-
See COPYING.rdoc for
|
82
|
+
See COPYING.rdoc for details.
|
80
83
|
|
data/lib/confection.rb
CHANGED
@@ -5,30 +5,45 @@ require 'confection/basic_object'
|
|
5
5
|
module Confection
|
6
6
|
|
7
7
|
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
@config = Hash.new{|h,k| h[k]={}}
|
9
|
+
|
10
|
+
#
|
11
|
+
def self.filename
|
12
|
+
@filename ||= (
|
13
|
+
$CONFIG_FILE ? $CONFIG_FILE : '{.,}confile{.rb,}'
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Configuration file can be changed using this method.
|
18
|
+
# Alternatively it can be changed using `$CONFIG_FILE`.
|
19
|
+
def self.filename=(glob)
|
20
|
+
@filename = glob
|
12
21
|
end
|
13
22
|
|
14
23
|
# Bootstrap the system, loading current configurations.
|
15
24
|
#
|
16
25
|
def self.bootstrap
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
26
|
+
if file
|
27
|
+
@config[Dir.pwd] = {}
|
28
|
+
begin
|
29
|
+
::Kernel.eval(read, Evaluator.binding, file)
|
30
|
+
rescue => e
|
31
|
+
raise e if $DEBUG
|
32
|
+
warn e.message
|
33
|
+
end
|
23
34
|
end
|
24
|
-
@config
|
35
|
+
@config[Dir.pwd]
|
25
36
|
end
|
26
37
|
|
27
38
|
# Stores the configuration blocks.
|
28
39
|
#
|
29
40
|
# @return [Hash] configuration store
|
30
41
|
def self.config
|
31
|
-
@config
|
42
|
+
if @config.key?(Dir.pwd)
|
43
|
+
@config[Dir.pwd]
|
44
|
+
else
|
45
|
+
bootstrap
|
46
|
+
end
|
32
47
|
end
|
33
48
|
|
34
49
|
# Look-up configuration block.
|
@@ -55,30 +70,26 @@ module Confection
|
|
55
70
|
|
56
71
|
# Read config file.
|
57
72
|
#
|
58
|
-
# @return [String] contents of the `.
|
73
|
+
# @return [String] contents of the `.conf.rb` file
|
59
74
|
def self.read
|
60
75
|
File.read(file)
|
61
76
|
end
|
62
77
|
|
63
|
-
# Find config file by looking up the '.
|
78
|
+
# Find config file by looking up the '.conf.rb' file.
|
64
79
|
#
|
65
80
|
# @param dir [String]
|
66
81
|
# Optional directory to begin search.
|
67
82
|
#
|
68
83
|
# @return [String] file path
|
69
84
|
def self.file(dir=nil)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
FILENAMES.each do |fname|
|
75
|
-
f = File.join(dir, fname)
|
76
|
-
break(file = f) if File.exist?(f)
|
77
|
-
end
|
78
|
-
dir = File.dirname(dir)
|
85
|
+
dir = dir || Dir.pwd
|
86
|
+
while dir != '/'
|
87
|
+
if file = Dir.glob(File.join(dir,filename),File::FNM_CASEFOLD).first
|
88
|
+
return file
|
79
89
|
end
|
80
|
-
|
81
|
-
|
90
|
+
dir = File.dirname(dir)
|
91
|
+
end
|
92
|
+
nil
|
82
93
|
end
|
83
94
|
|
84
95
|
# Root directory, where config file is located.
|
@@ -99,7 +110,7 @@ module Confection
|
|
99
110
|
new.__binding__
|
100
111
|
end
|
101
112
|
def __binding__
|
102
|
-
|
113
|
+
binding
|
103
114
|
end
|
104
115
|
def method_missing(sym, *args, &block)
|
105
116
|
#def block.call
|
@@ -113,18 +124,26 @@ module Confection
|
|
113
124
|
# that are posible on configuration blocks.
|
114
125
|
#
|
115
126
|
class Controller
|
116
|
-
def initialize(
|
117
|
-
@
|
118
|
-
@
|
127
|
+
def initialize(scope, &block)
|
128
|
+
@scope = scope
|
129
|
+
@block = block
|
119
130
|
end
|
120
|
-
def exec(*args)
|
121
|
-
@
|
131
|
+
def exec(*args) # should this be named #call instead?
|
132
|
+
@scope.instance_exec(*args, &@block)
|
122
133
|
end
|
123
134
|
def call(*args)
|
124
135
|
::Kernel.eval('self',::TOPLEVEL_BINDING).instance_exec(*args, &@block)
|
125
136
|
end
|
137
|
+
def to_proc
|
138
|
+
@block
|
139
|
+
end
|
126
140
|
end
|
127
141
|
|
142
|
+
class NullController
|
143
|
+
def exec(*); end
|
144
|
+
def call(*); end
|
145
|
+
def to_proc; Proc.new{}; end
|
146
|
+
end
|
128
147
|
end
|
129
148
|
|
130
149
|
# Confection's primary use method.
|
@@ -133,11 +152,10 @@ end
|
|
133
152
|
def confection(name, *args)
|
134
153
|
config_block = Confection[name.to_sym]
|
135
154
|
if config_block
|
136
|
-
Confection::Controller.new(config_block)
|
137
|
-
instance_exec *args, &config_block
|
138
|
-
end
|
155
|
+
Confection::Controller.new(self, &config_block)
|
139
156
|
else
|
140
|
-
warn "no configuration -- `#{name}'"
|
157
|
+
#warn "no configuration -- `#{name}'"
|
158
|
+
Confection::NullController.new
|
141
159
|
end
|
142
160
|
end
|
143
161
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: confection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: blankslate
|
16
|
-
requirement: &
|
16
|
+
requirement: &26062180 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *26062180
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: detroit
|
27
|
-
requirement: &
|
27
|
+
requirement: &26077440 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *26077440
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: qed
|
38
|
-
requirement: &
|
38
|
+
requirement: &26076620 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *26076620
|
47
47
|
description: Confection is a multi-tenant configuration system for Ruby projects.
|
48
48
|
email:
|
49
49
|
- transfire@gmail.com
|