breadboard 1.0.0.alpha.1 → 1.0.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  *.sw?
2
2
  pkg/*
3
3
  *.gemspec
4
+ *.gem
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ v1.0.0.alpha.2
2
+ Bug fix: site in breadboard wasn't getting parsed
3
+
4
+ v1.0.0.alpha.1
5
+ Complete rewrite. You now configure Breadboard through a Ruby DSL.
6
+
1
7
  v0.2.0
2
8
  Rails 3 compatible! thx Dorren Chen!
3
9
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha.1
1
+ 1.0.0.alpha.2
@@ -59,4 +59,4 @@ Feature: ActiveResource::Base looks up site config in breadboard
59
59
  And an empty Breadboard configuration
60
60
  And my Rails environment is "production"
61
61
  When I call the model's site method
62
- Then I should recieve an empty string
62
+ Then I should recieve nil
@@ -137,15 +137,15 @@ Given /^my Rails environment is "([^"]*)"$/ do |environment|
137
137
  end
138
138
 
139
139
  Then /^I should recieve the value configured in the Breadboard "([^"]*)" environment settings for that model$/ do |environment|
140
- NoSiteAttribute.site.to_s.should == Breadboard.config.NoSiteAttribute.send(environment.to_sym)
140
+ NoSiteAttribute.site.should == Breadboard.config.NoSiteAttribute.send(environment.to_sym)
141
141
  end
142
142
 
143
143
  Then /^I should recieve the value configured in the Breadboard "([^"]*)" environment settings for the ancestor of that model$/ do |environment|
144
- NoSiteAttribute.site.to_s.should == Breadboard.config.Parent.send(environment.to_sym)
144
+ NoSiteAttribute.site.should == Breadboard.config.Parent.send(environment.to_sym)
145
145
  end
146
146
 
147
147
  Then /^I should recieve the value configured in the Breadboard "([^"]*)" environment settings in the breadboard defaults section$/ do |environment|
148
- NoSiteAttribute.site.to_s.should == Breadboard.config.default.send(environment.to_sym)
148
+ NoSiteAttribute.site.should == Breadboard.config.default.send(environment.to_sym)
149
149
  end
150
150
 
151
151
  Then /^ActiveResource should ignore more generic configurations in Breadboard$/ do
@@ -154,6 +154,6 @@ end
154
154
  Given /^an empty Breadboard configuration$/ do
155
155
  end
156
156
 
157
- Then /^I should recieve an empty string$/ do
158
- NoSiteAttribute.site.to_s.should be_empty
157
+ Then /^I should recieve nil$/ do
158
+ NoSiteAttribute.site.should be_nil
159
159
  end
@@ -17,8 +17,8 @@ Then /^I should be able to configure breadboard via Ruby blocks$/ do
17
17
  end
18
18
  end
19
19
 
20
- Breadboard.config.default.all.should == "http://localhost:3000"
21
- Breadboard.config.default.production.should == "http://test.com"
20
+ Breadboard.config.default.all.to_s.should == "http://localhost:3000"
21
+ Breadboard.config.default.production.to_s.should == "http://test.com"
22
22
  end
23
23
 
24
24
  Then /^I should be able to create a default configuration via the "default" Config method$/ do
@@ -31,8 +31,8 @@ Then /^I should be able to create a default configuration via the "default" Conf
31
31
  end
32
32
  end
33
33
 
34
- Breadboard.config.default.all.should == "http://localhost:3000"
35
- Breadboard.config.default.production.should == "http://test.com"
34
+ Breadboard.config.default.all.to_s.should == "http://localhost:3000"
35
+ Breadboard.config.default.production.to_s.should == "http://test.com"
36
36
  end
37
37
 
38
38
  Then /^I should be able to configure models via their lowercased, underscored method equivalents$/ do
@@ -40,11 +40,11 @@ Then /^I should be able to configure models via their lowercased, underscored me
40
40
 
41
41
  Breadboard.configure do
42
42
  article do
43
- production "haha"
43
+ production "http://haha"
44
44
  end
45
45
  end
46
46
 
47
- Breadboard.config.Article.production.should == "haha"
47
+ Breadboard.config.Article.production.to_s.should == "http://haha"
48
48
  end
49
49
 
50
50
  Then /^I should be able to configure a model by passing the constant for the model to the "model" method$/ do
@@ -52,11 +52,11 @@ Then /^I should be able to configure a model by passing the constant for the mod
52
52
 
53
53
  Breadboard.configure do
54
54
  model Smarticle do
55
- production "haha"
55
+ production "http://haha"
56
56
  end
57
57
  end
58
58
 
59
- Breadboard.config.Smarticle.production.should == "haha"
59
+ Breadboard.config.Smarticle.production.to_s.should == "http://haha"
60
60
  end
61
61
 
62
62
  Then /^I should be able to configure multiple models simultaneously by passing their constants to the "models" method$/ do
@@ -65,12 +65,12 @@ Then /^I should be able to configure multiple models simultaneously by passing t
65
65
 
66
66
  Breadboard.configure do
67
67
  models Particle, Yarticle do
68
- production "haha"
68
+ production "http://haha"
69
69
  end
70
70
  end
71
71
 
72
- Breadboard.config.Particle.production.should == "haha"
73
- Breadboard.config.Yarticle.production.should == "haha"
72
+ Breadboard.config.Particle.production.to_s.should == "http://haha"
73
+ Breadboard.config.Yarticle.production.to_s.should == "http://haha"
74
74
  end
75
75
 
76
76
  Then /^I should be able to override the default Rails\.env environment retrieval in case I'm not in a rails app$/ do
@@ -7,7 +7,7 @@ Given /^I have configured breadboard$/ do
7
7
  end
8
8
 
9
9
  When /^I call the method Breadboard\.reset$/ do
10
- Breadboard.config.default.all.should == "http://test.com"
10
+ Breadboard.config.default.all.to_s.should == "http://test.com"
11
11
  Breadboard.reset
12
12
  end
13
13
 
@@ -7,12 +7,12 @@ module Breadboard
7
7
 
8
8
  def test(url=nil)
9
9
  return @environments[:test] if url.nil?
10
- @environments[:test] = url
10
+ @environments[:test] = URI.parse url
11
11
  end
12
12
 
13
13
  def method_missing(method_name, *args, &block)
14
14
  return @environments[method_name] if args.length == 0
15
- @environments[method_name] = args.first
15
+ @environments[method_name] = URI.parse args.first
16
16
  end
17
17
  end
18
18
  end
data/readme.md CHANGED
@@ -1,53 +1,131 @@
1
1
  #Introduction
2
2
 
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.
3
+ Change your ActiveResource service providers based on your environment.
4
4
 
5
5
  ##Install
6
6
 
7
7
  Breadboard is available as a gem:
8
8
 
9
- # gem install breadboard
10
-
11
- If you'd like to use this in your rails project, add the following to your config/environment.rb:
12
-
13
- config.gem 'breadboard'
9
+ # gem install breadboard
14
10
 
15
11
  ##Usage
16
12
 
17
- All you have to do is create a breadboard.yml file in your RAILS_ROOT/config directory.
13
+ If you're using this in a Rails app, you'll want to configure `Breadboard` in an initializer.
18
14
 
19
- In the simplest scenario, all of your ActiveResource models connect to the same service provider in all environments. In this case, you really don't need this gem, but if you're determined to use it just because you know it's the coolest thing ever, then we've got you covered:
15
+ In the simplest scenario, all of your `ActiveResource` models connect to the same service provider in all environments.
16
+ In this case, you really don't need this gem, but if you're determined to use it just because you know it's the coolest thing ever, then we've got you covered:
20
17
 
21
- default:
22
- all: http://my.universal.service.provider.com
18
+ Breadboard.configure do
19
+ default do
20
+ all "http://my.universal.service.provider.com"
21
+ end
22
+ end
23
23
 
24
- This means: for all ActiveResource models, in all environments, connect them to http://my.universal.service.provider.com
24
+ This means: for all ActiveResource models, in all environments, connect them to `http://my.universal.service.provider.com`
25
25
 
26
- However, it's more likely that you're using this gem because you are in a situation where you need to connect your models to different services based on a rails environment. This is also trivial with breadboard:
26
+ However, it's more likely that you're using this gem because you are in a situation where you need to connect your models to different
27
+ services based on a rails environment. This is also trivial with breadboard:
27
28
 
28
- default:
29
- production: http://my.production.service.provider.com
30
- development: http://my.development.service.provider
31
-
29
+ Breadboard.configure do
30
+ default do
31
+ all "http://my.universal.service.provider.com"
32
+ production "http://my.production.service.provider.com"
33
+ end
34
+ end
35
+
32
36
  Now suppose you have an 'Author' model that needs to connect to a completely different service from everything else, in all environments:
33
-
34
- default:
35
- production: http://my.production.service.provider.com
36
- development: http://my.development.service.provider
37
37
 
38
- author:
39
- all: http://my.author.service.prodiver
38
+ Breadboard.configure do
39
+ default do
40
+ all "http://my.universal.service.provider.com"
41
+ production "http://my.production.service.provider.com"
42
+ end
43
+
44
+ author do
45
+ all "http://my.author.service.provider"
46
+ end
47
+ end
48
+
49
+ You can use this alternate syntax, if you prefer:
50
+
51
+ Breadboard.configure do
52
+ default do
53
+ all "http://my.universal.service.provider.com"
54
+ production "http://my.production.service.provider.com"
55
+ end
56
+
57
+ model Author do
58
+ all "http://my.author.service.provider"
59
+ end
60
+ end
40
61
 
41
62
  Now suppose you have a 'Book' model that needs to connect to a different service provider than the default when in 'production' mode:
42
63
 
43
- default:
44
- production: http://my.production.service.provider.com
45
- development: http://my.development.service.provider
64
+ Breadboard.configure do
65
+ default do
66
+ all "http://my.universal.service.provider.com"
67
+ production "http://my.production.service.provider.com"
68
+ end
69
+
70
+ model Author do
71
+ all "http://my.author.service.provider"
72
+ end
73
+
74
+ model Book do
75
+ production "http://my.book.production.service.provider"
76
+ end
77
+ end
78
+
79
+ ## Configuring the environment
80
+
81
+ By default, Breadboard will check `Rails.env` to see what environment your app is in.
82
+
83
+ If your using Breadboard in something other than a rails app, you can configure how Breadboard determines your app's environment:
84
+
85
+ Breadboard.configure do
86
+ env do
87
+ # your app environment lookup logic here
88
+ end
89
+ end
90
+
91
+ ## Mutiple models with the same configuration
92
+
93
+ Imagine you have several models that all share the same app configuration. There's two ways to about this configuration:
94
+
95
+ - Let all of your models inherit from the same parent class and configure the parent class in breadboard
96
+ - use the `models` method
97
+
98
+ ### Inheritance
99
+
100
+ Let's imagine you have three models that should all share the same configuration: `Article`, `Author`, `Comment`. If they all inherited from the same parent,
101
+ `Publishing`, then you could simply configure the parent class in breadboard:
102
+
103
+ Breadboard.configure do
104
+ model Publishing do
105
+ all "http://my.publishing.service.provider"
106
+ end
107
+ end
108
+
109
+ If any of the children needed some configuration override, that will take precedence
110
+
111
+ Breadboard.configure do
112
+ model Publishing do
113
+ all "http://my.publishing.service.provider"
114
+ end
115
+
116
+ model Article do
117
+ production "http://my.article.production.service.provider"
118
+ end
119
+ end
120
+
121
+ ### `models` Method
46
122
 
47
- author:
48
- all: http://my.author.service.prodiver
49
-
50
- book:
51
- production: http://my.book.production.service.provider
123
+ If your `Article`, `Author`, and `Comment` models couldn't all inherit from the same parent, you can still easily provide the same configuration for them
124
+ via the `models` method:
52
125
 
53
- I think you can see where this is going...
126
+ Breadboard.configure do
127
+ models Article, Author, Comment do
128
+ all "http://my.publishing.service.provider"
129
+ production "http://my.production.publishing.service.provider"
130
+ end
131
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breadboard
3
3
  version: !ruby/object:Gem::Version
4
- hash: -3702664322
4
+ hash: -3702664328
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
10
  - alpha
11
- - 1
12
- version: 1.0.0.alpha.1
11
+ - 2
12
+ version: 1.0.0.alpha.2
13
13
  platform: ruby
14
14
  authors:
15
15
  - Matt Parker