company_scope 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e23f0f1665e578c9287a203ebff02717f204dfe4
4
- data.tar.gz: 83ba3007224cc8c97f5003263efc18e97ee7e111
3
+ metadata.gz: 78d74779542e73e301d7e76aa127dd7fd66cf662
4
+ data.tar.gz: ef46ca27b38a368b41dd64d168194904a6a3b925
5
5
  SHA512:
6
- metadata.gz: e0835d33a937cb22c23d5fa021f644470050ffbd4f160e0096f28a018cb902ace3bb83b44cd55b5c615194d7302949a7d5760999f8fe4a8771fea1f0514035f5
7
- data.tar.gz: d73b5642d099a30aec593f7b4c124b766312237b20c2cb4838fbea1d84bb6216fed20305d1e0d1f46ce706a11003ef7ec06aab0ed56997382bda1e562bbf7f28
6
+ metadata.gz: 4bc0411012a43a13235521568587a663986d0952dce1899b8d80ee0231db6bcb3c613ba292e310eba024b93196cb4f9db2dccfdbdce8277b724b4f60b4b5db21
7
+ data.tar.gz: da8def416750d32902413b3a7dea14a1619efbe035129f34db0eb532f2e90823f93b76a4624bd787761dd57aa618d7118b5d681c37e4095866dbc656f1a0edab
data/README.md CHANGED
@@ -68,15 +68,18 @@ The domain 'lvh.me' points to 127.0.0.1 and is therefore an ideal candidate for
68
68
 
69
69
  NB: The middleware currently uses a regex to ensure the domain name can only obtain the following:
70
70
 
71
- * A-Z
72
- * a-z
73
- * 0-9
71
+ * A-Z, a-z, 0-9
74
72
 
75
- The middleware then uses the column called "class_name"_name i.e. "company_name"
73
+ The middleware then uses the column called "company_name" to retrieve the company by the subdomain.
76
74
 
77
- No spaces or special characters are permitted and the name is also upcased - which needs to be handled
78
- by the model you use for scoping! This just keeps the name clean and simple.
79
- We would strongly recommend you to have a proper index on the company
75
+ The name is also upcased - which needs to be handled by the model you use for scoping! This just keeps the name clean and simple. We would strongly recommend you to have a proper index on the company_name field.
76
+
77
+ NB: If you are using a different model and don't like the idea of using the company_name field you can simply
78
+ use the ruby alias method.
79
+
80
+ ```ruby
81
+ alias_method :company_name, :your_account_name_method
82
+ ```
80
83
 
81
84
  The method below is included in the Controller stack (see notes further down), and retrieves
82
85
  the company object the request object. The Rack Middleware "Rack::MultiCompany" injects this
@@ -143,13 +146,17 @@ NB: The "CompanyScope" gem does not handle the process of adding migrations or c
143
146
 
144
147
  ### Scoping your models ###
145
148
 
146
- * The "acts_as_guardian" method injects the behaviour required for the scoping model.
149
+ * The "acts_as_guardian" method injects the behaviour required for the scoping model. The model
150
+ needs to have a string column that is called by the "model"_name i.e. 'company_name'. The gem
151
+ adds a uniqueness validator. NB to ensure this will not cause race conditions at the DB level
152
+ you really need to add an index for this column.
147
153
 
148
154
  ```ruby
149
155
  class Company < ActiveRecord::Base
150
156
 
151
157
  acts_as_guardian
152
158
 
159
+ # NB - the gem adds a uniqueness validator for the company_name field
153
160
  ...
154
161
 
155
162
  end
@@ -174,6 +181,11 @@ class User < ActiveRecord::Base
174
181
  end
175
182
  ```
176
183
 
184
+ ### The Gem is currently being used in Rails 4 and Rails-API apps and is tested against Postgres,
185
+ using UUID based ID/primary keys ###
186
+
187
+ ### It should work with other databases such as MySQL without any issues ###
188
+
177
189
 
178
190
  ## Development
179
191
 
@@ -15,7 +15,6 @@ module CompanyScope
15
15
 
16
16
  validates_presence_of "#{tenant.to_s}_id".to_sym #:company_id
17
17
 
18
- #default_scope { where("#{self.table_name}.company_id = ?", Company.current_id) }
19
18
  default_scope { where("#{self.table_name}.#{tenant.to_s.underscore}_id = ?",
20
19
  Module.const_get("#{tenant.to_s.classify}").current_id) }
21
20
 
@@ -33,7 +32,6 @@ module CompanyScope
33
32
 
34
33
  before_destroy do |obj|
35
34
  # force company to be correct for current_user
36
- #raise ::CompanyScope::Control::CompanyAccessViolationError unless obj.company_id == Company.current_id
37
35
  raise ::CompanyScope::Control::CompanyAccessViolationError unless
38
36
  obj.attributes["#{tenant.to_s.underscore}_id"] == Module.const_get("#{tenant.to_s.classify}").current_id
39
37
  true
@@ -11,8 +11,8 @@ module CompanyScope
11
11
  #
12
12
  def acts_as_guardian
13
13
  #
14
- #puts "\n\n\n Class Name: #{self.class.to_s.downcase}\n\n\n"
15
- #validates_uniqueness_of "#{self.class.to_s.downcase}_name".to_sym #:company_name
14
+ # ensure the column that carries the company unique id/subdomain is unique
15
+ validates_uniqueness_of :company_name
16
16
  #
17
17
  def current_id=(id)
18
18
  RequestStore.store[:default_scope_company_id] = id
@@ -1,3 +1,3 @@
1
1
  module CompanyScope
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: company_scope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Forkin