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
# File 'app/models/design_management/design_action.rb', line 31

def initialize(design, action, content = nil)
  @design, @action, @content = design, action, 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


40
41
42
# File 'app/models/design_management/design_action.rb', line 40

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.


46
47
48
# File 'app/models/design_management/design_action.rb', line 46

def performed
  design.clear_version_cache
end

#row_attrs(version) ⇒ Object


36
37
38
# File 'app/models/design_management/design_action.rb', line 36

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