Class: Hoodoo::Services::Interface::ToList
- Inherits:
-
Object
- Object
- Hoodoo::Services::Interface::ToList
- 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
-
#default_sort_key ⇒ Object
readonly
Default sort key.
-
#do_not_filter ⇒ Object
readonly
Array of prohibited framework filter keys as Strings; empty for none defined.
-
#do_not_search ⇒ Object
readonly
Array of prohibited framework search keys as Strings; empty for none defined.
-
#filter ⇒ Object
readonly
Array of supported filter keys as Strings; empty for none defined.
-
#limit ⇒ Object
readonly
Limit value; an integer that limits page size in lists.
-
#search ⇒ Object
readonly
Array of supported search keys as Strings; empty for none defined.
-
#sort ⇒ Object
readonly
Sort hash.
Instance Method Summary collapse
-
#default_sort_direction ⇒ Object
Default sort direction.
-
#initialize ⇒ ToList
constructor
Create an instance with default settings.
Constructor Details
#initialize ⇒ ToList
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_key ⇒ Object
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_filter ⇒ Object
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_search ⇒ Object
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 |
#filter ⇒ Object
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 |
#limit ⇒ Object
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 |
#search ⇒ Object
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 |
#sort ⇒ Object
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_direction ⇒ Object
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 |