Class: Koz::Poti

Inherits:
BasePoti show all
Defined in:
lib/koz/poti.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasePoti

call, class_initialize, enter, inheritance, inherited, inspect, to_proc

Constructor Details

#initialize(event) ⇒ Poti

Returns a new instance of Poti.



85
86
87
# File 'lib/koz/poti.rb', line 85

def initialize event
  @event = event
end

Instance Attribute Details

#eventObject

, :nowa_block



83
84
85
# File 'lib/koz/poti.rb', line 83

def event
  @event
end

Class Method Details

.>>(pot) ⇒ Object



70
71
72
# File 'lib/koz/poti.rb', line 70

def >> pot
  -> (event) { pot.call self.call event }
end

._call(event) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/koz/poti.rb', line 60

def _call event
  return event if event.stopped
  event = super(event)
  box = new(event)
  catch :outer_of_enter do
    @_entrance.call(box)
  end
  event
end

.test {|ev| ... } ⇒ Object

Yields:

  • (ev)


74
75
76
77
78
79
# File 'lib/koz/poti.rb', line 74

def test(**, &blk)
  ev = Event.new
  ev.data = {**}
  yield(ev) if blk
  call(ev)
end

Instance Method Details

#dataObject



89
# File 'lib/koz/poti.rb', line 89

def data; @event.data; end

#group(name = nil, cond = true, &blk) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/koz/poti.rb', line 119

def group name=nil, cond=true, &blk
  if cond
    catch :outer do
      if name
        catch :"group_of_#{name}" do
          blk.call
        end
      else
        blk.call
      end
    end
  end
end

#on(type = true, **kws, &blk) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/koz/poti.rb', line 97

def on(type=true, **kws, &blk)
  case type
  when false, nil
    return type
  when true
  when Array
    type.include?(@event.type)
  else
    type === @event.type
  end

  s_kws = kws.transform_keys(&:to_s)
  all_match = s_kws.map { |k, v| v === @event.data[k] }.all?
  if all_match && blk
    # orig_block = @nowa_block
    # @nowa_scope = blk
    catch(:outer) { blk.call }
    # @nowa_block = orig_block
  end
  all_match
end

#outObject



142
143
# File 'lib/koz/poti.rb', line 142

def out; throw :outer
end

#passObject



133
134
# File 'lib/koz/poti.rb', line 133

def pass; throw :outer_of_enter, self
end

#stopObject

def halt; throw :outer_of_pipe, self end



139
140
# File 'lib/koz/poti.rb', line 139

def stop; @event.stopped = true
end

#targetObject



90
# File 'lib/koz/poti.rb', line 90

def target; @event.target; end

#typeObject



91
# File 'lib/koz/poti.rb', line 91

def type; @event.type; end

#type=(ano) ⇒ Object



92
# File 'lib/koz/poti.rb', line 92

def type= ano; @event.type= ano; end