Class: Sprout::User

Inherits:
Object
  • Object
show all
Defined in:
lib/sprout/user.rb

Overview

The User class provides a single and consistent interface to User based paths and features so that Sprout implementation code doesn’t need to be concerned with which Operating system it is running on.

Constant Summary collapse

@@user =
nil

Class Method Summary collapse

Class Method Details

.application_home(name) ⇒ Object

Returns the home path for a named application based on the currently logged in user and operating system. If the user name is lbayes and the application name is Sprouts, this path will be:

Windows XP

C:Documents And SettingslbayesLocal SettingsApplication DataSprouts

Cygwin

/cygdrive/c/Documents And Settings/Local Settings/Application Data/Sprouts

OS X

/Users/lbayes/Library/Sprouts

Linux

~/.sprouts



83
84
85
# File 'lib/sprout/user.rb', line 83

def User.application_home(name)
  return User.new().application_home(name)
end

.clean_path(path) ⇒ Object

Clean a path string in such a way that works for each platform. For example, Windows doesn’t like it when we backslash to escape spaces in a path because that is the character they use as a delimiter. And OS X doesn’t really like it when we wrap paths in quotes.



120
121
122
# File 'lib/sprout/user.rb', line 120

def User.clean_path(path)
  return User.new().clean_path(path)
end

.execute(tool, options = '') ⇒ Object

Execute a named tool sprout. The full sprout name should be provided to the tool parameter, and a string of shell parameters that will be sent to the tool itself.



100
101
102
# File 'lib/sprout/user.rb', line 100

def User.execute(tool, options='')
  return User.new().execute(tool, options)
end

.execute_silent(tool, options = '') ⇒ Object



104
105
106
# File 'lib/sprout/user.rb', line 104

def User.execute_silent(tool, options='')
  return User.new().execute_silent(tool, options)
end

.execute_thread(tool, options = '') ⇒ Object

Execute a named tool sprout as a new thread and return that thread



109
110
111
112
113
114
115
# File 'lib/sprout/user.rb', line 109

def User.execute_thread(tool, options='')
  if(Log.debug)
     return ThreadMock.new
  else
     return User.new().execute_thread(tool, options)
  end
end

.get_exe_path(executable) ⇒ Object

Retrieve the full path to an executable that exists in the user path



62
63
64
# File 'lib/sprout/user.rb', line 62

def User.get_exe_path(executable)
  return User.new().get_exe_path(executable)
end

.homeObject

Return the home path for the currently logged in user. If the user name is lbayes, this should be:

Windows XP

C:Documents And Settingslbayes

Cygwin

/cygdrive/c/Documents And Settings/lbayes

OS X

/Users/lbayes

Linux

~/



72
73
74
# File 'lib/sprout/user.rb', line 72

def User.home
  User.new().home
end

.home=(path) ⇒ Object

:nodoc:



47
48
49
# File 'lib/sprout/user.rb', line 47

def User.home=(path) # :nodoc:
  User.new().home = path
end

.in_path?(executable) ⇒ Boolean

Pass an executable or binary file name and find out if that file exists in the system path or not

Returns:

  • (Boolean)


57
58
59
# File 'lib/sprout/user.rb', line 57

def User.in_path?(executable)
  User.new().in_path?(executable)
end

.is_a?(type) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/sprout/user.rb', line 51

def User.is_a?(type)
  User.new().is_a?(type)
end

.libraryObject

Returns the library path on the current system. This is the general path where all applications should store configuration or session data.

Windows XP

C:Documents And SettingslbayesLocal SettingsApplication Data

Cygwin

/cygdrive/c/Documents And Settings/lbayes/Local Settings/Application Data

OS X

/Users/lbayes/Library

Linux

~/



94
95
96
# File 'lib/sprout/user.rb', line 94

def User.library
  return User.new().library
end

.new(os = nil, impl = nil) ⇒ Object

Retrieve a user instance that represents the currently logged in user on this system.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sprout/user.rb', line 18

def User.new(os=nil, impl=nil)
    if(os.nil? && impl.nil? && @@user)
      return @@user
    end
    if(os.nil?)
      os = Platform::OS
    end
    if(impl.nil?)
      impl = Platform::IMPL
    end
    if(os == :win32 && impl == :vista)
      @@user = VistaUser.new
    elsif(os == :win32 && impl == :cygwin)
      @@user = CygwinUser.new
    elsif(os == :win32)
      @@user = WinUser.new
    elsif(os == :unix && impl == :macosx)
      @@user = OSXUser.new
#        elsif(os == :unix && impl == :linux)
#          @@user = UnixUser.new
    else
      @@user = UnixUser.new
    end
end

.user=(user) ⇒ Object

:nodoc:



43
44
45
# File 'lib/sprout/user.rb', line 43

def User.user=(user) # :nodoc:
  @@user = user
end