Module: Vedeu::Models::Focus
Overview
-
Interfaces are added to the collection in the order they are defined.
-
If the interface definition contains ‘focus!`, (see Vedeu::Interfaces::DSL#focus!) then that interface is prepended to the list.
-
If the ‘Vedeu.focus_by_name ’some_interface’‘ declaration is used, then the list pointer (`current`) is set to the interface of that name.
The Focus repository is simply a collection of interface names, this module serving to store and manipulate the which interface is currently being focussed.
Class Method Summary collapse
-
.add(name, focus = false) ⇒ Array
Add an interface name to the focus list unless it is already registered.
-
.by_name(name) ⇒ String|Symbol
(also: #focus_by_name)
Focus an interface by name.
-
.current ⇒ String
(also: #focus)
Return the interface currently focussed.
-
.current?(name) ⇒ Boolean
(also: #focussed?)
Returns a boolean indicating whether the named interface is focussed.
-
.empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
-
.in_memory ⇒ Array
private
Returns an empty collection ready for the storing of interface names.
-
.next_item ⇒ String
(also: #next)
Put the next interface relative to the current interfaces in focus.
-
.next_visible_item ⇒ String
(also: #focus_next)
Put the next visible interface relative to the current interfaces in focus.
- .no_interfaces_registered! ⇒ Object private
- .not_registered! ⇒ Object private
-
.prev_item ⇒ String
(also: #prev, #previous)
Put the previous interface relative to the current interface in focus.
-
.prev_visible_item ⇒ String
(also: #focus_previous)
Put the previous visible interface relative to the current interfaces in focus.
-
.refresh ⇒ Array
Refresh the interface in focus.
-
.registered ⇒ Array
Returns a collection of the names of all the registered entities.
-
.registered?(name) ⇒ Boolean
Returns a boolean indicating whether the named model is registered.
-
.reset ⇒ Array|Hash|Set
Reset the repository.
-
.storage ⇒ Array
private
Access to the storage for this repository.
-
.update ⇒ String|FalseClass
private
Return the name of the interface in focus after triggering the refresh event for that interface.
- .visible_items? ⇒ Boolean private
Instance Method Summary collapse
-
#add(name, focus = false) ⇒ Array
Add an interface name to the focus list unless it is already registered.
-
#by_name(name) ⇒ String|Symbol
(also: #focus_by_name)
Focus an interface by name.
-
#current ⇒ String
(also: #focus)
Return the interface currently focussed.
-
#current?(name) ⇒ Boolean
(also: #focussed?)
Returns a boolean indicating whether the named interface is focussed.
-
#empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
-
#in_memory ⇒ Array
private
Returns an empty collection ready for the storing of interface names.
-
#next_item ⇒ String
(also: #next)
Put the next interface relative to the current interfaces in focus.
-
#next_visible_item ⇒ String
(also: #focus_next)
Put the next visible interface relative to the current interfaces in focus.
- #no_interfaces_registered! ⇒ Object private
- #not_registered! ⇒ Object private
-
#prev_item ⇒ String
(also: #prev, #previous)
Put the previous interface relative to the current interface in focus.
-
#prev_visible_item ⇒ String
(also: #focus_previous)
Put the previous visible interface relative to the current interfaces in focus.
-
#refresh ⇒ Array
Refresh the interface in focus.
-
#registered ⇒ Array
Returns a collection of the names of all the registered entities.
-
#registered?(name) ⇒ Boolean
Returns a boolean indicating whether the named model is registered.
-
#reset ⇒ Array|Hash|Set
Reset the repository.
-
#storage ⇒ Array
private
Access to the storage for this repository.
-
#update ⇒ String|FalseClass
private
Return the name of the interface in focus after triggering the refresh event for that interface.
- #visible_items? ⇒ Boolean private
Class Method Details
.add(name, focus = false) ⇒ Array
Add an interface name to the focus list unless it is already registered.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vedeu/models/focus.rb', line 31 def add(name, focus = false) if registered?(name) return storage unless focus by_name(name) else Vedeu.log(type: :store, message: "Storing focus entry: '#{name}'".freeze) focus ? storage.unshift(name) : storage.push(name) end end |
.by_name(name) ⇒ String|Symbol Also known as: focus_by_name
Focus an interface by name. Used after defining an interface or interfaces to set the initially focussed interface.
58 59 60 61 62 63 64 |
# File 'lib/vedeu/models/focus.rb', line 58 def by_name(name) not_registered! unless registered?(name) storage.rotate!(storage.index(name)) update end |
.current ⇒ String Also known as: focus
Return the interface currently focussed.
73 74 75 76 77 |
# File 'lib/vedeu/models/focus.rb', line 73 def current return storage[0] unless empty? no_interfaces_registered! end |
.current?(name) ⇒ Boolean Also known as: focussed?
Returns a boolean indicating whether the named interface is focussed.
88 89 90 |
# File 'lib/vedeu/models/focus.rb', line 88 def current?(name) current == name end |
.empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
96 97 98 |
# File 'lib/vedeu/models/focus.rb', line 96 def empty? storage.empty? end |
.in_memory ⇒ Array (private)
Returns an empty collection ready for the storing of interface names.
242 243 244 |
# File 'lib/vedeu/models/focus.rb', line 242 def in_memory [] end |
.next_item ⇒ String Also known as: next
Put the next interface relative to the current interfaces in focus.
108 109 110 111 112 |
# File 'lib/vedeu/models/focus.rb', line 108 def next_item storage.rotate! update end |
.next_visible_item ⇒ String Also known as: focus_next
Put the next visible interface relative to the current interfaces in focus.
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/vedeu/models/focus.rb', line 119 def next_visible_item return update unless visible_items? loop do storage.rotate! break if Vedeu.interfaces.by_name(current).visible? end update end |
.no_interfaces_registered! ⇒ Object (private)
203 204 205 206 207 |
# File 'lib/vedeu/models/focus.rb', line 203 def no_interfaces_registered! fail Vedeu::Error::Fatal, 'No interfaces or views have been registered, therefore the ' \ 'focus table is empty.'.freeze end |
.not_registered! ⇒ Object (private)
210 211 212 213 214 |
# File 'lib/vedeu/models/focus.rb', line 210 def not_registered! fail Vedeu::Error::ModelNotFound, "Cannot focus '#{name}' as this interface has not been " \ 'registered.'.freeze end |
.prev_item ⇒ String Also known as: prev, previous
Put the previous interface relative to the current interface in focus.
139 140 141 142 143 |
# File 'lib/vedeu/models/focus.rb', line 139 def prev_item storage.rotate!(-1) update end |
.prev_visible_item ⇒ String Also known as: focus_previous
Put the previous visible interface relative to the current interfaces in focus.
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/vedeu/models/focus.rb', line 151 def prev_visible_item return update unless visible_items? loop do storage.rotate!(-1) break if Vedeu.interfaces.by_name(current).visible? end update end |
.refresh ⇒ Array
Refresh the interface in focus.
166 167 168 169 170 |
# File 'lib/vedeu/models/focus.rb', line 166 def refresh Vedeu.trigger(:_refresh_view_, current) Vedeu.trigger(:_refresh_cursor_, current) end |
.registered ⇒ Array
Returns a collection of the names of all the registered entities.
176 177 178 179 180 |
# File 'lib/vedeu/models/focus.rb', line 176 def registered return [] if empty? storage end |
.registered?(name) ⇒ Boolean
Returns a boolean indicating whether the named model is registered.
187 188 189 190 191 |
# File 'lib/vedeu/models/focus.rb', line 187 def registered?(name) return false if empty? storage.include?(name) end |
.reset ⇒ Array|Hash|Set
Reset the repository.
196 197 198 |
# File 'lib/vedeu/models/focus.rb', line 196 def reset @storage = in_memory end |
.storage ⇒ Array (private)
Access to the storage for this repository.
234 235 236 |
# File 'lib/vedeu/models/focus.rb', line 234 def storage @storage ||= in_memory end |
.update ⇒ String|FalseClass (private)
Return the name of the interface in focus after triggering the refresh event for that interface. Returns false when the storage is empty.
221 222 223 224 225 226 227 228 229 |
# File 'lib/vedeu/models/focus.rb', line 221 def update return false if empty? Vedeu.log(message: "Interface in focus: '#{current}'".freeze) refresh current end |
.visible_items? ⇒ Boolean (private)
247 248 249 |
# File 'lib/vedeu/models/focus.rb', line 247 def visible_items? storage.any? { |name| Vedeu.interfaces.by_name(name).visible? } end |
Instance Method Details
#add(name, focus = false) ⇒ Array
Add an interface name to the focus list unless it is already registered.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vedeu/models/focus.rb', line 31 def add(name, focus = false) if registered?(name) return storage unless focus by_name(name) else Vedeu.log(type: :store, message: "Storing focus entry: '#{name}'".freeze) focus ? storage.unshift(name) : storage.push(name) end end |
#by_name(name) ⇒ String|Symbol Also known as: focus_by_name
Focus an interface by name. Used after defining an interface or interfaces to set the initially focussed interface.
58 59 60 61 62 63 64 |
# File 'lib/vedeu/models/focus.rb', line 58 def by_name(name) not_registered! unless registered?(name) storage.rotate!(storage.index(name)) update end |
#current ⇒ String Also known as: focus
Return the interface currently focussed.
73 74 75 76 77 |
# File 'lib/vedeu/models/focus.rb', line 73 def current return storage[0] unless empty? no_interfaces_registered! end |
#current?(name) ⇒ Boolean Also known as: focussed?
Returns a boolean indicating whether the named interface is focussed.
88 89 90 |
# File 'lib/vedeu/models/focus.rb', line 88 def current?(name) current == name end |
#empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
96 97 98 |
# File 'lib/vedeu/models/focus.rb', line 96 def empty? storage.empty? end |
#in_memory ⇒ Array (private)
Returns an empty collection ready for the storing of interface names.
242 243 244 |
# File 'lib/vedeu/models/focus.rb', line 242 def in_memory [] end |
#next_item ⇒ String Also known as: next
Put the next interface relative to the current interfaces in focus.
108 109 110 111 112 |
# File 'lib/vedeu/models/focus.rb', line 108 def next_item storage.rotate! update end |
#next_visible_item ⇒ String Also known as: focus_next
Put the next visible interface relative to the current interfaces in focus.
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/vedeu/models/focus.rb', line 119 def next_visible_item return update unless visible_items? loop do storage.rotate! break if Vedeu.interfaces.by_name(current).visible? end update end |
#no_interfaces_registered! ⇒ Object (private)
203 204 205 206 207 |
# File 'lib/vedeu/models/focus.rb', line 203 def no_interfaces_registered! fail Vedeu::Error::Fatal, 'No interfaces or views have been registered, therefore the ' \ 'focus table is empty.'.freeze end |
#not_registered! ⇒ Object (private)
210 211 212 213 214 |
# File 'lib/vedeu/models/focus.rb', line 210 def not_registered! fail Vedeu::Error::ModelNotFound, "Cannot focus '#{name}' as this interface has not been " \ 'registered.'.freeze end |
#prev_item ⇒ String Also known as: prev, previous
Put the previous interface relative to the current interface in focus.
139 140 141 142 143 |
# File 'lib/vedeu/models/focus.rb', line 139 def prev_item storage.rotate!(-1) update end |
#prev_visible_item ⇒ String Also known as: focus_previous
Put the previous visible interface relative to the current interfaces in focus.
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/vedeu/models/focus.rb', line 151 def prev_visible_item return update unless visible_items? loop do storage.rotate!(-1) break if Vedeu.interfaces.by_name(current).visible? end update end |
#refresh ⇒ Array
Refresh the interface in focus.
166 167 168 169 170 |
# File 'lib/vedeu/models/focus.rb', line 166 def refresh Vedeu.trigger(:_refresh_view_, current) Vedeu.trigger(:_refresh_cursor_, current) end |
#registered ⇒ Array
Returns a collection of the names of all the registered entities.
176 177 178 179 180 |
# File 'lib/vedeu/models/focus.rb', line 176 def registered return [] if empty? storage end |
#registered?(name) ⇒ Boolean
Returns a boolean indicating whether the named model is registered.
187 188 189 190 191 |
# File 'lib/vedeu/models/focus.rb', line 187 def registered?(name) return false if empty? storage.include?(name) end |
#reset ⇒ Array|Hash|Set
Reset the repository.
196 197 198 |
# File 'lib/vedeu/models/focus.rb', line 196 def reset @storage = in_memory end |
#storage ⇒ Array (private)
Access to the storage for this repository.
234 235 236 |
# File 'lib/vedeu/models/focus.rb', line 234 def storage @storage ||= in_memory end |
#update ⇒ String|FalseClass (private)
Return the name of the interface in focus after triggering the refresh event for that interface. Returns false when the storage is empty.
221 222 223 224 225 226 227 228 229 |
# File 'lib/vedeu/models/focus.rb', line 221 def update return false if empty? Vedeu.log(message: "Interface in focus: '#{current}'".freeze) refresh current end |
#visible_items? ⇒ Boolean (private)
247 248 249 |
# File 'lib/vedeu/models/focus.rb', line 247 def visible_items? storage.any? { |name| Vedeu.interfaces.by_name(name).visible? } end |