activerecord-multi-tenant 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/active-record-multi-tenant-tests.yml +80 -0
  3. data/.gitignore +6 -0
  4. data/.readthedocs.yaml +15 -0
  5. data/.rspec +0 -0
  6. data/.rubocop.yml +51 -0
  7. data/Appraisals +0 -0
  8. data/CHANGELOG.md +6 -0
  9. data/Gemfile +3 -1
  10. data/LICENSE +0 -0
  11. data/README.md +2 -1
  12. data/Rakefile +1 -1
  13. data/activerecord-multi-tenant.gemspec +28 -22
  14. data/docker-compose.yml +24 -18
  15. data/docs/.gitignore +3 -0
  16. data/docs/Makefile +28 -0
  17. data/docs/api-reference.sh +10 -0
  18. data/docs/requirements.in +4 -0
  19. data/docs/requirements.txt +62 -0
  20. data/docs/source/_static/api-reference/ActiveRecord/Associations/Association.html +285 -0
  21. data/docs/source/_static/api-reference/ActiveRecord/Associations/ClassMethods.html +255 -0
  22. data/docs/source/_static/api-reference/ActiveRecord/Associations.html +117 -0
  23. data/docs/source/_static/api-reference/ActiveRecord/ConnectionAdapters/SchemaStatements.html +232 -0
  24. data/docs/source/_static/api-reference/ActiveRecord/ConnectionAdapters.html +126 -0
  25. data/docs/source/_static/api-reference/ActiveRecord/QueryMethods.html +336 -0
  26. data/docs/source/_static/api-reference/ActiveRecord/SchemaDumper.html +121 -0
  27. data/docs/source/_static/api-reference/ActiveRecord.html +130 -0
  28. data/docs/source/_static/api-reference/MultiTenant/ArelTenantVisitor.html +755 -0
  29. data/docs/source/_static/api-reference/MultiTenant/ArelVisitorsDepthFirst.html +208 -0
  30. data/docs/source/_static/api-reference/MultiTenant/BaseTenantEnforcementClause.html +462 -0
  31. data/docs/source/_static/api-reference/MultiTenant/Context.html +659 -0
  32. data/docs/source/_static/api-reference/MultiTenant/ControllerExtensions.html +202 -0
  33. data/docs/source/_static/api-reference/MultiTenant/CopyFromClient.html +186 -0
  34. data/docs/source/_static/api-reference/MultiTenant/CopyFromClientHelper.html +362 -0
  35. data/docs/source/_static/api-reference/MultiTenant/Current.html +124 -0
  36. data/docs/source/_static/api-reference/MultiTenant/DatabaseStatements.html +366 -0
  37. data/docs/source/_static/api-reference/MultiTenant/FastTruncate.html +226 -0
  38. data/docs/source/_static/api-reference/MultiTenant/MigrationExtensions.html +554 -0
  39. data/docs/source/_static/api-reference/MultiTenant/MissingTenantError.html +124 -0
  40. data/docs/source/_static/api-reference/MultiTenant/ModelExtensionsClassMethods.html +492 -0
  41. data/docs/source/_static/api-reference/MultiTenant/QueryMonitor.html +257 -0
  42. data/docs/source/_static/api-reference/MultiTenant/Table.html +419 -0
  43. data/docs/source/_static/api-reference/MultiTenant/TenantEnforcementClause.html +148 -0
  44. data/docs/source/_static/api-reference/MultiTenant/TenantIsImmutable.html +135 -0
  45. data/docs/source/_static/api-reference/MultiTenant/TenantJoinEnforcementClause.html +310 -0
  46. data/docs/source/_static/api-reference/MultiTenant/TenantValueVisitor.html +239 -0
  47. data/docs/source/_static/api-reference/MultiTenant.html +1454 -0
  48. data/docs/source/_static/api-reference/MultiTenantFindBy.html +180 -0
  49. data/docs/source/_static/api-reference/Sidekiq/Client.html +302 -0
  50. data/docs/source/_static/api-reference/Sidekiq/Middleware/MultiTenant/Client.html +217 -0
  51. data/docs/source/_static/api-reference/Sidekiq/Middleware/MultiTenant/Server.html +219 -0
  52. data/docs/source/_static/api-reference/Sidekiq/Middleware/MultiTenant.html +126 -0
  53. data/docs/source/_static/api-reference/Sidekiq.html +126 -0
  54. data/docs/source/_static/api-reference/_index.html +399 -0
  55. data/docs/source/_static/api-reference/class_list.html +51 -0
  56. data/docs/source/_static/api-reference/css/common.css +1 -0
  57. data/docs/source/_static/api-reference/css/full_list.css +58 -0
  58. data/docs/source/_static/api-reference/css/style.css +497 -0
  59. data/docs/source/_static/api-reference/file.README.html +167 -0
  60. data/docs/source/_static/api-reference/file_list.html +56 -0
  61. data/docs/source/_static/api-reference/frames.html +17 -0
  62. data/docs/source/_static/api-reference/index.html +167 -0
  63. data/docs/source/_static/api-reference/js/app.js +314 -0
  64. data/docs/source/_static/api-reference/js/full_list.js +216 -0
  65. data/docs/source/_static/api-reference/js/jquery.js +4 -0
  66. data/docs/source/_static/api-reference/method_list.html +715 -0
  67. data/docs/source/_static/api-reference/top-level-namespace.html +126 -0
  68. data/docs/source/_templates/.gitignore +4 -0
  69. data/docs/source/api-reference.rst +8 -0
  70. data/docs/source/appendix.rst +26 -0
  71. data/docs/source/changelog.rst +8 -0
  72. data/docs/source/community-and-support.rst +26 -0
  73. data/docs/source/conf.py +30 -0
  74. data/docs/source/contributing.rst +70 -0
  75. data/docs/source/getting-started.rst +37 -0
  76. data/docs/source/guides-and-tutorials.rst +129 -0
  77. data/docs/source/index.rst +54 -0
  78. data/docs/source/introduction.rst +33 -0
  79. data/docs/source/license.rst +22 -0
  80. data/docs/source/troubleshooting.rst +41 -0
  81. data/docs/source/usage-guide.rst +59 -0
  82. data/lib/activerecord-multi-tenant/arel_visitors_depth_first.rb +183 -174
  83. data/lib/activerecord-multi-tenant/controller_extensions.rb +15 -4
  84. data/lib/activerecord-multi-tenant/copy_from_client.rb +4 -0
  85. data/lib/activerecord-multi-tenant/fast_truncate.rb +4 -2
  86. data/lib/activerecord-multi-tenant/habtm.rb +50 -0
  87. data/lib/activerecord-multi-tenant/migrations.rb +18 -8
  88. data/lib/activerecord-multi-tenant/model_extensions.rb +78 -37
  89. data/lib/activerecord-multi-tenant/multi_tenant.rb +40 -21
  90. data/lib/activerecord-multi-tenant/query_monitor.rb +21 -5
  91. data/lib/activerecord-multi-tenant/query_rewriter.rb +111 -80
  92. data/lib/activerecord-multi-tenant/sidekiq.rb +31 -20
  93. data/lib/activerecord-multi-tenant/version.rb +1 -1
  94. data/lib/activerecord-multi-tenant.rb +3 -12
  95. data/lib/activerecord_multi_tenant.rb +12 -0
  96. data/spec/activerecord-multi-tenant/associations_spec.rb +21 -0
  97. data/spec/activerecord-multi-tenant/controller_extensions_spec.rb +3 -2
  98. data/spec/activerecord-multi-tenant/fast_truncate_spec.rb +8 -6
  99. data/spec/activerecord-multi-tenant/model_extensions_spec.rb +233 -153
  100. data/spec/activerecord-multi-tenant/multi_tenant_spec.rb +15 -13
  101. data/spec/activerecord-multi-tenant/query_rewriter_spec.rb +60 -59
  102. data/spec/activerecord-multi-tenant/record_callback_spec.rb +0 -0
  103. data/spec/activerecord-multi-tenant/record_finding_spec.rb +11 -11
  104. data/spec/activerecord-multi-tenant/record_modifications_spec.rb +4 -4
  105. data/spec/activerecord-multi-tenant/sidekiq_spec.rb +10 -10
  106. data/spec/database.yml +0 -0
  107. data/spec/schema.rb +20 -2
  108. data/spec/spec_helper.rb +46 -17
  109. data/spec/support/format_sql.rb +20 -0
  110. metadata +130 -25
  111. data/.github/workflows/CI.yml +0 -47
  112. data/gemfiles/.bundle/config +0 -2
  113. data/gemfiles/active_record_6.0.gemfile +0 -8
  114. data/gemfiles/active_record_6.1.gemfile +0 -8
  115. data/gemfiles/active_record_7.0.gemfile +0 -8
  116. data/gemfiles/rails_6.0.gemfile +0 -8
  117. data/gemfiles/rails_6.1.gemfile +0 -8
  118. data/gemfiles/rails_7.0.gemfile +0 -8
  119. data/lib/activerecord-multi-tenant/with_lock.rb +0 -15
  120. data/spec/activerecord-multi-tenant/schema_dumper_tester.rb +0 -0
@@ -0,0 +1,56 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
+ <meta charset="utf-8" />
6
+
7
+ <link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" />
8
+
9
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" />
10
+
11
+
12
+
13
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
16
+
17
+
18
+ <title>File List</title>
19
+ <base id="base_target" target="_parent" />
20
+ </head>
21
+ <body>
22
+ <div id="content">
23
+ <div class="fixed_header">
24
+ <h1 id="full_list_header">File List</h1>
25
+ <div id="full_list_nav">
26
+
27
+ <span><a target="_self" href="class_list.html">
28
+ Classes
29
+ </a></span>
30
+
31
+ <span><a target="_self" href="method_list.html">
32
+ Methods
33
+ </a></span>
34
+
35
+ <span><a target="_self" href="file_list.html">
36
+ Files
37
+ </a></span>
38
+
39
+ </div>
40
+
41
+ <div id="search">Search: <input type="text" /></div>
42
+ </div>
43
+
44
+ <ul id="full_list" class="file">
45
+
46
+
47
+ <li id="object_README" class="odd">
48
+ <div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
49
+ </li>
50
+
51
+
52
+
53
+ </ul>
54
+ </div>
55
+ </body>
56
+ </html>
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Documentation by YARD 0.9.34</title>
6
+ </head>
7
+ <script type="text/javascript">
8
+ var match = unescape(window.location.hash).match(/^#!(.+)/);
9
+ var name = match ? match[1] : 'index.html';
10
+ name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
11
+ window.top.location = name;
12
+ </script>
13
+ <noscript>
14
+ <h1>Oops!</h1>
15
+ <h2>YARD requires JavaScript!</h2>
16
+ </noscript>
17
+ </html>
@@ -0,0 +1,167 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ File: README
8
+
9
+ &mdash; Documentation by YARD 0.9.34
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "README";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
+ <span class="title">File: README</span>
41
+
42
+ </div>
43
+
44
+ <div id="search">
45
+
46
+ <a class="full_list_link" id="class_list_link"
47
+ href="class_list.html">
48
+
49
+ <svg width="24" height="24">
50
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
51
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
52
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
53
+ </svg>
54
+ </a>
55
+
56
+ </div>
57
+ <div class="clear"></div>
58
+ </div>
59
+
60
+ <div id="content"><div id='filecontents'>
61
+ <h1 id="label-activerecord-multi-tenant++rdoc-image-3Ahttps-3A-2F-2Fimg.shields.io-2Fgem-2Fv-2Factiverecord-multi-tenant.svg++rdoc-image-3Ahttps-3A-2F-2Fimg.shields.io-2Fgem-2Fdt-2Factiverecord-multi-tenant.svg">activerecord-multi-tenant <a href="https://rubygems.org/gems/activerecord-multi-tenant"> rdoc-image:https://img.shields.io/gem/v/activerecord-multi-tenant.svg</a> <a href="https://rubygems.org/gems/activerecord-multi-tenant"> rdoc-image:https://img.shields.io/gem/dt/activerecord-multi-tenant.svg</a></h1>
62
+
63
+ <p>Introduction Post: <a href="https://www.citusdata.com/blog/2017/01/05/easily-scale-out-multi-tenant-apps">www.citusdata.com/blog/2017/01/05/easily-scale-out-multi-tenant-apps</a>/</p>
64
+
65
+ <p>ActiveRecord/Rails integration for multi-tenant databases, in particular the open-source <a href="https://github.com/citusdata/citus">Citus</a> extension for PostgreSQL.</p>
66
+
67
+ <p>Enables easy scale-out by adding the tenant context to your queries, enabling the database (e.g. Citus) to efficiently route queries to the right database node.</p>
68
+
69
+ <h2 id="label-Installation">Installation</h2>
70
+
71
+ <p>Add the following to your Gemfile:</p>
72
+
73
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>activerecord-multi-tenant</span><span class='tstring_end'>&#39;</span></span>
74
+ </code></pre>
75
+
76
+ <h2 id="label-Supported+Rails+versions">Supported Rails versions</h2>
77
+
78
+ <p>All Ruby on Rails versions starting with 6.0 or newer (up to 7.0) are supported.</p>
79
+
80
+ <p>This gem only supports ActiveRecord (the Rails default ORM), and not alternative ORMs like Sequel.</p>
81
+
82
+ <h2 id="label-Usage">Usage</h2>
83
+
84
+ <p>It is required that you add <code>multi_tenant</code> definitions to your model in order to have full support for Citus, in particular when updating records.</p>
85
+
86
+ <p>In the example of an analytics application, sharding on <code>customer_id</code>, annotate your models like this:</p>
87
+
88
+ <pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>PageView</span> <span class='op'>&lt;</span> <span class='const'><span class='object_link'><a href="ActiveRecord.html" title="ActiveRecord (module)">ActiveRecord</a></span></span><span class='op'>::</span><span class='const'>Base</span>
89
+ <span class='id identifier rubyid_multi_tenant'>multi_tenant</span> <span class='symbol'>:customer</span>
90
+ <span class='id identifier rubyid_belongs_to'>belongs_to</span> <span class='symbol'>:site</span>
91
+
92
+ <span class='comment'># ...
93
+ </span><span class='kw'>end</span>
94
+
95
+ <span class='kw'>class</span> <span class='const'>Site</span> <span class='op'>&lt;</span> <span class='const'><span class='object_link'><a href="ActiveRecord.html" title="ActiveRecord (module)">ActiveRecord</a></span></span><span class='op'>::</span><span class='const'>Base</span>
96
+ <span class='id identifier rubyid_multi_tenant'>multi_tenant</span> <span class='symbol'>:customer</span>
97
+ <span class='id identifier rubyid_has_many'>has_many</span> <span class='symbol'>:page_views</span>
98
+
99
+ <span class='comment'># ...
100
+ </span><span class='kw'>end</span>
101
+ </code></pre>
102
+
103
+ <p>and then wrap all code that runs queries/modifications in blocks like this:</p>
104
+
105
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_customer'>customer</span> <span class='op'>=</span> <span class='const'>Customer</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_session'>session</span><span class='lbracket'>[</span><span class='symbol'>:current_customer_id</span><span class='rbracket'>]</span><span class='rparen'>)</span>
106
+ <span class='comment'># ...
107
+ </span><span class='const'><span class='object_link'><a href="MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_with'><span class='object_link'><a href="MultiTenant.html#with-class_method" title="MultiTenant.with (method)">with</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_customer'>customer</span><span class='rparen'>)</span> <span class='kw'>do</span>
108
+ <span class='id identifier rubyid_site'>site</span> <span class='op'>=</span> <span class='const'>Site</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:site_id</span><span class='rbracket'>]</span><span class='rparen'>)</span>
109
+ <span class='id identifier rubyid_site'>site</span><span class='period'>.</span><span class='id identifier rubyid_update!'>update!</span> <span class='label'>last_accessed_at:</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span>
110
+ <span class='id identifier rubyid_site'>site</span><span class='period'>.</span><span class='id identifier rubyid_page_views'>page_views</span><span class='period'>.</span><span class='id identifier rubyid_count'>count</span>
111
+ <span class='kw'>end</span>
112
+ </code></pre>
113
+
114
+ <p>Inside controllers you can use a before_action together with set_current_tenant, to set the tenant for the current request:</p>
115
+
116
+ <pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>ApplicationController</span> <span class='op'>&lt;</span> <span class='const'>ActionController</span><span class='op'>::</span><span class='const'>Base</span>
117
+ <span class='id identifier rubyid_set_current_tenant_through_filter'>set_current_tenant_through_filter</span> <span class='comment'># Required to opt into this behavior
118
+ </span> <span class='id identifier rubyid_before_action'>before_action</span> <span class='symbol'>:set_customer_as_tenant</span>
119
+
120
+ <span class='kw'>def</span> <span class='id identifier rubyid_set_customer_as_tenant'>set_customer_as_tenant</span>
121
+ <span class='id identifier rubyid_customer'>customer</span> <span class='op'>=</span> <span class='const'>Customer</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_session'>session</span><span class='lbracket'>[</span><span class='symbol'>:current_customer_id</span><span class='rbracket'>]</span><span class='rparen'>)</span>
122
+ <span class='id identifier rubyid_set_current_tenant'>set_current_tenant</span><span class='lparen'>(</span><span class='id identifier rubyid_customer'>customer</span><span class='rparen'>)</span>
123
+ <span class='kw'>end</span>
124
+ <span class='kw'>end</span>
125
+ </code></pre>
126
+
127
+ <h2 id="label-Rolling+out+activerecord-multi-tenant+for+your+application+-28write-only+mode-29">Rolling out activerecord-multi-tenant for your application (write-only mode)</h2>
128
+
129
+ <p>The library relies on tenant_id to be present and NOT NULL for all rows. However, its often useful to have the library set the tenant_id for new records, and then backfilling tenant_id for existing records as a background task.</p>
130
+
131
+ <p>To support this, there is a write-only mode, in which tenant_id is not included in queries, but only set for new records. Include the following in an initializer to enable it:</p>
132
+
133
+ <pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_enable_write_only_mode'><span class='object_link'><a href="MultiTenant.html#enable_write_only_mode-class_method" title="MultiTenant.enable_write_only_mode (method)">enable_write_only_mode</a></span></span>
134
+ </code></pre>
135
+
136
+ <p>Once you are ready to enforce tenancy, make your tenant_id column NOT NULL and simply remove that line.</p>
137
+
138
+ <h2 id="label-Frequently+Asked+Questions">Frequently Asked Questions</h2>
139
+ <ul><li>
140
+ <p><strong>What if I have a table that doesn’t relate to my tenant?</strong> (e.g. templates that are the same in every account)</p>
141
+ </li></ul>
142
+
143
+ <p>We recommend not using activerecord-multi-tenant on these tables. In case only some records in a table are not associated to a tenant (i.e. your templates are in the same table as actual objects), we recommend setting the tenant_id to 0, and then using MultiTenant.with(0) to access these objects.</p>
144
+ <ul><li>
145
+ <p><strong>What if my tenant model is not defined in my application?</strong></p>
146
+ </li></ul>
147
+
148
+ <p>The tenant model does not have to be defined. Use the gem as if the model was present. <code>MultiTenant.with</code> accepts either a tenant id or model instance.</p>
149
+
150
+ <h2 id="label-Credits">Credits</h2>
151
+
152
+ <p>This gem was initially based on <a href="https://github.com/ErwinM/acts_as_tenant">acts_as_tenant</a>, and still shares some code. We thank the authors for their efforts.</p>
153
+
154
+ <h2 id="label-License">License</h2>
155
+
156
+ <p>Copyright © 2018, Citus Data Inc.<br> Licensed under the MIT license, see LICENSE file for details.</p>
157
+ </div></div>
158
+
159
+ <div id="footer">
160
+ Generated on Sat May 27 10:16:23 2023 by
161
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
162
+ 0.9.34 (ruby-3.2.2).
163
+ </div>
164
+
165
+ </div>
166
+ </body>
167
+ </html>
@@ -0,0 +1,314 @@
1
+ (function() {
2
+
3
+ var localStorage = {}, sessionStorage = {};
4
+ try { localStorage = window.localStorage; } catch (e) { }
5
+ try { sessionStorage = window.sessionStorage; } catch (e) { }
6
+
7
+ function createSourceLinks() {
8
+ $('.method_details_list .source_code').
9
+ before("<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>");
10
+ $('.toggleSource').toggle(function() {
11
+ $(this).parent().nextAll('.source_code').slideDown(100);
12
+ $(this).text("Hide source");
13
+ },
14
+ function() {
15
+ $(this).parent().nextAll('.source_code').slideUp(100);
16
+ $(this).text("View source");
17
+ });
18
+ }
19
+
20
+ function createDefineLinks() {
21
+ var tHeight = 0;
22
+ $('.defines').after(" <a href='#' class='toggleDefines'>more...</a>");
23
+ $('.toggleDefines').toggle(function() {
24
+ tHeight = $(this).parent().prev().height();
25
+ $(this).prev().css('display', 'inline');
26
+ $(this).parent().prev().height($(this).parent().height());
27
+ $(this).text("(less)");
28
+ },
29
+ function() {
30
+ $(this).prev().hide();
31
+ $(this).parent().prev().height(tHeight);
32
+ $(this).text("more...");
33
+ });
34
+ }
35
+
36
+ function createFullTreeLinks() {
37
+ var tHeight = 0;
38
+ $('.inheritanceTree').toggle(function() {
39
+ tHeight = $(this).parent().prev().height();
40
+ $(this).parent().toggleClass('showAll');
41
+ $(this).text("(hide)");
42
+ $(this).parent().prev().height($(this).parent().height());
43
+ },
44
+ function() {
45
+ $(this).parent().toggleClass('showAll');
46
+ $(this).parent().prev().height(tHeight);
47
+ $(this).text("show all");
48
+ });
49
+ }
50
+
51
+ function searchFrameButtons() {
52
+ $('.full_list_link').click(function() {
53
+ toggleSearchFrame(this, $(this).attr('href'));
54
+ return false;
55
+ });
56
+ window.addEventListener('message', function(e) {
57
+ if (e.data === 'navEscape') {
58
+ $('#nav').slideUp(100);
59
+ $('#search a').removeClass('active inactive');
60
+ $(window).focus();
61
+ }
62
+ });
63
+
64
+ $(window).resize(function() {
65
+ if ($('#search:visible').length === 0) {
66
+ $('#nav').removeAttr('style');
67
+ $('#search a').removeClass('active inactive');
68
+ $(window).focus();
69
+ }
70
+ });
71
+ }
72
+
73
+ function toggleSearchFrame(id, link) {
74
+ var frame = $('#nav');
75
+ $('#search a').removeClass('active').addClass('inactive');
76
+ if (frame.attr('src') === link && frame.css('display') !== "none") {
77
+ frame.slideUp(100);
78
+ $('#search a').removeClass('active inactive');
79
+ }
80
+ else {
81
+ $(id).addClass('active').removeClass('inactive');
82
+ if (frame.attr('src') !== link) frame.attr('src', link);
83
+ frame.slideDown(100);
84
+ }
85
+ }
86
+
87
+ function linkSummaries() {
88
+ $('.summary_signature').click(function() {
89
+ document.location = $(this).find('a').attr('href');
90
+ });
91
+ }
92
+
93
+ function summaryToggle() {
94
+ $('.summary_toggle').click(function(e) {
95
+ e.preventDefault();
96
+ localStorage.summaryCollapsed = $(this).text();
97
+ $('.summary_toggle').each(function() {
98
+ $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
99
+ var next = $(this).parent().parent().nextAll('ul.summary').first();
100
+ if (next.hasClass('compact')) {
101
+ next.toggle();
102
+ next.nextAll('ul.summary').first().toggle();
103
+ }
104
+ else if (next.hasClass('summary')) {
105
+ var list = $('<ul class="summary compact" />');
106
+ list.html(next.html());
107
+ list.find('.summary_desc, .note').remove();
108
+ list.find('a').each(function() {
109
+ $(this).html($(this).find('strong').html());
110
+ $(this).parent().html($(this)[0].outerHTML);
111
+ });
112
+ next.before(list);
113
+ next.toggle();
114
+ }
115
+ });
116
+ return false;
117
+ });
118
+ if (localStorage.summaryCollapsed == "collapse") {
119
+ $('.summary_toggle').first().click();
120
+ } else { localStorage.summaryCollapsed = "expand"; }
121
+ }
122
+
123
+ function constantSummaryToggle() {
124
+ $('.constants_summary_toggle').click(function(e) {
125
+ e.preventDefault();
126
+ localStorage.summaryCollapsed = $(this).text();
127
+ $('.constants_summary_toggle').each(function() {
128
+ $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
129
+ var next = $(this).parent().parent().nextAll('dl.constants').first();
130
+ if (next.hasClass('compact')) {
131
+ next.toggle();
132
+ next.nextAll('dl.constants').first().toggle();
133
+ }
134
+ else if (next.hasClass('constants')) {
135
+ var list = $('<dl class="constants compact" />');
136
+ list.html(next.html());
137
+ list.find('dt').each(function() {
138
+ $(this).addClass('summary_signature');
139
+ $(this).text( $(this).text().split('=')[0]);
140
+ if ($(this).has(".deprecated").length) {
141
+ $(this).addClass('deprecated');
142
+ };
143
+ });
144
+ // Add the value of the constant as "Tooltip" to the summary object
145
+ list.find('pre.code').each(function() {
146
+ console.log($(this).parent());
147
+ var dt_element = $(this).parent().prev();
148
+ var tooltip = $(this).text();
149
+ if (dt_element.hasClass("deprecated")) {
150
+ tooltip = 'Deprecated. ' + tooltip;
151
+ };
152
+ dt_element.attr('title', tooltip);
153
+ });
154
+ list.find('.docstring, .tags, dd').remove();
155
+ next.before(list);
156
+ next.toggle();
157
+ }
158
+ });
159
+ return false;
160
+ });
161
+ if (localStorage.summaryCollapsed == "collapse") {
162
+ $('.constants_summary_toggle').first().click();
163
+ } else { localStorage.summaryCollapsed = "expand"; }
164
+ }
165
+
166
+ function generateTOC() {
167
+ if ($('#filecontents').length === 0) return;
168
+ var _toc = $('<ol class="top"></ol>');
169
+ var show = false;
170
+ var toc = _toc;
171
+ var counter = 0;
172
+ var tags = ['h2', 'h3', 'h4', 'h5', 'h6'];
173
+ var i;
174
+ var curli;
175
+ if ($('#filecontents h1').length > 1) tags.unshift('h1');
176
+ for (i = 0; i < tags.length; i++) { tags[i] = '#filecontents ' + tags[i]; }
177
+ var lastTag = parseInt(tags[0][1], 10);
178
+ $(tags.join(', ')).each(function() {
179
+ if ($(this).parents('.method_details .docstring').length != 0) return;
180
+ if (this.id == "filecontents") return;
181
+ show = true;
182
+ var thisTag = parseInt(this.tagName[1], 10);
183
+ if (this.id.length === 0) {
184
+ var proposedId = $(this).attr('toc-id');
185
+ if (typeof(proposedId) != "undefined") this.id = proposedId;
186
+ else {
187
+ var proposedId = $(this).text().replace(/[^a-z0-9-]/ig, '_');
188
+ if ($('#' + proposedId).length > 0) { proposedId += counter; counter++; }
189
+ this.id = proposedId;
190
+ }
191
+ }
192
+ if (thisTag > lastTag) {
193
+ for (i = 0; i < thisTag - lastTag; i++) {
194
+ if ( typeof(curli) == "undefined" ) {
195
+ curli = $('<li/>');
196
+ toc.append(curli);
197
+ }
198
+ toc = $('<ol/>');
199
+ curli.append(toc);
200
+ curli = undefined;
201
+ }
202
+ }
203
+ if (thisTag < lastTag) {
204
+ for (i = 0; i < lastTag - thisTag; i++) {
205
+ toc = toc.parent();
206
+ toc = toc.parent();
207
+ }
208
+ }
209
+ var title = $(this).attr('toc-title');
210
+ if (typeof(title) == "undefined") title = $(this).text();
211
+ curli =$('<li><a href="#' + this.id + '">' + title + '</a></li>');
212
+ toc.append(curli);
213
+ lastTag = thisTag;
214
+ });
215
+ if (!show) return;
216
+ html = '<div id="toc"><p class="title hide_toc"><a href="#"><strong>Table of Contents</strong></a></p></div>';
217
+ $('#content').prepend(html);
218
+ $('#toc').append(_toc);
219
+ $('#toc .hide_toc').toggle(function() {
220
+ $('#toc .top').slideUp('fast');
221
+ $('#toc').toggleClass('hidden');
222
+ $('#toc .title small').toggle();
223
+ }, function() {
224
+ $('#toc .top').slideDown('fast');
225
+ $('#toc').toggleClass('hidden');
226
+ $('#toc .title small').toggle();
227
+ });
228
+ }
229
+
230
+ function navResizeFn(e) {
231
+ if (e.which !== 1) {
232
+ navResizeFnStop();
233
+ return;
234
+ }
235
+
236
+ sessionStorage.navWidth = e.pageX.toString();
237
+ $('.nav_wrap').css('width', e.pageX);
238
+ $('.nav_wrap').css('-ms-flex', 'inherit');
239
+ }
240
+
241
+ function navResizeFnStop() {
242
+ $(window).unbind('mousemove', navResizeFn);
243
+ window.removeEventListener('message', navMessageFn, false);
244
+ }
245
+
246
+ function navMessageFn(e) {
247
+ if (e.data.action === 'mousemove') navResizeFn(e.data.event);
248
+ if (e.data.action === 'mouseup') navResizeFnStop();
249
+ }
250
+
251
+ function navResizer() {
252
+ $('#resizer').mousedown(function(e) {
253
+ e.preventDefault();
254
+ $(window).mousemove(navResizeFn);
255
+ window.addEventListener('message', navMessageFn, false);
256
+ });
257
+ $(window).mouseup(navResizeFnStop);
258
+
259
+ if (sessionStorage.navWidth) {
260
+ navResizeFn({which: 1, pageX: parseInt(sessionStorage.navWidth, 10)});
261
+ }
262
+ }
263
+
264
+ function navExpander() {
265
+ var done = false, timer = setTimeout(postMessage, 500);
266
+ function postMessage() {
267
+ if (done) return;
268
+ clearTimeout(timer);
269
+ var opts = { action: 'expand', path: pathId };
270
+ document.getElementById('nav').contentWindow.postMessage(opts, '*');
271
+ done = true;
272
+ }
273
+
274
+ window.addEventListener('message', function(event) {
275
+ if (event.data === 'navReady') postMessage();
276
+ return false;
277
+ }, false);
278
+ }
279
+
280
+ function mainFocus() {
281
+ var hash = window.location.hash;
282
+ if (hash !== '' && $(hash)[0]) {
283
+ $(hash)[0].scrollIntoView();
284
+ }
285
+
286
+ setTimeout(function() { $('#main').focus(); }, 10);
287
+ }
288
+
289
+ function navigationChange() {
290
+ // This works around the broken anchor navigation with the YARD template.
291
+ window.onpopstate = function() {
292
+ var hash = window.location.hash;
293
+ if (hash !== '' && $(hash)[0]) {
294
+ $(hash)[0].scrollIntoView();
295
+ }
296
+ };
297
+ }
298
+
299
+ $(document).ready(function() {
300
+ navResizer();
301
+ navExpander();
302
+ createSourceLinks();
303
+ createDefineLinks();
304
+ createFullTreeLinks();
305
+ searchFrameButtons();
306
+ linkSummaries();
307
+ summaryToggle();
308
+ constantSummaryToggle();
309
+ generateTOC();
310
+ mainFocus();
311
+ navigationChange();
312
+ });
313
+
314
+ })();