Class: ActiveSupport::Editor
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activesupport/lib/active_support/editor.rb |
Class Method Summary
-
.current
Returns the current editor pattern if it is known.
- .new(url_pattern) ⇒ Editor constructor
-
.register(name, url_pattern, aliases: [])
Registers a URL pattern for opening file in a given editor.
- .reset
- .find(name) Internal use only
Instance Method Summary
Constructor Details
.new(url_pattern) ⇒ Editor
# File 'activesupport/lib/active_support/editor.rb', line 48
def initialize(url_pattern) @url_pattern = url_pattern end
Class Method Details
.current
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.
# File 'activesupport/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)
This method is for internal use only.
[ GitHub ]
# File 'activesupport/lib/active_support/editor.rb', line 39
def find(name) @editors[name] end
.register(name, url_pattern, aliases: [])
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")
# File 'activesupport/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
[ GitHub ]# File 'activesupport/lib/active_support/editor.rb', line 43
def reset @current = false end
Instance Method Details
#url_for(path, line)
[ GitHub ]# File 'activesupport/lib/active_support/editor.rb', line 52
def url_for(path, line) sprintf(@url_pattern, path, line) end