Class: Appfuel::Repository::Settings
- Inherits:
-
Object
- Object
- Appfuel::Repository::Settings
- Defined in:
- lib/appfuel/storage/repository/settings.rb
Overview
The Criteria represents the interface between the repositories and actions or commands. The allow you to find entities in the application storage ( a database) without knowledge of that storage system. The criteria will always refer to its queries in the domain language for which the repo is responsible for mapping that query to its persistence layer.
settings:
page: 1
per_page: 2
disable_pagination
first
last
all
error_on_empty
parser
transform
search_name
Constant Summary collapse
- DEFAULT_PAGE =
1
- DEFAULT_PER_PAGE =
20
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#transform ⇒ Object
readonly
Returns the value of attribute transform.
Instance Method Summary collapse
- #all ⇒ Object
- #all? ⇒ Boolean
- #disable_pagination ⇒ Object
- #disable_pagination? ⇒ Boolean
-
#empty_dataset_is_valid! ⇒ Object
Tells the repo to return and empty collection, or nil if single is invoked, if the entity is not found.
- #enable_pagination ⇒ Object
-
#error_on_empty_dataset! ⇒ Object
Tells the repo to return an error when entity is not found.
- #error_on_empty_dataset? ⇒ Boolean
- #first ⇒ Object
- #first? ⇒ Boolean
- #initialize(settings = {}) ⇒ Criteria constructor
- #last ⇒ Object
- #last? ⇒ Boolean
- #manual_query(value = nil) ⇒ Object
- #manual_query? ⇒ Boolean
- #page(value = nil) ⇒ Object
- #per_page(value = nil) ⇒ Object
- #single? ⇒ Boolean
Constructor Details
#initialize(settings = {}) ⇒ Criteria
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/appfuel/storage/repository/settings.rb', line 30 def initialize(settings = {}) @parser = settings[:parser] || SearchParser.new @transform = settings[:transform] || SearchTransform.new empty_dataset_is_valid! enable_pagination disable_all disable_first disable_last if settings[:error_on_empty] == true error_on_empty_dataset! end if settings[:disable_pagination] == true disable_pagination end if settings[:first] == true first elsif settings[:last] == true last elsif settings[:all] all end manual_query(settings[:manual_query]) if settings.key?(:manual_query) page(settings[:page] || DEFAULT_PAGE) per_page(settings[:per_page] || DEFAULT_PER_PAGE) end |
Instance Attribute Details
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
25 26 27 |
# File 'lib/appfuel/storage/repository/settings.rb', line 25 def parser @parser end |
#transform ⇒ Object (readonly)
Returns the value of attribute transform.
25 26 27 |
# File 'lib/appfuel/storage/repository/settings.rb', line 25 def transform @transform end |
Instance Method Details
#all ⇒ Object
107 108 109 110 111 112 |
# File 'lib/appfuel/storage/repository/settings.rb', line 107 def all @all = true disable_first disable_last self end |
#all? ⇒ Boolean
103 104 105 |
# File 'lib/appfuel/storage/repository/settings.rb', line 103 def all? @all end |
#disable_pagination ⇒ Object
82 83 84 85 |
# File 'lib/appfuel/storage/repository/settings.rb', line 82 def disable_pagination @disable_pagination = true self end |
#disable_pagination? ⇒ Boolean
73 74 75 |
# File 'lib/appfuel/storage/repository/settings.rb', line 73 def disable_pagination? @disable_pagination end |
#empty_dataset_is_valid! ⇒ Object
Tells the repo to return and empty collection, or nil if single is invoked, if the entity is not found
148 149 150 151 |
# File 'lib/appfuel/storage/repository/settings.rb', line 148 def empty_dataset_is_valid! @error_on_empty = false self end |
#enable_pagination ⇒ Object
77 78 79 80 |
# File 'lib/appfuel/storage/repository/settings.rb', line 77 def enable_pagination @disable_pagination = false self end |
#error_on_empty_dataset! ⇒ Object
Tells the repo to return an error when entity is not found
139 140 141 142 |
# File 'lib/appfuel/storage/repository/settings.rb', line 139 def error_on_empty_dataset! @error_on_empty = true self end |
#error_on_empty_dataset? ⇒ Boolean
153 154 155 |
# File 'lib/appfuel/storage/repository/settings.rb', line 153 def error_on_empty_dataset? @error_on_empty end |
#first ⇒ Object
118 119 120 121 122 123 |
# File 'lib/appfuel/storage/repository/settings.rb', line 118 def first @first = true disable_last disable_all self end |
#first? ⇒ Boolean
114 115 116 |
# File 'lib/appfuel/storage/repository/settings.rb', line 114 def first? @first end |
#last ⇒ Object
129 130 131 132 133 134 |
# File 'lib/appfuel/storage/repository/settings.rb', line 129 def last @last = true disable_first disable_all self end |
#last? ⇒ Boolean
125 126 127 |
# File 'lib/appfuel/storage/repository/settings.rb', line 125 def last? @last end |
#manual_query(value = nil) ⇒ Object
67 68 69 70 71 |
# File 'lib/appfuel/storage/repository/settings.rb', line 67 def manual_query(value = nil) return @manual_query if value.nil? @manual_query = value self end |
#manual_query? ⇒ Boolean
63 64 65 |
# File 'lib/appfuel/storage/repository/settings.rb', line 63 def manual_query? !manual_query.nil? end |
#page(value = nil) ⇒ Object
87 88 89 90 91 |
# File 'lib/appfuel/storage/repository/settings.rb', line 87 def page(value = nil) return @page if value.nil? @page = Integer(value) self end |
#per_page(value = nil) ⇒ Object
93 94 95 96 97 |
# File 'lib/appfuel/storage/repository/settings.rb', line 93 def per_page(value = nil) return @per_page if value.nil? @per_page = Integer(value) self end |
#single? ⇒ Boolean
99 100 101 |
# File 'lib/appfuel/storage/repository/settings.rb', line 99 def single? first? || last? end |