Class: Rmate::Command
- Inherits:
-
Object
- Object
- Rmate::Command
- Defined in:
- lib/rmate.rb
Instance Method Summary collapse
- #[]=(name, value) ⇒ Object
-
#initialize(name) ⇒ Command
constructor
A new instance of Command.
- #read_file(path) ⇒ Object
- #read_stdin ⇒ Object
- #send(socket) ⇒ Object
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_stdin ⇒ Object
94 95 96 97 |
# File 'lib/rmate.rb', line 94 def read_stdin @data = $stdin.read @size = @data.size 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 |