breadboard 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/breadboard.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  require 'active_resource'
2
2
  require 'breadboard/breadboard'
3
- Breadboard.new((File.open(RAILS_ROOT + "/config/breadboard.yml") rescue "")) if defined?(RAILS_ROOT)
3
+ BREAD_BOARD = Breadboard.new((File.open(RAILS_ROOT + "/config/breadboard.yml") rescue "")) if defined?(RAILS_ROOT)
@@ -5,7 +5,6 @@ class Breadboard
5
5
 
6
6
  def initialize(config_yml)
7
7
  @config = YAML.load config_yml
8
- configure_services
9
8
  end
10
9
 
11
10
  def environment
@@ -24,12 +23,21 @@ class Breadboard
24
23
  (@config['default']['all'] rescue nil) ||
25
24
  ''
26
25
  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) if klass.constantize.site == nil
26
+ end
27
+
28
+ class ActiveResource::Base
29
+ class << self
30
+ def site_with_breadboard
31
+ if defined?(BREAD_BOARD)
32
+ unless @site
33
+ self.site = BREAD_BOARD.service_for(self.to_s)
34
+ end
35
+ @site
36
+ else
37
+ self.site_without_breadboard
38
+ end
33
39
  end
40
+
41
+ alias_method_chain :site, :breadboard
34
42
  end
35
- end
43
+ end
@@ -28,7 +28,7 @@ describe Breadboard do
28
28
  class Author < ActiveResource::Base; end
29
29
  class Article < ActiveResource::Base; end
30
30
  class Genre < ActiveResource::Base; end
31
- Breadboard.new(@yml)
31
+ define_const "BREAD_BOARD", Breadboard.new(@yml)
32
32
  Book.site.host.should == "all.book.services.com"
33
33
  Author.site.host.should == "development.author.services.com"
34
34
  Article.site.host.should == "services.com"
@@ -67,4 +67,4 @@ describe Breadboard do
67
67
  @s.service_for('Book').should == 'http://all.book.services.com'
68
68
  end
69
69
  end
70
- end
70
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breadboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Parker