sublease 0.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.
Files changed (100) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +62 -0
  3. data/.travis.yml +68 -0
  4. data/CHANGELOG.md +3 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +29 -0
  7. data/Gemfile.lock +141 -0
  8. data/LICENSE +21 -0
  9. data/README.md +126 -0
  10. data/Rakefile +36 -0
  11. data/app/models/sublease/lodger.rb +71 -0
  12. data/app/models/sublease/tenant.rb +29 -0
  13. data/bin/rails +14 -0
  14. data/config/locales/de.yml +28 -0
  15. data/config/locales/en.yml +28 -0
  16. data/config/locales/es.yml +28 -0
  17. data/config/locales/fr.yml +28 -0
  18. data/config/locales/it.yml +28 -0
  19. data/config/locales/po.yml +28 -0
  20. data/gemfiles/Gemfile.jruby.rails-4.1-stable +29 -0
  21. data/gemfiles/Gemfile.jruby.rails-4.1-stable.lock +129 -0
  22. data/gemfiles/Gemfile.jruby.rails-4.2-stable +29 -0
  23. data/gemfiles/Gemfile.jruby.rails-4.2-stable.lock +152 -0
  24. data/gemfiles/Gemfile.jruby.rails-5.0-stable +29 -0
  25. data/gemfiles/Gemfile.jruby.rails-5.0-stable.lock +163 -0
  26. data/gemfiles/Gemfile.rails-4.1-stable +29 -0
  27. data/gemfiles/Gemfile.rails-4.1-stable.lock +115 -0
  28. data/gemfiles/Gemfile.rails-4.2-stable +29 -0
  29. data/gemfiles/Gemfile.rails-4.2-stable.lock +140 -0
  30. data/gemfiles/Gemfile.rails-5.0-stable +29 -0
  31. data/gemfiles/Gemfile.rails-5.0-stable.lock +141 -0
  32. data/lib/generators/sublease/install/USAGE +5 -0
  33. data/lib/generators/sublease/install/install_generator.rb +9 -0
  34. data/lib/generators/sublease/install/templates/sublease.rb +23 -0
  35. data/lib/sublease.rb +132 -0
  36. data/lib/sublease/engine.rb +5 -0
  37. data/lib/sublease/errors.rb +10 -0
  38. data/lib/sublease/tenant_switcher.rb +75 -0
  39. data/lib/sublease/version.rb +5 -0
  40. data/sublease.gemspec +28 -0
  41. data/test/dummy/README.rdoc +28 -0
  42. data/test/dummy/Rakefile +6 -0
  43. data/test/dummy/app/assets/images/.keep +0 -0
  44. data/test/dummy/app/assets/javascripts/application.js +13 -0
  45. data/test/dummy/app/assets/javascripts/lodgers.js +2 -0
  46. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  47. data/test/dummy/app/assets/stylesheets/lodgers.css +4 -0
  48. data/test/dummy/app/controllers/application_controller.rb +7 -0
  49. data/test/dummy/app/controllers/concerns/.keep +0 -0
  50. data/test/dummy/app/controllers/lodgers_controller.rb +7 -0
  51. data/test/dummy/app/helpers/application_helper.rb +2 -0
  52. data/test/dummy/app/helpers/lodgers_helper.rb +2 -0
  53. data/test/dummy/app/mailers/.keep +0 -0
  54. data/test/dummy/app/models/.keep +0 -0
  55. data/test/dummy/app/models/concerns/.keep +0 -0
  56. data/test/dummy/app/models/lodger.rb +3 -0
  57. data/test/dummy/app/models/tenant.rb +3 -0
  58. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  59. data/test/dummy/app/views/lodgers/index.html.erb +6 -0
  60. data/test/dummy/bin/bundle +3 -0
  61. data/test/dummy/bin/rails +4 -0
  62. data/test/dummy/bin/rake +4 -0
  63. data/test/dummy/config.ru +4 -0
  64. data/test/dummy/config/application.rb +23 -0
  65. data/test/dummy/config/boot.rb +5 -0
  66. data/test/dummy/config/database.yml +23 -0
  67. data/test/dummy/config/environment.rb +5 -0
  68. data/test/dummy/config/environments/development.rb +37 -0
  69. data/test/dummy/config/environments/production.rb +78 -0
  70. data/test/dummy/config/environments/test.rb +39 -0
  71. data/test/dummy/config/initializers/assets.rb +8 -0
  72. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  73. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  74. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  75. data/test/dummy/config/initializers/inflections.rb +16 -0
  76. data/test/dummy/config/initializers/mime_types.rb +4 -0
  77. data/test/dummy/config/initializers/session_store.rb +3 -0
  78. data/test/dummy/config/initializers/sublease.rb +24 -0
  79. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  80. data/test/dummy/config/locales/en.yml +23 -0
  81. data/test/dummy/config/routes.rb +3 -0
  82. data/test/dummy/config/secrets.yml +22 -0
  83. data/test/dummy/db/migrate/20180114164205_create_tenants.rb +10 -0
  84. data/test/dummy/db/migrate/20180115012642_create_lodgers.rb +9 -0
  85. data/test/dummy/db/schema.rb +31 -0
  86. data/test/dummy/lib/assets/.keep +0 -0
  87. data/test/dummy/log/.keep +0 -0
  88. data/test/dummy/public/404.html +67 -0
  89. data/test/dummy/public/422.html +67 -0
  90. data/test/dummy/public/500.html +66 -0
  91. data/test/dummy/public/favicon.ico +0 -0
  92. data/test/fixtures/lodgers.yml +14 -0
  93. data/test/fixtures/tenants.yml +18 -0
  94. data/test/integration/navigation_test.rb +41 -0
  95. data/test/lib/generators/sublease/install_generator_test.rb +25 -0
  96. data/test/models/sublease/lodger_test.rb +67 -0
  97. data/test/models/sublease/tenant_test.rb +25 -0
  98. data/test/sublease_test.rb +133 -0
  99. data/test/test_helper.rb +23 -0
  100. metadata +265 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b1c458d5eb065f845834f0b68125d1a0806fd68e43c19243132f2719cf06570c
4
+ data.tar.gz: 1e731164736e3e56e8480041e70623294111de7cbd50d2a3c0d3137280096bf7
5
+ SHA512:
6
+ metadata.gz: e0b40e28f0ab57015f85e91bb9f86fafefaee9f6f12463047f7a8c89f099ed62279b147c07ec6f860f2fa3cedeb99ca8727e9cf1a8a4cc8379a0981d4974f17e
7
+ data.tar.gz: bce2fd5028bc0af4d46c74c7bec501c7e13cf774777ef54aac7b014140943a16e6dd1fee734231ba8991cc50f77f80a127416bfe4f9517a4d3f8ed15d0aa2dd2
data/.gitignore ADDED
@@ -0,0 +1,62 @@
1
+ *.gem
2
+ *.rbc
3
+ /.idea/
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/examples.txt
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ test/dummy/db/*.sqlite3
13
+ test/dummy/db/*.sqlite3-journal
14
+ test/dummy/log/*.log
15
+ test/dummy/tmp/
16
+ /tmp/
17
+ log/*.log
18
+
19
+ # Used by dotenv library to load environment variables.
20
+ # .env
21
+
22
+ ## Specific to RubyMotion:
23
+ .dat*
24
+ .repl_history
25
+ build/
26
+ *.bridgesupport
27
+ build-iPhoneOS/
28
+ build-iPhoneSimulator/
29
+
30
+ ## Specific to RubyMotion (use of CocoaPods):
31
+ #
32
+ # We recommend against adding the Pods directory to your .gitignore. However
33
+ # you should judge for yourself, the pros and cons are mentioned at:
34
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
35
+ #
36
+ # vendor/Pods/
37
+
38
+ ## Documentation cache and generated files:
39
+ /.yardoc/
40
+ /_yardoc/
41
+ /doc/
42
+ /rdoc/
43
+
44
+ ## Environment normalization:
45
+ /.bundle/
46
+ /vendor/bundle
47
+ /lib/bundler/man/
48
+
49
+ # for a library or gem, you might want to ignore these files since the code is
50
+ # intended to run in multiple environments; otherwise, check them in:
51
+ # Gemfile.lock
52
+ .ruby-version
53
+ .ruby-gemset
54
+
55
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
56
+ .rvmrc
57
+
58
+ # rspec failure tracking
59
+ .rspec_status
60
+
61
+ # byebug
62
+ .byebug_history
data/.travis.yml ADDED
@@ -0,0 +1,68 @@
1
+ addons:
2
+ apt:
3
+ packages:
4
+ - libsqlite3-dev
5
+ - sqlite3
6
+ language: ruby
7
+ rvm:
8
+ - 2.3.1
9
+ - 2.4.3
10
+ - 2.5.0
11
+ - ruby-head
12
+ - jruby
13
+
14
+ gemfile:
15
+ - Gemfile
16
+ - gemfiles/Gemfile.rails-5.0-stable
17
+ - gemfiles/Gemfile.rails-4.2-stable
18
+ - gemfiles/Gemfile.rails-4.1-stable
19
+ - gemfiles/Gemfile.jruby.rails-5.0-stable
20
+ - gemfiles/Gemfile.jruby.rails-4.2-stable
21
+ - gemfiles/Gemfile.jruby.rails-4.1-stable
22
+
23
+ matrix:
24
+ allow_failures:
25
+ - rvm: ruby-head
26
+ exclude:
27
+ - rvm: 2.5.0
28
+ gemfile: gemfiles/Gemfile.rails-4.1-stable
29
+ - rvm: 2.5.0
30
+ gemfile: gemfiles/Gemfile.jruby.rails-4.1-stable
31
+ - rvm: 2.5.0
32
+ gemfile: gemfiles/Gemfile.jruby.rails-4.2-stable
33
+ - rvm: 2.5.0
34
+ gemfile: gemfiles/Gemfile.jruby.rails-5.0-stable
35
+ - rvm: 2.4.3
36
+ gemfile: gemfiles/Gemfile.rails-4.1-stable
37
+ - rvm: 2.4.3
38
+ gemfile: gemfiles/Gemfile.jruby.rails-4.1-stable
39
+ - rvm: 2.4.3
40
+ gemfile: gemfiles/Gemfile.jruby.rails-4.2-stable
41
+ - rvm: 2.4.3
42
+ gemfile: gemfiles/Gemfile.jruby.rails-5.0-stable
43
+ - rvm: 2.3.1
44
+ gemfile: gemfiles/Gemfile.jruby.rails-4.1-stable
45
+ - rvm: 2.3.1
46
+ gemfile: gemfiles/Gemfile.jruby.rails-4.2-stable
47
+ - rvm: 2.3.1
48
+ gemfile: gemfiles/Gemfile.jruby.rails-5.0-stable
49
+ - rvm: ruby-head
50
+ gemfile: gemfiles/Gemfile.rails-4.1-stable
51
+ - rvm: ruby-head
52
+ gemfile: gemfiles/Gemfile.jruby.rails-4.1-stable
53
+ - rvm: ruby-head
54
+ gemfile: gemfiles/Gemfile.jruby.rails-4.2-stable
55
+ - rvm: ruby-head
56
+ gemfile: gemfiles/Gemfile.jruby.rails-5.0-stable
57
+ - rvm: jruby
58
+ gemfile: gemfiles/Gemfile.rails-4.1-stable
59
+ - rvm: jruby
60
+ gemfile: gemfiles/Gemfile.rails-4.2-stable
61
+ - rvm: jruby
62
+ gemfile: gemfiles/Gemfile.rails-5.0-stable
63
+
64
+ cache: bundler
65
+
66
+ before_install:
67
+ - "rm ${BUNDLE_GEMFILE}.lock"
68
+ - gem install bundler -v 1.16.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ 0.1.0
2
+ -----
3
+ * Initial release
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at bacrossland@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,29 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '>= 2.3.1'
4
+ gem 'rails', '~> 5.1'
5
+ gem 'rdoc'
6
+
7
+ gem 'shoulda', group: [:development, :test]
8
+
9
+ # Declare your gem's dependencies in sublease.gemspec
10
+ # Bundler will treat runtime dependencies like base dependencies, and
11
+ # development dependencies will be added by default to the :development group.
12
+ gemspec
13
+
14
+ # Declare any dependencies that are still in development here instead of in
15
+ # your gemspec. These might include edge Rails or gems from your path or
16
+ # Git. Remember to move these dependencies to your gemspec before releasing
17
+ # your gem to rubygems.org.
18
+
19
+ platforms :jruby do
20
+ gem 'pry', group: [:development, :test]
21
+ gem 'activerecord-jdbc-adapter'
22
+ gem 'activerecord-jdbcsqlite3-adapter'
23
+ gem 'jruby-openssl'
24
+ end
25
+
26
+ platforms :ruby do
27
+ gem 'byebug', group: [:development, :test]
28
+ gem 'sqlite3'
29
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,141 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sublease (0.1.0)
5
+ rails (>= 4.1, < 6.0)
6
+ request_store (>= 1.4.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (5.1.4)
12
+ actionpack (= 5.1.4)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (~> 0.6.1)
15
+ actionmailer (5.1.4)
16
+ actionpack (= 5.1.4)
17
+ actionview (= 5.1.4)
18
+ activejob (= 5.1.4)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.1.4)
22
+ actionview (= 5.1.4)
23
+ activesupport (= 5.1.4)
24
+ rack (~> 2.0)
25
+ rack-test (>= 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.1.4)
29
+ activesupport (= 5.1.4)
30
+ builder (~> 3.1)
31
+ erubi (~> 1.4)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
+ activejob (5.1.4)
35
+ activesupport (= 5.1.4)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.1.4)
38
+ activesupport (= 5.1.4)
39
+ activerecord (5.1.4)
40
+ activemodel (= 5.1.4)
41
+ activesupport (= 5.1.4)
42
+ arel (~> 8.0)
43
+ activesupport (5.1.4)
44
+ concurrent-ruby (~> 1.0, >= 1.0.2)
45
+ i18n (~> 0.7)
46
+ minitest (~> 5.1)
47
+ tzinfo (~> 1.1)
48
+ arel (8.0.0)
49
+ builder (3.2.3)
50
+ byebug (10.0.0)
51
+ concurrent-ruby (1.0.5)
52
+ crass (1.0.3)
53
+ erubi (1.7.0)
54
+ globalid (0.4.1)
55
+ activesupport (>= 4.2.0)
56
+ i18n (0.9.3)
57
+ concurrent-ruby (~> 1.0)
58
+ loofah (2.1.1)
59
+ crass (~> 1.0.2)
60
+ nokogiri (>= 1.5.9)
61
+ mail (2.7.0)
62
+ mini_mime (>= 0.1.1)
63
+ method_source (0.9.0)
64
+ mini_mime (1.0.0)
65
+ mini_portile2 (2.3.0)
66
+ minitest (5.11.3)
67
+ nio4r (2.2.0)
68
+ nokogiri (1.8.2)
69
+ mini_portile2 (~> 2.3.0)
70
+ rack (2.0.3)
71
+ rack-test (0.8.2)
72
+ rack (>= 1.0, < 3)
73
+ rails (5.1.4)
74
+ actioncable (= 5.1.4)
75
+ actionmailer (= 5.1.4)
76
+ actionpack (= 5.1.4)
77
+ actionview (= 5.1.4)
78
+ activejob (= 5.1.4)
79
+ activemodel (= 5.1.4)
80
+ activerecord (= 5.1.4)
81
+ activesupport (= 5.1.4)
82
+ bundler (>= 1.3.0)
83
+ railties (= 5.1.4)
84
+ sprockets-rails (>= 2.0.0)
85
+ rails-dom-testing (2.0.3)
86
+ activesupport (>= 4.2.0)
87
+ nokogiri (>= 1.6)
88
+ rails-html-sanitizer (1.0.3)
89
+ loofah (~> 2.0)
90
+ railties (5.1.4)
91
+ actionpack (= 5.1.4)
92
+ activesupport (= 5.1.4)
93
+ method_source
94
+ rake (>= 0.8.7)
95
+ thor (>= 0.18.1, < 2.0)
96
+ rake (12.3.0)
97
+ rdoc (6.0.1)
98
+ request_store (1.4.0)
99
+ rack (>= 1.4)
100
+ shoulda (3.5.0)
101
+ shoulda-context (~> 1.0, >= 1.0.1)
102
+ shoulda-matchers (>= 1.4.1, < 3.0)
103
+ shoulda-context (1.2.2)
104
+ shoulda-matchers (2.8.0)
105
+ activesupport (>= 3.0.0)
106
+ sprockets (3.7.1)
107
+ concurrent-ruby (~> 1.0)
108
+ rack (> 1, < 3)
109
+ sprockets-rails (3.2.1)
110
+ actionpack (>= 4.0)
111
+ activesupport (>= 4.0)
112
+ sprockets (>= 3.0.0)
113
+ sqlite3 (1.3.13)
114
+ thor (0.20.0)
115
+ thread_safe (0.3.6)
116
+ tzinfo (1.2.4)
117
+ thread_safe (~> 0.1)
118
+ websocket-driver (0.6.5)
119
+ websocket-extensions (>= 0.1.0)
120
+ websocket-extensions (0.1.3)
121
+
122
+ PLATFORMS
123
+ ruby
124
+
125
+ DEPENDENCIES
126
+ activerecord-jdbc-adapter
127
+ activerecord-jdbcsqlite3-adapter
128
+ byebug
129
+ jruby-openssl
130
+ pry
131
+ rails (~> 5.1)
132
+ rdoc
133
+ shoulda
134
+ sqlite3
135
+ sublease!
136
+
137
+ RUBY VERSION
138
+ ruby 2.5.0p0
139
+
140
+ BUNDLED WITH
141
+ 1.16.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 bacrossland
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,126 @@
1
+ [![Build Status](https://travis-ci.org/bacrossland/sublease.svg?branch=master)](https://travis-ci.org/bacrossland/sublease)
2
+
3
+ # Sublease
4
+
5
+ Sublease is a tenanting engine for Rails 4.2 and greater applications using a shared database or schema. It's a Rails Engine
6
+ designed to be lightweight, simple to implement, and easy to use. Sublease works with existing as well as new applications.
7
+
8
+ ## Ruby Versions
9
+
10
+ The following Ruby MRI and jRuby versions or greater are supported. Sublease was not built for or tested against other versions.
11
+
12
+ Ruby >= 2.3.1
13
+ jRuby >= 9.1.8.0
14
+
15
+ ## Rails Versions
16
+
17
+ Sublease is built and tested to run using Rails version 4.2 or greater. While Sublease will run on Rails 4.1.16, it is not officially supported.
18
+
19
+ ## Installation
20
+
21
+ 1. On the model that you want tenanted, add the fields 'domain' and 'subdomain' through a migration. Both of these fields should be strings.
22
+
23
+ 1. Add this line to your application's Gemfile:
24
+
25
+ gem 'sublease'
26
+
27
+ And then execute:
28
+
29
+ $ bundle install
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install sublease
34
+
35
+ 1. Finally, install the Sublease configuration file. This will add config/initializers/sublease.rb to you application.
36
+
37
+
38
+ $ rails generate sublease:install
39
+
40
+
41
+
42
+ ## Usage
43
+
44
+ ### Models
45
+
46
+ Sublease works by create controlled has_many and belongs_to relationships between your tenant and any other model. The has_many_subleases
47
+ model should inherit from Sublease::Tenant and the belongs_to_subleases model should inherit from Sublease::Lodger. For
48
+ instance, if your application allowed for accounts to be created that would be shared by many users, your models would
49
+ look like this:
50
+
51
+ class Account < Sublease::Tenant
52
+ has_many_subleases(:users)
53
+ end
54
+
55
+ class User < Sublease::Lodger
56
+ belongs_to_sublease(:account)
57
+ end
58
+
59
+ The relationships work just like normal has_many and belongs_to ActiveRecord Relationships even taking the same options.
60
+ The difference is that the relationship is immutable and all dependencies on the relationship are overridden to call
61
+ the destroy method. This is to ensure that all callback are called on the model in the event of a delete or destroy method call.
62
+
63
+ #### Scoping For Unique Records
64
+
65
+ When adding unique record scope on your model, just do it as you would normally in ActiveRecord. Sublease is designed to
66
+ be simple and not replace things that Rails and ActiveRecord can do just fine. Using the example above, if you wanted to
67
+ scope a user's email to be unique per account, you might add a validator like so:
68
+
69
+ class User < Sublease::Lodger
70
+ belongs_to_sublease(:account)
71
+
72
+ validates :email, presence: true, uniqueness: { case_sensitive: false, scope: :account_id }
73
+ end
74
+
75
+ #### Moving Tenants
76
+
77
+ In most cases, once a record is tenanted it stays with it's tenant. Sublease prevents switching tenants by default.
78
+ However, sometimes it is necessary to move a record from one tenant to another. To do this set the allow_sublease_change
79
+ property to true. Using the example above, we'll move user 1 from account 1 to account 2.
80
+
81
+ $ user = User.find 1
82
+ $ user.allow_sublease_change = true
83
+ $ user.account_id = 2
84
+ $ user.save
85
+
86
+ ### Controllers
87
+
88
+ Sublease can change your tenant on the fly based on a requests subdomain, domain, or both. This switching is handled in
89
+ any controller you want by including Sublease::TenantSwitcher. In the example below, we include it into ApplicationController
90
+ which means that every controller in the application will check the request to make sure the correct tenant is set.
91
+ You might not want every request to a controller checking to set the tenant so make sure you only add it to the controllers
92
+ that need it.
93
+
94
+ class ApplicationController < ActionController::Base
95
+
96
+ include Sublease::TenantSwitcher
97
+ end
98
+
99
+ The current tenant can be accessed from `Sublease.current_tenant`. Use this to set the tenant for new records or even to
100
+ show records belonging to that tenant.
101
+
102
+
103
+ ## Configuration
104
+
105
+ Sublease can be configured to set a default subdomain and/or domain. It can also be configured to determine by which method
106
+ to switch the tenant: subdomain, domain, or subdomain and domain. See config/initializers/sublease.rb for all options.
107
+
108
+
109
+ ## Development
110
+
111
+ After checking out the repo, run `bundle` to install dependencies. Then, run `rake test` to run the tests.
112
+
113
+ To install this gem onto your local machine, run `bundle exec rake install`.
114
+
115
+ ## Contributing
116
+
117
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bacrossland/sublease. All pull requests should be against the
118
+ development branch. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
119
+
120
+ ## License
121
+
122
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
123
+
124
+ ## Code of Conduct
125
+
126
+ Everyone interacting in the Sublease project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sublease/blob/master/CODE_OF_CONDUCT.md).