Module: Vedeu::Buffers Private

Extended by:
Buffers
Includes:
Common, Repository
Included in:
Buffers
Defined in:
lib/vedeu/repositories/buffers.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Stores interface views to be later combined with interface geometry to be displayed.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Repository

#all, #find, #missing_required, #registered, #registered?, #reset, #storage, #validate_attributes!

Methods included from Common

#defined_value?

Class Method Details

.add(attributes) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add an interface view into the back buffer. If the buffer is already registered, then we preserve its front buffer. Returns the name of the buffer added to storage.

Parameters:

  • attributes (Hash)

Returns:

  • (String)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vedeu/repositories/buffers.rb', line 19

def add(attributes)
  validate_attributes!(attributes)

  if registered?(attributes[:name])
    buffer = find(attributes[:name])

    buffer[:back_buffer] = attributes

  else
    storage.store(attributes[:name], {
      back_buffer:  attributes,
      front_buffer: nil,
    })

  end

  attributes[:name]
end

.back_buffer(name) ⇒ Hash|Nil (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the named back buffer.

Parameters:

  • name (String)

Returns:

  • (Hash|Nil)


106
107
108
# File 'lib/vedeu/repositories/buffers.rb', line 106

def back_buffer(name)
  find(name)[:back_buffer]
end

.front_buffer(name) ⇒ Hash|Nil (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the named front buffer.

Parameters:

  • name (String)

Returns:

  • (Hash|Nil)


115
116
117
# File 'lib/vedeu/repositories/buffers.rb', line 115

def front_buffer(name)
  find(name)[:front_buffer]
end

.in_memoryHash (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


121
122
123
124
125
126
127
128
# File 'lib/vedeu/repositories/buffers.rb', line 121

def in_memory
  Hash.new do |hash, interface_name|
    hash[interface_name] = {
      front_buffer: nil,
      back_buffer:  nil,
    }
  end
end

.latest(name) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the latest content for the named buffer. The latest content always goes on to the back buffer. The content which was last output is on the front buffer.

When the back buffer has new content, we swap the back onto the front and return the front buffer to be rendered.

When the back buffer has no new content, we display that which we previously displayed, by returning the front buffer.

If both the back and front buffers have no content, then the view is blank and we should return nothing.

Parameters:

  • name (String)

Returns:

  • (Hash)


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vedeu/repositories/buffers.rb', line 53

def latest(name)
  if new_content?(name)
    swap_buffers(name)
    front_buffer(name)

  elsif old_content?(name)
    front_buffer(name)

  else
    nil

  end
end

.new_content?(name) ⇒ Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a boolean indicating whether the named back buffer has new content.

Parameters:

  • name (String)

Returns:

  • (Boolean)


88
89
90
# File 'lib/vedeu/repositories/buffers.rb', line 88

def new_content?(name)
  defined_value?(back_buffer(name))
end

.not_found(name) ⇒ BufferNotFound (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • name (String)

Returns:

Raises:

  • (BufferNotFound)

    When the entity cannot be found with this name.



134
135
136
# File 'lib/vedeu/repositories/buffers.rb', line 134

def not_found(name)
  fail BufferNotFound, "Cannot find buffer with this name: #{name.to_s}."
end

.old_content?(name) ⇒ Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a boolean indicating whether the named front buffer has content.

Parameters:

  • name (String)

Returns:

  • (Boolean)


97
98
99
# File 'lib/vedeu/repositories/buffers.rb', line 97

def old_content?(name)
  defined_value?(front_buffer(name))
end

.swap_buffers(name) ⇒ Hash (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Swap the named back buffer into the front buffer of the same name.

Parameters:

  • name (String)

Returns:

  • (Hash)


74
75
76
77
78
79
80
81
# File 'lib/vedeu/repositories/buffers.rb', line 74

def swap_buffers(name)
  buffer = find(name)

  storage.store(name, {
    front_buffer: buffer[:back_buffer],
    back_buffer:  nil,
  })
end

Instance Method Details

#add(attributes) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add an interface view into the back buffer. If the buffer is already registered, then we preserve its front buffer. Returns the name of the buffer added to storage.

Parameters:

  • attributes (Hash)

Returns:

  • (String)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vedeu/repositories/buffers.rb', line 19

def add(attributes)
  validate_attributes!(attributes)

  if registered?(attributes[:name])
    buffer = find(attributes[:name])

    buffer[:back_buffer] = attributes

  else
    storage.store(attributes[:name], {
      back_buffer:  attributes,
      front_buffer: nil,
    })

  end

  attributes[:name]
end

#back_buffer(name) ⇒ Hash|Nil (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the named back buffer.

Parameters:

  • name (String)

Returns:

  • (Hash|Nil)


106
107
108
# File 'lib/vedeu/repositories/buffers.rb', line 106

def back_buffer(name)
  find(name)[:back_buffer]
end

#front_buffer(name) ⇒ Hash|Nil (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the named front buffer.

Parameters:

  • name (String)

Returns:

  • (Hash|Nil)


115
116
117
# File 'lib/vedeu/repositories/buffers.rb', line 115

def front_buffer(name)
  find(name)[:front_buffer]
end

#in_memoryHash (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


121
122
123
124
125
126
127
128
# File 'lib/vedeu/repositories/buffers.rb', line 121

def in_memory
  Hash.new do |hash, interface_name|
    hash[interface_name] = {
      front_buffer: nil,
      back_buffer:  nil,
    }
  end
end

#latest(name) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the latest content for the named buffer. The latest content always goes on to the back buffer. The content which was last output is on the front buffer.

When the back buffer has new content, we swap the back onto the front and return the front buffer to be rendered.

When the back buffer has no new content, we display that which we previously displayed, by returning the front buffer.

If both the back and front buffers have no content, then the view is blank and we should return nothing.

Parameters:

  • name (String)

Returns:

  • (Hash)


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vedeu/repositories/buffers.rb', line 53

def latest(name)
  if new_content?(name)
    swap_buffers(name)
    front_buffer(name)

  elsif old_content?(name)
    front_buffer(name)

  else
    nil

  end
end

#new_content?(name) ⇒ Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a boolean indicating whether the named back buffer has new content.

Parameters:

  • name (String)

Returns:

  • (Boolean)


88
89
90
# File 'lib/vedeu/repositories/buffers.rb', line 88

def new_content?(name)
  defined_value?(back_buffer(name))
end

#not_found(name) ⇒ BufferNotFound (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • name (String)

Returns:

Raises:

  • (BufferNotFound)

    When the entity cannot be found with this name.



134
135
136
# File 'lib/vedeu/repositories/buffers.rb', line 134

def not_found(name)
  fail BufferNotFound, "Cannot find buffer with this name: #{name.to_s}."
end

#old_content?(name) ⇒ Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a boolean indicating whether the named front buffer has content.

Parameters:

  • name (String)

Returns:

  • (Boolean)


97
98
99
# File 'lib/vedeu/repositories/buffers.rb', line 97

def old_content?(name)
  defined_value?(front_buffer(name))
end

#swap_buffers(name) ⇒ Hash (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Swap the named back buffer into the front buffer of the same name.

Parameters:

  • name (String)

Returns:

  • (Hash)


74
75
76
77
78
79
80
81
# File 'lib/vedeu/repositories/buffers.rb', line 74

def swap_buffers(name)
  buffer = find(name)

  storage.store(name, {
    front_buffer: buffer[:back_buffer],
    back_buffer:  nil,
  })
end