memflash 1.0.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 943332e33834ec641d1020b589037e59006fb352a7b1e3ac2f1d6119483cd436
4
+ data.tar.gz: d7f6c2e6311631be58c63f49e42f86b3a628689f8caba17e69dad23a0853fa68
5
+ SHA512:
6
+ metadata.gz: 14056a3d5619cfb6277a8a79a8cfa375ed09f3f0a349d10570257687251439df7e9d652ddfe86490aa42f7460c24ab2202a5814c64976a37b24d252aeb60403b
7
+ data.tar.gz: bd46e039c1b18165fc75d0c6c924e112e7f91fed35ec22203ad12d548a334c4f3f950c5ef9cb9d00f4be80bc9122bc2ec0d43917b70a2736d8b80bedf7e9be0c
data/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,62 @@
1
+ ## Memflash [![Build Status](https://secure.travis-ci.org/zendesk/memflash.png)](http://travis-ci.org/zendesk/memflash)
2
+
3
+ Memflash is a gem which enables storing really long values in the Rails FlashHash
4
+ without writing them to the session. Instead, it transparently uses `Rails.cache`, thus
5
+ enabling the flash in your actions to contain large values, and still fit in a cookie-based
6
+ session store.
7
+
8
+ ## How do I use it?
9
+
10
+ Memflash is completely transparent -- requiring the gem automatically enhances FlashHash
11
+ with caching-enabled reads and writes.
12
+
13
+ By default, any message that is over 300 characters long, will be saved in Rails.cache,
14
+ and a pointer to it stored in the flash. You can change this anywhere in your app by:
15
+
16
+ ```ruby
17
+ Memflash.threshold = #{length-at-which-writing-to-the-cache-is-trigerred}
18
+ ```
19
+
20
+ ## How does it work?
21
+
22
+ Memflash ties into the `[]` and `[]=` methods of Rails's FlashHash. On writes, if the value
23
+ being written has a length over Memflash.threshold, Memflash generates a pseudo-random
24
+ key for it, writes the pseudo-random key and original value to `Rails.cache`, and stores
25
+ the original key and pseudo-random key in the flash. Conceptually, when you write
26
+ `flash[:error] = "some message"`, this is equivalent to:
27
+
28
+ ```ruby
29
+ if "some message".length >= Memflash.threshold
30
+ # generate a psedudo-random key, memflash_key
31
+ # write memflash_key, "some message" to Rails.cache
32
+ # write :error, memflash_key to the flash
33
+ else
34
+ # write :error, "some message" to the flash, as usual
35
+ end
36
+ ```
37
+
38
+ On the flip side, reading from the flash, `flash[:error]` is conceptually equivalent to:
39
+
40
+ ```ruby
41
+ if the value for :error stored in the flash is a memflash key
42
+ # read the original (large) value from Rails.cache
43
+ # return the original (large) value
44
+ else
45
+ # return the value stored in the flash, as usual
46
+ end
47
+ ```
48
+
49
+ ## Author
50
+
51
+ Authored by [Vladimir Andrijevik](mailto:vladimir@zendesk.com)
52
+
53
+ ## Copyright and license
54
+
55
+ Copyright 2013 Zendesk
56
+
57
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
58
+ You may obtain a copy of the License at
59
+
60
+ http://www.apache.org/licenses/LICENSE-2.0
61
+
62
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
@@ -1,17 +1,11 @@
1
1
  module Memflash
2
- mattr_accessor :threshold
3
- self.threshold = 300 # Messages longer than this will be stored in Rails.cache
4
-
5
- def self.included(base)
6
- base.class_eval do
7
- include InstanceMethods
8
- alias_method_chain :[]=, :caching
9
- alias_method_chain :[], :caching
10
- end
2
+ class << self
3
+ attr_accessor :threshold
11
4
  end
5
+ self.threshold = 300 # Messages longer than this will be stored in Rails.cache
12
6
 
13
- module InstanceMethods
14
- define_method "[]_with_caching=" do |key, value|
7
+ module CachingLayer
8
+ def []=(key, value)
15
9
  value_for_hash = value
16
10
 
17
11
  if value.kind_of?(String) && value.length >= Memflash.threshold
@@ -19,25 +13,29 @@ module Memflash
19
13
  Rails.cache.write(value_for_hash, value)
20
14
  end
21
15
 
22
- send("[]_without_caching=", key, value_for_hash)
16
+ super(key, value_for_hash)
23
17
  end
24
18
 
25
- define_method "[]_with_caching" do |key|
26
- value_in_hash = send("[]_without_caching", key)
27
- memflashed?(key, value_in_hash) ? Rails.cache.read(value_in_hash) : value_in_hash
19
+ def [](key)
20
+ value_in_hash = super
21
+ if memflashed?(key, value_in_hash)
22
+ Rails.cache.read(value_in_hash)
23
+ else
24
+ value_in_hash
25
+ end
28
26
  end
29
27
 
30
28
  private
31
- def memflash_key(hash_key)
32
- "Memflash-#{hash_key}-#{Time.now.to_f}-#{Kernel.rand}"
33
- end
34
29
 
35
- def memflashed?(key, value)
36
- !!(value =~ /^Memflash-#{key}/)
37
- end
38
- end # InstanceMethods
39
- end # Memflash
30
+ def memflash_key(hash_key)
31
+ "Memflash-#{hash_key}-#{Time.now.to_f}-#{Kernel.rand}"
32
+ end
33
+
34
+ def memflashed?(key, value)
35
+ !!(value =~ /^Memflash-#{key}/)
36
+ end
37
+ end
38
+ end
40
39
 
41
- require 'action_pack'
42
- require 'action_controller'
43
- ActionController::Flash::FlashHash.class_eval { include Memflash }
40
+ require 'action_dispatch'
41
+ ActionDispatch::Flash::FlashHash.prepend Memflash::CachingLayer
metadata CHANGED
@@ -1,132 +1,154 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: memflash
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.2.1
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Vladimir Andrijevik
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2010-09-14 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2020-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
22
14
  name: actionpack
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 9
30
- segments:
31
- - 2
32
- - 3
33
- - 5
34
- version: 2.3.5
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.11
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
35
23
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: rails
39
24
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 9
46
- segments:
47
- - 2
48
- - 3
49
- - 5
50
- version: 2.3.5
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.2.11
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: minitest-rg
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
51
68
  type: :development
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: shoulda
55
69
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 35
62
- segments:
63
- - 2
64
- - 11
65
- - 0
66
- version: 2.11.0
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: wwtd
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
67
82
  type: :development
68
- version_requirements: *id003
69
- description: Memflash is a gem which enables storing really long values in the Rails FlashHash without writing them to the session. Instead, it transparently uses `Rails.cache`, thus enabling the flash in your actions to contain large values, and still fit in a cookie-based session store
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: bump
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: mocha
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ description: Memflash is a gem which enables storing really long values in the Rails
118
+ FlashHash without writing them to the session. Instead, it transparently uses `Rails.cache`,
119
+ thus enabling the flash in your actions to contain large values, and still fit in
120
+ a cookie-based session store
70
121
  email: vladimir@zendesk.com
71
122
  executables: []
72
-
73
123
  extensions: []
74
-
75
- extra_rdoc_files:
76
- - README.markdown
77
- files:
78
- - .gitignore
79
- - MIT-LICENSE
80
- - README.markdown
81
- - Rakefile
124
+ extra_rdoc_files: []
125
+ files:
126
+ - LICENSE
127
+ - README.md
82
128
  - lib/memflash.rb
83
- - memflash.gemspec
84
- - test/memflash_test.rb
85
- - test/rails/app/controllers/application.rb
86
- - test/rails/config/boot.rb
87
- - test/rails/config/environment.rb
88
- - test/rails/config/environments/test.rb
89
- - test/rails/config/routes.rb
90
- - test/test_helper.rb
91
- has_rdoc: true
92
- homepage: http://github.com/zendesk/memflash
93
- licenses: []
94
-
129
+ homepage: https://github.com/zendesk/memflash
130
+ licenses:
131
+ - Apache License Version 2.0
132
+ metadata: {}
95
133
  post_install_message:
96
- rdoc_options:
97
- - --charset=UTF-8
98
- require_paths:
134
+ rdoc_options: []
135
+ require_paths:
99
136
  - lib
100
- required_ruby_version: !ruby/object:Gem::Requirement
101
- none: false
102
- requirements:
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
103
139
  - - ">="
104
- - !ruby/object:Gem::Version
105
- hash: 3
106
- segments:
107
- - 0
108
- version: "0"
109
- required_rubygems_version: !ruby/object:Gem::Requirement
110
- none: false
111
- requirements:
140
+ - !ruby/object:Gem::Version
141
+ version: '2.5'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
112
144
  - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
- version: "0"
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
118
147
  requirements: []
119
-
120
148
  rubyforge_project:
121
- rubygems_version: 1.3.7
149
+ rubygems_version: 2.7.6.2
122
150
  signing_key:
123
- specification_version: 3
124
- summary: Memflash is a gem which enables storing really long values in the Rails FlashHash without writing them to the session
125
- test_files:
126
- - test/memflash_test.rb
127
- - test/rails/app/controllers/application.rb
128
- - test/rails/config/boot.rb
129
- - test/rails/config/environment.rb
130
- - test/rails/config/environments/test.rb
131
- - test/rails/config/routes.rb
132
- - test/test_helper.rb
151
+ specification_version: 4
152
+ summary: Memflash is a gem which enables storing really long values in the Rails FlashHash
153
+ without writing them to the session
154
+ test_files: []
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- test/rails/log/*.log
2
- pkg
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 [name of plugin creator]
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,53 +0,0 @@
1
- Memflash
2
- ========
3
-
4
- Memflash is a gem which enables storing really long values in the Rails FlashHash
5
- without writing them to the session. Instead, it transparently uses `Rails.cache`, thus
6
- enabling the flash in your actions to contain large values, and still fit in a cookie-based
7
- session store.
8
-
9
- How do I use it?
10
- ================
11
-
12
- Memflash is completely transparent -- requiring the gem automatically enhances FlashHash
13
- with caching-enabled reads and writes.
14
-
15
- By default, any message that is over 300 characters long, will be saved in Rails.cache,
16
- and a pointer to it stored in the flash. You can change this anywhere in your app by:
17
-
18
- Memflash.threshold = #{length-at-which-writing-to-the-cache-is-trigerred}
19
-
20
- How does it work?
21
- =================
22
-
23
- Memflash ties into the [] and []= methods of Rails's FlashHash. On writes, if the value
24
- being written has a length over Memflash.threshold, Memflash generates a pseudo-random
25
- key for it, writes the pseudo-random key and original value to `Rails.cache`, and stores
26
- the original key and pseudo-random key in the flash. Conceptually, when you write
27
- `flash[:error] = "some message"`, this is equivalent to:
28
-
29
- if "some message".length >= Memflash.threshold
30
- # generate a psedudo-random key, memflash_key
31
- # write memflash_key, "some message" to Rails.cache
32
- # write :error, memflash_key to the flash
33
- else
34
- # write :error, "some message" to the flash, as usual
35
- end
36
-
37
- On the flip side, reading from the flash, `flash[:error]` is conceptually equivalent to:
38
-
39
- if the value for :error stored in the flash is a memflash key
40
- # read the original (large) value from Rails.cache
41
- # return the original (large) value
42
- else
43
- # return the value stored in the flash, as usual
44
- end
45
-
46
- Anything else?
47
- ==============
48
-
49
- We'd love to hear from you!
50
-
51
- Authored by [Vladimir Andrijevik](mailto:vladimir@zendesk.com)
52
-
53
- Copyright (c) 2010 Zendesk, released under the MIT license
data/Rakefile DELETED
@@ -1,32 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "memflash"
8
- gem.summary = "Memflash is a gem which enables storing really long values in the Rails FlashHash without writing them to the session"
9
- gem.description = "Memflash is a gem which enables storing really long values in the Rails FlashHash without writing them to the session. Instead, it transparently uses `Rails.cache`, thus enabling the flash in your actions to contain large values, and still fit in a cookie-based session store"
10
- gem.email = "vladimir@zendesk.com"
11
- gem.homepage = "http://github.com/zendesk/memflash"
12
- gem.authors = ["Vladimir Andrijevik"]
13
- gem.version = "1.0.0"
14
- gem.add_dependency "actionpack", "~> 2.3.5"
15
- gem.add_development_dependency "rails", "~> 2.3.5"
16
- gem.add_development_dependency "shoulda", "~> 2.11.0"
17
-
18
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
- end
20
- Jeweler::GemcutterTasks.new
21
- rescue LoadError
22
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
- end
24
-
25
- require 'rake/testtask'
26
- Rake::TestTask.new(:test) do |test|
27
- test.libs << 'lib' << 'test'
28
- test.pattern = 'test/**/*_test.rb'
29
- test.verbose = true
30
- end
31
-
32
- task :default => :test
@@ -1,67 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{memflash}
8
- s.version = "1.0.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Vladimir Andrijevik"]
12
- s.date = %q{2010-09-14}
13
- s.description = %q{Memflash is a gem which enables storing really long values in the Rails FlashHash without writing them to the session. Instead, it transparently uses `Rails.cache`, thus enabling the flash in your actions to contain large values, and still fit in a cookie-based session store}
14
- s.email = %q{vladimir@zendesk.com}
15
- s.extra_rdoc_files = [
16
- "README.markdown"
17
- ]
18
- s.files = [
19
- ".gitignore",
20
- "MIT-LICENSE",
21
- "README.markdown",
22
- "Rakefile",
23
- "lib/memflash.rb",
24
- "memflash.gemspec",
25
- "test/memflash_test.rb",
26
- "test/rails/app/controllers/application.rb",
27
- "test/rails/config/boot.rb",
28
- "test/rails/config/environment.rb",
29
- "test/rails/config/environments/test.rb",
30
- "test/rails/config/routes.rb",
31
- "test/test_helper.rb"
32
- ]
33
- s.homepage = %q{http://github.com/zendesk/memflash}
34
- s.rdoc_options = ["--charset=UTF-8"]
35
- s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.3.7}
37
- s.summary = %q{Memflash is a gem which enables storing really long values in the Rails FlashHash without writing them to the session}
38
- s.test_files = [
39
- "test/memflash_test.rb",
40
- "test/rails/app/controllers/application.rb",
41
- "test/rails/config/boot.rb",
42
- "test/rails/config/environment.rb",
43
- "test/rails/config/environments/test.rb",
44
- "test/rails/config/routes.rb",
45
- "test/test_helper.rb"
46
- ]
47
-
48
- if s.respond_to? :specification_version then
49
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
- s.specification_version = 3
51
-
52
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
- s.add_runtime_dependency(%q<actionpack>, ["~> 2.3.5"])
54
- s.add_development_dependency(%q<rails>, ["~> 2.3.5"])
55
- s.add_development_dependency(%q<shoulda>, ["~> 2.11.0"])
56
- else
57
- s.add_dependency(%q<actionpack>, ["~> 2.3.5"])
58
- s.add_dependency(%q<rails>, ["~> 2.3.5"])
59
- s.add_dependency(%q<shoulda>, ["~> 2.11.0"])
60
- end
61
- else
62
- s.add_dependency(%q<actionpack>, ["~> 2.3.5"])
63
- s.add_dependency(%q<rails>, ["~> 2.3.5"])
64
- s.add_dependency(%q<shoulda>, ["~> 2.11.0"])
65
- end
66
- end
67
-
@@ -1,117 +0,0 @@
1
- require "test_helper"
2
-
3
- class MemflashTest < Test::Unit::TestCase
4
- class EnhancedHash < Hash
5
- include Memflash
6
- end
7
-
8
- def setup
9
- @hash = EnhancedHash.new
10
- end
11
-
12
- context "A memflash-enhanced Hash" do
13
- should "have a caching-enabled []" do
14
- assert @hash.respond_to?("[]_with_caching")
15
- end
16
-
17
- should "have a caching-enabled []=" do
18
- assert @hash.respond_to?("[]_with_caching=")
19
- end
20
- end # A memflash-enhanced Hash
21
-
22
- context "In a memflash-enhanced Hash, storing a value" do
23
- context "that is a String" do
24
- context "shorter than Memflash.threshold" do
25
- should "not affect the cache" do
26
- Rails.cache.expects(:write).never
27
-
28
- @hash[:hello] = "a" * (Memflash.threshold - 1)
29
- end # not affect the cache
30
- end # shorter than Memflash.threshold
31
-
32
- context "at least as long as Memflash.threshold" do
33
- setup do
34
- @key = "a-sample-key"
35
- @value = "a" * (Memflash.threshold)
36
- end
37
-
38
- should "call memflash_key with the key" do
39
- @hash.expects(:memflash_key).with(@key)
40
-
41
- @hash[@key] = @value
42
- end # call memflash_key with the key
43
-
44
- should "write the memflash_key and value to Rails.cache" do
45
- # Stubbing out memflash_key is necessary so we can set a proper expectation below.
46
- # Without it, the key generated when setting the expectation and the one during
47
- # the actual write are different, so the assertion fails
48
- @hash.stubs(:memflash_key).with(@key).returns("a-memflash-key")
49
-
50
- Rails.cache.expects(:write).with("a-memflash-key", @value)
51
-
52
- @hash[@key] = @value
53
- end # write the memflash_key and value to Rails.cache
54
-
55
- should "store the memflash_key in place of the original value" do
56
- # Stubbing out memflash_key is necessary so we can assert against the value
57
- # in the hash below. Without it, we don't know the memflash key that is generated,
58
- # so we cannot test whether it's in the hash or not.
59
- @hash.stubs(:memflash_key).with(@key).returns("a-memflash-key")
60
- @hash[@key] = @value
61
-
62
- assert_equal "a-memflash-key", @hash[@key]
63
- end # store the memflash_key in place of the original value
64
- end # at least as long as Memflash.threshold
65
- end # that is a String
66
-
67
- context "that is not a String" do
68
- should "not affect the cache" do
69
- Rails.cache.expects(:write).never
70
-
71
- @hash[:time] = Time.now.to_i
72
- end # not affect the cache
73
- end # that is not a String
74
- end # In a memflash-enhanced Hash, storing a value
75
-
76
- context "From a memflash-enhanced Hash, reading by a key" do
77
- should "check whether the value in the hash was memflashed" do
78
- @hash[:hello] = "world"
79
-
80
- @hash.expects(:memflashed?).with(:hello, "world")
81
-
82
- @hash[:hello]
83
- end
84
-
85
- context "whose value was memflashed" do
86
- setup do
87
- @hash.stubs(:memflashed?).returns(true)
88
- end
89
-
90
- should "retrieve the original value from Rails.cache" do
91
- key = "a-sample-memflashed-key"
92
- @hash[key] = "key-to-look-up-in-rails-cache"
93
- Rails.cache.expects(:read).with("key-to-look-up-in-rails-cache")
94
-
95
- @hash[key]
96
- end # retrieve the original value from Rails.cache
97
- end # whose value was memflashed
98
-
99
- context "whose value was not memflashed" do
100
- setup do
101
- @hash.stubs(:memflashed?).returns(false)
102
- end
103
-
104
- should "not read from Rails.cache" do
105
- Rails.cache.expects(:read).never
106
-
107
- @hash["a-non-memflashed-key"]
108
- end # not read from Rails.cache
109
- end # whose value was not memflashed
110
- end # From a memflash-enhanced Hash, reading a value
111
-
112
- context "ActionController::Flash::FlashHash" do
113
- should "be automatically cache-enhanced" do
114
- assert ActionController::Flash::FlashHash.ancestors.include?(Memflash)
115
- end
116
- end # ActionController::Flash::FlashHash
117
- end
File without changes
@@ -1,109 +0,0 @@
1
- # Don't change this file!
2
- # Configure your app in config/environment.rb and config/environments/*.rb
3
-
4
- RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
-
6
- module Rails
7
- class << self
8
- def boot!
9
- unless booted?
10
- preinitialize
11
- pick_boot.run
12
- end
13
- end
14
-
15
- def booted?
16
- defined? Rails::Initializer
17
- end
18
-
19
- def pick_boot
20
- (vendor_rails? ? VendorBoot : GemBoot).new
21
- end
22
-
23
- def vendor_rails?
24
- File.exist?("#{RAILS_ROOT}/vendor/rails")
25
- end
26
-
27
- def preinitialize
28
- load(preinitializer_path) if File.exist?(preinitializer_path)
29
- end
30
-
31
- def preinitializer_path
32
- "#{RAILS_ROOT}/config/preinitializer.rb"
33
- end
34
- end
35
-
36
- class Boot
37
- def run
38
- load_initializer
39
- Rails::Initializer.run(:set_load_path)
40
- end
41
- end
42
-
43
- class VendorBoot < Boot
44
- def load_initializer
45
- require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
- Rails::Initializer.run(:install_gem_spec_stubs)
47
- end
48
- end
49
-
50
- class GemBoot < Boot
51
- def load_initializer
52
- self.class.load_rubygems
53
- load_rails_gem
54
- require 'initializer'
55
- end
56
-
57
- def load_rails_gem
58
- if version = self.class.gem_version
59
- gem 'rails', version
60
- else
61
- gem 'rails'
62
- end
63
- rescue Gem::LoadError => load_error
64
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
65
- exit 1
66
- end
67
-
68
- class << self
69
- def rubygems_version
70
- Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
71
- end
72
-
73
- def gem_version
74
- if defined? RAILS_GEM_VERSION
75
- RAILS_GEM_VERSION
76
- elsif ENV.include?('RAILS_GEM_VERSION')
77
- ENV['RAILS_GEM_VERSION']
78
- else
79
- parse_gem_version(read_environment_rb)
80
- end
81
- end
82
-
83
- def load_rubygems
84
- require 'rubygems'
85
-
86
- unless rubygems_version >= '0.9.4'
87
- $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
88
- exit 1
89
- end
90
-
91
- rescue LoadError
92
- $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
93
- exit 1
94
- end
95
-
96
- def parse_gem_version(text)
97
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
98
- end
99
-
100
- private
101
- def read_environment_rb
102
- File.read("#{RAILS_ROOT}/config/environment.rb")
103
- end
104
- end
105
- end
106
- end
107
-
108
- # All that for this:
109
- Rails.boot!
@@ -1,9 +0,0 @@
1
- # Bootstrap the Rails environment, frameworks, and default configuration
2
- require File.join(File.dirname(__FILE__), 'boot')
3
-
4
- Rails::Initializer.run do |config|
5
- config.frameworks -= [ :active_record ]
6
- config.action_controller.session = { :key => "_memflash_session", :secret => "ac0dcc5b4d9eef497e671126a845c3c5" }
7
-
8
- config.gem 'shoulda', :lib => 'shoulda/rails'
9
- end
@@ -1,19 +0,0 @@
1
- # Settings specified here will take precedence over those in config/environment.rb
2
-
3
- # The test environment is used exclusively to run your application's
4
- # test suite. You never need to work with it otherwise. Remember that
5
- # your test database is "scratch space" for the test suite and is wiped
6
- # and recreated between test runs. Don't rely on the data there!
7
- config.cache_classes = true
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
- config.action_controller.consider_all_requests_local = true
14
- config.action_controller.perform_caching = false
15
-
16
- # Tell ActionMailer not to deliver emails to the real world.
17
- # The :test delivery method accumulates sent emails in the
18
- # ActionMailer::Base.deliveries array.
19
- config.action_mailer.delivery_method = :test
File without changes
@@ -1,6 +0,0 @@
1
- ENV["RAILS_ENV"] = "test"
2
- require File.expand_path(File.join(File.dirname(__FILE__), "rails", "config", "environment"))
3
-
4
- require 'rubygems'
5
- require 'active_support/test_case'
6
- require "memflash"