Class: CopyPaste

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

Constant Summary collapse

VERSION =
"0.9.1"
CONFIGURATION =
"#{ENV['HOME']}/.copypaste"

Class Method Summary collapse

Class Method Details

.copy(queue, io) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/copypaste.rb', line 13

def copy(queue, io)
  queue ||= "default"
  server
  data = io.read
  server.set("copypaste-#{queue}", data)
  data
end

.paste(queue) ⇒ Object



21
22
23
24
# File 'lib/copypaste.rb', line 21

def paste(queue)
  queue ||= "default"
  server.get("copypaste-#{queue}")
end

.serverObject



46
47
48
49
50
51
52
53
# File 'lib/copypaste.rb', line 46

def server
  if RConfig.config == {}
    puts "Please run #{$0} --setup"
    exit -1
  else
    @@server = Starling.new(RConfig.config.server)
  end
end

.setup(value) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/copypaste.rb', line 26

def setup(value)
  if value.to_s.empty?
    print "What is your starling server address (127.0.0.1:22122): "
    $stdout.flush
    server = gets.strip
  else
    server = value
  end
  
  if server.empty?
    server = "127.0.0.1:22122"
  end
  if !server.include?(":")
    server = "#{server}:22122"
  end
  
  File.open("#{CONFIGURATION}/config.yml", "w"){|f| f << {"server" => server}.to_yaml }
  puts "\nSaved to #{CONFIGURATION}/config.yml"
end