breadboard 0.1.0 → 0.1.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 -1
- data/lib/breadboard.rb +1 -0
- data/lib/breadboard/breadboard.rb +19 -4
- data/spec/lib_specs/breadboard_spec.rb +12 -6
- metadata +29 -9
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
=Introduction
|
2
2
|
|
3
|
-
breadboard.yml is to ActiveResource as database.yml is to ActiveRecord
|
3
|
+
breadboard.yml is to ActiveResource as database.yml is to ActiveRecord, taking the data source configuration out of the models and putting it where it belongs, in a configuration file. If the services you connect your ActiveResource models to depends on your RAILS_ENV, then breadboard is for you.
|
4
4
|
|
5
5
|
=Install
|
6
6
|
|
data/lib/breadboard.rb
CHANGED
@@ -16,9 +16,15 @@ class Breadboard
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def service_for(klass)
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
serv = nil
|
20
|
+
while serv.nil? && klass != ActiveResource::Base do
|
21
|
+
table = klass.to_s.tableize.singularize
|
22
|
+
serv = (@config[table][environment] rescue nil) ||
|
23
|
+
(@config[table]['all'] rescue nil) ||
|
24
|
+
nil
|
25
|
+
klass = klass.superclass
|
26
|
+
end
|
27
|
+
serv ||
|
22
28
|
(@config['default'][environment] rescue nil) ||
|
23
29
|
(@config['default']['all'] rescue nil) ||
|
24
30
|
''
|
@@ -30,7 +36,7 @@ class ActiveResource::Base
|
|
30
36
|
def site_with_breadboard
|
31
37
|
if defined?(BREAD_BOARD)
|
32
38
|
unless @site
|
33
|
-
self.site = BREAD_BOARD.service_for(self
|
39
|
+
self.site = BREAD_BOARD.service_for(self)
|
34
40
|
end
|
35
41
|
@site
|
36
42
|
else
|
@@ -39,5 +45,14 @@ class ActiveResource::Base
|
|
39
45
|
end
|
40
46
|
|
41
47
|
alias_method_chain :site, :breadboard
|
48
|
+
|
49
|
+
def connection_with_breadboard(refresh = false)
|
50
|
+
# setting @connection = nil would trigger Connection.new(site...
|
51
|
+
# @connection is set to nil when calling self.site = 'url' as well
|
52
|
+
@connection = nil
|
53
|
+
connection_without_breadboard
|
54
|
+
end
|
55
|
+
|
56
|
+
alias_method_chain :connection, :breadboard
|
42
57
|
end
|
43
58
|
end
|
@@ -6,7 +6,9 @@ describe Breadboard do
|
|
6
6
|
"default:\n all: http://services.com\n\n" +
|
7
7
|
"article:\n production: http://article.services.com\n\n" +
|
8
8
|
"author:\n development: http://development.author.services.com\n\n" +
|
9
|
-
"book:\n all: http://all.book.services.com"
|
9
|
+
"book:\n all: http://all.book.services.com\n\n" +
|
10
|
+
"genre:\n all: http://all.genre.services.com\n\n" +
|
11
|
+
"sub_genre:\n production: http://all.sub.genre.services.com"
|
10
12
|
end
|
11
13
|
|
12
14
|
describe "#initialize" do
|
@@ -28,11 +30,13 @@ describe Breadboard do
|
|
28
30
|
class Author < ActiveResource::Base; end
|
29
31
|
class Article < ActiveResource::Base; end
|
30
32
|
class Genre < ActiveResource::Base; end
|
33
|
+
class SubGenre < Genre; end
|
31
34
|
define_const "BREAD_BOARD", Breadboard.new(@yml)
|
32
35
|
Book.site.host.should == "all.book.services.com"
|
33
36
|
Author.site.host.should == "development.author.services.com"
|
34
37
|
Article.site.host.should == "services.com"
|
35
|
-
Genre.site.host.should == "services.com"
|
38
|
+
Genre.site.host.should == "all.genre.services.com"
|
39
|
+
SubGenre.site.host.should == "all.genre.services.com"
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
@@ -62,9 +66,11 @@ describe Breadboard do
|
|
62
66
|
end
|
63
67
|
|
64
68
|
it "should return the appropriate service for that class" do
|
65
|
-
@s.service_for(
|
66
|
-
@s.service_for(
|
67
|
-
@s.service_for(
|
69
|
+
@s.service_for(Article).should == 'http://article.services.com'
|
70
|
+
@s.service_for(Author).should == 'http://services.com'
|
71
|
+
@s.service_for(Book).should == 'http://all.book.services.com'
|
72
|
+
@s.service_for(Genre).should == 'http://all.genre.services.com'
|
73
|
+
@s.service_for(SubGenre).should == 'http://all.sub.genre.services.com'
|
68
74
|
end
|
69
75
|
end
|
70
|
-
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breadboard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Matt Parker
|
@@ -10,19 +16,25 @@ autorequire:
|
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
18
|
|
13
|
-
date: 2010-
|
19
|
+
date: 2010-08-11 00:00:00 -04:00
|
14
20
|
default_executable:
|
15
21
|
dependencies:
|
16
22
|
- !ruby/object:Gem::Dependency
|
17
23
|
name: rails
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
21
27
|
requirements:
|
22
28
|
- - ">="
|
23
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 5
|
31
|
+
segments:
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
- 3
|
24
35
|
version: 2.3.3
|
25
|
-
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
26
38
|
description: "Breadboard allows you to define what services your ActiveResource derived classes connect to based on your rails environment. "
|
27
39
|
email: moonmaster9000@gmail.com
|
28
40
|
executables: []
|
@@ -35,6 +47,8 @@ files:
|
|
35
47
|
- README.rdoc
|
36
48
|
- lib/breadboard.rb
|
37
49
|
- lib/breadboard/breadboard.rb
|
50
|
+
- spec/lib_specs/breadboard_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
38
52
|
has_rdoc: true
|
39
53
|
homepage: http://github.com/moonmaster9000/breadboard
|
40
54
|
licenses: []
|
@@ -45,21 +59,27 @@ rdoc_options:
|
|
45
59
|
require_paths:
|
46
60
|
- lib
|
47
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
48
63
|
requirements:
|
49
64
|
- - ">="
|
50
65
|
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
51
69
|
version: "0"
|
52
|
-
version:
|
53
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
54
72
|
requirements:
|
55
73
|
- - ">="
|
56
74
|
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
57
78
|
version: "0"
|
58
|
-
version:
|
59
79
|
requirements: []
|
60
80
|
|
61
81
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.3.
|
82
|
+
rubygems_version: 1.3.7
|
63
83
|
signing_key:
|
64
84
|
specification_version: 3
|
65
85
|
summary: breadboard.yml is to ActiveResource as database.yml is to ActiveRecord
|