class Rmate::Settings
Attributes
force[RW]
host[RW]
lines[RW]
names[RW]
port[RW]
types[RW]
unixsocket[RW]
verbose[RW]
wait[RW]
Public Class Methods
new()
click to toggle source
# File lib/rmate.rb, line 21 def initialize @host, @port, @unixsocket = 'localhost', 52698, '~/.rmate.socket' @wait = false @force = false @verbose = false @lines = [] @names = [] @types = [] read_disk_settings @host = ENV['RMATE_HOST'].to_s if ENV.has_key? 'RMATE_HOST' @port = ENV['RMATE_PORT'].to_i if ENV.has_key? 'RMATE_PORT' @unixsocket = ENV['RMATE_UNIXSOCKET'].to_s if ENV.has_key? 'RMATE_UNIXSOCKET' parse_cli_options @host = parse_ssh_connection if @host == 'auto' end
Public Instance Methods
parse_cli_options()
click to toggle source
# File lib/rmate.rb, line 54 def parse_cli_options OptionParser.new do |o| o.on( '--host=name', "Connect to host.", "Use 'auto' to detect the host from SSH.", "Defaults to #{@host}.") { |v| @host = v } o.on('-s', '--unixsocket=name', "UNIX socket path.", "Takes precedence over host/port if the file exists", \ "Default #{@unixsocket}") { |v| @unixsocket = v } o.on('-p', '--port=#', Integer, "Port number to use for connection.", "Defaults to #{@port}.") { |v| @port = v } o.on('-w', '--[no-]wait', 'Wait for file to be closed by TextMate.') { |v| @wait = v } o.on('-l', '--line [NUMBER]', 'Place caret on line [NUMBER] after loading file.') { |v| @lines <<= v } o.on('-m', '--name [NAME]', 'The display name shown in TextMate.') { |v| @names <<= v } o.on('-t', '--type [TYPE]', 'Treat file as having [TYPE].') { |v| @types <<= v } o.on('-f', '--force', 'Open even if the file is not writable.') { |v| @force = v } o.on('-v', '--verbose', 'Verbose logging messages.') { |v| @verbose = v } o.on_tail('-h', '--help', 'Show this message.') { puts o; exit } o.on_tail( '--version', 'Show version.') { puts VERSION_STRING; exit } o.parse! end end
parse_ssh_connection()
click to toggle source
# File lib/rmate.rb, line 72 def parse_ssh_connection ENV['SSH_CONNECTION'].nil? ? 'localhost' : ENV['SSH_CONNECTION'].split(' ').first end
read_disk_settings()
click to toggle source
# File lib/rmate.rb, line 42 def read_disk_settings [ "/etc/rmate.rc", "/usr/local/etc/rmate.rc", "~/.rmate.rc"].each do |current_file| file = File.expand_path current_file if File.exist? file params = YAML::load(File.open(file)) @host = params["host"] unless params["host"].nil? @port = params["port"] unless params["port"].nil? @unixsocket = params["unixsocket"] unless params["unixsocket"].nil? end end end