strip_params 0.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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format documentation
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in strip_params.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Strip Params
2
+
3
+ Recursively run strip! on input (built to handle params in a Rails form after some were erroring because on not-removed trailing spaces)
4
+
5
+ ## Usage
6
+
7
+ In a Rails app, add a before_filter in the ApplicationController
8
+
9
+ ```ruby
10
+ before_filter :strip_params
11
+ def strip_params
12
+ StripParams.all!(params)
13
+ end
14
+ ```
15
+
16
+ This will automatically call strip! on all the params as they are passed in.
17
+
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ require "strip_params/version"
2
+
3
+ module StripParams
4
+ def self.all!(params)
5
+ params.each do |k, v|
6
+ if v.respond_to? :strip!
7
+ v.strip!
8
+ elsif v.respond_to? :each_pair
9
+ all!(v)
10
+ end
11
+ end
12
+ params
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module StripParams
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require 'strip_params'
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe StripParams do
4
+
5
+ context "single param" do
6
+ describe "string" do
7
+ it "should strip" do
8
+ StripParams.all!(:key => "email@dev.null ").should ==
9
+ {:key => "email@dev.null"}
10
+ end
11
+ end
12
+ describe "number" do
13
+ it "should be unchanged" do
14
+ StripParams.all!(:key => 42).should == {:key => 42}
15
+ end
16
+ end
17
+ describe "nil" do
18
+ it "should be unchanged" do
19
+ StripParams.all!(:key => nil).should == {:key => nil}
20
+ end
21
+ end
22
+ end
23
+
24
+ context "nested params" do
25
+ describe "string" do
26
+ it "should strip" do
27
+ StripParams.all!(:inner => {:key => "email@dev.null "}).should ==
28
+ {:inner => {:key => "email@dev.null"}}
29
+ end
30
+ end
31
+ describe "number" do
32
+ it "should be unchanged" do
33
+ StripParams.all!(:inner => {:key => 42}).should ==
34
+ {:inner => {:key => 42}}
35
+ end
36
+ end
37
+ describe "nil" do
38
+ it "should be unchanged" do
39
+ StripParams.all!(:inner => {:key => nil}).should ==
40
+ {:inner => {:key => nil}}
41
+ end
42
+ end
43
+ end
44
+
45
+ context "doubly-nested params" do
46
+ describe "string" do
47
+ it "should strip" do
48
+ StripParams.all!(:outer => {:inner => {:key => "email@dev.null "}})
49
+ .should == {:outer => {:inner => {:key => "email@dev.null"}}}
50
+ end
51
+ end
52
+ describe "number" do
53
+ it "should be unchanged" do
54
+ StripParams.all!(:outer => {:inner => {:key => 42}}).should ==
55
+ {:outer => {:inner => {:key => 42}}}
56
+ end
57
+ end
58
+ describe "nil" do
59
+ it "should be unchanged" do
60
+ StripParams.all!(:outer => {:inner => {:key => nil}}).should ==
61
+ {:outer => {:inner => {:key => nil}}}
62
+ end
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "strip_params/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "strip_params"
7
+ s.version = StripParams::VERSION
8
+ s.authors = ["Sean Miller"]
9
+ s.email = ["sean@seanmiller.ca"]
10
+ s.homepage = "http://github.com/smiller/strip_params"
11
+ s.summary = %q{Runs strip! recursively on input params}
12
+ s.description = %q{Usage: before_filter :strip_params; def strip_params; StripParams.all!(params); end}
13
+
14
+ s.rubyforge_project = "strip_params"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.add_development_dependency "rake"
18
+ s.add_development_dependency "rspec"
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strip_params
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sean Miller
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-06 00:00:00.000000000 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: &2152044540 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *2152044540
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &2152043980 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2152043980
37
+ description: ! 'Usage: before_filter :strip_params; def strip_params; StripParams.all!(params);
38
+ end'
39
+ email:
40
+ - sean@seanmiller.ca
41
+ executables: []
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - .gitignore
46
+ - .rspec
47
+ - CHANGELOG
48
+ - Gemfile
49
+ - README.md
50
+ - Rakefile
51
+ - lib/strip_params.rb
52
+ - lib/strip_params/version.rb
53
+ - spec/spec_helper.rb
54
+ - spec/strip_params_spec.rb
55
+ - strip_params.gemspec
56
+ has_rdoc: true
57
+ homepage: http://github.com/smiller/strip_params
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ segments:
70
+ - 0
71
+ hash: 3314155479738909170
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ segments:
79
+ - 0
80
+ hash: 3314155479738909170
81
+ requirements: []
82
+ rubyforge_project: strip_params
83
+ rubygems_version: 1.6.2
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Runs strip! recursively on input params
87
+ test_files:
88
+ - spec/spec_helper.rb
89
+ - spec/strip_params_spec.rb