Class: Familia::Validation::CommandRecorder::TransactionBlock
- Inherits:
-
Object
- Object
- Familia::Validation::CommandRecorder::TransactionBlock
- Defined in:
- lib/familia/validation/command_recorder.rb
Overview
Represents a transaction block (MULTI/EXEC)
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#end_index ⇒ Object
readonly
Returns the value of attribute end_index.
-
#start_index ⇒ Object
readonly
Returns the value of attribute start_index.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Instance Method Summary collapse
-
#command_count ⇒ Object
-
#finalize(all_commands) ⇒ Object
-
#initialize(context = {}) ⇒ TransactionBlock
constructor
A new instance of TransactionBlock.
-
#valid? ⇒ Boolean
Constructor Details
#initialize(context = {}) ⇒ TransactionBlock
Returns a new instance of TransactionBlock.
172 173 174 175 176 177 178 |
# File 'lib/familia/validation/command_recorder.rb', line 172 def initialize(context = {}) @context = context @started_at = Time.now @start_index = nil @end_index = nil @commands = [] end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
170 171 172 |
# File 'lib/familia/validation/command_recorder.rb', line 170 def commands @commands end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
170 171 172 |
# File 'lib/familia/validation/command_recorder.rb', line 170 def context @context end |
#end_index ⇒ Object (readonly)
Returns the value of attribute end_index.
170 171 172 |
# File 'lib/familia/validation/command_recorder.rb', line 170 def end_index @end_index end |
#start_index ⇒ Object (readonly)
Returns the value of attribute start_index.
170 171 172 |
# File 'lib/familia/validation/command_recorder.rb', line 170 def start_index @start_index end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
170 171 172 |
# File 'lib/familia/validation/command_recorder.rb', line 170 def started_at @started_at end |
Instance Method Details
#command_count ⇒ Object
196 197 198 |
# File 'lib/familia/validation/command_recorder.rb', line 196 def command_count @commands.length end |
#finalize(all_commands) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/familia/validation/command_recorder.rb', line 180 def finalize(all_commands) # Find MULTI and EXEC commands multi_index = all_commands.rindex { |cmd| cmd.command == 'MULTI' } exec_index = all_commands.rindex { |cmd| cmd.command == 'EXEC' } return unless multi_index && exec_index && exec_index > multi_index @start_index = multi_index @end_index = exec_index @commands = all_commands[(multi_index + 1)...exec_index] end |
#valid? ⇒ Boolean
192 193 194 |
# File 'lib/familia/validation/command_recorder.rb', line 192 def valid? @start_index && @end_index && @commands.any? end |