company_scope 0.9 → 1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afc9477877707a43dea45f4700e9bd2901a39709
4
- data.tar.gz: d0afae4228b12188111476a736228f03ae26654e
3
+ metadata.gz: 40d1345b7a3a4eea16b8ce890f7237b5065a7473
4
+ data.tar.gz: 06711cac801368b1649a8646551e70d61b5ac5a1
5
5
  SHA512:
6
- metadata.gz: 2437b536e02709af7019f4859aaf8aaa253dcf8338ef7aebf906d4148dfaa523d57c84b59d5c3f14d6d777488bc73100d45970697f685308d69fb30d9e688235
7
- data.tar.gz: 53f8a2ff5a11fb53f3aa64626517730bbb96b2b858601d3f506963b2868b05346b2bd8ed46674da7569e0130082e82ba330629e8566314ef1986a57c51cdf1b7
6
+ metadata.gz: 892cebfa91f98953b29cb85f2a624dc997b2d1d36a0940a3a6053e5bf4380eb20f4e362ac9614ba3c547ca95f72c13dcedb2a83daec96fe12125227a70b3a414
7
+ data.tar.gz: ab32aa31826ef03cdd942b2b4be03ef2401c2c72af0ca514613154e53f165db79aebf11768ce4db520335b5a6de96348e1f1ad5c17da91d3bceeb8ce8a551e6c
@@ -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
- before_validation(on: :create) do |obj|
23
- obj.send(eval(":#{tenant.to_s.underscore}_id="), Module.const_get("#{tenant.to_s.classify}").current_id)
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
@@ -1,3 +1,3 @@
1
1
  module CompanyScope
2
- VERSION = "0.9"
2
+ VERSION = "1.0"
3
3
  end
@@ -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.9'
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-07-04 00:00:00.000000000 Z
11
+ date: 2015-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler