Class: Hoodoo::Services::Interface::ToList

Inherits:
Object
  • Object
show all
Defined in:
lib/hoodoo/services/services/interface.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeToList

Create an instance with default settings.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# 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

Instance Attribute Details

#default_sort_keyObject

Default sort key.



49
50
51
# File 'lib/hoodoo/services/services/interface.rb', line 49

def default_sort_key
  @default_sort_key
end

#do_not_filterObject

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



73
74
75
# File 'lib/hoodoo/services/services/interface.rb', line 73

def do_not_filter
  @do_not_filter
end

#do_not_searchObject

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



64
65
66
# File 'lib/hoodoo/services/services/interface.rb', line 64

def do_not_search
  @do_not_search
end

#filterObject

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



68
69
70
# File 'lib/hoodoo/services/services/interface.rb', line 68

def filter
  @filter
end

#limitObject

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



39
40
41
# File 'lib/hoodoo/services/services/interface.rb', line 39

def limit
  @limit
end

#searchObject

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



59
60
61
# File 'lib/hoodoo/services/services/interface.rb', line 59

def search
  @search
end

#sortObject

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.



45
46
47
# File 'lib/hoodoo/services/services/interface.rb', line 45

def sort
  @sort
end

Instance Method Details

#default_sort_directionObject

Default sort direction.



53
54
55
# File 'lib/hoodoo/services/services/interface.rb', line 53

def default_sort_direction
  @sort[ default_sort_key() ].first
end