class CheckPlease::Diffs
Custom collection class for Diff
instances. Can retrieve members using indexes or paths.
Attributes
flags[R]
Public Class Methods
new(diff_list = nil, flags: {})
click to toggle source
# File lib/check_please/diffs.rb, line 9 def initialize(diff_list = nil, flags: {}) @flags = Flags.reify(flags) @list = [] @hash = {} Array(diff_list).each do |diff| self << diff end end
Public Instance Methods
<<(diff)
click to toggle source
# File lib/check_please/diffs.rb, line 31 def <<(diff) if flags.fail_fast && length > 0 throw :max_diffs_reached end if (n = flags.max_diffs) # It seems no one can help me now / I'm in too deep, there's no way out throw :max_diffs_reached if length >= n end @list << diff @hash[diff.path] = diff end
[](key)
click to toggle source
this is probably a terrible idea, but this method:
-
treats integer keys as array-style positional indexes
-
treats string keys as path strings and does a hash-like lookup (raising if the path is not found)
(In my defense, I only did it to make the tests easier to write.)
# File lib/check_please/diffs.rb, line 23 def [](key) if key.is_a?(Integer) @list[key] else @hash.fetch(key) end end
data()
click to toggle source
# File lib/check_please/diffs.rb, line 45 def data @list.map(&:attributes) end
filter_by_flags(flags)
click to toggle source
# File lib/check_please/diffs.rb, line 49 def filter_by_flags(flags) new_list = @list.reject { |diff| Path.new(diff.path).excluded?(flags) } self.class.new(new_list, flags: flags) end
formats()
click to toggle source
# File lib/check_please/diffs.rb, line 66 def formats CheckPlease::Printers::FORMATS end
method_missing(meth, *args, &blk)
click to toggle source
Calls superclass method
# File lib/check_please/diffs.rb, line 58 def method_missing(meth, *args, &blk) if formats.include?(meth.to_sym) CheckPlease::Printers.render(self, format: meth) else super end end
to_s(flags = {})
click to toggle source
# File lib/check_please/diffs.rb, line 54 def to_s(flags = {}) CheckPlease::Printers.render(self, flags) end