Class: Editors
- Inherits:
-
Object
- Object
- Editors
- Includes:
- Helpers::EditorSyntax, Helpers::PlatformDetection
- Defined in:
- lib/editor.rb,
lib/editors/version.rb,
lib/editors/helpers/editor_syntax.rb,
lib/editors/helpers/platform_detection.rb
Overview
Editor class. Lets you edit both real and temporary files, and returns their values after editing.
Defined Under Namespace
Modules: Helpers
Constant Summary collapse
- MAJOR =
0- MINOR =
0- PATCH =
1- VERSION =
[MAJOR, MINOR, PATCH].join('.')
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Class Method Summary collapse
-
.file(file, line = 1, blocking = true) ⇒ String
Edit a file from the filesystem, and return its value.
-
.temp(initial_content, line = 1) ⇒ String
Edits a temporary file, and return its value.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Editor
constructor
Initialize a new editor, with options.
Methods included from Helpers::EditorSyntax
#blocking_flag_for_editor, #editor_name, #start_line_syntax_for_editor
Methods included from Helpers::PlatformDetection
#jruby?, #jruby_19?, #mri?, #mri_19?, #mri_20?, #mri_21?, #mri_2?, #rbx?, #windows?, #windows_ansi?
Constructor Details
#initialize(options = {}) ⇒ Editor
Initialize a new editor, with options. You should probably use Editor.edit or Editor.new instead of these You must pass a file OR temp string, but NOT both
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/editor.rb', line 24 def initialize( = {}) opts = { file: nil, temp: nil, line: 1, blocking: true }.merge() if !opts_is_valid?opts fail ArgumentError, 'define file OR temp' elsif opts[:file] edit_file(opts) elsif opts[:temp] edit_temp(opts) end end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
13 14 15 |
# File 'lib/editor.rb', line 13 def content @content end |
Class Method Details
.file(file, line = 1, blocking = true) ⇒ String
Edit a file from the filesystem, and return its value
42 43 44 |
# File 'lib/editor.rb', line 42 def file(file, line = 1, blocking = true) new(file: file, line: line, blocking: blocking).content end |
.temp(initial_content, line = 1) ⇒ String
Edits a temporary file, and return its value
51 52 53 |
# File 'lib/editor.rb', line 51 def temp(initial_content, line = 1) new(temp: initial_content, line: line, blocking: true).content end |