Class: TuyaCIMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/tuya/ci/DSL/tuya_ci_monitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTuyaCIMonitor

Returns a new instance of TuyaCIMonitor.



3
4
5
6
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 3

def initialize
  # puts 'in initialize'
  @methods = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



72
73
74
75
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 72

def method_missing(m, *args, &block)
  # puts "in method_missing method is: #{m}, args is: #{args}"
  dsl m, args, &block
end

Instance Attribute Details

#methodsObject

Returns the value of attribute methods.



2
3
4
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 2

def methods
  @methods
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 2

def name
  @name
end

Instance Method Details

#ci(*args, &block) ⇒ Object



53
54
55
56
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 53

def ci(*args, &block)
  # puts "in ci args is: #{args}"
  dsl 'root', args, &block
end

#dsl(process, args, &block) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 58

def dsl(process, args, &block)
  # puts "in dsl process is: #{process} args is: #{args}"
  if block_given?
    if process
      # puts "process: #{process}"
      if process == 'root'
        instance_eval &block
      else
        @methods[process] = block
      end
    end
  end
end

#exeObject



46
47
48
49
50
51
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 46

def exe
  @methods.each_key do |key|
    l = @methods[key]
    l.call
  end
end

#exe_action(action, options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 8

def exe_action(action, options)
  method = @methods[action.to_sym]
  begin
    method.call options if method
  rescue Exception => e
    if e.class == TuyaCIMonitorStopError
      puts "Trigger Exception cached, tuya_stop_build has been used. the build is end here".red
      raise $!
    else
      puts "Trigger Exception cached, you can puts detail in your error method".red
      exe_error action, $!, $@, options
    end

  ensure
  end
end

#exe_error(process, error, position, options) ⇒ Object



40
41
42
43
44
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 40

def exe_error(process, error, position, options)
  method = @methods['error'.to_sym]
  # require 'tuya/ci/DSL/exe/dsl_exe'
  method.call error, position, options, process
end

#tuya_sh(shell) ⇒ Object



29
30
31
32
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 29

def tuya_sh(shell)
  dsl = TuyaCIDSL::DSLExecute.new shell
  dsl.execute
end

#tuya_sh_from_git(shell, git) ⇒ Object



34
35
36
37
38
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 34

def tuya_sh_from_git(shell, git)
  dsl = TuyaCIDSL::DSLExecute.new shell
  dsl.download git
  dsl.execute
end

#tuya_stop_build(message) ⇒ Object



25
26
27
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 25

def tuya_stop_build(message)
  raise TuyaCIMonitorStopError, message
end