Class: Isort::FileSorter
- Inherits:
-
Object
- Object
- Isort::FileSorter
- Defined in:
- lib/isort.rb
Overview
FileSorter provides the public API for sorting imports in a Ruby file
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
-
#check ⇒ Object
Check if file would change (dry-run).
-
#diff ⇒ Object
Get diff of changes without applying.
-
#initialize(file_path, options = {}) ⇒ FileSorter
constructor
A new instance of FileSorter.
-
#sort_and_format_imports ⇒ Object
Sort and format imports in the file Returns true if changes were made (or would be made in check mode).
-
#sort_imports ⇒ Object
deprecated
Deprecated.
Use sort_and_format_imports instead
Constructor Details
#initialize(file_path, options = {}) ⇒ FileSorter
Returns a new instance of FileSorter.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/isort.rb', line 41 def initialize(file_path, = {}) @file_path = file_path @options = { check: false, diff: false, atomic: false, quiet: false }.merge() @processor = FileProcessor.new(file_path, @options) end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
39 40 41 |
# File 'lib/isort.rb', line 39 def file_path @file_path end |
Instance Method Details
#check ⇒ Object
Check if file would change (dry-run)
66 67 68 |
# File 'lib/isort.rb', line 66 def check @processor.check end |
#diff ⇒ Object
Get diff of changes without applying
71 72 73 |
# File 'lib/isort.rb', line 71 def diff @processor.diff end |
#sort_and_format_imports ⇒ Object
Sort and format imports in the file Returns true if changes were made (or would be made in check mode)
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/isort.rb', line 54 def sort_and_format_imports @processor.process rescue Errno::ENOENT raise rescue ExistingSyntaxErrors, IntroducedSyntaxErrors, FileSkipped raise rescue StandardError => e puts "An error occurred: #{e.}" unless @options[:quiet] raise end |
#sort_imports ⇒ Object
Deprecated.
Use sort_and_format_imports instead
Legacy method for backward compatibility
77 78 79 |
# File 'lib/isort.rb', line 77 def sort_imports sort_and_format_imports end |