rc 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
1
+ module RC
2
+
3
+ # ToolConfiguration encapsulates configurations for a specific tool.
4
+ # It is essentially a subset taken from a project's full set of
5
+ # configurations.
6
+ #
7
+ class ToolConfiguration < Module
8
+ include Enumerable
9
+
10
+ #
11
+ # Initialize new ToolConfiguration.
12
+ #
13
+ # @param [String,Symbol] Tool name.
14
+ #
15
+ # @param [Configuraiton] Project configuration instance.
16
+ #
17
+ def initialize(tool, configuration)
18
+ include configuration
19
+
20
+ @_tool = tool.to_s
21
+ @_list = configuration.select{ |c| c.tool?(tool) }
22
+ end
23
+
24
+ #
25
+ #
26
+ #
27
+ def tool
28
+ @_tool
29
+ end
30
+
31
+ #
32
+ #
33
+ #
34
+ def [](profile)
35
+ @_list.select{ |c| c.profile?(profile) }
36
+ end
37
+
38
+ #
39
+ #
40
+ #
41
+ def each(&block)
42
+ @_list.each(&block)
43
+ end
44
+
45
+ #
46
+ #
47
+ #
48
+ def size
49
+ @_list.size
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,28 @@
1
+ require 'rake'
2
+
3
+ module Rake
4
+ RC_FILES = '.config.rb', 'config.rb', 'Config.rb'
5
+
6
+ class Application
7
+ remove_const(:DEFAULT_RAKEFILES)
8
+ DEFAULT_RAKEFILES = [
9
+ 'rakefile', 'Rakefile', 'rakefile.rb', 'Rakefile.rb',
10
+ ] + RC_FILES
11
+ end
12
+
13
+ def self.load_rakefile(path)
14
+ case File.basename(path)
15
+ when *RC_FILES
16
+ # do nothing, RC will do it
17
+ else
18
+ load(path)
19
+ end
20
+ end
21
+ end
22
+
23
+ module RC
24
+ class Configuration
25
+ include Rake::DSL
26
+ end
27
+ end
28
+
@@ -0,0 +1,22 @@
1
+ = RC
2
+
3
+ The purpose of RC is to provide unified configuration management across multiple
4
+ tools for Ruby. The structure of an RC configuration file is very simple.
5
+ It is a ruby script sectioned into named blocks:
6
+
7
+ config :rake do
8
+ # ... rake tasks ...
9
+ end
10
+
11
+ config :vclog do
12
+ # ... configure vclog ...
13
+ end
14
+
15
+ Utilization of the these configurations may be handled by the consuming
16
+ application, but can be used by any tool if `rc` is loaded via RUBYOPT.
17
+
18
+ To work with RC in this specification, we want to avoid the automatic
19
+ bootstrap, so we load the `interface` script instead.
20
+
21
+ require 'rc/interface'
22
+
@@ -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', 'bar') do
7
+ :baz
8
+ end
9
+
10
+ config.tool #=> :foo
11
+ config.profile #=> :bar
12
+ config.to_proc.call #=> :baz
13
+
14
+
@@ -0,0 +1,65 @@
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.instance_eval(<<-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 #=> nil
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.instance_eval(<<-HERE)
28
+ config :sample2, :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.instance_eval(<<-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
+ RC also support YAML-based configuration, if the last argument is
52
+ a multi-line string it will create a block using `YAML.load`.
53
+
54
+ rc.instance_eval(<<-HERE)
55
+ config :sample3, %{
56
+ ---
57
+ note: This is the note.
58
+ }
59
+ HERE
60
+
61
+ sample = rc.configurations.last
62
+ sample.tool #=> :sample3
63
+ sample.profile #=> nil
64
+ sample.call.assert == {'note'=>'This is the note.'}
65
+
@@ -0,0 +1,48 @@
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.size.assert == 1
13
+
14
+ The configuration can also be imported from a different profile.
15
+
16
+ rc.config :qed, :coverage, :from=>'qed', :profile=>:simplecov
17
+
18
+ rc.size.assert == 2
19
+
20
+ Although it will rarely be useful, it may also be imported from another tool.
21
+
22
+ rc.config :example, :from=>'qed', :tool=>:sample
23
+
24
+ Imported configurations can also be augmented via a block.
25
+
26
+ rc = RC::Configuration.new
27
+
28
+ rc.config :qed, :from=>'qed', :profile=>:simplecov do
29
+ # additional code here
30
+ end
31
+
32
+ rc.size.assert == 2
33
+
34
+ Technically this last form just creates two configurations for the same
35
+ tool and profile, but the ultimate effect is the same.
36
+
37
+ ## Script Importing
38
+
39
+ Library files can be imported directly into configuration blocks via the
40
+ `#import` method.
41
+
42
+ rc.config :example do
43
+ import "fruitbasket/example.rb"
44
+ end
45
+
46
+ This looks up the file via the `finder` gem and then evals it in the context
47
+ of the config block.
48
+
@@ -0,0 +1,36 @@
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, :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, we can 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 `profiles`
27
+ method.
28
+
29
+ RC.profiles(:example)
30
+
31
+ The number of configurations in the current project can be had via
32
+ the `size` method. (This is the number of configurations we have
33
+ defined in our test fixture.)
34
+
35
+ RC.configuration.configurations.size.assert == 2
36
+
@@ -0,0 +1 @@
1
+ require 'ae'
@@ -0,0 +1,8 @@
1
+ require 'rc/interface'
2
+
3
+ When 'configuration file `(((\S+)))` containing' do |slots, text|
4
+ RC.clear! #configurations.clear
5
+ fname = [slots].flatten.first # temporary transition to new QED
6
+ File.open(fname, 'w'){ |f| f << text }
7
+ end
8
+
@@ -0,0 +1,10 @@
1
+ # Setup the fixtures.
2
+
3
+ dir = File.dirname(__FILE__) + '/fixture'
4
+ Dir.entries(dir).each do |file|
5
+ next if file == '.' or file == '..'
6
+ path = File.join(dir, file)
7
+ next if File.directory?(path)
8
+ FileUtils.install(path, Dir.pwd)
9
+ end
10
+
@@ -0,0 +1,16 @@
1
+ # exmaple configuration file
2
+
3
+ config :example do
4
+ "example config"
5
+ end
6
+
7
+ config :example, :yaml, %{
8
+ ---
9
+ note: example text config
10
+ }
11
+
12
+ config :example, :data do |ex|
13
+ ex.name = 'Tommy'
14
+ ex.age = 42
15
+ end
16
+
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Trans
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: finder
16
+ requirement: &8666580 !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: *8666580
25
+ - !ruby/object:Gem::Dependency
26
+ name: detroit
27
+ requirement: &8663120 !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: *8663120
36
+ - !ruby/object:Gem::Dependency
37
+ name: qed
38
+ requirement: &6999260 !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: *6999260
47
+ - !ruby/object:Gem::Dependency
48
+ name: ae
49
+ requirement: &6997500 !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: *6997500
58
+ description: ! "RC is a multi-tenant configuration system for Ruby projects.\nIt is
59
+ a spin-off of the original Confection project with\na simplifed overall design and
60
+ the ability to work with \nalmost any Ruby-based command line tool."
61
+ email:
62
+ - transfire@gmail.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files:
66
+ - LICENSE.txt
67
+ - NOTES.md
68
+ - HISTORY.md
69
+ - README.md
70
+ files:
71
+ - .ruby
72
+ - .yardopts
73
+ - lib/c.rb
74
+ - lib/rc/config.rb
75
+ - lib/rc/configuration.rb
76
+ - lib/rc/core_ext.rb
77
+ - lib/rc/interface.rb
78
+ - lib/rc/properties.rb
79
+ - lib/rc/tool_configuration.rb
80
+ - lib/rc/tweaks/rake.rb
81
+ - lib/rc.rb
82
+ - spec/00_concept.md
83
+ - spec/01_config.md
84
+ - spec/02_configuration.md
85
+ - spec/03_import.md
86
+ - spec/06_interface.md
87
+ - spec/applique/ae.rb
88
+ - spec/applique/file.rb
89
+ - spec/applique/fixture/config.rb
90
+ - spec/applique/fixture.rb
91
+ - NOTES.md
92
+ - LICENSE.txt
93
+ - HISTORY.md
94
+ - README.md
95
+ - Config.rb
96
+ homepage: http://rubyworks.github.com/rc
97
+ licenses:
98
+ - BSD-2-Clause
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.11
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Multi-tenant configuration for Ruby.
121
+ test_files: []