domain_switcher 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,7 +19,7 @@ module DomainSwitcher
19
19
  Rails.logger.info "DomainSwitcher: Use existing cache => namespace is the same: #{namespace}"
20
20
  RAILS_CACHE
21
21
  else
22
- c.class.new(d.class.new(instance_variable_get('@servers'), d.instance_variable_get('@options').merge(:namespace => namespace, :prefix_key => namespace)))
22
+ c.class.new(d.class.new(d.instance_variable_get('@servers'), d.instance_variable_get('@options').merge(:namespace => namespace, :prefix_key => namespace)))
23
23
  end
24
24
  elsif c.is_a? ActiveSupport::Cache::FileStore
25
25
  c.class.new("tmp/cache/#{namespace}")
@@ -17,6 +17,7 @@ module DomainSwitcher
17
17
  @env = env
18
18
  @websites = []
19
19
  @domains = []
20
+ @websites_hash = {}
20
21
  parse_conf!
21
22
  end
22
23
 
@@ -36,7 +37,7 @@ module DomainSwitcher
36
37
  website << Domain.new(website, d, conf.merge(conf))
37
38
  else # It's an hash like this: {"www.website1.com"=>{"name"=>"Website 1 override", "width"=>900}}
38
39
  raise "DomainSwitcher: Bad indentation in the config file" if d.size != 1
39
- website << Domain.new(website, d.first.first, d.first.last.merge(conf))
40
+ website << Domain.new(website, d.first.first, conf.merge(d.first.last))
40
41
  end
41
42
  end
42
43
 
@@ -45,6 +46,7 @@ module DomainSwitcher
45
46
 
46
47
  # Collect websites and domains
47
48
  @websites << website
49
+ @websites_hash[website.symbol.to_sym] = website
48
50
  @domains += website.domains
49
51
  end
50
52
  end
@@ -56,6 +58,11 @@ module DomainSwitcher
56
58
 
57
59
  def default_domain
58
60
  @default_domain ||= @domains.find { |d| d.default? } || @domains.first
59
- end
61
+ end
62
+
63
+ # Retrieve a website by symbol
64
+ def [](website_symbol)
65
+ @websites_hash[website_symbol]
66
+ end
60
67
  end
61
68
  end
@@ -11,12 +11,19 @@ module DomainSwitcher
11
11
  @name = name
12
12
  @symbol = symbol
13
13
  @domains = domains
14
+ @domains_hash = {}
14
15
  build_config!(conf)
15
16
  end
16
17
 
17
18
  def <<(domain)
19
+ @domains_hash[domain.domain] = domain
18
20
  @domains << domain
19
21
  end
22
+
23
+ # Retrieve a domain by the domain
24
+ def [](domain)
25
+ @domains_hash[domain]
26
+ end
20
27
 
21
28
  end
22
29
  end
@@ -81,6 +81,10 @@ 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 "stuff should be overriden in domain" do
86
+ @config[:website1]['www.website1.com'].name.should == 'Website 1 override'
87
+ end
84
88
 
85
89
  it "handle properly environments" do
86
90
  c = DomainSwitcher::ConfigLoader.new(File.join(File.dirname(__FILE__), '../config/websites.yml'))
data/spec/spec_helper.rb CHANGED
@@ -24,11 +24,18 @@ module ActiveSupport
24
24
  module Cache
25
25
  class MemCacheStore
26
26
  def initialize(*args)
27
- @data = Memcached.new(*args)
27
+ if args.first.respond_to? :prefix_key
28
+ @data = args.first
29
+ else
30
+ @data = Memcached.new(*args)
31
+ end
28
32
  end
29
33
  end
30
34
 
31
- class Memcached
35
+ class Memcached
36
+ attr_reader :servers
37
+ attr_reader :options
38
+
32
39
  def initialize(servers, options = {})
33
40
  @servers = servers
34
41
  @options = options
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Guillaume Luccisano