Skip to content

Instantly share code, notes, and snippets.

@Smolations
Created January 13, 2015 21:50
Show Gist options
  • Save Smolations/beb38a84f1de0fcf059b to your computer and use it in GitHub Desktop.
Save Smolations/beb38a84f1de0fcf059b to your computer and use it in GitHub Desktop.
Fix Flagger Floundering
# assume that model params are not automatically added to a controller's
# @params. this will allow for more flexibility for the current endpoint
# implementation. they can, however, be stored somewhere on the controller
# so that these blocks below can explicitly state whether or not they should
# be available for use in a route
# media_controller example
resource do |r|
# r.class == Flagger::Controller
# need some way to create reusable params not included in the param
# list by default
r.param :sort, { type: :string, location: :query }
r.param :order, { type: :string, location: :query }
# these can then be associated with routes that need them. both return
# a Flagger::ParamList
model_params = r.model_params
nested_model_params = r.model_params nested: true
route ':owner_type/:owner_id/media', { owner_type: :string } do |e|
# e.class == Flagger::Endpoint
# executes code formerly found in build_restful_endpoints
e.restful # or maybe: r.restful e
# this will override the :post endpoint created from e.restful
e.post do |params|
# params.class == Flagger::ParamList
params << model_params.except :file_name, :user_id
params.define :application, { type: :string, desc: 'Context for media. One of "banner", "icon", "avatar' }
params.define :collections_add, { type: :array, desc: 'IDs for the destination collections for the new media item.' }
# if a &block is given, :media_file will automatically be of type :object
params.define :media_file, { required: true } do |p|
# p.class == Flagger::Param
# ALT: p.define.string :filename
# ALT: p.string :filename
p.define :filename, { type: :string }
p.define :type, { type: :string }
p.define :headers, { type: :string, required: false }
p.define :tempfile, { type: :string }
end
end
e.get do |params|
params << r.params.only :sort, :order
end
end
end
# champions_controller example
resource do |r|
route 'champions' do |e|
e.restful
e.post 'name_check' do |params|
params << model_params.only(:name)
end
# just realized that passing params in nested route calls could
# get unwieldy...
route 'search' do
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment