Class: ActiveSupport::Editor

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url_pattern) ⇒ Editor

Returns a new instance of Editor.



48
49
50
# File 'lib/active_support/editor.rb', line 48

def initialize(url_pattern)
  @url_pattern = url_pattern
end

Class Method Details

.currentObject

Returns the current editor pattern if it is known. First check for the ‘RAILS_EDITOR` environment variable, and if it’s missing, check for the ‘EDITOR` environment variable.



28
29
30
31
32
33
34
35
# File 'lib/active_support/editor.rb', line 28

def current
  if @current == false
    @current = if editor_name = ENV["RAILS_EDITOR"] || ENV["EDITOR"]
      @editors[editor_name]
    end
  end
  @current
end

.find(name) ⇒ Object

:nodoc:



39
40
41
# File 'lib/active_support/editor.rb', line 39

def find(name)
  @editors[name]
end

.register(name, url_pattern, aliases: []) ⇒ Object

Registers a URL pattern for opening file in a given editor. This allows Rails to generate clickable links to control known editors.

Example:

ActiveSupport::Editor.register("myeditor", "myeditor://%s:%d")


17
18
19
20
21
22
23
# File 'lib/active_support/editor.rb', line 17

def register(name, url_pattern, aliases: [])
  editor = new(url_pattern)
  @editors[name] = editor
  aliases.each do |a|
    @editors[a] = editor
  end
end

.resetObject



43
44
45
# File 'lib/active_support/editor.rb', line 43

def reset
  @current = false
end

Instance Method Details

#url_for(path, line) ⇒ Object



52
53
54
# File 'lib/active_support/editor.rb', line 52

def url_for(path, line)
  sprintf(@url_pattern, path, line)
end