Class: Ruku::SimpleStorage

Inherits:
Storage
  • Object
show all
Defined in:
lib/ruku/storage.rb

Overview

Stores Roku box information on disk in a plain text file, one box per line, in the format:

HOSTNAME:BOX_NAME

HOSTNAME is the hostname or IP address of a Roku box. This is the only required portion of the box configuration line. You may also include an optional, more readable box name.

Examples of valid box config lines include:

192.168.1.7 192.168.1.8:Living Room NP-20F8A0003472:Bedroom

Constant Summary

Constants inherited from Storage

Ruku::Storage::FILE_NAME

Instance Attribute Summary

Attributes inherited from Storage

#storage_path

Instance Method Summary collapse

Methods inherited from Storage

#initialize

Constructor Details

This class inherits a constructor from Ruku::Storage

Instance Method Details

#loadObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ruku/storage.rb', line 46

def load
  if File.exist? @storage_path
    remotes = Remotes.new
    IO.read(@storage_path).split("\n").each do |line|
      host, name = line.split(':')
      remotes.boxes << Remote.new(host, name)
    end
    remotes
  else
    Remotes.new
  end
end

#store(remotes) ⇒ Object



40
41
42
43
44
# File 'lib/ruku/storage.rb', line 40

def store(remotes)
  File.open(@storage_path, 'w') do |f|
    remotes.each {|r| f.puts "#{r.host}#{r.name ? ':'+r.name : ''}" }
  end
end