Class: Jaql::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/jaql/resource.rb

Overview

Resource wraps a scope, which can be an ActiveRecord::Relation, Sequel dataset, table name, ORM model instance, etc. It provides index and show methods that produce JSON for the scope.

Defined Under Namespace

Classes: NotFoundError

Instance Method Summary collapse

Constructor Details

#initialize(scope, options = {}) ⇒ Resource



15
16
17
# File 'lib/jaql/resource.rb', line 15

def initialize(scope, options={})
  @scope = scope
end

Instance Method Details

#index(query_spec = {}) ⇒ Object



19
20
21
# File 'lib/jaql/resource.rb', line 19

def index(query_spec={})
  JSONString.new SqlGeneration::RunnableQuery.for(scope, query_spec).json_array
end

#show(query_spec = {}) ⇒ Object



23
24
25
# File 'lib/jaql/resource.rb', line 23

def show(query_spec={})
  JSONString.new SqlGeneration::RunnableQuery.for(scope, query_spec).json_row
end