Class: WEEL

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

Defined Under Namespace

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ WEEL

{{{



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

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

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

Class Method Details

.connectionwrapper(aClassname, *args) ⇒ Object

}}}



424
425
426
427
428
429
# File 'lib/weel.rb', line 424

def self::connectionwrapper(aClassname, *args)# {{{
  define_method :initialize_connectionwrapper do
    self.connectionwrapper = aClassname
    self.connectionwrapper_args = args unless args.empty?
  end
end

.control(flow, &block) ⇒ Object

}}}



430
431
432
433
434
# File 'lib/weel.rb', line 430

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

.data(data_elements) ⇒ Object

}}}



415
416
417
418
419
420
421
422
423
# File 'lib/weel.rb', line 415

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

}}}



405
406
407
408
409
410
411
412
413
414
# File 'lib/weel.rb', line 405

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

.flow(flow_data = nil) ⇒ Object

}}}



435
436
437
438
439
# File 'lib/weel.rb', line 435

def self::flow(flow_data=nil) # {{{
  define_method :initialize_flow_data do
    self.flow_data = flow_data
  end if flow_data
end

.search(*weel_search) ⇒ Object

}}}



400
401
402
403
404
# File 'lib/weel.rb', line 400

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

Instance Method Details

#abandonObject

}}}



1070
1071
1072
# File 'lib/weel.rb', line 1070

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

#connectionwrapperObject

set the connectionwrapper



1038
1039
1040
# File 'lib/weel.rb', line 1038

def connectionwrapper # {{{
  @dslr.__weel_connectionwrapper
end

#connectionwrapper=(new_weel_connectionwrapper) ⇒ Object

}}}



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

def connectionwrapper=(new_weel_connectionwrapper) # {{{
  superclass = new_weel_connectionwrapper
  while superclass
    check_ok = true if superclass == WEEL::ConnectionWrapperBase
    superclass = superclass.superclass
  end
  raise "ConnectionWrapper is not inherited from ConnectionWrapperBase" unless check_ok
  @dslr.__weel_connectionwrapper = new_weel_connectionwrapper
end

#connectionwrapper_argsObject

Get/Set the connectionwrapper arguments



1052
1053
1054
# File 'lib/weel.rb', line 1052

def connectionwrapper_args # {{{
  @dslr.__weel_connectionwrapper_args
end

#connectionwrapper_args=(args) ⇒ Object

}}}



1055
1056
1057
1058
1059
1060
# File 'lib/weel.rb', line 1055

def connectionwrapper_args=(args) # {{{
  if args.class == Array
    @dslr.__weel_connectionwrapper_args = args
  end
  nil
end

#data(new_data = nil) ⇒ Object

}}}



1134
1135
1136
1137
1138
1139
# File 'lib/weel.rb', line 1134

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



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

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

#description=(code) ⇒ Object

{{{



1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
# File 'lib/weel.rb', line 1078

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_connectionwrapper::inform_syntax_error(@dslr.__weel_connectionwrapper_args,se,code)
      rescue NameError => err # don't look into it, or it will explode
        @dslr.__weel_state = :stopping
        @dslr.__weel_connectionwrapper::inform_syntax_error(@dslr.__weel_connectionwrapper_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_connectionwrapper::inform_syntax_error(@dslr.__weel_connectionwrapper_args,err,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_connectionwrapper::inform_position_change(@dslr.__weel_connectionwrapper_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

}}}



1146
1147
1148
1149
1150
1151
# File 'lib/weel.rb', line 1146

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

}}}



1140
1141
1142
1143
1144
1145
# File 'lib/weel.rb', line 1140

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

#positionsObject

{{{



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

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)



1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
# File 'lib/weel.rb', line 1119

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

}}}



1182
1183
1184
1185
1186
1187
1188
# File 'lib/weel.rb', line 1182

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



1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
# File 'lib/weel.rb', line 1168

def start # {{{
  return nil if @dslr.__weel_state != :ready && @dslr.__weel_state != :stopped
  @dslr.__weel_main = Thread.new do
    Thread.current[:branch_search] = true if @dslr.__weel_search_positions.any?
    begin
      __weel_control_flow(:running)
    rescue => e
      puts e.message
      puts e.backtrace
      connectionwrapper::inform_connectionwrapper_error connectionwrapper_args, e
    end
  end
end

#stateObject

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



1063
1064
1065
# File 'lib/weel.rb', line 1063

def state # {{{
  @dslr.__weel_state
end

#state_signalObject

}}}



1066
1067
1068
1069
# File 'lib/weel.rb', line 1066

def state_signal # {{{
  connectionwrapper::inform_state_change connectionwrapper_args, state
  state
end

#statusObject

}}}



1152
1153
1154
# File 'lib/weel.rb', line 1152

def status # {{{
  @dslr.__weel_status
end

#stopObject

Stop the workflow execution



1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
# File 'lib/weel.rb', line 1157

def stop # {{{
  Thread.new do
    if  @dslr.__weel_state == :running
      @dslr.__weel_state = :stopping
      @dslr.__weel_main.join if @dslr.__weel_main
    elsif @dslr.__weel_state == :ready || @dslr.__weel_state == :stopped
      @dslr.__weel_state = :stopped
    end
  end
end