rails_param 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79d1fa666d9f249c4e2758fff4fe24be7856eeb8
4
- data.tar.gz: c65e6e4d12a12a57667c659157229da75b9ce6c9
3
+ metadata.gz: 49836118ba306758e4157e7466e8ec67d79222b9
4
+ data.tar.gz: 48dde691b94c3e089b74e7f8d7279414b53ecf25
5
5
  SHA512:
6
- metadata.gz: a3c7b0fbafd0072dd049879f47b3c0d892411712dac4ca3c2a0d34d0221b42c5a40c90b732005998c3798920ec964b68961accfccabd3fb6996a88b77a331172
7
- data.tar.gz: e0901f1e7eb5bb94f91480925f6b4876b63e3d85168159edf34c3fa4aec6fc98c137b89b7932825e2e323981b185351a17db70a87e56483464d964c26f9a9ab2
6
+ metadata.gz: d92e097419c2abd3f19c000c39485ec59aba60f214b6266ea25d9f2241aa091250f1e11e4b64cbf8621c621f2c038909e9b7826f162fee1306a4aa6a5683e6d1
7
+ data.tar.gz: 20a00f69034b111898d91ba86da224e01637bdc13b6ce1a89e316f8bbfcd5364dfbc8238dfbf111c85c191857285fb58d3787c190defa939ab0cb10a741728ee
data/README.md CHANGED
@@ -1,20 +1,20 @@
1
1
  # rails-param
2
2
  _Parameter Validation & Type Coercion for Rails_
3
3
 
4
+ [![Build Status](https://travis-ci.org/nicolasblanco/rails_param.svg?branch=master)](https://travis-ci.org/nicolasblanco/rails_param)
5
+
4
6
  This is a port of the gem [sinatra-param](https://github.com/mattt/sinatra-param) for the Rails framework.
5
7
  All the credits go to [@mattt](https://twitter.com/mattt).
6
- It has all the features of the sinatra-param gem, I used bang methods (param! and one_of!) to indicate that they are destructive as they change the controller params object and may raise an exception.
8
+ It has all the features of the sinatra-param gem, I used bang methods (like param!) to indicate that they are destructive as they change the controller params object and may raise an exception.
7
9
 
8
10
  REST conventions take the guesswork out of designing and consuming web APIs. Simply `GET`, `POST`, `PATCH`, or `DELETE` resource endpoints, and you get what you'd expect.
9
11
 
10
12
  However, when it comes to figuring out what parameters are expected... well, all bets are off.
11
13
 
12
- This Rails extension takes a first step to solving this problem on the developer side
14
+ This Rails extension takes a first step to solving this problem on the developer side.
13
15
 
14
16
  **`rails-param` allows you to declare, validate, and transform endpoint parameters as you would in frameworks like [ActiveModel](http://rubydoc.info/gems/activemodel/3.2.3/frames) or [DataMapper](http://datamapper.org/).**
15
17
 
16
- > Use `rails-param` in combination with [`Rack::PostBodyContentTypeParser` and `Rack::NestedParams`](https://github.com/rack/rack-contrib) to automatically parameterize JSON `POST` bodies and nested parameters.
17
-
18
18
  ## Example
19
19
 
20
20
  ``` ruby
@@ -25,7 +25,7 @@ This Rails extension takes a first step to solving this problem on the developer
25
25
  param! :q, String, required: true
26
26
  param! :categories, Array
27
27
  param! :sort, String, default: "title"
28
- param! :order, String, in: ["ASC", "DESC"], transform: :upcase, default: "ASC"
28
+ param! :order, String, in: %w(asc desc), transform: :downcase, default: "asc"
29
29
  param! :price, String, format: "[<\=>]\s*\$\d+"
30
30
 
31
31
  {...}
@@ -47,7 +47,8 @@ By declaring parameter types, incoming parameters will automatically be transfor
47
47
 
48
48
  ### Validations
49
49
 
50
- Encapsulate business logic in a consistent way with validations. If a parameter does not satisfy a particular condition, a `400` error is returned with a message explaining the failure.
50
+ Encapsulate business logic in a consistent way with validations. If a parameter does not satisfy a particular condition, an exception (RailsParam::Param::InvalidParameterError) is raised.
51
+ You may use the [rescue_from](http://api.rubyonrails.org/classes/ActiveSupport/Rescuable/ClassMethods.html#method-i-rescue_from) method in your controller to catch this kind of exception.
51
52
 
52
53
  - `required`
53
54
  - `blank`
@@ -15,21 +15,13 @@ module RailsParam
15
15
  params[name] = (options[:default].call if options[:default].respond_to?(:call)) || options[:default] if params[name].nil? and options[:default]
16
16
  params[name] = options[:transform].to_proc.call(params[name]) if params[name] and options[:transform]
17
17
  validate!(params[name], options)
18
- # rescue InvalidParameterError => exception
19
- # if options[:raise]
20
- # exception.param, exception.options = name, options
21
- # raise exception
22
- # end
23
-
24
- # error = "Invalid Parameter: #{name}"
25
- # if content_type and content_type.match(mime_type(:json))
26
- # error = {message: error, errors: {name => exception.message}}.to_json
27
- # end
28
-
29
- # # do something with error object
18
+ rescue InvalidParameterError => exception
19
+ exception.param, exception.options = name, options
20
+ raise exception
30
21
  end
31
22
  end
32
23
 
24
+ # TODO: should we reintegrate this method?
33
25
  # def one_of!(*names)
34
26
  # count = 0
35
27
  # names.each do |name|
@@ -1,3 +1,3 @@
1
1
  module RailsParam #:nodoc
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_param
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Blanco
@@ -44,29 +44,29 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 4.1.0
47
+ version: 3.2.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 4.1.0
54
+ version: 3.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activesupport
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 4.1.0
61
+ version: 3.2.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 4.1.0
69
- description: "\n Parameter Validation & Type Coercion for Rails\n "
68
+ version: 3.2.0
69
+ description: "\n Parameter Validation and Type Coercion for Rails\n "
70
70
  email: nicolas@nicolasblanco.fr
71
71
  executables: []
72
72
  extensions: []
@@ -78,7 +78,7 @@ files:
78
78
  - lib/rails_param/version.rb
79
79
  homepage: http://github.com/nicolasblanco/rails_param
80
80
  licenses:
81
- - WTFPL
81
+ - MIT
82
82
  metadata: {}
83
83
  post_install_message:
84
84
  rdoc_options:
@@ -100,5 +100,5 @@ rubyforge_project:
100
100
  rubygems_version: 2.2.2
101
101
  signing_key:
102
102
  specification_version: 4
103
- summary: Parameter Validation & Type Coercion for Rails
103
+ summary: Parameter Validation and Type Coercion for Rails
104
104
  test_files: []