Class: ActiveSupport::Editor
Class Method Summary collapse
-
.current ⇒ Object
Returns the current editor pattern if it is known.
-
.find(name) ⇒ Object
:nodoc:.
-
.register(name, url_pattern, aliases: []) ⇒ Object
Registers a URL pattern for opening file in a given editor.
- .reset ⇒ Object
Instance Method Summary collapse
-
#initialize(url_pattern) ⇒ Editor
constructor
A new instance of Editor.
- #url_for(path, line) ⇒ Object
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
.current ⇒ Object
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 |
.reset ⇒ Object
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 |