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.
74 75 76 77 78 79 |
# File 'lib/rmate.rb', line 74 def initialize(name) @command = name @variables = {} @data = nil @size = nil end |
Instance Method Details
#[]=(name, value) ⇒ Object
81 82 83 |
# File 'lib/rmate.rb', line 81 def []=(name, value) @variables[name] = value end |
#read_file(path) ⇒ Object
85 86 87 88 |
# File 'lib/rmate.rb', line 85 def read_file(path) @size = File.size(path) @data = File.open(path, "rb") { |io| io.read(@size) } end |
#read_stdin ⇒ Object
90 91 92 93 |
# File 'lib/rmate.rb', line 90 def read_stdin @data = $stdin.read @size = @data.size end |
#send(socket) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rmate.rb', line 95 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 |