class TuyaCIMonitor

Constants

ALWAYS_CLOSE
ALWAYS_OPEN
AUTO

Attributes

methods[RW]
name[RW]

Public Class Methods

new() click to toggle source
# File lib/tuya/ci/DSL/tuya_ci_monitor.rb, line 8
def initialize
        # puts 'in initialize'
        @methods = {}
end

Public Instance Methods

ci(*args, &block) click to toggle source
# 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) click to toggle source
# 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
exe() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
method_missing(m, *args, &block) click to toggle source
# 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
strategy_always_close() click to toggle source
# File lib/tuya/ci/DSL/tuya_ci_monitor.rb, line 63
def strategy_always_close
        ALWAYS_CLOSE
end
strategy_always_open() click to toggle source
# File lib/tuya/ci/DSL/tuya_ci_monitor.rb, line 59
def strategy_always_open
        ALWAYS_OPEN
end
strategy_auto() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/tuya/ci/DSL/tuya_ci_monitor.rb, line 72
def tuya_stop_build(message)
        raise TuyaCIMonitorStopError, message
end