class Rly::Shortcuts

shortcuts repository

Public Class Methods

new() click to toggle source
# File lib/rly/shortcuts.rb, line 6
def initialize
  @name = Dir.pwd.tr('/', '')
  @filename = %(/var/lib/rly/#{@name}.json)
  @shortcuts = read
end

Public Instance Methods

all() click to toggle source
# File lib/rly/shortcuts.rb, line 12
def all
  @shortcuts
end
create(name, url) click to toggle source
# File lib/rly/shortcuts.rb, line 24
def create(name, url)
  @shortcuts[name] = url
  save
end
destroy(name) click to toggle source
# File lib/rly/shortcuts.rb, line 29
def destroy(name)
  @shortcuts.delete(name)
  save
end
exist?(name) click to toggle source
# File lib/rly/shortcuts.rb, line 20
def exist?(name)
  @shortcuts.key?(name)
end
find(name) click to toggle source
# File lib/rly/shortcuts.rb, line 16
def find(name)
  @shortcuts[name]
end

Private Instance Methods

read() click to toggle source
# File lib/rly/shortcuts.rb, line 36
def read
  return {} unless File.file?(@filename)
  f = File.read(@filename)
  return {} if f == ""
  JSON.parse(f)
end
save() click to toggle source
# File lib/rly/shortcuts.rb, line 43
def save
  unless File.file?(@filename)

  end

  File.write(@filename, @shortcuts.to_json)
end