acts_as_tenant 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ 0.2.7
2
+ -----
3
+ * Changed the interface for passing in the current_tenant manually in the controller. `set_current_tenant_to` has been deprecated and replaced by `set_current_tenant_through_filter` declaration and the `set_current_tenant` method. See readme for details.
4
+
1
5
  0.2.6
2
6
  -----
3
7
  * Fixed a bug with resolving the tenant model name (thx devton!)
data/README.md CHANGED
@@ -43,10 +43,15 @@ This tells acts_as_tenant to use the current subdomain to identify the current t
43
43
  **OR Pass in the current tenant yourself**
44
44
 
45
45
  class ApplicationController < ActionController::Base
46
- current_account = Account.find_the_current_account
47
- set_current_tenant_to(current_account)
46
+ set_current_tenant_through_filter
47
+ before_filter :your_method_that_finds_the_current_tenant
48
+
49
+ def your_method_that_finds_the_current_tenant
50
+ current_account = Account.find_it
51
+ set_current_tenant(current_account)
52
+ end
48
53
  end
49
- This allows you to pass in the current tenant yourself.
54
+ Setting the current_tenant yourself, requires you to declare `set_current_tenant_through_filter` at the top of your application_controller to tell acts_as_tenant that you are going to use a before_filter to setup the current tenant. Next you should actually setup that before_filter to fetch the current tenant and pass it to `acts_as_tenant` by using `set_current_tenant(current_tenant)` in the before_filter.
50
55
 
51
56
  **note:** If the current tenant is not set by either of these methods, Acts_as_tenant will be unable to apply the proper scope to your models. So make sure you use one of the two methods to tell acts_as_tenant about the current tenant.
52
57
 
@@ -31,13 +31,36 @@ module ActsAsTenant
31
31
  end
32
32
  end
33
33
 
34
+ # This method sets up a method that allows manual setting of the current_tenant. This method should
35
+ # be used in a before_filter. In addition, a helper is setup that returns the current_tenant
36
+ def set_current_tenant_through_filter
37
+ self.class_eval do
38
+ helper_method :current_tenant
39
+
40
+ def set_current_tenant(current_tenant_object)
41
+ ActsAsTenant.current_tenant = current_tenant_object
42
+ end
43
+
44
+ private
45
+ # helper method to have the current_tenant available in the controller
46
+ def current_tenant
47
+ ActsAsTenant.current_tenant
48
+ end
49
+ end
50
+ end
51
+
52
+
53
+
34
54
  # this method allows manual setting of the current_tenant by passing in a tenant object
35
55
  #
36
56
  def set_current_tenant_to(current_tenant_object)
37
57
  self.class_eval do
38
58
  cattr_accessor :tenant_class
39
59
  attr_accessor :current_tenant
40
- before_filter lambda { @current_tenant_instance = ActsAsTenant.current_tenant = current_tenant_object }
60
+ before_filter lambda {
61
+ ActiveSupport::Deprecation.warn "set_current_tenant_to is deprecated and will be removed from Acts_as_tenant in a future releases, please use set_current_tenant_through_filter instead.", caller
62
+ @current_tenant_instance = ActsAsTenant.current_tenant = current_tenant_object
63
+ }
41
64
 
42
65
  helper_method :current_tenant
43
66
 
@@ -1,3 +1,3 @@
1
1
  module ActsAsTenant
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-09 00:00:00.000000000Z
12
+ date: 2012-03-24 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Integrates multi-tenancy into a Rails application in a convenient and
15
15
  out-of-your way manner
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  version: '0'
55
55
  requirements: []
56
56
  rubyforge_project: acts_as_tenant
57
- rubygems_version: 1.8.10
57
+ rubygems_version: 1.8.15
58
58
  signing_key:
59
59
  specification_version: 3
60
60
  summary: Add multi-tenancy to Rails applications using a shared db strategy