Class: Rmate::Settings
- Inherits:
-
Object
- Object
- Rmate::Settings
- Defined in:
- lib/rmate.rb
Instance Attribute Summary collapse
-
#force ⇒ Object
Returns the value of attribute force.
-
#host ⇒ Object
Returns the value of attribute host.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#names ⇒ Object
Returns the value of attribute names.
-
#port ⇒ Object
Returns the value of attribute port.
-
#types ⇒ Object
Returns the value of attribute types.
-
#unixsocket ⇒ Object
Returns the value of attribute unixsocket.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#wait ⇒ Object
Returns the value of attribute wait.
Instance Method Summary collapse
-
#initialize ⇒ Settings
constructor
A new instance of Settings.
- #parse_cli_options ⇒ Object
- #parse_ssh_connection ⇒ Object
- #read_disk_settings ⇒ Object
Constructor Details
#initialize ⇒ Settings
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' @host = parse_ssh_connection if @host == 'auto' end |
Instance Attribute Details
#force ⇒ Object
Returns the value of attribute force.
19 20 21 |
# File 'lib/rmate.rb', line 19 def force @force end |
#host ⇒ Object
Returns the value of attribute host.
19 20 21 |
# File 'lib/rmate.rb', line 19 def host @host end |
#lines ⇒ Object
Returns the value of attribute lines.
19 20 21 |
# File 'lib/rmate.rb', line 19 def lines @lines end |
#names ⇒ Object
Returns the value of attribute names.
19 20 21 |
# File 'lib/rmate.rb', line 19 def names @names end |
#port ⇒ Object
Returns the value of attribute port.
19 20 21 |
# File 'lib/rmate.rb', line 19 def port @port end |
#types ⇒ Object
Returns the value of attribute types.
19 20 21 |
# File 'lib/rmate.rb', line 19 def types @types end |
#unixsocket ⇒ Object
Returns the value of attribute unixsocket.
19 20 21 |
# File 'lib/rmate.rb', line 19 def unixsocket @unixsocket end |
#verbose ⇒ Object
Returns the value of attribute verbose.
19 20 21 |
# File 'lib/rmate.rb', line 19 def verbose @verbose end |
#wait ⇒ Object
Returns the value of attribute wait.
19 20 21 |
# File 'lib/rmate.rb', line 19 def wait @wait end |
Instance Method Details
#parse_cli_options ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rmate.rb', line 54 def 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 ⇒ Object
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_settings ⇒ Object
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. 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 |