Class: Cocina::Instance::Action
- Inherits:
-
Object
- Object
- Cocina::Instance::Action
- Defined in:
- lib/cocina/instance/action.rb
Constant Summary collapse
- UnknownAction =
Class.new(StandardError)
- ACTIONS =
[:destroy, :create, :converge, :verify]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #after(cmd = nil) ⇒ Object
- #before(cmd = nil) ⇒ Object
-
#create? ⇒ Bool
Check if this action is a destroy action.
-
#destroy? ⇒ Bool
Check if this action is a destroy action.
-
#initialize(name) {|_self| ... } ⇒ Action
constructor
A new instance of Action.
Constructor Details
#initialize(name) {|_self| ... } ⇒ Action
Returns a new instance of Action.
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
#name ⇒ Object (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
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
37 38 39 |
# File 'lib/cocina/instance/action.rb', line 37 def destroy? name == :destroy end |