params_inquirer 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 +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/lib/params_inquirer/action_controller/base.rb +14 -0
- data/lib/params_inquirer/parameters.rb +32 -0
- data/lib/params_inquirer/railtie.rb +9 -0
- data/lib/params_inquirer/version.rb +3 -0
- data/lib/params_inquirer.rb +6 -0
- data/params_inquirer.gemspec +22 -0
- data/spec/params_inquirer/parameters_spec.rb +41 -0
- data/spec/spec_helper.rb +2 -0
- metadata +92 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 naoty
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# ParamsInquirer
|
2
|
+
|
3
|
+
ParamsInquirer gives you a prettier way to inquire params value.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'params_inquirer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install params_inquirer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
def index
|
23
|
+
if params[:status].accepted? # this means `params[:status] == 'accepted'`
|
24
|
+
# ...
|
25
|
+
elsif params[:status].rejected?
|
26
|
+
# ...
|
27
|
+
else
|
28
|
+
# ...
|
29
|
+
end
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'active_support/core_ext/module/attr_internal'
|
2
|
+
require 'params_inquirer/parameters'
|
3
|
+
|
4
|
+
module ParamsInquirer
|
5
|
+
module ActionController
|
6
|
+
module Base
|
7
|
+
attr_internal :params
|
8
|
+
|
9
|
+
def params
|
10
|
+
@_params ||= ParamsInquirer::Parameters.new(super)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
2
|
+
require 'active_support/string_inquirer'
|
3
|
+
|
4
|
+
module ParamsInquirer
|
5
|
+
class Parameters < ActiveSupport::HashWithIndifferentAccess
|
6
|
+
def initialize(other_hash = {})
|
7
|
+
params = super()
|
8
|
+
other_hash.each_pair do |key, value|
|
9
|
+
params[key] = convert_value(value)
|
10
|
+
end
|
11
|
+
params
|
12
|
+
end
|
13
|
+
|
14
|
+
def []=(key, value)
|
15
|
+
super(key, convert_value(value))
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def convert_value(value)
|
21
|
+
if value.is_a?(String)
|
22
|
+
ActiveSupport::StringInquirer.new(value)
|
23
|
+
elsif value.is_a?(Symbol)
|
24
|
+
ActiveSupport::StringInquirer.new(value.to_s)
|
25
|
+
elsif value.is_a?(Hash)
|
26
|
+
Parameters.new(value)
|
27
|
+
else
|
28
|
+
value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'params_inquirer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "params_inquirer"
|
8
|
+
gem.version = ParamsInquirer::VERSION
|
9
|
+
gem.authors = ["Naoto Kaneko"]
|
10
|
+
gem.email = ["naoty.k@gmail.com"]
|
11
|
+
gem.description = %q{ParamsInquirer gives you a prettier way to inquire params value.}
|
12
|
+
gem.summary = %q{ParamsInquirer gives you a prettier way to inquire params value.}
|
13
|
+
gem.homepage = "https://github.com/naoty/params_inquirer"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'activesupport'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ParamsInquirer::Parameters do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'generates instance from other Hash' do
|
6
|
+
params = described_class.new({ key: 'value' })
|
7
|
+
params[:key].should be_value
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'generates instance from other HashWithIndifferentAccess' do
|
11
|
+
hash = ActiveSupport::HashWithIndifferentAccess.new({ key: 'value' })
|
12
|
+
params = described_class.new(hash)
|
13
|
+
params[:key].should be_value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#[]=' do
|
18
|
+
let(:params) { described_class.new }
|
19
|
+
|
20
|
+
it 'generates an inquirer from String' do
|
21
|
+
params[:key] = 'value'
|
22
|
+
params[:key].should be_value
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'generates an inquirer from Symbol' do
|
26
|
+
params[:key] = :value
|
27
|
+
params[:key].should be_value
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'generates a nested inquirer from Hash' do
|
31
|
+
params[:key1] = { key2: 'value' }
|
32
|
+
params[:key1][:key2].should be_value
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'generates a nested inquirer from blank Hash' do
|
36
|
+
params[:key1] = {}
|
37
|
+
params[:key1][:key2] = 'value'
|
38
|
+
params[:key1][:key2].should be_value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: params_inquirer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Naoto Kaneko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: ParamsInquirer gives you a prettier way to inquire params value.
|
47
|
+
email:
|
48
|
+
- naoty.k@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/params_inquirer.rb
|
59
|
+
- lib/params_inquirer/action_controller/base.rb
|
60
|
+
- lib/params_inquirer/parameters.rb
|
61
|
+
- lib/params_inquirer/railtie.rb
|
62
|
+
- lib/params_inquirer/version.rb
|
63
|
+
- params_inquirer.gemspec
|
64
|
+
- spec/params_inquirer/parameters_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: https://github.com/naoty/params_inquirer
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.24
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: ParamsInquirer gives you a prettier way to inquire params value.
|
90
|
+
test_files:
|
91
|
+
- spec/params_inquirer/parameters_spec.rb
|
92
|
+
- spec/spec_helper.rb
|