Class: Decorators::Repeat

Inherits:
Decorator
  • Object
show all
Defined in:
lib/behave_fun/decorators/repeat.rb

Constant Summary collapse

ParamsSchema =
Types::Hash.schema(
  times: Types::Coercible::Integer.optional.default(nil)
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#counterObject

Returns the value of attribute counter.



3
4
5
# File 'lib/behave_fun/decorators/repeat.rb', line 3

def counter
  @counter
end

Instance Method Details

#child_failObject



22
23
24
# File 'lib/behave_fun/decorators/repeat.rb', line 22

def child_fail
  child_success
end

#child_successObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/behave_fun/decorators/repeat.rb', line 10

def child_success
  return @children[0].reset unless params[:times]

  @counter += 1
  if @counter < params[:times]
    @children[0].reset
    execute
  else
    success
  end
end

#params=(params) ⇒ Object



30
31
32
# File 'lib/behave_fun/decorators/repeat.rb', line 30

def params=(params)
  @params = ParamsSchema[params]
end

#serializable_status_fieldsObject



26
27
28
# File 'lib/behave_fun/decorators/repeat.rb', line 26

def serializable_status_fields
  [:counter]
end

#startObject



5
6
7
8
# File 'lib/behave_fun/decorators/repeat.rb', line 5

def start
  super
  @counter = 0
end