Skip to content

[Idea] Extract validation to external file #86

@mike927

Description

@mike927

Basic Info

  • rails_param Version: 0.11.1
  • Ruby Version: 3.0.1
  • Rails Version: 6.1.1

Issue description

I've been leveraging rails_params in one of prior projects. It works great however I prefer to keep controller neat. I wrote a chuck of code to extract validation rules to external files under some path e.g /app/validators/.../*._validator.rb. Validation file itself could look like:

module Api
  module V1
    class SessionsValidator
      include RailsParam::Param

      attr_reader :params

      def initialize(params)
        @params = params
      end

      def create
        param! :username, String, required: true, blank: false
        param! :password, String, required: true, blank: false
      end

      def refresh
        param! :refresh_token, String, required: true, blank: false
      end
    end
  end
end

What do you think about such solution? If you find it as useful I could open a PR.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions