Class: Smooth::Query

Inherits:
Command show all
Includes:
Documentation
Defined in:
lib/smooth/query.rb

Defined Under Namespace

Classes: Response

Constant Summary

Constants inherited from Command

Command::Patterns

Instance Attribute Summary

Attributes inherited from Command

#current_user

Instance Method Summary collapse

Methods included from Documentation

#desc, included, #inline_description

Methods inherited from Command

as, base_scope, belongs_to_resource, event_namespace, #event_namespace, execute, filter_for_param, filter_options_for_param, find_serializer_for, get_execution_pattern, input_argument_names, interface, interface_description, interface_documentation, #interface_for, #model_class, object_path, #object_path, parent_api, #parent_api, #parent_resource, resource_alias, #resource_alias, #resource_name, resource_name, respond_to_request, scope, #scope, #scope=, #scoped_find_object, serializer_options

Methods included from Command::Instrumented

included, #run_with_instrumentation, #run_with_outcome

Instance Method Details

#apply_filtersObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/smooth/query.rb', line 16

def apply_filters
  params.each(&method(:apply_filter))

  if raw_inputs['ids']
    ids = raw_inputs['ids']
    ids = ids.split(',') if ids.is_a?(String)

    self.scope = scope.where(id: Array(ids))
  end
end

#executeObject

To customize the filtering behavior of the query you can supply your own execute method body. The execute method is expected to mutate the value of the self.scope or @scope instance variable and to return something which can be serialized as JSON using the Smooth::Serializer



11
12
13
14
# File 'lib/smooth/query.rb', line 11

def execute
  apply_filters
  scope
end

#validateObject



27
28
29
# File 'lib/smooth/query.rb', line 27

def validate
  true
end