Class: CheckPlease::Diffs
- Inherits:
-
Object
- Object
- CheckPlease::Diffs
- Extended by:
- Forwardable
- Defined in:
- lib/check_please/diffs.rb
Overview
Custom collection class for Diff instances. Can retrieve members using indexes or paths.
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
Instance Method Summary collapse
- #<<(diff) ⇒ Object
-
#[](key) ⇒ Object
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).
- #data ⇒ Object
- #filter_by_flags(flags) ⇒ Object
- #formats ⇒ Object
-
#initialize(diff_list = nil, flags: {}) ⇒ Diffs
constructor
A new instance of Diffs.
- #method_missing(meth, *args, &blk) ⇒ Object
- #to_s(flags = {}) ⇒ Object
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
58 59 60 61 62 63 64 |
# 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 |
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
8 9 10 |
# File 'lib/check_please/diffs.rb', line 8 def flags @flags end |
Instance Method Details
#<<(diff) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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) ⇒ Object
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.)
23 24 25 26 27 28 29 |
# File 'lib/check_please/diffs.rb', line 23 def [](key) if key.is_a?(Integer) @list[key] else @hash.fetch(key) end end |
#data ⇒ Object
45 46 47 |
# File 'lib/check_please/diffs.rb', line 45 def data @list.map(&:attributes) end |
#filter_by_flags(flags) ⇒ Object
49 50 51 52 |
# 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 ⇒ Object
66 67 68 |
# File 'lib/check_please/diffs.rb', line 66 def formats CheckPlease::Printers::FORMATS end |
#to_s(flags = {}) ⇒ Object
54 55 56 |
# File 'lib/check_please/diffs.rb', line 54 def to_s(flags = {}) CheckPlease::Printers.render(self, flags) end |