Class: DesignManagement::DesignAction

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/design_management/design_action.rb

Overview

Parameter object which is a tuple of the database record and the last gitaly call made to change it. This serves to perform the logical mapping from git action to database representation.

Constant Summary collapse

EVENT_FOR_GITALY_ACTION =
{
  create: DesignManagement::Action.events[:creation],
  update: DesignManagement::Action.events[:modification],
  delete: DesignManagement::Action.events[:deletion]
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(design, action, content = nil) ⇒ DesignAction

Parameters:

  • design [DesignManagement::Design]: the design that was changed

  • action [Symbol]: the action that gitaly performed


31
32
33
34
35
36
# File 'app/models/design_management/design_action.rb', line 31

def initialize(design, action, content = nil)
  @design = design
  @action = action
  @content = content
  validate!
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.


16
17
18
# File 'app/models/design_management/design_action.rb', line 16

def action
  @action
end

#contentObject (readonly)

Returns the value of attribute content.


16
17
18
# File 'app/models/design_management/design_action.rb', line 16

def content
  @content
end

#designObject (readonly)

Returns the value of attribute design.


16
17
18
# File 'app/models/design_management/design_action.rb', line 16

def design
  @design
end

Instance Method Details

#gitaly_actionObject


42
43
44
# File 'app/models/design_management/design_action.rb', line 42

def gitaly_action
  { action: action, file_path: design.full_path, content: content }.compact
end

#performedObject

This action has been performed - do any post-creation actions such as clearing method caches.


48
49
50
# File 'app/models/design_management/design_action.rb', line 48

def performed
  design.clear_version_cache
end

#row_attrs(version) ⇒ Object


38
39
40
# File 'app/models/design_management/design_action.rb', line 38

def row_attrs(version)
  { design_id: design.id, version_id: version.id, event: event }
end