company_scope 0.9 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/company_scope/base.rb +9 -5
- data/lib/company_scope/version.rb +1 -1
- data/log/test.log +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40d1345b7a3a4eea16b8ce890f7237b5065a7473
|
4
|
+
data.tar.gz: 06711cac801368b1649a8646551e70d61b5ac5a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 892cebfa91f98953b29cb85f2a624dc997b2d1d36a0940a3a6053e5bf4380eb20f4e362ac9614ba3c547ca95f72c13dcedb2a83daec96fe12125227a70b3a414
|
7
|
+
data.tar.gz: ab32aa31826ef03cdd942b2b4be03ef2401c2c72af0ca514613154e53f165db79aebf11768ce4db520335b5a6de96348e1f1ad5c17da91d3bceeb8ce8a551e6c
|
data/lib/company_scope/base.rb
CHANGED
@@ -5,6 +5,11 @@ module CompanyScope
|
|
5
5
|
#
|
6
6
|
def self.included(base)
|
7
7
|
base.extend(CompanyScopeClassMethods)
|
8
|
+
|
9
|
+
private
|
10
|
+
def set_company_id(tenant, obj)
|
11
|
+
obj.send(eval(":#{tenant.to_s.underscore}_id="), Module.const_get("#{tenant.to_s.classify}").current_id)
|
12
|
+
end
|
8
13
|
end
|
9
14
|
#
|
10
15
|
module CompanyScopeClassMethods
|
@@ -18,13 +23,12 @@ module CompanyScope
|
|
18
23
|
default_scope { where("#{self.table_name}.#{tenant.to_s.underscore}_id = ?",
|
19
24
|
Module.const_get("#{tenant.to_s.classify}").current_id) }
|
20
25
|
|
21
|
-
# - on creation we make sure the company_id is set!
|
22
|
-
|
23
|
-
|
24
|
-
end
|
26
|
+
# - on intialize & creation we make sure the company_id is set!
|
27
|
+
after_initialize { |obj| set_company_id(tenant, obj) }
|
28
|
+
before_validation(on: :create) { |obj| set_company_id(tenant, obj) }
|
25
29
|
|
30
|
+
# - before we save - catch each time someone attempts to violate the company relationship!
|
26
31
|
before_save do |obj|
|
27
|
-
# catch each time someone attempts to violate the company relationship!
|
28
32
|
raise ::CompanyScope::Control::CompanyAccessViolationError unless
|
29
33
|
obj.attributes["#{tenant.to_s.underscore}_id"] == Module.const_get("#{tenant.to_s.classify}").current_id
|
30
34
|
true
|
data/log/test.log
CHANGED
@@ -558,3 +558,35 @@ Processing by DummyApplicationController#index as HTML
|
|
558
558
|
Completed 200 OK in 0ms (Views: 0.2ms)
|
559
559
|
Processing by DummyApplicationController#index as HTML
|
560
560
|
Completed 500 Internal Server Error in 0ms
|
561
|
+
Processing by DummyApplicationController#index as HTML
|
562
|
+
Completed 200 OK in 1ms (Views: 0.4ms)
|
563
|
+
Processing by DummyApplicationController#index as HTML
|
564
|
+
Completed 200 OK in 0ms (Views: 0.1ms)
|
565
|
+
Processing by DummyApplicationController#index as HTML
|
566
|
+
Completed 200 OK in 0ms (Views: 0.1ms)
|
567
|
+
Processing by DummyApplicationController#index as HTML
|
568
|
+
Completed 500 Internal Server Error in 0ms
|
569
|
+
Processing by DummyApplicationController#index as HTML
|
570
|
+
Completed 200 OK in 1ms (Views: 0.4ms)
|
571
|
+
Processing by DummyApplicationController#index as HTML
|
572
|
+
Completed 200 OK in 0ms (Views: 0.2ms)
|
573
|
+
Processing by DummyApplicationController#index as HTML
|
574
|
+
Completed 200 OK in 0ms (Views: 0.1ms)
|
575
|
+
Processing by DummyApplicationController#index as HTML
|
576
|
+
Completed 500 Internal Server Error in 0ms
|
577
|
+
Processing by DummyApplicationController#index as HTML
|
578
|
+
Completed 200 OK in 1ms (Views: 0.4ms)
|
579
|
+
Processing by DummyApplicationController#index as HTML
|
580
|
+
Completed 200 OK in 0ms (Views: 0.1ms)
|
581
|
+
Processing by DummyApplicationController#index as HTML
|
582
|
+
Completed 200 OK in 0ms (Views: 0.1ms)
|
583
|
+
Processing by DummyApplicationController#index as HTML
|
584
|
+
Completed 500 Internal Server Error in 0ms
|
585
|
+
Processing by DummyApplicationController#index as HTML
|
586
|
+
Completed 200 OK in 1ms (Views: 0.4ms)
|
587
|
+
Processing by DummyApplicationController#index as HTML
|
588
|
+
Completed 200 OK in 1ms (Views: 0.4ms)
|
589
|
+
Processing by DummyApplicationController#index as HTML
|
590
|
+
Completed 200 OK in 1ms (Views: 0.3ms)
|
591
|
+
Processing by DummyApplicationController#index as HTML
|
592
|
+
Completed 500 Internal Server Error in 0ms
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: company_scope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Forkin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|