Class: Gat::Action::Base

Inherits:
Object
  • Object
show all
Includes:
Interpreter
Defined in:
lib/gat/action/base.rb

Direct Known Subclasses

RubyMethod, ShellCommand

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Interpreter

#interpreter_parameter, #interpreter_parameters, #interpreter_shell_command

Constructor Details

#initialize(name, config, operation) ⇒ Base

Returns a new instance of Base.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/gat/action/base.rb', line 97

def initialize(name, config, operation)

	operation.gatget.logger.log("trace", "action", "Initialize action #{ self.class } @#{ name }")

	@times            = Hash.new
	@times['init']    = Time.now
	@operation        = operation
	@config           = config
	@name             = name
	@description      = config['description'] || "Another Action named #{ name }"
	@flags            = config['flags'] || [ ]
	@output           = ''
	@error            = nil

	@onfail           = config['onfail'] 	   || 'abort'
	@onfail_message   = config['onfail_message']
	@onfail_callback  = config['onfail_callback']

	@@current_action = self
end

Instance Attribute Details

#argumentObject (readonly)

Returns the value of attribute argument.



70
71
72
# File 'lib/gat/action/base.rb', line 70

def argument
  @argument
end

#configObject (readonly)

Returns the value of attribute config.



68
69
70
# File 'lib/gat/action/base.rb', line 68

def config
  @config
end

#descriptionObject (readonly)

Returns the value of attribute description.



71
72
73
# File 'lib/gat/action/base.rb', line 71

def description
  @description
end

#errorObject

Returns the value of attribute error.



73
74
75
# File 'lib/gat/action/base.rb', line 73

def error
  @error
end

#errorsObject

Returns the value of attribute errors.



78
79
80
# File 'lib/gat/action/base.rb', line 78

def errors
  @errors
end

#exit_levelObject

Returns the value of attribute exit_level.



79
80
81
# File 'lib/gat/action/base.rb', line 79

def exit_level
  @exit_level
end

#flagsObject (readonly)

Returns the value of attribute flags.



72
73
74
# File 'lib/gat/action/base.rb', line 72

def flags
  @flags
end

#nameObject (readonly)

Returns the value of attribute name.



69
70
71
# File 'lib/gat/action/base.rb', line 69

def name
  @name
end

#onfailObject

Returns the value of attribute onfail.



85
86
87
# File 'lib/gat/action/base.rb', line 85

def onfail
  @onfail
end

#onfail_callbackObject

Returns the value of attribute onfail_callback.



87
88
89
# File 'lib/gat/action/base.rb', line 87

def onfail_callback
  @onfail_callback
end

#onfail_messageObject

Returns the value of attribute onfail_message.



86
87
88
# File 'lib/gat/action/base.rb', line 86

def onfail_message
  @onfail_message
end

#operationObject (readonly)

Returns the value of attribute operation.



67
68
69
# File 'lib/gat/action/base.rb', line 67

def operation
  @operation
end

#outputObject

Returns the value of attribute output.



77
78
79
# File 'lib/gat/action/base.rb', line 77

def output
  @output
end

#parsed_syntaxObject

Returns the value of attribute parsed_syntax.



83
84
85
# File 'lib/gat/action/base.rb', line 83

def parsed_syntax
  @parsed_syntax
end

#statusObject

Returns the value of attribute status.



81
82
83
# File 'lib/gat/action/base.rb', line 81

def status
  @status
end

#timesObject

Returns the value of attribute times.



76
77
78
# File 'lib/gat/action/base.rb', line 76

def times
  @times
end

Class Method Details

.get_current_actionObject

Get the current action



92
93
94
# File 'lib/gat/action/base.rb', line 92

def self.get_current_action
	@@current_action
end

Instance Method Details

#executeObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/gat/action/base.rb', line 119

def execute

 if self.execute?

   self.run

   #self.set_outputs

   unless self.exit_level == 0
      self.operation.gatget.logger.log("warning", "action_error", "#{self.error}")
     self.operation.gatget.logger.log("warning", "action_error", "Action #{ self.name } finished with status #{self.exit_level}")

     if self.onfail_callback
       self.operation.gatget.send(self.onfail_callback)
     end

     if self.onfail == 'abort'
       self.operation.gatget.logger.log('error', 'action_execute', "Action #{ self.name } abort Gatget")
       self.operation.status = 'fail'

       raise GatgetProcessException.new(self.error, "execute_action", self.onfail_message ? {:message => self.onfail_message} : {} )
     end
   end

 end

 @times['end'] = Time.now
end

#execute?Boolean

Execute? Method check if action must be executed. It test the follow conditions If flags is set, check that all flags are true If operation state is to abort or skip actions, skip actions

Returns:

  • (Boolean)


152
153
154
# File 'lib/gat/action/base.rb', line 152

def execute?
	flags_ok? and status_ok?
end