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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ OSX

Returns a new instance of OSX.



24
25
26
27
28
29
30
31
32
# File 'lib/desktop/osx/osx.rb', line 24

def initialize(options = nil)
  options ||= {}
  @skip_reload = options[:skip_reload]
  @skip_database = options[:skip_database]
  @desktop_image_path = \
    options[:desktop_image_path] || default_desktop_image_path
  @cached_image_path = \
    options[:cached_image_path] || default_cached_image_path
end

Class Method Details

.chmod_commandObject



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

def self.chmod_command
  self.new.chmod_command
end

.chown_commandObject



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

def self.chown_command
  self.new.chown_command
end

.desktop_image=(image) ⇒ Object



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

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

.update_desktop_image_permissionsObject



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

def self.update_desktop_image_permissions
  self.new.update_desktop_image_permissions
end

Instance Method Details

#chmod_commandObject



56
57
58
59
60
# File 'lib/desktop/osx/osx.rb', line 56

def chmod_command
  [' -h ', ' '].map do |option|
    "sudo chmod#{option}664 #{desktop_image_path}"
  end.join(" && ")
end

#chown_commandObject



50
51
52
53
54
# File 'lib/desktop/osx/osx.rb', line 50

def chown_command
  [' -h ', ' '].map do |option|
    "sudo chown#{option}$('whoami'):staff #{desktop_image_path}"
  end.join(" && ")
end

#desktop_image=(image) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/desktop/osx/osx.rb', line 34

def desktop_image=(image)
  write_default_desktop image
  clear_custom_desktop_image unless skip_database
  touch_desktop_image
  remove_cached_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



46
47
48
# File 'lib/desktop/osx/osx.rb', line 46

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