rack-undefined 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.MIT +19 -0
  3. data/README.md +41 -0
  4. data/lib/rack-undefined.rb +25 -0
  5. metadata +74 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b92e7d0c14484c9a2dccc449cd6414c56df613c
4
+ data.tar.gz: 09890a88ced2490a262ab9c48bd7e21407b8fe5f
5
+ SHA512:
6
+ metadata.gz: b409da04cdc2f63d7a84daf07eb93cd87a3126b9ab0263d019720f9357711b77aa21e6ac3798da9797032b93f50560672655b230940b4c93610fabd11b659370
7
+ data.tar.gz: 51dbd7ad928e4cec5e2d967ef034ffa9734f45c808bae18800ce3852c42ec2964907f38853337708a4f19569fdb92966dd4b60bbc244ea60887dee2c3c90bf88
data/LICENSE.MIT ADDED
@@ -0,0 +1,19 @@
1
+ Copyright © 2013 Conrad Irwin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ rack-undefined replaces any parameters with the string "undefined" or "null" by an honest Ruby nil.
2
+
3
+ ## Installation
4
+
5
+ Like for any rubygem, you can do:
6
+
7
+ ```shell
8
+ gem install rack-undefined
9
+ ```
10
+
11
+ Or add it to your Gemfile:
12
+
13
+ ```ruby
14
+ gem 'rack-undefined'
15
+ ```
16
+
17
+ ## Introduction
18
+
19
+ Some javascript libraries, that shall remain [zepto](http://zeptojs.com/), like to send the string "undefined" if you serialize an object with undefined values.
20
+
21
+ This library fixes that problem at the rack level, so your rails app doesn't need to care. The benefits of this should be obvious:
22
+
23
+ 1. Transparently fixes `validates_presence_of` without needing to monkey patch.
24
+ 2. Saves space in your database, the null byte is waay smaller than the word "null".
25
+ 3. Simplifies `if foo.nil? || foo == "undefined"` into just `if foo.nil?`.
26
+
27
+ ## Testimonials
28
+
29
+ * "This library is awesome, it removes the temptation for me to use badly coded websites." — John M. Null, CA
30
+ * "undefined is not a function, man" — Steve Toner.
31
+
32
+ ## TODO
33
+
34
+ * ruby-1.9 support
35
+ * (maybe) handle typos (like null or nudefined)
36
+
37
+ ## Meta-fu
38
+
39
+ Dual licensed under WTFPL and MIT (see LICENSE.MIT for details).
40
+
41
+ <small>In case you didn't realise yet, it is a joke, please don't use it.</small>
@@ -0,0 +1,25 @@
1
+ require 'funkify'
2
+ class RackUndefined < Struct.new(:app)
3
+ include Funkify and auto_curry
4
+
5
+ def call(env)
6
+ request = Rack::Request.new(env)
7
+ request.params.each do |key, value|
8
+ request.update_param key, undefine(value)
9
+ end
10
+ app.call(env)
11
+ end
12
+
13
+ def undefine(obj)
14
+ case obj
15
+ when "null", "undefined"
16
+ nil
17
+ when Array
18
+ obj.map(&undefine)
19
+ when Hash
20
+ Hash[obj.map(&undefine)]
21
+ else
22
+ obj
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-undefined
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Conrad Irwin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: funkify
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Now you don't have to worry about bugs in your javascript code anymore!
42
+ email: conrad.irwin@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - LICENSE.MIT
48
+ - README.md
49
+ - lib/rack-undefined.rb
50
+ homepage: http://github.com/ConradIrwin/rack-undefined
51
+ licenses: []
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.0.3
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Replaces 'undefined' and 'null' parameters with nil.
73
+ test_files: []
74
+ has_rdoc: