Class: Familia::Validation::CommandRecorder::TransactionBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/familia/validation/command_recorder.rb

Overview

Represents a transaction block (MULTI/EXEC)

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commandsObject (readonly)

Returns the value of attribute commands.



170
171
172
# File 'lib/familia/validation/command_recorder.rb', line 170

def commands
  @commands
end

#contextObject (readonly)

Returns the value of attribute context.



170
171
172
# File 'lib/familia/validation/command_recorder.rb', line 170

def context
  @context
end

#end_indexObject (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_indexObject (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_atObject (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_countObject



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

Returns:

  • (Boolean)


192
193
194
# File 'lib/familia/validation/command_recorder.rb', line 192

def valid?
  @start_index && @end_index && @commands.any?
end