Class: Vedeu::Buffers::Buffer
- Inherits:
-
Object
- Object
- Vedeu::Buffers::Buffer
- Includes:
- Repositories::Model
- Defined in:
- lib/vedeu/buffers/buffer.rb,
lib/vedeu/buffers/repository.rb
Overview
Repository
Instance Attribute Summary collapse
-
#back ⇒ Vedeu::Views::View
The next buffer to be displayed; contains the content which will be shown on next refresh.
-
#front ⇒ Vedeu::Views::View
The currently displayed buffer, contains the content which was last output.
- #name ⇒ String readonly
-
#previous ⇒ Vedeu::Views::View
The previous buffer which was displayed; contains the content that was shown before ‘front’.
- #repository ⇒ Vedeu::Repositories::Repository included from Repositories::Model
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable is nil or empty.
-
#add(content) ⇒ Boolean
Add the content to the back buffer, then update the repository.
-
#back? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
-
#defaults ⇒ Hash<Symbol => NilClass, String>
private
Returns the default options/attributes for this class.
-
#demodulize(klass) ⇒ String
included
from Common
Removes the module part from the expression in the string.
-
#deputy(client = nil) ⇒ void
included
from Repositories::Model
Returns a DSL instance responsible for defining the DSL methods of this model.
-
#dsl_class ⇒ String
included
from Repositories::Model
private
Returns the DSL class name responsible for this model.
-
#front? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
-
#initialize(attributes = {}) ⇒ Vedeu::Buffers::Buffer
constructor
Return a new instance of Buffer.
-
#present?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable has a useful value.
-
#previous? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
-
#render ⇒ Array<Array<Array<Vedeu::Views::Char>>>
Retrieve the latest content from the buffer.
-
#snake_case(name) ⇒ String
included
from Common
Converts a class name to a lowercase snake case string.
-
#store ⇒ void
included
from Repositories::Model
The model instance stored in the repository.
-
#swap ⇒ Boolean
private
Return a boolean indicating content was swapped between buffers.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Buffers::Buffer
Return a new instance of Buffer. Generally a Buffer is initialized with only a ‘name’ and ‘back’ parameter.
47 48 49 50 51 |
# File 'lib/vedeu/buffers/buffer.rb', line 47 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#back ⇒ Vedeu::Views::View
The next buffer to be displayed; contains the content which will be shown on next refresh.
17 18 19 |
# File 'lib/vedeu/buffers/buffer.rb', line 17 def back @back end |
#front ⇒ Vedeu::Views::View
The currently displayed buffer, contains the content which was last output.
24 25 26 |
# File 'lib/vedeu/buffers/buffer.rb', line 24 def front @front end |
#name ⇒ String (readonly)
35 36 37 |
# File 'lib/vedeu/buffers/buffer.rb', line 35 def name @name end |
#previous ⇒ Vedeu::Views::View
The previous buffer which was displayed; contains the content that was shown before ‘front’.
31 32 33 |
# File 'lib/vedeu/buffers/buffer.rb', line 31 def previous @previous end |
#repository ⇒ Vedeu::Repositories::Repository Originally defined in module Repositories::Model
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable is nil or empty.
#add(content) ⇒ Boolean
Add the content to the back buffer, then update the repository. Returns boolean indicating that the repository was updated.
59 60 61 62 63 64 65 |
# File 'lib/vedeu/buffers/buffer.rb', line 59 def add(content) @back = content store true end |
#back? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
71 72 73 74 75 |
# File 'lib/vedeu/buffers/buffer.rb', line 71 def back? return false if back.nil? || back.lines.empty? true end |
#defaults ⇒ Hash<Symbol => NilClass, String> (private)
Returns the default options/attributes for this class.
131 132 133 134 135 136 137 138 139 |
# File 'lib/vedeu/buffers/buffer.rb', line 131 def defaults { back: nil, front: nil, name: '', previous: nil, repository: Vedeu.buffers, } end |
#demodulize(klass) ⇒ String Originally defined in module Common
Removes the module part from the expression in the string.
#deputy(client = nil) ⇒ void Originally defined in module Repositories::Model
This method returns an undefined value.
Returns a DSL instance responsible for defining the DSL methods of this model.
#dsl_class ⇒ String (private) Originally defined in module Repositories::Model
Returns the DSL class name responsible for this model.
#front? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
81 82 83 84 85 |
# File 'lib/vedeu/buffers/buffer.rb', line 81 def front? return false if front.nil? || front.lines.empty? true end |
#present?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable has a useful value.
#previous? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
91 92 93 94 95 |
# File 'lib/vedeu/buffers/buffer.rb', line 91 def previous? return false if previous.nil? || previous.lines.empty? true end |
#render ⇒ Array<Array<Array<Vedeu::Views::Char>>>
Retrieve the latest content from the buffer.
-
If we have new content (i.e. content on ‘back’) to be shown, we first clear the area occupied by the previous content, then clear the area for the new content, and then finally render the new content.
-
If there is no new content (i.e. ‘back’ is empty), check the ‘front’ buffer and display that.
-
If there is no new content, and the front buffer is empty, display the ‘previous’ buffer.
-
If the ‘previous’ buffer is empty, return an empty collection.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/vedeu/buffers/buffer.rb', line 111 def render if back? swap Vedeu::Output::Viewport.render(front) elsif front? Vedeu::Output::Viewport.render(front) elsif previous? Vedeu::Output::Viewport.render(previous) end end |
#snake_case(name) ⇒ String Originally defined in module Common
Converts a class name to a lowercase snake case string.
#store ⇒ void Originally defined in module Repositories::Model
Perhaps some validation could be added here?
If a block is given, store the model, return the model after yielding.
This method returns an undefined value.
Returns The model instance stored in the repository.
#swap ⇒ Boolean (private)
Return a boolean indicating content was swapped between buffers.
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/vedeu/buffers/buffer.rb', line 145 def swap Vedeu.log(type: :output, message: "Buffer swapping: '#{name}'".freeze) @previous = front @front = back @back = nil store true end |