roda-symbolized_params 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 63439f5e4d7cc0d903050328ae5c35355f2d5bee
4
+ data.tar.gz: fa21d7b13a65402643929e1fd8f7d31679888a28
5
+ SHA512:
6
+ metadata.gz: 8e02e5e9c4622c7311b40f7e7353d0ca51beeb1d5d34715d3ee518548457092c20981f177dd60dd7bb44392bc643f9e312addc18ba75723d5c1669e5f87422f6
7
+ data.tar.gz: 1479f818dd4e77633a0e9a7b7e1e987cfd5bf2f7fda13f4853e92a5de8e6b246f3ab19edfd762639e4c1b8a6eeb697a53d94822554e64f3f3615394009df8d40
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Janko Marohnić
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,42 @@
1
+ # Roda::SymbolizedParams
2
+
3
+ A [Roda](https://github.com/jeremyevans/roda) plugin that exposes symbolized
4
+ request params.
5
+
6
+ ## Installation
7
+
8
+ ```ruby
9
+ gem 'roda-symbolized_params'
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```ruby
15
+ require "roda"
16
+
17
+ class App < Roda
18
+ plugin :symbolized_params
19
+
20
+ route do |r|
21
+ r.root do
22
+ params[:foo] # symbolized request params
23
+ end
24
+ end
25
+ end
26
+ ```
27
+
28
+ This plugin exposes the `#params` method which is just a wrapper around
29
+ `request.params`, but with symbolized keys.
30
+
31
+ This plugin is similar to the built-in `indifferent_params` plugin, but with
32
+ real symbolized keys. Advantage of this plugin is that you don't have to always
33
+ keep in mind that you still actually have string keys, so you can normally use
34
+ methods like `Hash#fetch`, and you can use params as keyword arguments.
35
+
36
+ An obvious disadvantage is that new symbols are created each time, which have
37
+ to be garbage collected. So you shouldn't use this plugin in Ruby versions <
38
+ 2.2.0, because Ruby Symbol GC was only introduced in Ruby 2.2.0.
39
+
40
+ ## License
41
+
42
+ [MIT](LICENSE.txt)
@@ -0,0 +1,28 @@
1
+ class Roda
2
+ module RodaPlugins
3
+ module SymbolizedParams
4
+ module InstanceMethods
5
+ def params
6
+ @_params ||= symbolized_params(request.params)
7
+ end
8
+
9
+ private
10
+
11
+ def symbolized_params(params)
12
+ case params
13
+ when Hash
14
+ hash = {}
15
+ params.each { |k, v| hash[k.to_sym] = symbolized_params(v) }
16
+ hash
17
+ when Array
18
+ params.map { |x| symbolized_params(x) }
19
+ else
20
+ params
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ register_plugin(:symbolized_params, SymbolizedParams)
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roda-symbolized_params
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Janko Marohnić
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: roda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A plugin for Roda which exposes symbolized request params
56
+ email:
57
+ - janko.marohnic@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - README.md
64
+ - lib/roda/plugins/symbolized_params.rb
65
+ homepage: https://github.com/janko-m/roda-symbolized_params
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.5
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: A plugin for Roda which exposes symbolized request params
89
+ test_files: []
90
+ has_rdoc: