Module: LucidSimpleOperation::Mixin

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#propsObject (readonly)

Returns the value of attribute props.



23
24
25
# File 'lib/isomorfeus_operation/lucid_simple_operation/mixin.rb', line 23

def props
  @props
end

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/isomorfeus_operation/lucid_simple_operation/mixin.rb', line 3

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

  if RUBY_ENGINE == 'opal'
    base.instance_exec do
      def op
      end
    end
  else
    Isomorfeus.add_valid_operation_class(base) unless base == LucidSimpleOperation::Base

    base.instance_exec do
      def op(&block)
        @op = block
      end
    end
  end
end

Instance Method Details

#current_userObject



42
43
44
# File 'lib/isomorfeus_operation/lucid_simple_operation/mixin.rb', line 42

def current_user
  Isomorfeus.current_user
end

#initialize(**props_hash) ⇒ Object



25
26
27
28
# File 'lib/isomorfeus_operation/lucid_simple_operation/mixin.rb', line 25

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

#promise_runObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/isomorfeus_operation/lucid_simple_operation/mixin.rb', line 30

def promise_run
  original_promise = Promise.new

  operation = self
  promise = original_promise.then do |_|
    operation.instance_exec(&operation.class.instance_variable_get(:@op))
  end

  original_promise.resolve
  promise
end

#pub_sub_clientObject



46
47
48
# File 'lib/isomorfeus_operation/lucid_simple_operation/mixin.rb', line 46

def pub_sub_client
  Isomorfeus.pub_sub_client
end