breadboard 0.0.1
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/README.rdoc +1 -0
- data/lib/breadboard.rb +3 -0
- data/lib/breadboard/breadboard.rb +35 -0
- data/spec/lib_specs/breadboard_spec.rb +70 -0
- data/spec/spec_helper.rb +11 -0
- metadata +68 -0
data/README.rdoc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
breadboard.yml is to ActiveResource as database.yml is to ActiveRecord
|
data/lib/breadboard.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
class Breadboard
|
2
|
+
attr_reader :config
|
3
|
+
|
4
|
+
class EnvironmentUnknownError < StandardError; end
|
5
|
+
|
6
|
+
def initialize(config_yml)
|
7
|
+
@config = YAML.load config_yml
|
8
|
+
configure_services
|
9
|
+
end
|
10
|
+
|
11
|
+
def environment
|
12
|
+
begin
|
13
|
+
RAILS_ENV
|
14
|
+
rescue
|
15
|
+
raise EnvironmentUnknownError, "RAILS_ENV environment unknown"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def service_for(klass)
|
20
|
+
klass = klass.downcase
|
21
|
+
(@config[klass][environment] rescue nil) ||
|
22
|
+
(@config[klass]['all'] rescue nil) ||
|
23
|
+
(@config['default'][environment] rescue nil) ||
|
24
|
+
(@config['default']['all'] rescue nil) ||
|
25
|
+
''
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def configure_services
|
30
|
+
classes = ActiveResource::Base.send(:subclasses)
|
31
|
+
classes.each do |klass|
|
32
|
+
klass.constantize.site = service_for(klass)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Breadboard do
|
4
|
+
before do
|
5
|
+
@yml =
|
6
|
+
"default:\n all: http://services.com\n\n" +
|
7
|
+
"article:\n production: http://article.services.com\n\n" +
|
8
|
+
"author:\n development: http://development.author.services.com\n\n" +
|
9
|
+
"book:\n all: http://all.book.services.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#initialize" do
|
13
|
+
it "should accept a yml file string" do
|
14
|
+
proc { Breadboard.new(@yml) }.should_not raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should require that the yml be valid" do
|
18
|
+
proc { Breadboard.new(true) }.should raise_error
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should parse the configuration and store it internally" do
|
22
|
+
Breadboard.new(@yml).config["default"]["all"].should == "http://services.com"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should configure any ActiveResource::Base derived class with the appropriate site" do
|
26
|
+
define_const "RAILS_ENV", "development"
|
27
|
+
class Book < ActiveResource::Base; end
|
28
|
+
class Author < ActiveResource::Base; end
|
29
|
+
class Article < ActiveResource::Base; end
|
30
|
+
class Genre < ActiveResource::Base; end
|
31
|
+
Breadboard.new(@yml)
|
32
|
+
Book.site.host.should == "all.book.services.com"
|
33
|
+
Author.site.host.should == "development.author.services.com"
|
34
|
+
Article.site.host.should == "services.com"
|
35
|
+
Genre.site.host.should == "services.com"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#environment" do
|
40
|
+
before do
|
41
|
+
define_const "RAILS_ENV", 'breadboard_test'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return the rails environment if it is set" do
|
45
|
+
Breadboard.new(@yml).environment.should == 'breadboard_test'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return UNKNOWN_ENVIRONMENT if the rails environment isn't set" do
|
49
|
+
undefine_const "RAILS_ENV"
|
50
|
+
proc {Breadboard.new(@yml).environment}.should raise_error(Breadboard::EnvironmentUnknownError)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#service_for" do
|
55
|
+
before do
|
56
|
+
@s = Breadboard.new(@yml)
|
57
|
+
define_const "RAILS_ENV", 'production'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should require a class name" do
|
61
|
+
proc { @s.service_for }.should raise_error(ArgumentError)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return the appropriate service for that class" do
|
65
|
+
@s.service_for('Article').should == 'http://article.services.com'
|
66
|
+
@s.service_for('Author').should == 'http://services.com'
|
67
|
+
@s.service_for('Book').should == 'http://all.book.services.com'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift './lib'
|
2
|
+
require 'breadboard'
|
3
|
+
|
4
|
+
def define_const(const, value)
|
5
|
+
Object.send(:remove_const, const.to_sym) if Object.send(:const_defined?, const.to_sym)
|
6
|
+
Object.send :const_set, const, value
|
7
|
+
end
|
8
|
+
|
9
|
+
def undefine_const(const)
|
10
|
+
Object.send :remove_const, const.to_sym if Object.send(:const_defined?, const.to_sym)
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: breadboard
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Parker
|
8
|
+
- Steve Koppelman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2010-01-21 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rails
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.3.3
|
25
|
+
version:
|
26
|
+
description: "Breadboard allows you to define what services your ActiveResource derived classes connect to based on your rails environment. "
|
27
|
+
email: moonmaster9000@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- README.rdoc
|
36
|
+
- lib/breadboard.rb
|
37
|
+
- lib/breadboard/breadboard.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/moonmaster9000/breadboard
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --charset=UTF-8
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.3.5
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: breadboard.yml is to ActiveResource as database.yml is to ActiveRecord
|
66
|
+
test_files:
|
67
|
+
- spec/lib_specs/breadboard_spec.rb
|
68
|
+
- spec/spec_helper.rb
|