require_params 0.0.1

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: 92f164541ed22482a707740abf2ac7090156341e
4
+ data.tar.gz: 4c7920d9b7410ff7e6a49e79d4a3bc6cff0a4d07
5
+ SHA512:
6
+ metadata.gz: bfbd01a5edfb59416c3ab80914c3fdcb0beb042269a0d60c6e399c273f7d674b621c012ed921e23f9c64d99fd736082e441cffcb9729202141fa47f3340d660d
7
+ data.tar.gz: a86a352e6bc3e9beece792639c37f51cde05783d011d7c7e2f99b2c8a7529e3d01999c228f2156135f7bf0980c60f2d2b39b369ea1de2a01b613314c45f3006b
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # require_params
2
+ require_params ensures that parameters that your API actions require are present.
3
+
4
+ ## Usage
5
+ Include `RequireParams` to your `ApplicationController`:
6
+
7
+ ```ruby
8
+ class ApplicationController < ActionController::API
9
+ include RequireParams
10
+ end
11
+ ```
12
+
13
+ Use the `require_params` class method in your controllers to specify which parameters are required for which actions:
14
+
15
+ ```ruby
16
+ class UsersController < ApplicationController
17
+ require_params [:username, :email, :password], only: :create
18
+
19
+ def create
20
+ # Do important stuff here
21
+ end
22
+ end
23
+ ```
24
+
25
+ If any one of the required parameters is missing, your action handler will not be called at all. Instead, an error hash that looks like this will be served with 400 Bad Request:
26
+
27
+ ```ruby
28
+ {
29
+ errors: [{
30
+ username: ["is missing"],
31
+ password: ["is missing"]
32
+ }]
33
+ }
34
+ ```
35
+
36
+ ## Installation
37
+ Add this line to your application's Gemfile:
38
+
39
+ ```ruby
40
+ gem 'require_params'
41
+ ```
42
+
43
+ And then execute:
44
+ ```bash
45
+ $ bundle
46
+ ```
47
+
48
+ Or install it yourself as:
49
+ ```bash
50
+ $ gem install require_params
51
+ ```
52
+
53
+ ## License
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RequireParams'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,3 @@
1
+ module RequireParams
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,15 @@
1
+ module RequireParams
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ def require_params(required_params, options = {})
6
+ before_action options do
7
+ missing_params = required_params.reject { |x| params.has_key?(x) }
8
+ if missing_params.any?
9
+ render json: { errors: missing_params.map { |x| {x => ["is missing"]}} }, status: :bad_request
10
+ false
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :require_params do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: require_params
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yihang Ho
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0.beta2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 5.0.0.beta2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
33
+ description: require_params ensures that parameters that your Rails API actions require
34
+ are present.
35
+ email:
36
+ - hoyihang5@gmail.com
37
+ executables: []
38
+ extensions: []
39
+ extra_rdoc_files: []
40
+ files:
41
+ - README.md
42
+ - Rakefile
43
+ - lib/require_params.rb
44
+ - lib/require_params/version.rb
45
+ - lib/tasks/require_params_tasks.rake
46
+ homepage: https://github.com/yihangho/require_params
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.5.1
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Ensure that all the parameters required by your actions are present.
70
+ test_files: []