class Hoodoo::Services::Interface::ToList

A class containing a series of accessors that describe allowed parameters in a “list” call for a service implementation. The middleware uses this validate incoming query strings for lists and reject requests that ask for unsupported things. When instantiated the class sets itself up with defaults that match those described by the your platform’s API. When passed to a Hoodoo::Services::Interface::ToListDSL instance, the DSL methods, if called, update the values stored herein.

Attributes

default_sort_key[RW]

Default sort key.

do_not_filter[RW]

Array of prohibited framework filter keys as Strings; empty for none defined.

filter[RW]

Array of supported filter keys as Strings; empty for none defined.

limit[RW]

Limit value; an integer that limits page size in lists.

sort[RW]

Sort hash. Keys are supported sort fields, values are arrays of supported sort directions. The first array entry is the default sort order for the sort field.

Public Class Methods

new() click to toggle source

Create an instance with default settings.

# File lib/hoodoo/services/services/interface.rb, line 77
def initialize

  # Remember, these are defaults for the "to_list" object of an
  # interface only. For interface-wide top level defaults, use the
  # embedded calls to the DSL in Interface::interface.

  @limit            = 50
  @sort             = { 'created_at' => Set.new( [ 'desc', 'asc' ] ) }
  @default_sort_key = 'created_at'
  @search           = []
  @do_not_search    = []
  @filter           = []
  @do_not_filter    = []
end

Public Instance Methods

default_sort_direction() click to toggle source

Default sort direction.

# File lib/hoodoo/services/services/interface.rb, line 53
def default_sort_direction
  @sort[ default_sort_key() ].first
end