Class: Faulty::Storage::Memory::MemoryCircuit

Inherits:
Struct
  • Object
show all
Defined in:
lib/faulty/storage/memory.rb

Overview

The internal object for storing a circuit

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemoryCircuit

Returns a new instance of MemoryCircuit.



45
46
47
48
49
50
# File 'lib/faulty/storage/memory.rb', line 45

def initialize
  self.state = Concurrent::Atom.new(:closed)
  self.runs = Concurrent::MVar.new([], dup_on_deref: true)
  self.opened_at = Concurrent::Atom.new(nil)
  self.lock = nil
end

Instance Attribute Details

#lockObject

Returns the value of attribute lock

Returns:

  • (Object)

    the current value of lock



44
45
46
# File 'lib/faulty/storage/memory.rb', line 44

def lock
  @lock
end

#opened_atObject

Returns the value of attribute opened_at

Returns:

  • (Object)

    the current value of opened_at



44
45
46
# File 'lib/faulty/storage/memory.rb', line 44

def opened_at
  @opened_at
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



44
45
46
# File 'lib/faulty/storage/memory.rb', line 44

def options
  @options
end

#runsObject

Returns the value of attribute runs

Returns:

  • (Object)

    the current value of runs



44
45
46
# File 'lib/faulty/storage/memory.rb', line 44

def runs
  @runs
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



44
45
46
# File 'lib/faulty/storage/memory.rb', line 44

def state
  @state
end

Instance Method Details

#status(circuit_options) ⇒ Status

Create a status object from the current circuit state

Parameters:

Returns:

  • (Status)

    The newly created status



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/faulty/storage/memory.rb', line 56

def status(circuit_options)
  status = nil
  runs.borrow do |locked_runs|
    status = Faulty::Status.from_entries(
      locked_runs,
      state: state.value,
      lock: lock,
      opened_at: opened_at.value,
      options: circuit_options
    )
  end

  status
end