lib/vedeu/repositories/buffers.rb in vedeu-0.2.4 vs lib/vedeu/repositories/buffers.rb in vedeu-0.2.5
- old
+ new
@@ -33,10 +33,28 @@
end
attributes[:name]
end
+ # Return the named back buffer.
+ #
+ # @param name [String]
+ # @raise [BufferNotFound] When the named buffer cannot be found.
+ # @return [Hash|Nil]
+ def back(name)
+ find(name)[:back_buffer]
+ end
+
+ # Return the named front buffer.
+ #
+ # @param name [String]
+ # @raise [BufferNotFound] When the named buffer cannot be found.
+ # @return [Hash|Nil]
+ def front(name)
+ find(name)[:front_buffer]
+ end
+
# 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
@@ -51,11 +69,11 @@
# @param name [String]
# @return [Hash|NilClass]
def latest(name)
swap_buffers(name) if new_content?(name)
- front_buffer(name)
+ front(name)
end
private
# Swap the named back buffer into the front buffer of the same name. This is
@@ -78,37 +96,13 @@
# Return a boolean indicating whether the named back buffer has new content.
#
# @param name [String]
# @return [Boolean]
def new_content?(name)
- defined_value?(back_buffer(name))
+ defined_value?(back(name))
end
- # Return a boolean indicating whether the named front buffer has content.
- #
- # @param name [String]
- # @return [Boolean]
- # def old_content?(name)
- # defined_value?(front_buffer(name))
- # end
-
- # Return the named back buffer.
- #
- # @param name [String]
- # @return [Hash|Nil]
- def back_buffer(name)
- find(name)[:back_buffer]
- end
-
- # Return the named front buffer.
- #
- # @param name [String]
- # @return [Hash|Nil]
- def front_buffer(name)
- find(name)[:front_buffer]
- end
-
# @return [Hash]
def in_memory
Hash.new do |hash, interface_name|
hash[interface_name] = {
front_buffer: nil,
@@ -119,10 +113,10 @@
# @param name [String]
# @raise [BufferNotFound] When the entity cannot be found with this name.
# @return [BufferNotFound]
def not_found(name)
- fail BufferNotFound, "Cannot find buffer with this name: #{name.to_s}."
+ fail BufferNotFound, "Cannot find buffer with this name: #{name}."
end
end # Buffers
end # Vedeu