Class: WEEL

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

Overview

}}}

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

{{{



43
44
45
46
47
48
49
50
51
52
# File 'lib/weel.rb', line 43

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

}}}



324
325
326
327
328
329
# File 'lib/weel.rb', line 324

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

}}}



309
310
311
312
313
314
315
316
317
# File 'lib/weel.rb', line 309

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

}}}



299
300
301
302
303
304
305
306
307
308
# File 'lib/weel.rb', line 299

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

}}}



330
331
# File 'lib/weel.rb', line 330

def self::flow # {{{
end

.handlerwrapper(aClassname, *args) ⇒ Object

}}}



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

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

}}}



294
295
296
297
298
# File 'lib/weel.rb', line 294

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

Instance Method Details

#data(new_data = nil) ⇒ Object

}}}



976
977
978
979
980
981
# File 'lib/weel.rb', line 976

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



999
1000
1001
# File 'lib/weel.rb', line 999

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

#description=(code) ⇒ Object

{{{



1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
# File 'lib/weel.rb', line 1002

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

}}}



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

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

}}}



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

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



926
927
928
# File 'lib/weel.rb', line 926

def handlerwrapper # {{{
  @dslr.__weel_handlerwrapper
end

#handlerwrapper=(new_weel_handlerwrapper) ⇒ Object

}}}



929
930
931
932
933
934
935
936
937
# File 'lib/weel.rb', line 929

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



940
941
942
# File 'lib/weel.rb', line 940

def handlerwrapper_args # {{{
  @dslr.__weel_handlerwrapper_args
end

#handlerwrapper_args=(args) ⇒ Object

}}}



943
944
945
946
947
948
# File 'lib/weel.rb', line 943

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

#positionsObject

{{{



921
922
923
# File 'lib/weel.rb', line 921

def positions # {{{
  @dslr.__weel_positions
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)



961
962
963
964
965
966
967
968
969
970
971
972
973
974
# File 'lib/weel.rb', line 961

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

}}}



1062
1063
1064
1065
1066
1067
1068
# File 'lib/weel.rb', line 1062

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



1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
# File 'lib/weel.rb', line 1049

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)



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

def state # {{{
  @dslr.__weel_state
end

#state_signalObject

}}}



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

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

#statusObject

}}}



994
995
996
# File 'lib/weel.rb', line 994

def status # {{{
  @dslr.__weel_status
end

#stopObject

Stop the workflow execution



1042
1043
1044
1045
1046
1047
# File 'lib/weel.rb', line 1042

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