Last active
August 29, 2015 14:02
-
-
Save ehlyzov/bbe1b05a43285d442c03 to your computer and use it in GitHub Desktop.
systemé demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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