0.0
No release in over 3 years
Low commit activity in last 3 years
An easy and extendable controller validator helper for Rails.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

 Project Readme

LuckyParam

Build Status

A simple parameter checker in controller for Rails Api.

Do Check, Fail Fast

Usage

Gemfile

gem "lucky_param"

app/controllers/application_controller.rb

class ApplicationController
  include LuckyParam

  # If necessary, you can overide or define your own parameter checkers.
  LuckyParam::CUSTOM_CHECKER = {
    Password: [
      ->(params, column) { params[column] =~ /([0-9a-zA-Z]){6,30}/ },
      "must be valid password"
    ],
  }.freeze
end

app/controllers/sessions_controller.rb

class SessionsController < ApplicationController
  def create
    required :email, :Email
    required :password, :Password
    optional :nick_name, :String
    render json: 'ok'
  end
end

Internal Checkers

Checkers

Contributing

  1. Fork it ( https://github.com/shootingfly/lucky_param/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make your changes
  4. Run ruby test/lucky_param_test.rb to run the tests
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create a new Pull Request

License

The gem is available as open source under the terms of the MIT License.