Class: MARS::Runnable

Inherits:
Object
  • Object
show all
Includes:
Hooks
Defined in:
lib/mars/runnable.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hooks

included, #run_after_hooks, #run_before_hooks

Constructor Details

#initialize(name: self.class.step_name, state: {}, formatter: nil) ⇒ Runnable

Returns a new instance of Runnable.



23
24
25
26
27
# File 'lib/mars/runnable.rb', line 23

def initialize(name: self.class.step_name, state: {}, formatter: nil)
  @name = name
  @state = state
  @formatter = formatter || self.class.formatter&.new || Formatter.new
end

Instance Attribute Details

#formatterObject (readonly)

Returns the value of attribute formatter.



7
8
9
# File 'lib/mars/runnable.rb', line 7

def formatter
  @formatter
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/mars/runnable.rb', line 7

def name
  @name
end

#stateObject

Returns the value of attribute state.



8
9
10
# File 'lib/mars/runnable.rb', line 8

def state
  @state
end

Class Method Details

.formatter(klass = nil) ⇒ Object



18
19
20
# File 'lib/mars/runnable.rb', line 18

def formatter(klass = nil)
  klass ? @formatter_class = klass : @formatter_class
end

.step_nameObject



11
12
13
14
15
16
# File 'lib/mars/runnable.rb', line 11

def step_name
  return @step_name if defined?(@step_name)
  return unless name

  name.split("::").last.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
end

Instance Method Details

#run(context) ⇒ Object

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/mars/runnable.rb', line 29

def run(context)
  raise NotImplementedError
end