Class: LintFu::SourceControlProvider
- Inherits:
-
Object
- Object
- LintFu::SourceControlProvider
- Defined in:
- lib/lint_fu/source_control_provider.rb
Direct Known Subclasses
Constant Summary collapse
- @@subclasses =
Set.new
Class Method Summary collapse
-
.for_directory(path) ⇒ Object
Instantiate the appropriate Provider subclass for a given directory.
-
.inherited(base) ⇒ Object
Inherited callback to ensure this base class knows about all derived classes.
Instance Method Summary collapse
- #excerpt(file, range, options = {}) ⇒ Object
-
#initialize(path) ⇒ SourceControlProvider
constructor
A new instance of SourceControlProvider.
Constructor Details
#initialize(path) ⇒ SourceControlProvider
Returns a new instance of SourceControlProvider.
41 42 43 |
# File 'lib/lint_fu/source_control_provider.rb', line 41 def initialize(path) @root = path end |
Class Method Details
.for_directory(path) ⇒ Object
Instantiate the appropriate Provider subclass for a given directory.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lint_fu/source_control_provider.rb', line 29 def self.for_directory(path) @@subclasses.each do |provider| begin return provider.new(path) rescue Exception => e next end end return nil end |
.inherited(base) ⇒ Object
Inherited callback to ensure this base class knows about all derived classes.
24 25 26 |
# File 'lib/lint_fu/source_control_provider.rb', line 24 def self.inherited(base) @@subclasses << base end |
Instance Method Details
#excerpt(file, range, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lint_fu/source_control_provider.rb', line 45 def excerpt(file, range, ={}) blame = .has_key?(:blame) ? [:blame] : true raise ProviderError, "Blame is not supported for this source control provider" if blame Dir.chdir(@root) do start_line = range.first end_line = range.last io = File.open(File.relative_path(@root, file), 'r') lines = io.readlines return lines[(start_line-1)..(end_line-1)] end end |