captain_planet 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/README.markdown +36 -1
- data/VERSION +1 -1
- data/captain_planet.gemspec +7 -5
- data/lib/captain_planet.rb +4 -4
- data/lib/captain_planet/configurable.rb +25 -0
- data/spec/captain_planet/builder_spec.rb +1 -1
- data/spec/captain_planet/configurable_spec.rb +30 -0
- data/spec/captain_planet/environment_spec.rb +1 -1
- data/spec/captain_planet_spec.rb +0 -3
- metadata +30 -9
data/Gemfile
CHANGED
@@ -1 +0,0 @@
|
|
1
|
-
gem 'dirge'
|
data/README.markdown
CHANGED
@@ -23,4 +23,39 @@ YML sucks. When configs are implemented in YML, a lot of code is written that in
|
|
23
23
|
dev.webdav_mount_root = '/Volumes/www.polleverywhere.com'
|
24
24
|
dev.webdav_url = 'http://www.polleverywhere.com/'
|
25
25
|
end
|
26
|
-
})[ENV['ENV'] || 'development']
|
26
|
+
})[ENV['ENV'] || 'development']
|
27
|
+
|
28
|
+
## It Gets Even better!
|
29
|
+
|
30
|
+
There are some smart defaults for setting up environments in a project. For example, a folder structure typically mimics that like what's found in rails:
|
31
|
+
|
32
|
+
config
|
33
|
+
|- environment.rb
|
34
|
+
|- environments
|
35
|
+
|- production.rb
|
36
|
+
|- development.rb
|
37
|
+
|- test.rb
|
38
|
+
|
39
|
+
Why not mimic that? That's exactly where I thought too. Just define your configuration class and its defaults in your environments.rb file.
|
40
|
+
|
41
|
+
class QTZEnv < CaptainPlanet::Environment
|
42
|
+
attr_accessor :webdav_mount_root, :webdav_url, :polling_interval, :default_permalink
|
43
|
+
|
44
|
+
def initialize
|
45
|
+
self.webdav_mount_root = '/default/'
|
46
|
+
self.webdav_url = 'http://www.com/default/'
|
47
|
+
self.polling_interval = 3.0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Then initialize the Environment with CaptainPlanet and point it at the ./environments folder:
|
52
|
+
|
53
|
+
Environment = CaptainPlanet::Builder.process(QTZEnv, File.join(File.dirname(__FILE__), './environments/*.rb'))[ENV['ENV'] || 'development']
|
54
|
+
|
55
|
+
And finally use anywhere in your application!
|
56
|
+
|
57
|
+
Environment.webdav_mount_root # => '/default/'
|
58
|
+
|
59
|
+
The best part? You get full control over how the environment is bootstrapped, from the defaults to how the environment is specified, and you can configure your application dynamically through the power of the Ruby language.
|
60
|
+
|
61
|
+
Repeat after me, "YAML sucks".
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/captain_planet.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{captain_planet}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brad Gessler"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-03-05}
|
13
13
|
s.description = %q{Captain Planet is a Ruby DSL that makes dealing with Environments much easier.}
|
14
14
|
s.email = %q{brad@bradgessler.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,8 +27,10 @@ Gem::Specification.new do |s|
|
|
27
27
|
"captain_planet.gemspec",
|
28
28
|
"lib/captain_planet.rb",
|
29
29
|
"lib/captain_planet/builder.rb",
|
30
|
+
"lib/captain_planet/configurable.rb",
|
30
31
|
"lib/captain_planet/environment.rb",
|
31
32
|
"spec/captain_planet/builder_spec.rb",
|
33
|
+
"spec/captain_planet/configurable_spec.rb",
|
32
34
|
"spec/captain_planet/environment_spec.rb",
|
33
35
|
"spec/captain_planet_spec.rb",
|
34
36
|
"spec/fixtures/super_app/environment.rb",
|
@@ -51,10 +53,11 @@ Gem::Specification.new do |s|
|
|
51
53
|
s.homepage = %q{http://github.com/bradgessler/captain_planet}
|
52
54
|
s.rdoc_options = ["--charset=UTF-8"]
|
53
55
|
s.require_paths = ["lib"]
|
54
|
-
s.rubygems_version = %q{1.
|
56
|
+
s.rubygems_version = %q{1.4.2}
|
55
57
|
s.summary = %q{DSL for dealing with environments in Ruby projects}
|
56
58
|
s.test_files = [
|
57
59
|
"spec/captain_planet/builder_spec.rb",
|
60
|
+
"spec/captain_planet/configurable_spec.rb",
|
58
61
|
"spec/captain_planet/environment_spec.rb",
|
59
62
|
"spec/captain_planet_spec.rb",
|
60
63
|
"spec/fixtures/super_app/environment.rb",
|
@@ -66,10 +69,9 @@ Gem::Specification.new do |s|
|
|
66
69
|
]
|
67
70
|
|
68
71
|
if s.respond_to? :specification_version then
|
69
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
70
72
|
s.specification_version = 3
|
71
73
|
|
72
|
-
if Gem::Version.new(Gem::
|
74
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
73
75
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
74
76
|
else
|
75
77
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
data/lib/captain_planet.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
require 'dirge'
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
3
2
|
|
4
3
|
module CaptainPlanet
|
5
|
-
autoload :Environment,
|
6
|
-
autoload :Builder,
|
4
|
+
autoload :Environment, 'captain_planet/environment'
|
5
|
+
autoload :Builder, 'captain_planet/builder'
|
6
|
+
autoload :Configurable, 'captain_planet/configurable'
|
7
7
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CaptainPlanet
|
2
|
+
module Configurable
|
3
|
+
def self.included(base)
|
4
|
+
base.send :extend, ClassMethods
|
5
|
+
base.send :include, InstanceMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def attr_configurable(*attrs, &block)
|
13
|
+
attrs.each do |attr|
|
14
|
+
class_variable_set("@@__default_#{attr}", block)
|
15
|
+
|
16
|
+
class_eval %(
|
17
|
+
def #{attr}(val=nil)
|
18
|
+
return @#{attr} || (@@__default_#{attr}.call if @@__default_#{attr}.respond_to?(:call)) unless val
|
19
|
+
@#{attr} = val
|
20
|
+
end)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Configurable do
|
4
|
+
class MyConfig
|
5
|
+
include CaptainPlanet::Configurable
|
6
|
+
|
7
|
+
attr_configurable :color do
|
8
|
+
"red"
|
9
|
+
end
|
10
|
+
attr_configurable(:width, :height) { 100 }
|
11
|
+
end
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
@config = MyConfig.new
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should read and set configurable attributes" do
|
18
|
+
@config.color 'yellow'
|
19
|
+
@config.color.should eql('yellow')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should support default values" do
|
23
|
+
@config.color.should eql('red')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should default multiple attributes" do
|
27
|
+
@config.width.should eql(100)
|
28
|
+
@config.height.should eql(100)
|
29
|
+
end
|
30
|
+
end
|
data/spec/captain_planet_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: captain_planet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Brad Gessler
|
@@ -9,19 +15,25 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2011-03-05 00:00:00 -08:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: rspec
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
23
34
|
version: 1.2.9
|
24
|
-
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
25
37
|
description: Captain Planet is a Ruby DSL that makes dealing with Environments much easier.
|
26
38
|
email: brad@bradgessler.com
|
27
39
|
executables: []
|
@@ -42,8 +54,10 @@ files:
|
|
42
54
|
- captain_planet.gemspec
|
43
55
|
- lib/captain_planet.rb
|
44
56
|
- lib/captain_planet/builder.rb
|
57
|
+
- lib/captain_planet/configurable.rb
|
45
58
|
- lib/captain_planet/environment.rb
|
46
59
|
- spec/captain_planet/builder_spec.rb
|
60
|
+
- spec/captain_planet/configurable_spec.rb
|
47
61
|
- spec/captain_planet/environment_spec.rb
|
48
62
|
- spec/captain_planet_spec.rb
|
49
63
|
- spec/fixtures/super_app/environment.rb
|
@@ -72,26 +86,33 @@ rdoc_options:
|
|
72
86
|
require_paths:
|
73
87
|
- lib
|
74
88
|
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
75
90
|
requirements:
|
76
91
|
- - ">="
|
77
92
|
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
78
96
|
version: "0"
|
79
|
-
version:
|
80
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
81
99
|
requirements:
|
82
100
|
- - ">="
|
83
101
|
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
84
105
|
version: "0"
|
85
|
-
version:
|
86
106
|
requirements: []
|
87
107
|
|
88
108
|
rubyforge_project:
|
89
|
-
rubygems_version: 1.
|
109
|
+
rubygems_version: 1.4.2
|
90
110
|
signing_key:
|
91
111
|
specification_version: 3
|
92
112
|
summary: DSL for dealing with environments in Ruby projects
|
93
113
|
test_files:
|
94
114
|
- spec/captain_planet/builder_spec.rb
|
115
|
+
- spec/captain_planet/configurable_spec.rb
|
95
116
|
- spec/captain_planet/environment_spec.rb
|
96
117
|
- spec/captain_planet_spec.rb
|
97
118
|
- spec/fixtures/super_app/environment.rb
|