Module: LucidOperation::Mixin

Defined in:
lib/isomorfeus_operation/lucid_operation/mixin.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/isomorfeus_operation/lucid_operation/mixin.rb', line 5

def self.included(base)
  base.extend(LucidPropDeclaration::Mixin)
  base.extend(LucidOperation::Steps)
  base.extend(Isomorfeus::Operation::GenericClassApi)

  if RUBY_ENGINE == 'opal'
    def procedure(gherkin_text)
    end

    def steps
    end
    alias :gherkin :steps
    alias :ensure_steps :steps
    alias :failure_steps :steps
    alias :Given :steps
    alias :And :steps
    alias :Then :steps
    alias :When :steps
    alias :Ensure :steps
    alias :Failed :steps
    alias :If_failing :steps
    alias :When_failing :steps
    alias :If_this_failed :steps
    alias :If_that_failed :steps

    def First(regular_expression, &block)
      Isomorfeus.raise_error(message: "#{self}: First already defined, can only be defined once!") if @first_defined
      @first_defined = true
    end

    def Finally(regular_expression, &block)
      Isomorfeus.raise_error(message: "#{self}: Finally already defined, can only be defined once!") if @finally_defined
      @finally_defined = true
    end
  else
    Isomorfeus.add_valid_operation_class(base) unless base == LucidOperation::Base
    base.include(LucidOperation::PromiseRun)

    attr_reader :props
    attr_accessor :step_result

    def initialize(**props_hash)
      props_hash = self.class.validated_props(props_hash)
      @props = LucidProps.new(props_hash)
    end

    def current_user
      Isomorfeus.current_user
    end

    def pub_sub_client
      Isomorfeus.pub_sub_client
    end
  end
end