saasable 4.0.2 → 5.0.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: dad7c49704bb790278241fcb9867b97e72ced7b4
4
- data.tar.gz: 9163ab17a1a41437c6634ed917c742ae6f297700
3
+ metadata.gz: e713b6114bc528a35836f8533322fe5d99f43b11
4
+ data.tar.gz: 4bbf520d6c716841f9aae74cd1d7ca8774e97303
5
5
  SHA512:
6
- metadata.gz: 1926b99934abdcae4e9c5b432f9c98fde1599d0ad223e66aa4a43f78df7b1dea4443ebd60418187108d9bdef48719f8fc8652a4dfd9ba5db7833a443646cc992
7
- data.tar.gz: 752bf47c660c1d26a3fbfed9a0c681e738fe62dad60a125f4d2bb0ac10d1bd4d7e0f30cd508c130a2d3e76dee102ba8820479e7f7c3332ee25f275a9942ceb80
6
+ metadata.gz: 8720af7407fa29ce8abecd173d7264c81f36f623d6cae6a4ebfbff1fd0251e2239742cb1d0e6a7de9a42c41a4fe9d0c6c5f1a696d5b020f3710ab1d18382eb48
7
+ data.tar.gz: 6562a424cf45252f5bb110ecf3a26534f72363ed9ebd5a771c71485aea03873f550b05217b423a00388e16a8a20370a14d755d451daa35030fad535cf75d33d5
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.1
1
+ ruby-2.2
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "mongoid", "~> 4.0.0"
3
+ gem "mongoid", ">= 4.0.0"
4
4
 
5
5
  # Add dependencies to develop your gem here.
6
6
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -1,36 +1,35 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (4.1.4)
5
- activesupport (= 4.1.4)
4
+ activemodel (4.2.5)
5
+ activesupport (= 4.2.5)
6
6
  builder (~> 3.1)
7
- activesupport (4.1.4)
8
- i18n (~> 0.6, >= 0.6.9)
7
+ activesupport (4.2.5)
8
+ i18n (~> 0.7)
9
9
  json (~> 1.7, >= 1.7.7)
10
10
  minitest (~> 5.1)
11
- thread_safe (~> 0.1)
11
+ thread_safe (~> 0.3, >= 0.3.4)
12
12
  tzinfo (~> 1.1)
13
- addressable (2.3.6)
14
- bson (2.3.0)
13
+ addressable (2.3.8)
14
+ bson (3.2.6)
15
15
  builder (3.2.2)
16
- connection_pool (2.0.0)
17
16
  descendants_tracker (0.0.4)
18
17
  thread_safe (~> 0.3, >= 0.3.1)
19
18
  diff-lcs (1.2.5)
20
- faraday (0.9.0)
19
+ faraday (0.9.2)
21
20
  multipart-post (>= 1.2, < 3)
22
- git (1.2.7)
23
- github_api (0.11.3)
21
+ git (1.2.9.1)
22
+ github_api (0.13.0)
24
23
  addressable (~> 2.3)
25
- descendants_tracker (~> 0.0.1)
24
+ descendants_tracker (~> 0.0.4)
26
25
  faraday (~> 0.8, < 0.10)
27
- hashie (>= 1.2)
26
+ hashie (>= 3.4)
28
27
  multi_json (>= 1.7.5, < 2.0)
29
- nokogiri (~> 1.6.0)
28
+ nokogiri (~> 1.6.6)
30
29
  oauth2
31
- hashie (3.2.0)
32
- highline (1.6.21)
33
- i18n (0.6.11)
30
+ hashie (3.4.3)
31
+ highline (1.7.8)
32
+ i18n (0.7.0)
34
33
  jeweler (2.0.1)
35
34
  builder
36
35
  bundler (>= 1.0)
@@ -40,50 +39,47 @@ GEM
40
39
  nokogiri (>= 1.5.10)
41
40
  rake
42
41
  rdoc
43
- json (1.8.1)
44
- jwt (1.0.0)
45
- mini_portile (0.6.0)
46
- minitest (5.4.0)
47
- mongoid (4.0.0)
42
+ json (1.8.3)
43
+ jwt (1.5.2)
44
+ mini_portile (0.6.2)
45
+ minitest (5.8.3)
46
+ mongo (2.1.2)
47
+ bson (~> 3.0)
48
+ mongoid (5.0.1)
48
49
  activemodel (~> 4.0)
49
- moped (~> 2.0.0)
50
+ mongo (~> 2.1)
50
51
  origin (~> 2.1)
51
52
  tzinfo (>= 0.3.37)
52
- moped (2.0.0)
53
- bson (~> 2.2)
54
- connection_pool (~> 2.0)
55
- optionable (~> 0.2.0)
56
- multi_json (1.10.1)
53
+ multi_json (1.11.2)
57
54
  multi_xml (0.5.5)
58
55
  multipart-post (2.0.0)
59
- nokogiri (1.6.2.1)
60
- mini_portile (= 0.6.0)
56
+ nokogiri (1.6.6.4)
57
+ mini_portile (~> 0.6.0)
61
58
  oauth2 (1.0.0)
62
59
  faraday (>= 0.8, < 0.10)
63
60
  jwt (~> 1.0)
64
61
  multi_json (~> 1.3)
65
62
  multi_xml (~> 0.5)
66
63
  rack (~> 1.2)
67
- optionable (0.2.0)
68
64
  origin (2.1.1)
69
- rack (1.5.2)
70
- rake (10.3.2)
71
- rdoc (4.1.1)
72
- json (~> 1.4)
73
- rspec (3.0.0)
74
- rspec-core (~> 3.0.0)
75
- rspec-expectations (~> 3.0.0)
76
- rspec-mocks (~> 3.0.0)
77
- rspec-core (3.0.2)
78
- rspec-support (~> 3.0.0)
79
- rspec-expectations (3.0.2)
65
+ rack (1.6.4)
66
+ rake (10.4.2)
67
+ rdoc (4.2.0)
68
+ rspec (3.4.0)
69
+ rspec-core (~> 3.4.0)
70
+ rspec-expectations (~> 3.4.0)
71
+ rspec-mocks (~> 3.4.0)
72
+ rspec-core (3.4.1)
73
+ rspec-support (~> 3.4.0)
74
+ rspec-expectations (3.4.0)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.4.0)
77
+ rspec-mocks (3.4.0)
80
78
  diff-lcs (>= 1.2.0, < 2.0)
81
- rspec-support (~> 3.0.0)
82
- rspec-mocks (3.0.2)
83
- rspec-support (~> 3.0.0)
84
- rspec-support (3.0.2)
85
- thread_safe (0.3.4)
86
- tzinfo (1.2.1)
79
+ rspec-support (~> 3.4.0)
80
+ rspec-support (3.4.1)
81
+ thread_safe (0.3.5)
82
+ tzinfo (1.2.2)
87
83
  thread_safe (~> 0.1)
88
84
 
89
85
  PLATFORMS
@@ -92,6 +88,9 @@ PLATFORMS
92
88
  DEPENDENCIES
93
89
  bundler
94
90
  jeweler
95
- mongoid (~> 4.0.0)
91
+ mongoid (>= 4.0.0)
96
92
  rdoc
97
93
  rspec
94
+
95
+ BUNDLED WITH
96
+ 1.10.6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.2
1
+ 5.0.0
@@ -1,7 +1,7 @@
1
1
  module Saasable::Errors
2
- class MultipleSaasDocuments < StandardError; end
3
- class NoSaasDocuments < StandardError; end
4
-
2
+ class MultipleSaasDocuments < StandardError; end
3
+ class NoSaasDocuments < StandardError; end
4
+
5
5
  class MultipleSaasFound < StandardError; end
6
6
  class SaasNotFound < StandardError; end
7
- end
7
+ end
@@ -1,20 +1,15 @@
1
1
  class Saasable::Middleware
2
2
  def initialize app
3
3
  @app = app
4
-
5
- # Loads all models so we know how to apply the scopes on Rails
6
- Rails::Mongoid.load_models(Rails.application) if defined?(Rails::Mongoid)
7
4
  end
8
5
 
9
6
  def call env
10
7
  return @app.call(env) if env['PATH_INFO'].start_with?('/assets')
11
8
 
12
- env[:saasable] = {:current_saas => saas_for_host(env['SERVER_NAME'])}
13
- env[:saasable][:current_saas].activate! if env[:saasable][:current_saas]
9
+ saas = saas_for_host(env['SERVER_NAME'])
10
+ saas.activate! if saas
14
11
 
15
- @app.call(env).tap do
16
- env[:saasable][:current_saas].deactivate! if env[:saasable][:current_saas]
17
- end
12
+ @app.call(env).tap { saas.deactivate! if saas }
18
13
  end
19
14
 
20
15
  private
@@ -12,7 +12,7 @@ module Saasable::Mongoid::SaasDocument
12
12
  klass.send(:include, InstanceMethods)
13
13
  klass.class_eval do
14
14
  # Fields
15
- field :hosts, :type => Array
15
+ field :hosts, type: Array, default: []
16
16
 
17
17
  # Validations
18
18
  validates_uniqueness_of :hosts
@@ -21,7 +21,6 @@ module Saasable::Mongoid::SaasDocument
21
21
  index({hosts: 1})
22
22
  end
23
23
 
24
- klass.instance_variable_set("@_active_saas", nil)
25
24
  klass.instance_variable_set("@_after_activate_chain", [])
26
25
  klass.instance_variable_set("@_after_deactivate_chain", [])
27
26
  end
@@ -30,17 +29,13 @@ module Saasable::Mongoid::SaasDocument
30
29
  @saas_document
31
30
  end
32
31
 
32
+ def self.active_saas
33
+ @saas_document.active_saas
34
+ end
35
+
33
36
  module InstanceMethods
34
37
  def activate!
35
- Saasable::Mongoid::ScopedDocument.scoped_documents.each do |klass|
36
- saasble_criteria = Mongoid::Criteria.new(klass).where(saas_id: self._id)
37
- klass.default_scoping = klass.default_scoping? ? saasble_criteria.merge(klass.default_scoping.call).to_proc : saasble_criteria.to_proc
38
-
39
- klass.fields["saas_id"].default_val = self._id
40
- klass.fields["saas_id"].options[:default] = self._id
41
- end
42
-
43
- self.class.instance_variable_set("@_active_saas", self)
38
+ Thread.current[:saasable_active_saas] = self
44
39
  self.class.instance_variable_get("@_after_activate_chain").each { |method_name| send(method_name) }
45
40
  end
46
41
 
@@ -51,28 +46,16 @@ module Saasable::Mongoid::SaasDocument
51
46
 
52
47
  module ClassMethods
53
48
  def deactivate_all!
54
- Saasable::Mongoid::ScopedDocument.scoped_documents.each do |klass|
55
- saasble_criteria = Mongoid::Criteria.new(klass).where(saas_id: @_active_saas._id)
56
- klass.default_scoping = klass.default_scoping.call.remove_scoping(saasble_criteria).to_proc
57
-
58
- klass.fields["saas_id"].default_val = nil
59
- klass.fields["saas_id"].options.delete(:default)
60
- end
61
-
62
- last_active_saas, @_active_saas = active_saas, nil
49
+ last_active_saas, Thread.current[:saasable_active_saas] = active_saas, nil
63
50
  @_after_deactivate_chain.each { |method_name| last_active_saas.send(method_name) }
64
51
  end
65
52
 
66
53
  def find_by_host! a_host
67
54
  if Saasable::Mongoid::SaasDocument.saas_document.nil?
68
- if Rails.env.production?
69
- raise Saasable::Errors::NoSaasDocuments, "you need to set one Saasable::SaasDocument"
70
- else
71
- return nil
72
- end
55
+ raise Saasable::Errors::NoSaasDocuments, "you need to set one Saasable::SaasDocument"
73
56
  end
74
57
 
75
- possible_saas = Saasable::Mongoid::SaasDocument.saas_document.where(:hosts => a_host).to_a
58
+ possible_saas = Saasable::Mongoid::SaasDocument.saas_document.where(hosts: a_host.gsub(/^www\./, '')).to_a
76
59
  if possible_saas.empty?
77
60
  raise Saasable::Errors::SaasNotFound, "no #{Saasable::Mongoid::SaasDocument.saas_document.name} found for the host: \"#{a_host}\""
78
61
  elsif possible_saas.count > 1
@@ -83,7 +66,7 @@ module Saasable::Mongoid::SaasDocument
83
66
  end
84
67
 
85
68
  def active_saas
86
- @_active_saas
69
+ Thread.current[:saasable_active_saas]
87
70
  end
88
71
 
89
72
  def after_activate *method_names
@@ -1,13 +1,12 @@
1
1
  module Saasable::Mongoid::ScopedDocument
2
- @scoped_documents = []
3
-
4
2
  def self.included klass
5
- @scoped_documents << klass unless @scoped_documents.include? klass
6
-
7
3
  klass.extend ClassMethods
8
4
  klass.class_eval do
9
5
  # Fields
10
- field :saas_id, :type => BSON::ObjectId
6
+ field :saas_id, type: BSON::ObjectId, default: ->{ Saasable::Mongoid::SaasDocument.active_saas }
7
+
8
+ # Default scope
9
+ default_scope ->{ Saasable::Mongoid::SaasDocument.active_saas ? where(saas_id: Saasable::Mongoid::SaasDocument.active_saas) : all }
11
10
 
12
11
  # Indexes
13
12
  index({saas_id: 1})
@@ -19,10 +18,6 @@ module Saasable::Mongoid::ScopedDocument
19
18
  end
20
19
  end
21
20
 
22
- def self.scoped_documents
23
- @scoped_documents
24
- end
25
-
26
21
  def saas= a_saas
27
22
  self.saas_id = a_saas._id
28
23
  end
@@ -40,7 +35,7 @@ module Saasable::Mongoid::ScopedDocument
40
35
  validates_with(Mongoid::Validatable::UniquenessValidator, attributes)
41
36
  end
42
37
 
43
- def index_with_saasable(spec, options = nil)
38
+ def index_with_saasable(spec, options = {})
44
39
  index_without_saasable(spec, options.merge({unique: false}))
45
40
  index_without_saasable({saas_id: 1}.merge(spec), options) unless spec.include?(:saas_id)
46
41
  end
@@ -2,4 +2,4 @@ module Saasable::Mongoid
2
2
  # Documents
3
3
  autoload :SaasDocument, "saasable/mongoid/saas_document"
4
4
  autoload :ScopedDocument, "saasable/mongoid/scoped_document"
5
- end
5
+ end
@@ -2,8 +2,8 @@ require "saasable/railties"
2
2
 
3
3
  class Saasable::Railtie < Rails::Railtie
4
4
  config.app_middleware.use Saasable::Middleware
5
-
5
+
6
6
  initializer "include helpers" do
7
7
  ActionController::Base.send :include, Saasable::Railties::Helpers
8
8
  end
9
- end
9
+ end
@@ -5,7 +5,7 @@ module Saasable::Railties
5
5
  klass.send(:include, InstanceMethods)
6
6
  klass.class_eval do
7
7
  helper_method :current_saas
8
-
8
+
9
9
  before_filter :_redirect_if_saas_not_found unless Rails.env.development?
10
10
  saas_not_found_redirect_to "/404.html"
11
11
 
@@ -36,7 +36,7 @@ module Saasable::Railties
36
36
 
37
37
  module InstanceMethods
38
38
  def current_saas
39
- @current_saas ||= request.env[:saasable][:current_saas]
39
+ Saasable::Mongoid::SaasDocument.active_saas
40
40
  end
41
41
  end
42
42
  end
@@ -1,4 +1,4 @@
1
1
  module Saasable::Railties
2
2
  # Railties
3
3
  autoload :Helpers, "saasable/railties/helpers"
4
- end
4
+ end
data/lib/saasable.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  module Saasable
2
2
  # Errors
3
3
  autoload :Errors, "saasable/errors"
4
-
4
+
5
5
  # Middleware
6
6
  autoload :Middleware, "saasable/middleware"
7
-
7
+
8
8
  # Mongoid
9
9
  autoload :Mongoid, "saasable/mongoid"
10
- end
10
+ end
data/saasable.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: saasable 4.0.2 ruby lib
5
+ # stub: saasable 5.0.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "saasable"
9
- s.version = "4.0.2"
9
+ s.version = "5.0.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Educa2", "Rafael Gaspar"]
14
- s.date = "2014-07-18"
14
+ s.date = "2015-11-24"
15
15
  s.description = "A gem for making a Multi-Tenant SaaS using Mongoid"
16
16
  s.email = "suporte@educa2.com.br"
17
17
  s.extra_rdoc_files = [
@@ -44,27 +44,27 @@ Gem::Specification.new do |s|
44
44
  ]
45
45
  s.homepage = "http://github.com/educa2/saasable"
46
46
  s.licenses = ["MIT"]
47
- s.rubygems_version = "2.2.2"
47
+ s.rubygems_version = "2.4.5.1"
48
48
  s.summary = "A gem for making a Multi-Tenant SaaS using Mongoid"
49
49
 
50
50
  if s.respond_to? :specification_version then
51
51
  s.specification_version = 4
52
52
 
53
53
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
- s.add_runtime_dependency(%q<mongoid>, ["~> 4.0.0"])
54
+ s.add_runtime_dependency(%q<mongoid>, [">= 4.0.0"])
55
55
  s.add_development_dependency(%q<rspec>, [">= 0"])
56
56
  s.add_development_dependency(%q<bundler>, [">= 0"])
57
57
  s.add_development_dependency(%q<jeweler>, [">= 0"])
58
58
  s.add_development_dependency(%q<rdoc>, [">= 0"])
59
59
  else
60
- s.add_dependency(%q<mongoid>, ["~> 4.0.0"])
60
+ s.add_dependency(%q<mongoid>, [">= 4.0.0"])
61
61
  s.add_dependency(%q<rspec>, [">= 0"])
62
62
  s.add_dependency(%q<bundler>, [">= 0"])
63
63
  s.add_dependency(%q<jeweler>, [">= 0"])
64
64
  s.add_dependency(%q<rdoc>, [">= 0"])
65
65
  end
66
66
  else
67
- s.add_dependency(%q<mongoid>, ["~> 4.0.0"])
67
+ s.add_dependency(%q<mongoid>, [">= 4.0.0"])
68
68
  s.add_dependency(%q<rspec>, [">= 0"])
69
69
  s.add_dependency(%q<bundler>, [">= 0"])
70
70
  s.add_dependency(%q<jeweler>, [">= 0"])
data/spec/spec_helper.rb CHANGED
@@ -8,5 +8,5 @@ require 'saasable'
8
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
9
 
10
10
  RSpec.configure do |config|
11
-
11
+
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saasable
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Educa2
@@ -9,20 +9,20 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-18 00:00:00.000000000 Z
12
+ date: 2015-11-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: 4.0.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: 4.0.0
28
28
  - !ruby/object:Gem::Dependency
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  requirements: []
133
133
  rubyforge_project:
134
- rubygems_version: 2.2.2
134
+ rubygems_version: 2.4.5.1
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: A gem for making a Multi-Tenant SaaS using Mongoid