Class: RobotLab::HookContext

Inherits:
Object
  • Object
show all
Defined in:
lib/robot_lab/hook_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event:, metadata: nil) ⇒ HookContext

Returns a new instance of HookContext.



7
8
9
10
# File 'lib/robot_lab/hook_context.rb', line 7

def initialize(event:, metadata: nil)
  @event = event.to_sym
  @metadata =  || ExtensionState.new
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



5
6
7
# File 'lib/robot_lab/hook_context.rb', line 5

def event
  @event
end

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'lib/robot_lab/hook_context.rb', line 5

def 
  @metadata
end

Instance Method Details

#ext(name) ⇒ Object



12
13
14
# File 'lib/robot_lab/hook_context.rb', line 12

def ext(name)
  .ext(name)
end

#localObject

Raises:

  • (ArgumentError)


16
17
18
19
20
# File 'lib/robot_lab/hook_context.rb', line 16

def local
  raise ArgumentError, "No hook namespace active" unless @namespace

  ext(@namespace)
end

#to_hObject



30
31
32
# File 'lib/robot_lab/hook_context.rb', line 30

def to_h
  public_snapshot.merge(metadata: .to_h)
end

#with_namespace(namespace) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/robot_lab/hook_context.rb', line 22

def with_namespace(namespace)
  previous = @namespace
  @namespace = namespace&.to_sym
  yield self
ensure
  @namespace = previous
end