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

}}}



284
285
286
287
288
289
# File 'lib/weel.rb', line 284

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

}}}



269
270
271
272
273
274
275
276
277
# File 'lib/weel.rb', line 269

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

}}}



259
260
261
262
263
264
265
266
267
268
# File 'lib/weel.rb', line 259

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

}}}



290
291
# File 'lib/weel.rb', line 290

def self::flow # {{{
end

.handlerwrapper(aClassname, *args) ⇒ Object

}}}



278
279
280
281
282
283
# File 'lib/weel.rb', line 278

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

}}}



254
255
256
257
258
# File 'lib/weel.rb', line 254

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

Instance Method Details

#data(new_data = nil) ⇒ Object

}}}



881
882
883
884
885
886
# File 'lib/weel.rb', line 881

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



904
905
906
# File 'lib/weel.rb', line 904

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

#description=(code) ⇒ Object

{{{



907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
# File 'lib/weel.rb', line 907

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 # => 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("DSL error. I don't want to tell you where and why."),code)
      end
      if @dslr.__weel_state == :running
        @dslr.__weel_state = :finished
        ipc = { :unmark => [] }
        @dslr.__weel_positions.each{ |wp| ipc[:unmark] << wp.position }
        @dslr.__weel_positions.clear
        @dslr.__weel_handlerwrapper::inform_position_change(@dslr.__weel_handlerwrapper_args,ipc)
      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

}}}



893
894
895
896
897
898
# File 'lib/weel.rb', line 893

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

}}}



887
888
889
890
891
892
# File 'lib/weel.rb', line 887

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



831
832
833
# File 'lib/weel.rb', line 831

def handlerwrapper # {{{
  @dslr.__weel_handlerwrapper
end

#handlerwrapper=(new_weel_handlerwrapper) ⇒ Object

}}}



834
835
836
837
838
839
840
841
842
# File 'lib/weel.rb', line 834

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



845
846
847
# File 'lib/weel.rb', line 845

def handlerwrapper_args # {{{
  @dslr.__weel_handlerwrapper_args
end

#handlerwrapper_args=(args) ⇒ Object

}}}



848
849
850
851
852
853
# File 'lib/weel.rb', line 848

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

#positionsObject

{{{



826
827
828
# File 'lib/weel.rb', line 826

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)



866
867
868
869
870
871
872
873
874
875
876
877
878
879
# File 'lib/weel.rb', line 866

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

}}}



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

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



948
949
950
951
952
953
954
955
956
957
958
959
# File 'lib/weel.rb', line 948

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)



856
857
858
# File 'lib/weel.rb', line 856

def state # {{{
  @dslr.__weel_state
end

#state_signalObject

}}}



859
860
861
862
# File 'lib/weel.rb', line 859

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

#statusObject

}}}



899
900
901
# File 'lib/weel.rb', line 899

def status # {{{
  @dslr.__weel_status
end

#stopObject

Stop the workflow execution



941
942
943
944
945
946
# File 'lib/weel.rb', line 941

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