Module: Wooget::Util

Defined in:
lib/wooget/util/misc.rb

Class Method Summary collapse

Class Method Details

.authorObject



5
6
7
# File 'lib/wooget/util/misc.rb', line 5

def self.author
  `git config user.name || getent passwd $(id -un) | cut -d : -f 5 | cut -d , -f 1`.chomp
end

.file_contains?(filename, string) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/wooget/util/misc.rb', line 59

def self.file_contains? filename, string
  File.foreach(filename).grep(/#{Regexp.escape(string)}/).any?
end

.is_a_unity_project_dir(path) ⇒ Object



16
17
18
19
20
# File 'lib/wooget/util/misc.rb', line 16

def self.is_a_unity_project_dir path
  contents = Dir[File.join(path, "*")]
  contents.map! { |c| File.basename(c) }
  contents.include?("Assets") and contents.include?("ProjectSettings")
end

.is_a_wooget_package_dir(path) ⇒ Object



9
10
11
12
13
14
# File 'lib/wooget/util/misc.rb', line 9

def self.is_a_wooget_package_dir path
  contents = Dir[File.join(path, "*")]
  contents.map! { |c| File.basename(c) }

  contents.include?("paket.dependencies") and contents.include?("RELEASE_NOTES.md")
end

.run_cmd(cmd, path = Dir.pwd) ⇒ Object

runs a command in a separate process and working dir, takes a block which is yielded on every line of stdout returns [[stdout], exit_status]



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/wooget/util/misc.rb', line 25

def self.run_cmd cmd, path=Dir.pwd
  Wooget.log.debug "Running `#{cmd}` in path #{File.expand_path(path)}"

  cmd_output = []
  shutdown = -> {Wooget.log.error "Trying to shutdown child before pid recieved"}
  begin
    Signal.trap("INT") do
      shutdown.call()
    end

    PTY.spawn("cd #{path} && #{cmd}") do |stdout, stdin, pid|
      shutdown = -> {Process.kill(9, pid)}

      begin
        stdout.each do |line|
          cmd_output << line.uncolorize
          yield line if block_given?
        end
      rescue Errno::EIO
        #This means the process has finished giving output
      ensure
        Process.wait(pid)
      end
    end
  rescue PTY::ChildExited => e
    #Child process exited

  end


  exit_status = $?.exitstatus
  [cmd_output, exit_status]
end

.valid_version_string?(version) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/wooget/util/misc.rb', line 63

def self.valid_version_string? version
  !version.match(/(\d+\.\d+\.\d+)-?(\w*)/).nil?
end