Class: Greenhouse::Resources::IgnoreFile::IgnoredFiles
- Inherits:
-
Array
- Object
- Array
- Greenhouse::Resources::IgnoreFile::IgnoredFiles
- Defined in:
- lib/greenhouse/resources/ignore_file.rb
Instance Method Summary collapse
- #<<(file) ⇒ Object
- #[]=(index, file) ⇒ Object
- #delete(filename) ⇒ Object
- #delete_at(index) ⇒ Object
- #delete_if(&block) ⇒ Object
-
#initialize(ignore_file) ⇒ IgnoredFiles
constructor
A new instance of IgnoredFiles.
- #keep_if(&block) ⇒ Object
- #push(file) ⇒ Object
- #unshift(file) ⇒ Object
Constructor Details
#initialize(ignore_file) ⇒ IgnoredFiles
Returns a new instance of IgnoredFiles.
59 60 61 62 |
# File 'lib/greenhouse/resources/ignore_file.rb', line 59 def initialize(ignore_file) @ignore_file = ignore_file super() end |
Instance Method Details
#<<(file) ⇒ Object
24 25 26 |
# File 'lib/greenhouse/resources/ignore_file.rb', line 24 def <<(file) push(file) end |
#[]=(index, file) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/greenhouse/resources/ignore_file.rb', line 28 def []=(index,file) delete_at index if index < length file = IgnoredFile.new(file, @ignore_file.lines.length) if !file.is_a?(IgnoredFile) super(index,file) @ignore_file.lines[file.line] = file.to_s end |
#delete(filename) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/greenhouse/resources/ignore_file.rb', line 35 def delete(filename) # TODO delete any comments immediately preceding the filename deleted = super(select { |f| f.file == filename}.first) @ignore_file.ignored.each do |ignored| next if ignored.line <= deleted.line ignored.line -= 1 end line = @ignore_file.lines.slice!(deleted.line,1) deleted end |
#delete_at(index) ⇒ Object
46 47 48 |
# File 'lib/greenhouse/resources/ignore_file.rb', line 46 def delete_at(index) delete self[index].file end |
#delete_if(&block) ⇒ Object
50 51 52 |
# File 'lib/greenhouse/resources/ignore_file.rb', line 50 def delete_if(&block) select(&block).map { |ignored| delete ignored.file } end |
#keep_if(&block) ⇒ Object
54 55 56 57 |
# File 'lib/greenhouse/resources/ignore_file.rb', line 54 def keep_if(&block) kept = select(&block) clone.select { |ignored| !kept.map(&:file).include?(ignored.file) }.map { |ignored| delete ignored.file } end |
#push(file) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/greenhouse/resources/ignore_file.rb', line 16 def push(file) if !file.is_a?(IgnoredFile) file = IgnoredFile.new(file, @ignore_file.lines.length) end super(file) @ignore_file.lines[file.line] = file.to_s end |
#unshift(file) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/greenhouse/resources/ignore_file.rb', line 8 def unshift(file) if !file.is_a?(IgnoredFile) file = IgnoredFile.new(file, @ignore_file.lines.length) end super(file) @ignore_file.lines[file.line] = file.to_s end |