landlady 0.0.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTgxYWFkZmE2MWUzZjhmYzcxNTA1YzhjOTk2NGUzN2Y0OTUyNTBjMg==
5
+ data.tar.gz: !binary |-
6
+ YWYyNGQ4ZDRjNjE5M2JhODc2ZTJlMWYxOTU0Y2NjMWE4OTY0YTdlNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MjNmNWNiMGExOTJlMDVlYzUxN2UyZjEzMDdiM2Y3M2JiZjg1ZjUxODc1MTkz
10
+ M2I2ZjJjZWM0ZGQ2MTZkNzA3Mzg3NWFjNmZlZTM1OTliYzg2MzFkMjM3MGVi
11
+ MGFhZjk2MTk5ZTQyNjVjNzllMmJjZGRjODliNDViYmFkNTM1MDk=
12
+ data.tar.gz: !binary |-
13
+ ZTY5YmNlODZjOWE4ZGQ3OTAzNWFiNjg4N2UyNTIzYmQwNGQ2NDY5YmM4MTll
14
+ OTAwYWQxY2JlNzE3YjY3NmY2Y2MxYTQ5MDhlMjhjYTBlNjJlMmEzNTgzMTJi
15
+ M2RjZjk2MjdmYzJjYTM1YWZmZDMxNWQ5MzA1YWE4YzZhYTRmYjg=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in landlady.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013-2014 Kym McInerney
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+
2
+ # landlady
3
+
4
+ super easy postgres multitenancy
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'landlady'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install landlady
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
31
+
32
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/landlady.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'landlady/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "landlady"
8
+ spec.version = Landlady::VERSION
9
+ spec.authors = ["Kym McInerney"]
10
+ spec.email = ["kym@holodigm.com.au"]
11
+ spec.description = %q{Uses Postgres datbase name spacing to allow schema segregation multitenancy}
12
+ spec.summary = %q{Super simple postgres multitenancy}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,14 @@
1
+ require "rails/railtie"
2
+
3
+ module Landlady
4
+ class Railtie < ::Rails::Railtie
5
+
6
+ initializer "Landlady.handle_subdomains" do |app|
7
+ Landlady.set_search_path(@tenant.id) if @tenant = Tenant.find_by_subdomain(request.subdomain)
8
+ end
9
+
10
+ rake_tasks do
11
+ load "../tasks/tenants.rake"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Landlady
2
+ VERSION = "0.0.1"
3
+ end
data/lib/landlady.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "landlady/version"
2
+ require "landlady/railtie" if defined? Rails
3
+
4
+ module Landlady
5
+ extend self
6
+
7
+ def default_search_path
8
+ @default_search_path ||= %{"$user", public}
9
+ end
10
+
11
+ def set_search_path(name, include_public = true)
12
+ path_parts = [name.to_s, ("public" if include_public)].compact
13
+ ActiveRecord::Base.connection.schema_search_path = path_parts.join(",")
14
+ end
15
+
16
+ def restore_default_search_path
17
+ ActiveRecord::Base.connection.schema_search_path = default_search_path
18
+ end
19
+
20
+ def create_schema(name)
21
+ sql = %{CREATE SCHEMA "#{name}"}
22
+ ActiveRecord::Base.connection.execute sql
23
+ end
24
+
25
+ def schemas
26
+ sql = "SELECT nspname FROM pg_namespace WHERE nspname !~ '^pg_.*'"
27
+ ActiveRecord::Base.connection.query(sql).flatten
28
+ end
29
+ end
data/lib/subdomain.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Subdomain
2
+ def self.matches?(request)
3
+ request.subdomain.present? && request.subdomain != "www"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ namespace :tenants do
2
+ namespace :db do
3
+ desc "runs db:migrate on each tentant's private schema"
4
+ task :migrate => :environment do
5
+ verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
6
+ ActiveRecord::Migration.verbose = verbose
7
+
8
+ Tenant.all.each do |tenant|
9
+ puts "migrating tenant #{tenant.id} (#{tenant.subdomain})"
10
+ Landlady.set_search_path tenant.id, false
11
+ version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
12
+ ActiveRecord::Migrator.migrate("db/migrate/", version)
13
+ end
14
+ end
15
+ end
16
+ end
File without changes
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: landlady
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kym McInerney
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Uses Postgres datbase name spacing to allow schema segregation multitenancy
42
+ email:
43
+ - kym@holodigm.com.au
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .rspec
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - landlady.gemspec
55
+ - lib/landlady.rb
56
+ - lib/landlady/railtie.rb
57
+ - lib/landlady/version.rb
58
+ - lib/subdomain.rb
59
+ - lib/tasks/tenants.rake
60
+ - spec/spec_helper.rb
61
+ homepage: ''
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.1
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Super simple postgres multitenancy
85
+ test_files:
86
+ - spec/spec_helper.rb