class Pechkin::Command::SendData
Send data to channel and exit. Uses –preview flag to render message and flush it to STDOUT before sending
Public Instance Methods
execute()
click to toggle source
# File lib/pechkin/command/send_data.rb, line 10 def execute ch, msg = parse_endpoint(options.send_data) raise "#{ch}/#{msg} not found" unless handler.message?(ch, msg) data = read_data(options.data) if options.preview puts handler.preview(ch, msg, data) else handler.handle(ch, msg, data).each do |e| puts "* #{e.inspect}" end end end
matches?()
click to toggle source
# File lib/pechkin/command/send_data.rb, line 6 def matches? options.send_data end
Private Instance Methods
parse_endpoint(endpoint)
click to toggle source
# File lib/pechkin/command/send_data.rb, line 39 def parse_endpoint(endpoint) endpoint.match(%r{^([^/]+)/(.+)$}) do |m| [m[1], m[2]] end end
read_data(data)
click to toggle source
# File lib/pechkin/command/send_data.rb, line 28 def read_data(data) d = if data.start_with?('@') file = data[1..-1] raise "File not found #{file}" unless File.exist?(file) IO.read(file) else data end JSON.parse(d) end