Class: PryTheme::BasicEditor

Inherits:
Object
  • Object
show all
Defined in:
lib/pry-theme/basic_editor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ BasicEditor

Returns a new instance of BasicEditor.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pry-theme/basic_editor.rb', line 15

def initialize(filename)
  @filename = filename
  theme_path = themify(filename)

  @editor = Pry.config.editor
  @new_theme = false
  @output = Pry.output
  @current_file = File.open(theme_path, 'r+')
rescue Errno::ENOENT
  @new_theme = true
  @current_file = File.open(theme_path, 'w')
end

Instance Attribute Details

#current_fileObject (readonly)

Returns the value of attribute current_file.



13
14
15
# File 'lib/pry-theme/basic_editor.rb', line 13

def current_file
  @current_file
end

#outputObject (readonly)

Returns the value of attribute output.



13
14
15
# File 'lib/pry-theme/basic_editor.rb', line 13

def output
  @output
end

Class Method Details

.edit(theme_name) ⇒ Object



7
8
9
10
# File 'lib/pry-theme/basic_editor.rb', line 7

def edit(theme_name)
  editor = new(theme_name)
  editor.start_editing
end

Instance Method Details

#start_editingObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pry-theme/basic_editor.rb', line 28

def start_editing
  if @new_theme
    @output.puts 'Created a new theme.'
    @current_file.puts template
    @current_file.close
  end
  @output.puts "Opened in #{ @editor }: #{ themify(@filename) }"

  reload_theme!
  output_dashy_header("Current \"#@filename\"")

  Pry::Editor.invoke_editor(@current_file.path, 1)

  reload_theme!
  output_dashy_header("Edited \"#@filename\"")
end