Skip to content

Instantly share code, notes, and snippets.

@ehlyzov
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save ehlyzov/bbe1b05a43285d442c03 to your computer and use it in GitHub Desktop.

Select an option

Save ehlyzov/bbe1b05a43285d442c03 to your computer and use it in GitHub Desktop.
systemé demo
module Interviews
class DemoController < Interviews::ApplicationController
# explicit call of ask is not needed, implicit call will be perform when needed
def show
ask(:interview, :other_interviews)
end
def index
ask(:interviews)
end
end
end
require "interviews/engine"
require 'systeme'
module Interviews
module API
include Systeme::QueryDSL
extend Systeme::WrapperDSL
# return all intervies on every unqualified query in the demo controller (just a namespace)
query[:demo], [:city_id] do |args, scope|
Interviews::Models::Interview.where(city_id: args.city_id).includes(:author)
end
# qualification path: demo -> demo show -> demo show interview,
# so in scope will be all intervies (see previous declaration)
query [:demo, :show, :interview], [:id] do |args, scope|
scope.where(id, args.id).first
end
# globs are allowed
query [:*, :other_interviews] do |args, scope|
scope.order('random()').limit(3)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment