Class: GhettoNotes::Installer
- Inherits:
-
Object
- Object
- GhettoNotes::Installer
- Defined in:
- lib/ghetto_notes/installer.rb
Instance Attribute Summary collapse
-
#crontab ⇒ Object
readonly
Returns the value of attribute crontab.
-
#sync_dir ⇒ Object
readonly
Returns the value of attribute sync_dir.
Instance Method Summary collapse
-
#initialize(sync_dir, crontab: Crontab.new) ⇒ Installer
constructor
A new instance of Installer.
- #perform ⇒ Object
Constructor Details
#initialize(sync_dir, crontab: Crontab.new) ⇒ Installer
7 8 9 10 |
# File 'lib/ghetto_notes/installer.rb', line 7 def initialize(sync_dir, crontab: Crontab.new) @sync_dir = sync_dir @crontab = crontab end |
Instance Attribute Details
#crontab ⇒ Object (readonly)
Returns the value of attribute crontab.
5 6 7 |
# File 'lib/ghetto_notes/installer.rb', line 5 def crontab @crontab end |
#sync_dir ⇒ Object (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
#perform ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ghetto_notes/installer.rb', line 12 def perform cmd = "#{GhettoNotes.bin_file} sync #{sync_dir}" crontab_entry = "*/2 * * * * #{cmd}" existing_tab = crontab.current.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.set_from(new_crontab.path) end |