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 ⇒ NilClass|String|Symbol
(also: #focus, #name)
Return the interface currently focussed.
-
.current?(name) ⇒ Boolean
(also: #focussed?)
Returns a boolean indicating whether the named interface is focussed.
-
.focus? ⇒ Boolean
Returns a boolean indicating whether there are interfaces registered.
-
.in_memory ⇒ Array
private
Returns an empty collection ready for the storing of interface names.
- .interface ⇒ Vedeu::Interfaces::Interface private
-
.next_item ⇒ String|Symbol
Put the next interface relative to the current interfaces in focus.
-
.next_visible_item ⇒ String|Symbol
(also: #focus_next)
Put the next visible interface relative to the current interfaces in focus.
- .not_registered!(name) ⇒ Object private
-
.prev_item ⇒ String|Symbol
(also: #prev, #previous)
Put the previous interface relative to the current interface in focus.
-
.prev_visible_item ⇒ String|Symbol
(also: #focus_previous)
Put the previous visible interface relative to the current interfaces in focus.
-
.refresh ⇒ Array
Refresh the interface in focus.
-
.registered?(name) ⇒ Boolean
Returns a boolean indicating whether the named model is registered.
-
.reset! ⇒ Array|Hash|Set
(also: #reset)
Reset the repository.
-
.storage ⇒ Array
(also: #registered)
Access to the storage for this repository.
-
.update ⇒ String|Boolean
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 ⇒ NilClass|String|Symbol
(also: #focus, #name)
Return the interface currently focussed.
-
#current?(name) ⇒ Boolean
(also: #focussed?)
Returns a boolean indicating whether the named interface is focussed.
-
#focus? ⇒ Boolean
Returns a boolean indicating whether there are interfaces registered.
-
#in_memory ⇒ Array
private
Returns an empty collection ready for the storing of interface names.
- #interface ⇒ Vedeu::Interfaces::Interface private
-
#next_item ⇒ String|Symbol
Put the next interface relative to the current interfaces in focus.
-
#next_visible_item ⇒ String|Symbol
(also: #focus_next)
Put the next visible interface relative to the current interfaces in focus.
- #not_registered!(name) ⇒ Object private
-
#prev_item ⇒ String|Symbol
(also: #prev, #previous)
Put the previous interface relative to the current interface in focus.
-
#prev_visible_item ⇒ String|Symbol
(also: #focus_previous)
Put the previous visible interface relative to the current interfaces in focus.
-
#refresh ⇒ Array
Refresh the interface in focus.
-
#registered?(name) ⇒ Boolean
Returns a boolean indicating whether the named model is registered.
-
#reset! ⇒ Array|Hash|Set
(also: #reset)
Reset the repository.
-
#storage ⇒ Array
(also: #registered)
Access to the storage for this repository.
-
#update ⇒ String|Boolean
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.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vedeu/models/focus.rb', line 33 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}'") 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.
60 61 62 63 64 65 66 |
# File 'lib/vedeu/models/focus.rb', line 60 def by_name(name) not_registered!(name) unless registered?(name) storage.rotate!(storage.index(name)) update end |
.current ⇒ NilClass|String|Symbol Also known as: focus, name
Return the interface currently focussed.
75 76 77 78 79 |
# File 'lib/vedeu/models/focus.rb', line 75 def current return nil if storage.empty? storage[0] end |
.current?(name) ⇒ Boolean Also known as: focussed?
Returns a boolean indicating whether the named interface is focussed.
91 92 93 |
# File 'lib/vedeu/models/focus.rb', line 91 def current?(name) current == name end |
.focus? ⇒ Boolean
Returns a boolean indicating whether there are interfaces registered.
100 101 102 |
# File 'lib/vedeu/models/focus.rb', line 100 def focus? !storage.empty? end |
.in_memory ⇒ Array (private)
Returns an empty collection ready for the storing of interface names.
236 237 238 |
# File 'lib/vedeu/models/focus.rb', line 236 def in_memory [] end |
.interface ⇒ Vedeu::Interfaces::Interface (private)
206 207 208 |
# File 'lib/vedeu/models/focus.rb', line 206 def interface Vedeu.interfaces.by_name(current) end |
.next_item ⇒ String|Symbol
Put the next interface relative to the current interfaces in focus.
112 113 114 115 116 |
# File 'lib/vedeu/models/focus.rb', line 112 def next_item storage.rotate! update end |
.next_visible_item ⇒ String|Symbol Also known as: focus_next
Put the next visible interface relative to the current interfaces in focus.
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vedeu/models/focus.rb', line 123 def next_visible_item return update unless visible_items? loop do storage.rotate! break if interface.visible? end update end |
.not_registered!(name) ⇒ Object (private)
211 212 213 214 215 |
# File 'lib/vedeu/models/focus.rb', line 211 def not_registered!(name) fail Vedeu::Error::ModelNotFound, "Cannot focus '#{name}' as this interface has not been " \ 'registered.' end |
.prev_item ⇒ String|Symbol Also known as: prev, previous
Put the previous interface relative to the current interface in focus.
143 144 145 146 147 |
# File 'lib/vedeu/models/focus.rb', line 143 def prev_item storage.rotate!(-1) update end |
.prev_visible_item ⇒ String|Symbol Also known as: focus_previous
Put the previous visible interface relative to the current interfaces in focus.
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/vedeu/models/focus.rb', line 155 def prev_visible_item return update unless visible_items? loop do storage.rotate!(-1) break if interface.visible? end update end |
.refresh ⇒ Array
Refresh the interface in focus.
170 171 172 173 174 |
# File 'lib/vedeu/models/focus.rb', line 170 def refresh Vedeu.trigger(:_refresh_view_, current) Vedeu.trigger(:_refresh_cursor_, current) end |
.registered?(name) ⇒ Boolean
Returns a boolean indicating whether the named model is registered.
189 190 191 192 193 |
# File 'lib/vedeu/models/focus.rb', line 189 def registered?(name) return false if storage.empty? storage.include?(name) end |
.reset! ⇒ Array|Hash|Set Also known as: reset
Reset the repository.
198 199 200 |
# File 'lib/vedeu/models/focus.rb', line 198 def reset! @storage = in_memory end |
.storage ⇒ Array Also known as: registered
Access to the storage for this repository.
179 180 181 |
# File 'lib/vedeu/models/focus.rb', line 179 def storage @storage ||= in_memory end |
.update ⇒ String|Boolean (private)
Return the name of the interface in focus after triggering the refresh event for that interface. Returns false when the storage is empty.
222 223 224 225 226 227 228 229 230 |
# File 'lib/vedeu/models/focus.rb', line 222 def update return false if storage.empty? Vedeu.log(message: "Interface in focus: '#{current}'") refresh current end |
.visible_items? ⇒ Boolean (private)
241 242 243 |
# File 'lib/vedeu/models/focus.rb', line 241 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.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vedeu/models/focus.rb', line 33 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}'") 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.
60 61 62 63 64 65 66 |
# File 'lib/vedeu/models/focus.rb', line 60 def by_name(name) not_registered!(name) unless registered?(name) storage.rotate!(storage.index(name)) update end |
#current ⇒ NilClass|String|Symbol Also known as: focus, name
Return the interface currently focussed.
75 76 77 78 79 |
# File 'lib/vedeu/models/focus.rb', line 75 def current return nil if storage.empty? storage[0] end |
#current?(name) ⇒ Boolean Also known as: focussed?
Returns a boolean indicating whether the named interface is focussed.
91 92 93 |
# File 'lib/vedeu/models/focus.rb', line 91 def current?(name) current == name end |
#focus? ⇒ Boolean
Returns a boolean indicating whether there are interfaces registered.
100 101 102 |
# File 'lib/vedeu/models/focus.rb', line 100 def focus? !storage.empty? end |
#in_memory ⇒ Array (private)
Returns an empty collection ready for the storing of interface names.
236 237 238 |
# File 'lib/vedeu/models/focus.rb', line 236 def in_memory [] end |
#interface ⇒ Vedeu::Interfaces::Interface (private)
206 207 208 |
# File 'lib/vedeu/models/focus.rb', line 206 def interface Vedeu.interfaces.by_name(current) end |
#next_item ⇒ String|Symbol
Put the next interface relative to the current interfaces in focus.
112 113 114 115 116 |
# File 'lib/vedeu/models/focus.rb', line 112 def next_item storage.rotate! update end |
#next_visible_item ⇒ String|Symbol Also known as: focus_next
Put the next visible interface relative to the current interfaces in focus.
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vedeu/models/focus.rb', line 123 def next_visible_item return update unless visible_items? loop do storage.rotate! break if interface.visible? end update end |
#not_registered!(name) ⇒ Object (private)
211 212 213 214 215 |
# File 'lib/vedeu/models/focus.rb', line 211 def not_registered!(name) fail Vedeu::Error::ModelNotFound, "Cannot focus '#{name}' as this interface has not been " \ 'registered.' end |
#prev_item ⇒ String|Symbol Also known as: prev, previous
Put the previous interface relative to the current interface in focus.
143 144 145 146 147 |
# File 'lib/vedeu/models/focus.rb', line 143 def prev_item storage.rotate!(-1) update end |
#prev_visible_item ⇒ String|Symbol Also known as: focus_previous
Put the previous visible interface relative to the current interfaces in focus.
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/vedeu/models/focus.rb', line 155 def prev_visible_item return update unless visible_items? loop do storage.rotate!(-1) break if interface.visible? end update end |
#refresh ⇒ Array
Refresh the interface in focus.
170 171 172 173 174 |
# File 'lib/vedeu/models/focus.rb', line 170 def refresh Vedeu.trigger(:_refresh_view_, current) Vedeu.trigger(:_refresh_cursor_, current) end |
#registered?(name) ⇒ Boolean
Returns a boolean indicating whether the named model is registered.
189 190 191 192 193 |
# File 'lib/vedeu/models/focus.rb', line 189 def registered?(name) return false if storage.empty? storage.include?(name) end |
#reset! ⇒ Array|Hash|Set Also known as: reset
Reset the repository.
198 199 200 |
# File 'lib/vedeu/models/focus.rb', line 198 def reset! @storage = in_memory end |
#storage ⇒ Array Also known as: registered
Access to the storage for this repository.
179 180 181 |
# File 'lib/vedeu/models/focus.rb', line 179 def storage @storage ||= in_memory end |
#update ⇒ String|Boolean (private)
Return the name of the interface in focus after triggering the refresh event for that interface. Returns false when the storage is empty.
222 223 224 225 226 227 228 229 230 |
# File 'lib/vedeu/models/focus.rb', line 222 def update return false if storage.empty? Vedeu.log(message: "Interface in focus: '#{current}'") refresh current end |
#visible_items? ⇒ Boolean (private)
241 242 243 |
# File 'lib/vedeu/models/focus.rb', line 241 def visible_items? storage.any? { |name| Vedeu.interfaces.by_name(name).visible? } end |