Class: Intervention::Recorder

Inherits:
Object
  • Object
show all
Defined in:
app/models/intervention/recorder.rb,
app/models/intervention/recorder/cast.rb

Defined Under Namespace

Classes: Cast

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Recorder

Returns a new instance of Recorder.


5
6
7
8
9
10
# File 'app/models/intervention/recorder.rb', line 5

def initialize(attributes = {})
  @attributes = attributes
  @casting = {}
  @steps = []
  @intervention = Intervention.create!(@attributes)
end

Instance Attribute Details

#interventionObject (readonly)

Returns the value of attribute intervention


3
4
5
# File 'app/models/intervention/recorder.rb', line 3

def intervention
  @intervention
end

Instance Method Details

#cast(type, name, *args) ⇒ Object

Add a cast to the intervention


20
21
22
23
24
25
26
27
# File 'app/models/intervention/recorder.rb', line 20

def cast(type, name, *args)
  options = args.extract_options!
  object = args.shift || options[:object]
  cast = Cast.new(self, type, name, object, options)
  @casting[name] = cast
  @steps << cast
  cast
end

#write!Object


12
13
14
15
16
17
# File 'app/models/intervention/recorder.rb', line 12

def write!
  operation = @intervention.operations.create!(started_at: @intervention.started_at, stopped_at: @intervention.stopped_at, reference_name: '100')
  @steps.each(&:save!)
  @intervention.state = :done
  @intervention.save!
end