Class: Rmate::Command

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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Command

Returns a new instance of Command.



78
79
80
81
82
83
# File 'lib/rmate.rb', line 78

def initialize(name)
  @command   = name
  @variables = {}
  @data      = nil
  @size      = nil
end

Instance Method Details

#[]=(name, value) ⇒ Object



85
86
87
# File 'lib/rmate.rb', line 85

def []=(name, value)
  @variables[name] = value
end

#read_file(path) ⇒ Object



89
90
91
92
# File 'lib/rmate.rb', line 89

def read_file(path)
  @size = File.size(path)
  @data = File.open(path, "rb") { |io| io.read(@size) }
end

#read_stdinObject



94
95
96
97
# File 'lib/rmate.rb', line 94

def read_stdin
  @data = $stdin.read
  @size = @data.bytesize
end

#send(socket) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/rmate.rb', line 99

def send(socket)
  socket.puts @command
  @variables.each_pair do |name, value|
    value = 'yes' if value === true
    socket.puts "#{name}: #{value}"
  end
  if @data
    socket.puts "data: #{@size}"
    socket.puts @data
  end
  socket.puts
end