module ServiceTemplate::GrapeHelpers

Public Instance Methods

permitted_params(options = {}) click to toggle source
# File lib/service_template/grape_extensions/grape_helpers.rb, line 17
def permitted_params(options = {})
  options = { include_missing: false }.merge(options)
  declared(params, options)
end
present_error(code, message = '', reasons={}) click to toggle source
# File lib/service_template/grape_extensions/grape_helpers.rb, line 13
def present_error(code, message = '', reasons={})
  ServiceTemplate::JsonError.new(code, message, reasons)
end
represent(data, with: nil, **args) click to toggle source
# File lib/service_template/grape_extensions/grape_helpers.rb, line 3
def represent(data, with: nil, **args)
  raise ArgumentError.new(":with option is required") if with.nil?

  if data.respond_to?(:to_a)
    return { data: data.map{ |item| with.new(item).to_hash(args) } }
  else
    return { data: with.new(data).to_hash(args)}
  end
end