Class: Cocina::Instance::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina/instance/action.rb

Constant Summary collapse

UnknownAction =
Class.new(StandardError)
ACTIONS =
[:destroy, :create, :converge, :verify]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) {|_self| ... } ⇒ Action

Returns a new instance of Action.

Yields:

  • (_self)

Yield Parameters:

Raises:



9
10
11
12
13
14
15
# File 'lib/cocina/instance/action.rb', line 9

def initialize(name)
  @after = []
  @before = []
  @name = name
  raise UnknownAction unless ACTIONS.include?(name)
  yield self if block_given?
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/cocina/instance/action.rb', line 7

def name
  @name
end

Instance Method Details

#after(cmd = nil) ⇒ Object



23
24
25
26
27
# File 'lib/cocina/instance/action.rb', line 23

def after(cmd = nil)
  return nil if destroy?
  return @after if cmd.nil?
  @after << cmd
end

#before(cmd = nil) ⇒ Object



17
18
19
20
21
# File 'lib/cocina/instance/action.rb', line 17

def before(cmd = nil)
  return nil if create?
  return @before if cmd.nil?
  @before << cmd
end

#create?Bool

Check if this action is a destroy action

Returns:

  • (Bool)


31
32
33
# File 'lib/cocina/instance/action.rb', line 31

def create?
  name == :create
end

#destroy?Bool

Check if this action is a destroy action

Returns:

  • (Bool)


37
38
39
# File 'lib/cocina/instance/action.rb', line 37

def destroy?
  name == :destroy
end