Module: TurksatkabloCli::OnlineOperations::Helpers

Extended by:
Helpers
Included in:
Agent, Auth, Base, Helpers
Defined in:
lib/turksatkablo_cli/online_operations/helpers.rb

Instance Method Summary collapse

Instance Method Details

#add_lineObject



29
30
31
# File 'lib/turksatkablo_cli/online_operations/helpers.rb', line 29

def add_line
  puts "\n"
end

#agentObject



22
23
24
25
26
27
# File 'lib/turksatkablo_cli/online_operations/helpers.rb', line 22

def agent
  unless $agent
    $agent = TurksatkabloCli::OnlineOperations::Agent.new
  end
  $agent
end

#check_is_installed?(command, err_msg) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
# File 'lib/turksatkablo_cli/online_operations/helpers.rb', line 41

def check_is_installed?(command, err_msg)
  if which(command)
    true
  else
    abort(err_msg)
  end
end

#check_ruby_version(ruby_version = RUBY_VERSION) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/turksatkablo_cli/online_operations/helpers.rb', line 33

def check_ruby_version(ruby_version = RUBY_VERSION)
  if ruby_version < '2.2.0'
    abort "turksatkablo_cli requires Ruby 2.2.0 or higher"
  else
    ruby_version
  end
end

#internet_connection?(host = "8.8.8.8") ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
# File 'lib/turksatkablo_cli/online_operations/helpers.rb', line 8

def internet_connection?(host = "8.8.8.8")
  begin
    Net::Ping::External.new(host).ping?
  rescue
    nil
  end
end

#require_all(_dir) ⇒ Object



16
17
18
19
20
# File 'lib/turksatkablo_cli/online_operations/helpers.rb', line 16

def require_all(_dir)
  Dir[File.join(_dir, "**/*.rb")].each do |file|
    require file
  end
end

#which(command) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/turksatkablo_cli/online_operations/helpers.rb', line 49

def which(command)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each { |ext|
      exe = File.join(path, "#{command}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    }
  end
  return nil
end