Class: Desktop::OSX

Inherits:
Object
  • Object
show all
Defined in:
lib/desktop/osx/osx.rb,
lib/desktop/osx/database.rb

Defined Under Namespace

Classes: Database, DesktopImageMissingError, DesktopImagePermissionsError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(desktop_image_path = nil, skip_reload = false) ⇒ OSX

Returns a new instance of OSX.



25
26
27
28
# File 'lib/desktop/osx/osx.rb', line 25

def initialize(desktop_image_path = nil, skip_reload = false)
  @skip_reload = skip_reload
  @desktop_image_path = desktop_image_path || default_desktop_image_path
end

Instance Attribute Details

#desktop_image_pathObject (readonly)

Returns the value of attribute desktop_image_path.



5
6
7
# File 'lib/desktop/osx/osx.rb', line 5

def desktop_image_path
  @desktop_image_path
end

#skip_reloadObject (readonly)

Returns the value of attribute skip_reload.



5
6
7
# File 'lib/desktop/osx/osx.rb', line 5

def skip_reload
  @skip_reload
end

Class Method Details

.chmod_commandObject



21
22
23
# File 'lib/desktop/osx/osx.rb', line 21

def self.chmod_command
  self.new.chmod_command
end

.chown_commandObject



17
18
19
# File 'lib/desktop/osx/osx.rb', line 17

def self.chown_command
  self.new.chown_command
end

.desktop_image=(image) ⇒ Object



9
10
11
# File 'lib/desktop/osx/osx.rb', line 9

def self.desktop_image=(image)
  self.new.desktop_image = image
end

.update_desktop_image_permissionsObject



13
14
15
# File 'lib/desktop/osx/osx.rb', line 13

def self.update_desktop_image_permissions
  self.new.update_desktop_image_permissions
end

Instance Method Details

#chmod_commandObject



48
49
50
# File 'lib/desktop/osx/osx.rb', line 48

def chmod_command
  "sudo chmod 664 #{desktop_image_path}"
end

#chown_commandObject



44
45
46
# File 'lib/desktop/osx/osx.rb', line 44

def chown_command
  "sudo chown root:staff #{desktop_image_path}"
end

#desktop_image=(image) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/desktop/osx/osx.rb', line 30

def desktop_image=(image)
  write_default_desktop image
  clear_custom_desktop_image
  reload_desktop unless skip_reload
rescue Errno::EACCES => e
  raise DesktopImagePermissionsError.new(e)
rescue Errno::ENOENT => e
  raise DesktopImageMissingError.new(e)
end

#update_desktop_image_permissionsObject



40
41
42
# File 'lib/desktop/osx/osx.rb', line 40

def update_desktop_image_permissions
  system(chown_command) && system(chmod_command)
end