Class: Cane::FileLine
- Inherits:
-
Tailor::FileLine
- Object
- Tailor::FileLine
- Cane::FileLine
- Defined in:
- lib/cane/style_check.rb
Overview
The ‘tailor` gem was not designed to be used as a library, so interfacing with it is a bit of a mess. This wrapper is attempt to confine that mess to a single point in the code.
Instance Attribute Summary collapse
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #find_problems ⇒ Object
-
#initialize(source_line, opts) ⇒ FileLine
constructor
A new instance of FileLine.
- #line_length_max ⇒ Object
- #print_problem(message) ⇒ Object
- #problems ⇒ Object
- #spacing_conditions ⇒ Object
-
#spacing_problems ⇒ Object
A copy of the parent method that only uses a small subset of the spacing checks we actually want (the others are too buggy or controversial).
-
#too_long? ⇒ Boolean
Copy of parent method using a configurable line length.
Constructor Details
#initialize(source_line, opts) ⇒ FileLine
Returns a new instance of FileLine.
41 42 43 44 45 |
# File 'lib/cane/style_check.rb', line 41 def initialize(source_line, opts) self.opts = opts super(source_line, nil, nil) end |
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
39 40 41 |
# File 'lib/cane/style_check.rb', line 39 def opts @opts end |
Instance Method Details
#find_problems ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/cane/style_check.rb', line 47 def find_problems # This is weird. These methods actually have side-effects! We capture # the effects my monkey-patching #print_problem below. spacing_problems method_line? && camel_case_method? class_line? && snake_case_class? too_long? end |
#line_length_max ⇒ Object
93 94 95 |
# File 'lib/cane/style_check.rb', line 93 def line_length_max opts.fetch(:measure) end |
#print_problem(message) ⇒ Object
56 57 58 |
# File 'lib/cane/style_check.rb', line 56 def print_problem() @problems << .gsub(/\[.+\]\s+/, '') end |
#problems ⇒ Object
60 61 62 63 64 |
# File 'lib/cane/style_check.rb', line 60 def problems @problems = [] find_problems @problems end |
#spacing_conditions ⇒ Object
76 77 78 79 80 |
# File 'lib/cane/style_check.rb', line 76 def spacing_conditions SPACING_CONDITIONS.select {|k, _| [:hard_tabbed, :trailing_whitespace].include?(k) } end |
#spacing_problems ⇒ Object
A copy of the parent method that only uses a small subset of the spacing checks we actually want (the others are too buggy or controversial).
68 69 70 71 72 73 74 |
# File 'lib/cane/style_check.rb', line 68 def spacing_problems spacing_conditions.each_pair do |condition, values| unless self.scan(values.first).empty? print_problem values[1] end end end |
#too_long? ⇒ Boolean
Copy of parent method using a configurable line length.
83 84 85 86 87 88 89 90 91 |
# File 'lib/cane/style_check.rb', line 83 def too_long? length = self.chomp.length if length > line_length_max print_problem "Line is >#{line_length_max} characters (#{length})" return true end false end |