domain_switcher 0.1.2 → 0.1.3

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.
@@ -6,7 +6,7 @@ module DomainSwitcher
6
6
  attr_reader :websites
7
7
  attr_reader :domains
8
8
 
9
- def initialize(config_file = 'config/websites.yml')
9
+ def initialize(config_file = 'config/websites.yml', env = 'development')
10
10
  begin
11
11
  @conf = YAML::load_file(config_file)
12
12
  rescue ArgumentError => e
@@ -14,9 +14,10 @@ module DomainSwitcher
14
14
  end
15
15
  raise ArgumentError.new("DomainSwitcher: Empty config file (#{config_file})") if !@conf or @conf.size == 0
16
16
 
17
+ @env = env
17
18
  @websites = []
18
19
  @domains = []
19
- parse_conf!
20
+ parse_conf!
20
21
  end
21
22
 
22
23
  private
@@ -24,6 +25,7 @@ module DomainSwitcher
24
25
  @conf.each do |website, conf|
25
26
  domains = conf.delete('domains')
26
27
  default_domain = conf.delete('default_domain')
28
+ conf.merge!(conf.delete(@env)) if Hash === conf[@env] # Apply specific conf depending on the env
27
29
  raise "DomainSwitcher: Website without domain: #{website}" if !domains or domains.size == 0
28
30
  raise "DomainSwitcher: Website without default domain: #{website}" if !default_domain
29
31
 
@@ -3,7 +3,7 @@ module DomainSwitcher
3
3
 
4
4
  def initialize(app, config = nil)
5
5
  @app = app
6
- @config = config || DomainSwitcher::ConfigLoader.new
6
+ @config = config || DomainSwitcher::ConfigLoader.new(Rails.root.join('config/websites.yml'), Rails.env)
7
7
  @scanner = DomainSwitcher::Scanner.new(@config.domains)
8
8
 
9
9
  DomainSwitcher::Cache.init
@@ -24,4 +24,9 @@ website2:
24
24
  default: true
25
25
  - fr.website2.com
26
26
  lang: fr
27
- false_meth: false
27
+ false_meth: false
28
+ env_var: 'test'
29
+ development:
30
+ env_var: 'dev'
31
+ production:
32
+ env_var: 'prod'
@@ -81,6 +81,15 @@ describe :config_loader do
81
81
  it "cookie domain can be overrided" do
82
82
  @config.default_domain.cookie_domain.should == 'website2cookie.com'
83
83
  end
84
+
85
+ it "handle properly environments" do
86
+ c = DomainSwitcher::ConfigLoader.new(File.join(File.dirname(__FILE__), '../config/websites.yml'))
87
+ c.default_website.env_var.should == 'dev'
88
+ c = DomainSwitcher::ConfigLoader.new(File.join(File.dirname(__FILE__), '../config/websites.yml'), 'production')
89
+ c.default_website.env_var.should == 'prod'
90
+ c = DomainSwitcher::ConfigLoader.new(File.join(File.dirname(__FILE__), '../config/websites.yml'), 'test')
91
+ c.default_website.env_var.should == 'test'
92
+ end
84
93
 
85
94
  end
86
95
  end
@@ -6,6 +6,10 @@ describe :domain_switcher do
6
6
  @conf = DomainSwitcher::ConfigLoader.new(File.join(File.dirname(__FILE__), '../config/websites.yml'))
7
7
  @app = DomainSwitcher::Middleware.new(Proc.new {|b| [200, 'OK']}, @conf)
8
8
  end
9
+
10
+ before :each do
11
+ Thread.current[:domain_switcher_domain] = nil # reset
12
+ end
9
13
 
10
14
  it "not create a new memcache connection if namespace is the same" do
11
15
  @app.call({'HTTP_HOST' => 'www.website1.com', 'rack.session.options' => {:domain => :test, :something => true}})
@@ -14,7 +18,7 @@ describe :domain_switcher do
14
18
 
15
19
  it "switch on default when nothing is found" do
16
20
  @app.call({'HTTP_HOST' => 'nothing', 'rack.session.options' => {:domain => :test, :something => true}})
17
- Thread.current[:domain_switcher_domain].should == @conf.default_domain
21
+ Thread.current[:domain_switcher_domain].should == @conf.default_website.default_domain
18
22
  Thread.current[:domain_switcher_website].should == @conf.default_website
19
23
  end
20
24
 
@@ -6,6 +6,10 @@ describe :helper do
6
6
  @conf = DomainSwitcher::ConfigLoader.new(File.join(File.dirname(__FILE__), '../config/websites.yml'))
7
7
  @app = DomainSwitcher::Middleware.new(Proc.new {|b| [200, 'OK']}, @conf)
8
8
  end
9
+
10
+ before :each do
11
+ Thread.current[:domain_switcher_domain] = nil # reset
12
+ end
9
13
 
10
14
  it "Check helper" do
11
15
  @app.call({'HTTP_HOST' => 'www.website1.com', 'rack.session.options' => {:domain => :test, :something => true}})
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domain_switcher
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Guillaume Luccisano
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-25 00:00:00 -08:00
18
+ date: 2011-03-29 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency