Module: Vedeu::Focus

Extended by:
Focus
Included in:
Focus
Defined in:
lib/vedeu/models/focus.rb

Overview

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

Instance Method Summary collapse

Class Method Details

.add(name, focus = false) ⇒ Array

Add an interface name to the focus list unless it is already registered.

Parameters:

  • name (String)

    The name of the interface.

  • focus (Boolean) (defaults to: false)

    When true, prepends the interface name to the collection, making that interface the currently focussed interface.

Returns:

  • (Array)

    The collection of interface names.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vedeu/models/focus.rb', line 17

def add(name, focus = false)
  if registered?(name)
    return storage unless focus

    by_name(name)
    storage

  else
    Vedeu.log(type: :store, message: "Storing focus entry: '#{name}'")

    if focus
      storage.unshift(name)

    else
      storage.push(name)

    end
  end
end

.by_name(name) ⇒ String Also known as: focus_by_name

Focus an interface by name. Used after defining an interface or interfaces to set the initially focussed interface.

Parameters:

  • name (String)

    The interface to focus; must be defined.

Returns:

  • (String)

    The name of the interface now in focus.

Raises:

  • (ModelNotFound)

    When the interface cannot be found.



43
44
45
46
47
48
49
50
# File 'lib/vedeu/models/focus.rb', line 43

def by_name(name)
  fail ModelNotFound, "Cannot focus '#{name}' as this interface has not " \
                      "been registered." unless registered?(name)

  storage.rotate!(storage.index(name))

  update
end

.currentString Also known as: focus

Return the interface currently focussed.

Returns:

  • (String)


56
57
58
# File 'lib/vedeu/models/focus.rb', line 56

def current
  storage.first
end

.current?(name) ⇒ Boolean Also known as: focussed?

Returns a boolean indicating whether the named interface is focussed.

Parameters:

  • name (String)

Returns:

  • (Boolean)


65
66
67
# File 'lib/vedeu/models/focus.rb', line 65

def current?(name)
  current == name
end

.empty?Boolean

Return a boolean indicating whether the storage is empty.

Returns:

  • (Boolean)


73
74
75
# File 'lib/vedeu/models/focus.rb', line 73

def empty?
  storage.empty?
end

.in_memoryArray (private)

Returns an empty collection ready for the storing of interface names.

Returns:

  • (Array)


159
160
161
# File 'lib/vedeu/models/focus.rb', line 159

def in_memory
  []
end

.next_itemString Also known as: next, focus_next

Put the next interface relative to the current interfaces in focus.

Returns:

  • (String)


80
81
82
83
84
# File 'lib/vedeu/models/focus.rb', line 80

def next_item
  storage.rotate!

  update
end

.prev_itemString Also known as: prev, previous, focus_previous

Put the previous interface relative to the current interface in focus.

Returns:

  • (String)


91
92
93
94
95
# File 'lib/vedeu/models/focus.rb', line 91

def prev_item
  storage.rotate!(-1)

  update
end

.refreshArray

Refresh the interface in focus.

Returns:

  • (Array)


103
104
105
# File 'lib/vedeu/models/focus.rb', line 103

def refresh
  Vedeu.trigger(:_refresh_, current)
end

.registeredArray

Returns a collection of the names of all the registered entities.

Returns:

  • (Array)


110
111
112
113
114
# File 'lib/vedeu/models/focus.rb', line 110

def registered
  return [] if empty?

  storage
end

.registered?(name) ⇒ Boolean

Returns a boolean indicating whether the named model is registered.

Parameters:

  • name (String)

Returns:

  • (Boolean)


120
121
122
123
124
# File 'lib/vedeu/models/focus.rb', line 120

def registered?(name)
  return false if empty?

  storage.include?(name)
end

.resetArray|Hash|Set

Reset the repository.

Returns:

  • (Array|Hash|Set)


129
130
131
# File 'lib/vedeu/models/focus.rb', line 129

def reset
  @storage = in_memory
end

.storageArray (private)

Access to the storage for this repository.

Returns:

  • (Array)


152
153
154
# File 'lib/vedeu/models/focus.rb', line 152

def storage
  @storage ||= in_memory
end

.updateString|FalseClass (private)

Return the name of the interface in focus after triggering the refresh event for that interface. Returns false if the storage is empty.

Returns:

  • (String|FalseClass)


139
140
141
142
143
144
145
146
147
# File 'lib/vedeu/models/focus.rb', line 139

def update
  return false if empty?

  Vedeu.log(type: :info, message: "Interface in focus: '#{current}'")

  refresh

  current
end

Instance Method Details

#add(name, focus = false) ⇒ Array

Add an interface name to the focus list unless it is already registered.

Parameters:

  • name (String)

    The name of the interface.

  • focus (Boolean) (defaults to: false)

    When true, prepends the interface name to the collection, making that interface the currently focussed interface.

Returns:

  • (Array)

    The collection of interface names.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vedeu/models/focus.rb', line 17

def add(name, focus = false)
  if registered?(name)
    return storage unless focus

    by_name(name)
    storage

  else
    Vedeu.log(type: :store, message: "Storing focus entry: '#{name}'")

    if focus
      storage.unshift(name)

    else
      storage.push(name)

    end
  end
end

#by_name(name) ⇒ String Also known as: focus_by_name

Focus an interface by name. Used after defining an interface or interfaces to set the initially focussed interface.

Parameters:

  • name (String)

    The interface to focus; must be defined.

Returns:

  • (String)

    The name of the interface now in focus.

Raises:

  • (ModelNotFound)

    When the interface cannot be found.



43
44
45
46
47
48
49
50
# File 'lib/vedeu/models/focus.rb', line 43

def by_name(name)
  fail ModelNotFound, "Cannot focus '#{name}' as this interface has not " \
                      "been registered." unless registered?(name)

  storage.rotate!(storage.index(name))

  update
end

#currentString Also known as: focus

Return the interface currently focussed.

Returns:

  • (String)


56
57
58
# File 'lib/vedeu/models/focus.rb', line 56

def current
  storage.first
end

#current?(name) ⇒ Boolean Also known as: focussed?

Returns a boolean indicating whether the named interface is focussed.

Parameters:

  • name (String)

Returns:

  • (Boolean)


65
66
67
# File 'lib/vedeu/models/focus.rb', line 65

def current?(name)
  current == name
end

#empty?Boolean

Return a boolean indicating whether the storage is empty.

Returns:

  • (Boolean)


73
74
75
# File 'lib/vedeu/models/focus.rb', line 73

def empty?
  storage.empty?
end

#in_memoryArray (private)

Returns an empty collection ready for the storing of interface names.

Returns:

  • (Array)


159
160
161
# File 'lib/vedeu/models/focus.rb', line 159

def in_memory
  []
end

#next_itemString Also known as: next, focus_next

Put the next interface relative to the current interfaces in focus.

Returns:

  • (String)


80
81
82
83
84
# File 'lib/vedeu/models/focus.rb', line 80

def next_item
  storage.rotate!

  update
end

#prev_itemString Also known as: prev, previous, focus_previous

Put the previous interface relative to the current interface in focus.

Returns:

  • (String)


91
92
93
94
95
# File 'lib/vedeu/models/focus.rb', line 91

def prev_item
  storage.rotate!(-1)

  update
end

#refreshArray

Refresh the interface in focus.

Returns:

  • (Array)


103
104
105
# File 'lib/vedeu/models/focus.rb', line 103

def refresh
  Vedeu.trigger(:_refresh_, current)
end

#registeredArray

Returns a collection of the names of all the registered entities.

Returns:

  • (Array)


110
111
112
113
114
# File 'lib/vedeu/models/focus.rb', line 110

def registered
  return [] if empty?

  storage
end

#registered?(name) ⇒ Boolean

Returns a boolean indicating whether the named model is registered.

Parameters:

  • name (String)

Returns:

  • (Boolean)


120
121
122
123
124
# File 'lib/vedeu/models/focus.rb', line 120

def registered?(name)
  return false if empty?

  storage.include?(name)
end

#resetArray|Hash|Set

Reset the repository.

Returns:

  • (Array|Hash|Set)


129
130
131
# File 'lib/vedeu/models/focus.rb', line 129

def reset
  @storage = in_memory
end

#storageArray (private)

Access to the storage for this repository.

Returns:

  • (Array)


152
153
154
# File 'lib/vedeu/models/focus.rb', line 152

def storage
  @storage ||= in_memory
end

#updateString|FalseClass (private)

Return the name of the interface in focus after triggering the refresh event for that interface. Returns false if the storage is empty.

Returns:

  • (String|FalseClass)


139
140
141
142
143
144
145
146
147
# File 'lib/vedeu/models/focus.rb', line 139

def update
  return false if empty?

  Vedeu.log(type: :info, message: "Interface in focus: '#{current}'")

  refresh

  current
end