Class: WEEL

Inherits:
Object
  • Object
show all
Defined in:
lib/weel.rb

Defined Under Namespace

Modules: Signal Classes: Continue, DSLRealization, HandlerWrapperBase, ManipulateHash, ManipulateStructure, Position, ReadHash, ReadStructure, Status

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ WEEL

{{{



20
21
22
23
24
25
26
27
28
29
# File 'lib/weel.rb', line 20

def initialize(*args)# {{{
  @dslr = DSLRealization.new
  @dslr.__weel_handlerwrapper_args = args

  initialize_search if methods.include?(:initialize_search)
  initialize_data if methods.include?(:initialize_data)
  initialize_endpoints if methods.include?(:initialize_endpoints)
  initialize_handlerwrapper if methods.include?(:initialize_handlerwrapper)
  initialize_control if methods.include?(:initialize_control)
end

Class Method Details

.control(flow, &block) ⇒ Object

}}}



343
344
345
346
347
348
# File 'lib/weel.rb', line 343

def self::control(flow, &block)# {{{
  @@__weel_control_block = block
  define_method :initialize_control do
    self.description = @@__weel_control_block
  end
end

.data(data_elements) ⇒ Object

}}}



328
329
330
331
332
333
334
335
336
# File 'lib/weel.rb', line 328

def self::data(data_elements)# {{{
  @@__weel_new_data_elements ||= {}
  @@__weel_new_data_elements.merge! data_elements
  define_method :initialize_data do
    @@__weel_new_data_elements.each do |name,value|
      @dslr.__weel_data[name.to_s.to_sym] = value
    end
  end
end

.endpoint(new_endpoints) ⇒ Object

}}}



318
319
320
321
322
323
324
325
326
327
# File 'lib/weel.rb', line 318

def self::endpoint(new_endpoints)# {{{
  @@__weel_new_endpoints ||= {}
  @@__weel_new_endpoints.merge! new_endpoints
  remove_method :initialize_endpoints if method_defined? :initialize_endpoints
  define_method :initialize_endpoints do
    @@__weel_new_endpoints.each do |name,value|
      @dslr.__weel_endpoints[name.to_s.to_sym] = value
    end
  end
end

.flowObject

}}}



349
350
# File 'lib/weel.rb', line 349

def self::flow # {{{
end

.handlerwrapper(aClassname, *args) ⇒ Object

}}}



337
338
339
340
341
342
# File 'lib/weel.rb', line 337

def self::handlerwrapper(aClassname, *args)# {{{
  define_method :initialize_handlerwrapper do
    self.handlerwrapper = aClassname
    self.handlerwrapper_args = args unless args.empty?
  end
end

.search(*weel_search) ⇒ Object

}}}



313
314
315
316
317
# File 'lib/weel.rb', line 313

def self::search(*weel_search)# {{{
  define_method :initialize_search do
    self.search weel_search
  end
end

Instance Method Details

#abandonObject

}}}



988
989
990
# File 'lib/weel.rb', line 988

def abandon # {{{
  @dslr.__weel_state = :abandoned
end

#data(new_data = nil) ⇒ Object

}}}



1009
1010
1011
1012
1013
1014
# File 'lib/weel.rb', line 1009

def data(new_data=nil) # {{{
  unless new_data.nil? || !new_data.is_a?(Hash)
    new_data.each{ |k,v| @dslr.__weel_data[k] = v }
  end
  @dslr.__weel_data
end

#description(&blk) ⇒ Object

get/set workflow description



1032
1033
1034
# File 'lib/weel.rb', line 1032

def description(&blk)
  self.description=(blk)
end

#description=(code) ⇒ Object

{{{



1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
# File 'lib/weel.rb', line 1035

def description=(code) # {{{
  (class << self; self; end).class_eval do
    remove_method :__weel_control_flow if method_defined? :__weel_control_flow
    define_method :__weel_control_flow do |state,final_state=:finished|
      @dslr.__weel_positions.clear
      @dslr.__weel_state = state
      begin
        if code.is_a? Proc
          @dslr.instance_eval(&code)
        else
          @dslr.instance_eval(code)
        end
      rescue SyntaxError => se
        @dslr.__weel_state = :stopping
        @dslr.__weel_handlerwrapper::inform_syntax_error(@dslr.__weel_handlerwrapper_args,Exception.new(se.message),code)
      rescue NameError => err # don't look into it, or it will explode
        @dslr.__weel_state = :stopping
        @dslr.__weel_handlerwrapper::inform_syntax_error(@dslr.__weel_handlerwrapper_args,Exception.new("main: `#{err.name}` is not a thing that can be used. Maybe it is meant to be a string and you forgot quotes?"),code)
      rescue => err
        @dslr.__weel_state = :stopping
        @dslr.__weel_handlerwrapper::inform_syntax_error(@dslr.__weel_handlerwrapper_args,Exception.new(err.message),code)
      end
      if @dslr.__weel_state == :running || @dslr.__weel_state == :finishing
        ipc = { :unmark => [] }
        @dslr.__weel_positions.each{ |wp| ipc[:unmark] << wp }
        @dslr.__weel_positions.clear
        @dslr.__weel_handlerwrapper::inform_position_change(@dslr.__weel_handlerwrapper_args,ipc)
        @dslr.__weel_state = :finished
      end
      if @dslr.__weel_state == :simulating
        @dslr.__weel_state = final_state
      end
      if @dslr.__weel_state == :stopping
        @dslr.__weel_finalize
      end
    end
  end
end

#endpoint(new_endpoints) ⇒ Object

}}}



1021
1022
1023
1024
1025
1026
# File 'lib/weel.rb', line 1021

def endpoint(new_endpoints) # {{{
  unless new_endpoints.nil? || !new_endpoints.is_a?(Hash) || !new_endpoints.length == 1
    new_endpoints.each{ |k,v| @dslr.__weel_endpoints[k] = v }
  end
  nil
end

#endpoints(new_endpoints = nil) ⇒ Object

}}}



1015
1016
1017
1018
1019
1020
# File 'lib/weel.rb', line 1015

def endpoints(new_endpoints=nil) # {{{
  unless new_endpoints.nil? || !new_endpoints.is_a?(Hash)
    new_endpoints.each{ |k,v| @dslr.__weel_endpoints[k] = v }
  end
  @dslr.__weel_endpoints
end

#handlerwrapperObject

set the handlerwrapper



956
957
958
# File 'lib/weel.rb', line 956

def handlerwrapper # {{{
  @dslr.__weel_handlerwrapper
end

#handlerwrapper=(new_weel_handlerwrapper) ⇒ Object

}}}



959
960
961
962
963
964
965
966
967
# File 'lib/weel.rb', line 959

def handlerwrapper=(new_weel_handlerwrapper) # {{{
  superclass = new_weel_handlerwrapper
  while superclass
    check_ok = true if superclass == WEEL::HandlerWrapperBase
    superclass = superclass.superclass
  end
  raise "Handlerwrapper is not inherited from HandlerWrapperBase" unless check_ok
  @dslr.__weel_handlerwrapper = new_weel_handlerwrapper
end

#handlerwrapper_argsObject

Get/Set the handlerwrapper arguments



970
971
972
# File 'lib/weel.rb', line 970

def handlerwrapper_args # {{{
  @dslr.__weel_handlerwrapper_args
end

#handlerwrapper_args=(args) ⇒ Object

}}}



973
974
975
976
977
978
# File 'lib/weel.rb', line 973

def handlerwrapper_args=(args) # {{{
  if args.class == Array
    @dslr.__weel_handlerwrapper_args = args
  end
  nil
end

#positionsObject

{{{



951
952
953
# File 'lib/weel.rb', line 951

def positions # {{{
  @dslr.__weel_positions
end

#replayObject

}}}



1095
1096
1097
1098
# File 'lib/weel.rb', line 1095

def replay
  @dslr.__weel_replay = true
  start
end

#search(new_weel_search = false) ⇒ Object

Set search positions set new_weel_search to a boolean (or anything else) to start the process from beginning (reset serach positions)



994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
# File 'lib/weel.rb', line 994

def search(new_weel_search=false) # {{{
  @dslr.__weel_search_positions.clear

  new_weel_search = [new_weel_search] if new_weel_search.is_a?(Position)

  if !new_weel_search.is_a?(Array) || new_weel_search.empty?
    false
  else
    new_weel_search.each do |search_position|
      @dslr.__weel_search_positions[search_position.position] = search_position
    end
    true
  end
end

#simObject

{{{



1100
1101
1102
1103
1104
1105
1106
# File 'lib/weel.rb', line 1100

def sim # {{{
  stat = @dslr.__weel_state
  return nil unless stat == :ready || stat == :stopped
  @dslr.__weel_main = Thread.new do
    __weel_control_flow :simulating, stat
  end
end

#startObject

Start the workflow execution



1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
# File 'lib/weel.rb', line 1082

def start # {{{
  return nil if @dslr.__weel_state != :ready && @dslr.__weel_state != :stopped
  @dslr.__weel_main = Thread.new do
    begin
      __weel_control_flow(:running)
    rescue => e
      puts e.message
      puts e.backtrace
      handlerwrapper::inform_handlerwrapper_error handlerwrapper_args, e
    end
  end
end

#stateObject

Get the state of execution (ready|running|stopping|stopped|finished|simulating|abandoned)



981
982
983
# File 'lib/weel.rb', line 981

def state # {{{
  @dslr.__weel_state
end

#state_signalObject

}}}



984
985
986
987
# File 'lib/weel.rb', line 984

def state_signal # {{{
  handlerwrapper::inform_state_change handlerwrapper_args, state
  state
end

#statusObject

}}}



1027
1028
1029
# File 'lib/weel.rb', line 1027

def status # {{{
  @dslr.__weel_status
end

#stopObject

Stop the workflow execution



1075
1076
1077
1078
1079
1080
# File 'lib/weel.rb', line 1075

def stop # {{{
  Thread.new do
    @dslr.__weel_state = :stopping
    @dslr.__weel_main.join if @dslr.__weel_main
  end
end