LoginSignup
1
1

More than 5 years have passed since last update.

Grape で共通のパラメータを利用してDryにする

Posted at

認証情報や大きなオブジェクトのパラメータなど、複数のインターフェースで同じパラメータを定義したかった。
色々調べても解放が見つからなかったので、下記で頑張って解決

api/v1/users.rb
 resource users do
  params do
    eval APIParams::Group.new.auth_params
  end
  get '/new' do

  end

  params do
    eval APIParams::Group.new.auth_params
  end
  get '/edit' do

  end
end

lib/api_params.rb
module APIParams
  class User
    def auth_params
      <<-EOS
      optional :access_token, type: String
      optional :secret, type: String
      EOS
    end
  end
end
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1