lib/vedeu/repositories/buffers.rb in vedeu-0.2.0 vs lib/vedeu/repositories/buffers.rb in vedeu-0.2.1
- old
+ new
@@ -7,43 +7,31 @@
module Buffers
include Vedeu::Common
extend self
- # @param attributes [Hash]
- # @return [Hash]
- def create(attributes)
- add(attributes)
-
- Vedeu::Interfaces.add(attributes)
- Vedeu::Refresh.add_interface(attributes)
-
- Vedeu::Groups.add(attributes)
- Vedeu::Refresh.add_group(attributes)
-
- Vedeu::Focus.add(attributes)
- end
-
# Add an interface view into the back buffer. If the buffer is already
- # registered, then we preserve its front buffer.
+ # registered, then we preserve its front buffer. Returns the name of the
+ # buffer added to storage.
#
# @param attributes [Hash]
- # @return [Hash]
+ # @return [String]
def add(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
- storage
+ attributes[:name]
end
# Find the buffer by name.
#
# @param name [String]
@@ -70,31 +58,50 @@
# @param name [String]
# @return [Hash]
def latest(name)
if new_content?(name)
swap_buffers(name)
- content(name)
+ front_buffer(name)
elsif old_content?(name)
- content(name)
+ front_buffer(name)
else
nil
end
end
- # Returns the named front buffer.
+ # Returns a collection of the names of all registered buffers.
#
+ # @return [Array]
+ def registered
+ storage.keys
+ end
+
+ # Returns a boolean indicating whether the named buffer is registered.
+ #
+ # @api private
# @param name [String]
+ # @return [Boolean]
+ def registered?(name)
+ storage.key?(name)
+ end
+
+ # Reset the buffers repository; removing all buffers. This does not delete
+ # the interfaces themselves.
+ #
# @return [Hash]
- def content(name)
- front_buffer(name)
+ def reset
+ @_storage = in_memory
end
+ private
+
# Swap the named back buffer into the front buffer of the same name.
#
+ # @api private
# @param name [String]
# @return [Hash]
def swap_buffers(name)
buffer = find(name)
@@ -102,34 +109,24 @@
front_buffer: buffer[:back_buffer],
back_buffer: nil,
})
end
- # Reset the buffers repository; removing all buffers. This does not delete
- # the interfaces themselves.
- #
- # @return [Hash]
- def reset
- @_storage = in_memory
- end
-
- private
-
# Return a boolean indicating whether the named back buffer has new content.
#
# @api private
# @param name [String]
- # @return [TrueClass|FalseClass]
+ # @return [Boolean]
def new_content?(name)
defined_value?(back_buffer(name))
end
# Return a boolean indicating whether the named front buffer has content.
#
# @api private
# @param name [String]
- # @return [TrueClass|FalseClass]
+ # @return [Boolean]
def old_content?(name)
defined_value?(front_buffer(name))
end
# Return the named back buffer.
@@ -148,18 +145,11 @@
# @return [Hash|Nil]
def front_buffer(name)
find(name).fetch(:front_buffer, nil)
end
- # Returns a boolean indicating whether the named buffer is registered.
+ # Access to the storage for this repository.
#
- # @api private
- # @param name [String]
- # @return [TrueClass|FalseClass]
- def registered?(name)
- storage.key?(name)
- end
-
# @api private
# @return [Hash]
def storage
@_storage ||= in_memory
end