Top Level Namespace

Defined Under Namespace

Modules: Rays Classes: RaysCommand, RaysException

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.debug_onObject



50
51
52
# File 'lib/rays/loaders/logging.rb', line 50

def $log.debug_on
  $log.level = Logger::DEBUG
end

.resetObject



58
59
60
# File 'lib/rays/loaders/logging.rb', line 58

def $log.reset
  $log.level = Logger::INFO
end

.silent_onObject



54
55
56
# File 'lib/rays/loaders/logging.rb', line 54

def $log.silent_on
  $log.level = Logger::FATAL
end

Instance Method Details

#command?(command) ⇒ Boolean

Check if command in the PATH

Returns:

  • (Boolean)


150
151
152
# File 'lib/rays/utils/common_utils.rb', line 150

def command?(command)
  system("which #{ command} > /dev/null 2>&1")
end

#in_directory(directory) ⇒ Object

Execute a given code a directory.



103
104
105
106
107
108
109
110
111
# File 'lib/rays/utils/common_utils.rb', line 103

def in_directory(directory)
  original_directory = Dir.pwd
  Dir.chdir(directory) if Dir.exist?(directory)
  begin
    yield
  ensure
    Dir.chdir(original_directory)
  end
end

#in_local_environmentObject

In local environment



130
131
132
133
134
135
136
137
138
# File 'lib/rays/utils/common_utils.rb', line 130

def in_local_environment
  original_environment_name = $rays_config.environment.name
  begin
    $rays_config.environment = 'local'
    yield
  ensure
    $rays_config.environment = original_environment_name
  end
end

#log_block(message) ⇒ Object

Execute a given block and process any exception with a proper logging.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rays/utils/common_utils.rb', line 34

def log_block(message)
  begin
    yield
  rescue RaysException => e
    $log.error(e)
    $log.debug("#{e}:\tBacktrace:\r\n#{e.backtrace.join("\r\n")}")
    raise e
  rescue => e
    $log.error("Cannot #{message}.")
    $log.debug("#{e}:\tBacktrace:\r\n#{e.backtrace.join("\r\n")}")
    raise e
  end
end

#missing_environment_option(name, option) ⇒ Object

Create a missing option string



143
144
145
# File 'lib/rays/utils/common_utils.rb', line 143

def missing_environment_option(name, option)
  "#{name} does not contain #{option} information. see config/environment.yml"
end

#rays_exec(command) ⇒ Object

Execute OS command.

Raises:



82
83
84
85
86
87
88
89
90
91
# File 'lib/rays/utils/common_utils.rb', line 82

def rays_exec(command)
  success = false
  if $log.debug?
    success = system command
  else
    silent { success = system command }
  end
  raise RaysException.new("Failed to execute: #{command}") unless success
  success
end

#rays_safe_exec(command, *args) ⇒ Object

Safe execute. Use it for user input commands.



96
97
98
# File 'lib/rays/utils/common_utils.rb', line 96

def rays_safe_exec(command, *args)
  SafeShell.execute(command, *args)
end

#service_safe(stop = true) ⇒ Object

Execute a given command while liferay service is stopped.



116
117
118
119
120
121
122
123
124
125
# File 'lib/rays/utils/common_utils.rb', line 116

def service_safe(stop = true)
  environment = $rays_config.environment
  if stop and environment.liferay.service.alive?
    environment.liferay.service.stop
    yield
    environment.liferay.service.start
  else
    yield
  end
end

#silentObject

Block console output for a given block.



66
67
68
69
70
71
72
73
74
# File 'lib/rays/utils/common_utils.rb', line 66

def silent
  begin
    orig_stdout = $stdout.dup # does a dup2() internally
    $stdout.reopen('/dev/null', 'w')
    yield
  ensure
    $stdout.reopen(orig_stdout)
  end
end

#task(start_message, done_message, failed_message) ⇒ Object

Wrap a given block with progress information.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rays/utils/common_utils.rb', line 51

def task(start_message, done_message, failed_message)
  begin
    $log.info("<!#{start_message}!>")
    yield
    $log.info(done_message)
  rescue => e
    $log.error("#{failed_message}\nreason: #{e.message}")
    $log.debug("#{e}.:\tBacktrace:\r\n#{e.backtrace.join("\r\n")}")
    raise e
  end
end