Class: TuyaCIMonitor

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

Constant Summary collapse

ALWAYS_OPEN =
1
ALWAYS_CLOSE =
2
AUTO =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTuyaCIMonitor

Returns a new instance of TuyaCIMonitor.



8
9
10
11
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 8

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



119
120
121
122
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 119

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



100
101
102
103
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 100

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

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



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 105

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



93
94
95
96
97
98
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 93

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

#exe_action(action, options, key) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 13

def exe_action(action, options, key)
	method = @methods[action.to_sym]
	begin
		strategy_method = @methods[:strategy]
		strategy, strategy_key = strategy_method.call options if strategy_method

		unless strategy.class == Fixnum
			strategy = ALWAYS_OPEN
		end
		trigger_call method, action, options, key, strategy, strategy_key
	rescue Exception => e
		if e.class == TuyaCIMonitorStopError
			puts "Trigger Exception cached, tuya_stop_build has been used. the stop message is: #{$!}".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



87
88
89
90
91
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 87

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 if method
end

#strategy_always_closeObject



63
64
65
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 63

def strategy_always_close
	ALWAYS_CLOSE
end

#strategy_always_openObject



59
60
61
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 59

def strategy_always_open
	ALWAYS_OPEN
end

#strategy_autoObject



67
68
69
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 67

def strategy_auto
	AUTO
end

#trigger_call(method, action, options, key, strategy, strategy_key) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 36

def trigger_call(method, action, options, key, strategy, strategy_key)

	call_strategy = false
	if strategy == ALWAYS_CLOSE
		call_strategy = false
	elsif strategy == ALWAYS_OPEN
		call_strategy = true
	elsif strategy == AUTO
		monitors = TuyaCIDSL::TuyaDSL.instance
		if monitors.strategy_auto.has_key? strategy_key
			call_strategy = true
			options[:strategy] = monitors.strategy_auto[strategy_key]
		end
	end

	if call_strategy
		if method
			puts "Trigger '#{action}' in '#{key}'".green
			method.call options
		end
	end
end

#tuya_sh(shell) ⇒ Object



76
77
78
79
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 76

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

#tuya_sh_from_git(shell, git) ⇒ Object



81
82
83
84
85
# File 'lib/tuya/ci/DSL/tuya_ci_monitor.rb', line 81

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

#tuya_stop_build(message) ⇒ Object



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

def tuya_stop_build(message)
	raise TuyaCIMonitorStopError, message
end