Class: GhettoNotes::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/ghetto_notes/installer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sync_dir) ⇒ Installer

Returns a new instance of Installer.



7
8
9
# File 'lib/ghetto_notes/installer.rb', line 7

def initialize(sync_dir)
  @sync_dir = sync_dir
end

Instance Attribute Details

#sync_dirObject (readonly)

Returns the value of attribute sync_dir.



5
6
7
# File 'lib/ghetto_notes/installer.rb', line 5

def sync_dir
  @sync_dir
end

Instance Method Details

#performObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ghetto_notes/installer.rb', line 11

def perform
  cmd = "#{GhettoNotes.bin_file} sync #{sync_dir}"
  crontab_entry = "*/2 * * * * #{cmd}"
  existing_tab = `crontab -l`.split("\n")

  if existing_tab.include?(crontab_entry)
    $stderr.puts 'Already installed'
    return
  end

  new_crontab = Tempfile.new
  new_crontab << existing_tab.join("\n")
  new_crontab << "\n"
  new_crontab << crontab_entry
  new_crontab << "\n"
  new_crontab.close

  `crontab #{new_crontab.path}`
end