Class: Reenrb::Reen

Inherits:
Object
  • Object
show all
Defined in:
lib/reenrb/reen.rb

Overview

Renames pattern of files with given editor Examples:

Reenrb::Reen.new(editor: "code -w").call("spec/fixtures/example/*")
Reenrb::Reen.new(editor: nil).call("spec/fixtures/example/*") { ... }

Constant Summary collapse

DEL_ERROR =
"Do not remove any file/folder names (no changes made)"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(editor: "emacs", options: {}) ⇒ Reen

Returns a new instance of Reen.



13
14
15
16
# File 'lib/reenrb/reen.rb', line 13

def initialize(editor: "emacs", options: {})
  @editor = editor
  @options = options
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



11
12
13
# File 'lib/reenrb/reen.rb', line 11

def changes
  @changes
end

Instance Method Details

#execute(original_list, &block) ⇒ Object



27
28
29
30
# File 'lib/reenrb/reen.rb', line 27

def execute(original_list, &block)
  @changes ||= request(original_list, &block)
  @changes = @changes.execute_all
end

#request(original_list, &block) ⇒ Object

Raises:



18
19
20
21
22
23
24
25
# File 'lib/reenrb/reen.rb', line 18

def request(original_list, &block)
  changed_list = ChangesFile.new(original_list).allow_changes(@editor, &block)

  raise(Error, DEL_ERROR) if changed_list.size != original_list.size

  @changes = compare_lists(original_list, changed_list)
             .then { |change_array| Changes.new(change_array) }
end