Class: Flashtoggle::Toggler

Inherits:
Object
  • Object
show all
Defined in:
lib/flashtoggle/toggler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugins_dir, backup_dir) ⇒ Toggler

Returns a new instance of Toggler.



6
7
8
9
# File 'lib/flashtoggle/toggler.rb', line 6

def initialize(plugins_dir, backup_dir)
  self.plugins_dir = plugins_dir
  self.backup_dir = backup_dir
end

Instance Attribute Details

#backup_dirObject

Returns the value of attribute backup_dir.



4
5
6
# File 'lib/flashtoggle/toggler.rb', line 4

def backup_dir
  @backup_dir
end

#errorObject

Returns the value of attribute error.



4
5
6
# File 'lib/flashtoggle/toggler.rb', line 4

def error
  @error
end

#plugins_dirObject

Returns the value of attribute plugins_dir.



4
5
6
# File 'lib/flashtoggle/toggler.rb', line 4

def plugins_dir
  @plugins_dir
end

Instance Method Details

#disable_flash!Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/flashtoggle/toggler.rb', line 36

def disable_flash!
  return if flash_off?
  begin
    FileUtils.mkdir_p self.backup_dir
    Flashtoggle::FLASH_PLUGIN_FILES.each do |file|
      FileUtils.mv "#{self.plugins_dir}/#{file}", "#{self.backup_dir}/#{file}"
    end
  rescue Errno::EACCES => e
    self.error = "You must run this script by using -  sudo flashtoggle [options]"
  rescue Errno::ENOENT => e
    self.error = "That folder can't be found"
  end
end

#enable_flash!Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/flashtoggle/toggler.rb', line 23

def enable_flash!
  return if flash_on?
  begin
    Flashtoggle::FLASH_PLUGIN_FILES.each do |file|
      FileUtils.mv "#{self.backup_dir}/#{file}", "#{self.plugins_dir}/#{file}"
    end
  rescue Errno::EACCES => e
    self.error = "You must run this script by using -  sudo flashtoggle [options]"
  rescue Errno::ENOENT => e
    self.error = "That folder can't be found"
  end
end

#flash_off?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/flashtoggle/toggler.rb', line 54

def flash_off?
  File.exists?("#{self.backup_dir}/#{ Flashtoggle::FLASH_PLUGIN_FILES[0]}")
end

#flash_on?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/flashtoggle/toggler.rb', line 50

def flash_on?
  File.exists?("#{self.plugins_dir}/#{Flashtoggle::FLASH_PLUGIN_FILES[0]}")
end

#statusObject



19
20
21
# File 'lib/flashtoggle/toggler.rb', line 19

def status
  self.flash_on? ? "Flash is currently enabled" : "Flash is currently disabled"
end

#toggle!Object



11
12
13
14
15
16
17
# File 'lib/flashtoggle/toggler.rb', line 11

def toggle!
  if self.flash_off?
    self.enable_flash!
  else
    self.disable_flash!
  end
end