Class: Rmate::Settings

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSettings

Returns a new instance of Settings.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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

Instance Attribute Details

#forceObject

Returns the value of attribute force.



19
20
21
# File 'lib/rmate.rb', line 19

def force
  @force
end

#hostObject

Returns the value of attribute host.



19
20
21
# File 'lib/rmate.rb', line 19

def host
  @host
end

#linesObject

Returns the value of attribute lines.



19
20
21
# File 'lib/rmate.rb', line 19

def lines
  @lines
end

#namesObject

Returns the value of attribute names.



19
20
21
# File 'lib/rmate.rb', line 19

def names
  @names
end

#portObject

Returns the value of attribute port.



19
20
21
# File 'lib/rmate.rb', line 19

def port
  @port
end

#typesObject

Returns the value of attribute types.



19
20
21
# File 'lib/rmate.rb', line 19

def types
  @types
end

#unixsocketObject

Returns the value of attribute unixsocket.



19
20
21
# File 'lib/rmate.rb', line 19

def unixsocket
  @unixsocket
end

#verboseObject

Returns the value of attribute verbose.



19
20
21
# File 'lib/rmate.rb', line 19

def verbose
  @verbose
end

#waitObject

Returns the value of attribute wait.



19
20
21
# File 'lib/rmate.rb', line 19

def wait
  @wait
end

Instance Method Details

#parse_cli_optionsObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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_connectionObject



72
73
74
# File 'lib/rmate.rb', line 72

def parse_ssh_connection
  ENV['SSH_CONNECTION'].nil? ? 'localhost' : ENV['SSH_CONNECTION'].split(' ').first
end

#read_disk_settingsObject



42
43
44
45
46
47
48
49
50
51
52
# 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