Class: Miyako::Diagram::DiagramBody

Inherits:
Object
  • Object
show all
Defined in:
lib/Miyako/API/diagram.rb

Overview

遷移図クラス本体

但し、実質的にメソッドを呼び出すのはManagerクラスから呼び出す

Constant Summary collapse

TRIGGER_TYPES =
[:immediate, :next]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, body, trigger = nil) ⇒ DiagramBody

:nodoc:



196
197
198
199
200
201
202
# File 'lib/Miyako/API/diagram.rb', line 196

def initialize(name, body, trigger = nil) #:nodoc:
  @name = name # デバッグ用
  @node = body
  @trigger = trigger ? trigger : Miyako::Diagram::DefaultTrigger.new
  @arrow  = []
  @next_trigger = nil
end

Instance Attribute Details

#nameObject (readonly)

:nodoc:



193
194
195
# File 'lib/Miyako/API/diagram.rb', line 193

def name
  @name
end

#nodeObject (readonly)

:nodoc:



193
194
195
# File 'lib/Miyako/API/diagram.rb', line 193

def node
  @node
end

Instance Method Details

#[](name) ⇒ Object

:nodoc:



257
258
259
# File 'lib/Miyako/API/diagram.rb', line 257

def [](name) #:nodoc:
  return @node[name]
end

#[]=(name, value) ⇒ Object

:nodoc:



261
262
263
# File 'lib/Miyako/API/diagram.rb', line 261

def []=(name, value) #:nodoc:
 @node[name] = value
end

#add_arrow(to, trigger) ⇒ Object

:nodoc:



212
213
214
# File 'lib/Miyako/API/diagram.rb', line 212

def add_arrow(to, trigger) #:nodoc:
  @arrow.push(Miyako::Diagram::Arrow.new(to, trigger))
end

#disposeObject

:nodoc:



285
286
287
# File 'lib/Miyako/API/diagram.rb', line 285

def dispose #:nodoc:
  @node.dispose
end

#go_nextObject

:nodoc:



289
290
291
292
293
294
295
296
297
# File 'lib/Miyako/API/diagram.rb', line 289

def go_next #:nodoc:
  next_obj = self
  @arrow.each{|arrow|
    break (next_obj = arrow.to) if (arrow.trigger && arrow.trigger.call(@node))
    break (next_obj = arrow.to) if @node.finish?
  }
  @trigger.post_process unless self.equal?(next_obj)
  return next_obj
end

#initialize_copy(obj) ⇒ Object

:nodoc:



204
205
206
207
208
209
210
# File 'lib/Miyako/API/diagram.rb', line 204

def initialize_copy(obj) #:nodoc:
  @name = @name.dup # デバッグ用
  @node = @node.dup
  @trigger = @trigger.dup
  @arrow  = @arrow.dup
  @next_trigger = @next_trigger.dup
end

#pauseObject

:nodoc:



226
227
228
# File 'lib/Miyako/API/diagram.rb', line 226

def pause #:nodoc:
  @node.pause
end

#renderObject

:nodoc:



250
251
252
253
254
255
# File 'lib/Miyako/API/diagram.rb', line 250

def render #:nodoc:
  if @trigger.render?
    @node.render
    @trigger.post_render
  end
end

#replace_trigger(new_trigger, timing = :next) ⇒ Object

更新タイミングを計るトリガーオブジェクトを置き換える

現在実行しているトリガーを新しいトリガーオブジェクトに置き換える。 置き換えのタイミングは、以下の2種が選択可能(シンボルで指定)

:immediate

即時に置き換え。現在実行中のトリガーを停止して、引数で指定したトリガーに置き換えて実行を開始する

:next

次回更新時に置き換え。本メソッドが呼ばれた次の更新(updateメソッドが呼ばれた時)にトリガーを置き換える

new_trigger

置き換え対象のトリガーオブジェクト

timing

置き換えのタイミング。:immediateと:nextの2種類がある

Raises:



272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/Miyako/API/diagram.rb', line 272

def replace_trigger(new_trigger, timing=:next)
  raise MiyakoError, "I can't understand Timing Type! : #{timing}" unless TRIGGER_TYPES.include?(timing)
  case timing
  when :immediate
    @trigger.stop
    @trigger.post_process
    @trigger = new_trigger
    @trigger.pre_process
  when :next
    @next_trigger = new_trigger
  end
end

#resumeObject

:nodoc:



230
231
232
# File 'lib/Miyako/API/diagram.rb', line 230

def resume #:nodoc:
  @node.resume
end

#startObject

:nodoc:



216
217
218
219
# File 'lib/Miyako/API/diagram.rb', line 216

def start #:nodoc:
  @trigger.pre_process
  @node.start
end

#stopObject

:nodoc:



221
222
223
224
# File 'lib/Miyako/API/diagram.rb', line 221

def stop #:nodoc:
  @node.stop
  @trigger.post_process
end

#update(*params) ⇒ Object

:nodoc:



238
239
240
241
242
243
244
245
246
247
248
# File 'lib/Miyako/API/diagram.rb', line 238

def update(*params) #:nodoc:
  if @trigger.update?
    @node.update(*params)
    @trigger.post_update
    @node.reset_input
    if @next_trigger
      @trigger = @next_trigger
      @next_trigger = nil
    end
  end
end

#update_input(*params) ⇒ Object

:nodoc:



234
235
236
# File 'lib/Miyako/API/diagram.rb', line 234

def update_input(*params) #:nodoc:
  @node.update_input(*params)
end