class Inertia::Mass

Mass is a location where code lives. This represents a single location and encapsulates data relating to it.

Attributes

path[R]

Public Class Methods

new(path:) click to toggle source
# File lib/inertia/mass.rb, line 5
def initialize(path:)
  @path = path
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/inertia/mass.rb, line 68
def <=>(other)
  lines <=> other.lines
end
erb?() click to toggle source
# File lib/inertia/mass.rb, line 42
def erb?
  @erb ||= extension == '.erb'
end
extension() click to toggle source
# File lib/inertia/mass.rb, line 54
def extension
  @extension ||= File.extname(path)
end
haml?() click to toggle source
# File lib/inertia/mass.rb, line 34
def haml?
  @haml ||= extension == '.haml'
end
ignored?() click to toggle source
# File lib/inertia/mass.rb, line 76
def ignored?
  !text? ||
    scss? && Inertia.config.ignore_scss ||
    js? && Inertia.config.ignore_js ||
    jsx? && Inertia.config.ignore_jsx ||
    ts? && Inertia.config.ignore_ts ||
    tsx? && Inertia.config.ignore_tsx ||
    haml? && Inertia.config.ignore_haml ||
    rabl? && Inertia.config.ignore_rabl ||
    erb? && Inertia.config.ignore_erb ||
    ruby_spec? && Inertia.config.ignore_ruby_spec ||
    yml? && Inertia.config.ignore_yml
end
js?() click to toggle source
# File lib/inertia/mass.rb, line 18
def js?
  @js ||= extension == '.js'
end
jsx?() click to toggle source
# File lib/inertia/mass.rb, line 22
def jsx?
  @jsx ||= extension == '.jsx'
end
lines() click to toggle source
# File lib/inertia/mass.rb, line 58
def lines
  return 0 if ignored?

  @lines ||= File.open(path) { |file| file.each_line.count }
end
percent_overall_lines() click to toggle source
# File lib/inertia/mass.rb, line 64
def percent_overall_lines
  (lines / Inertia::Resistance.total_lines.to_f * 100).round(2)
end
rabl?() click to toggle source
# File lib/inertia/mass.rb, line 38
def rabl?
  @rabl ||= extension == '.rabl'
end
ruby_spec?() click to toggle source
# File lib/inertia/mass.rb, line 46
def ruby_spec?
  @ruby_spec ||= path.include?('_spec.rb')
end
scss?() click to toggle source
# File lib/inertia/mass.rb, line 14
def scss?
  @scss ||= extension == '.scss'
end
text?() click to toggle source
# File lib/inertia/mass.rb, line 10
def text?
  @text ||= File.open(path) { |file| file.read.ascii_only? }
end
to_s() click to toggle source
# File lib/inertia/mass.rb, line 72
def to_s
  sprintf("%6.2f%%\t%s", percent_overall_lines, path)
end
ts?() click to toggle source
# File lib/inertia/mass.rb, line 26
def ts?
  @ts ||= extension == '.ts'
end
tsx?() click to toggle source
# File lib/inertia/mass.rb, line 30
def tsx?
  @tsx ||= extension == '.tsx'
end
yml?() click to toggle source
# File lib/inertia/mass.rb, line 50
def yml?
  @yml ||= extension == '.yml'
end