Module: RailVerdict::RailsContext::Classifier
- Defined in:
- lib/rail_verdict/rails_context/classifier.rb
Constant Summary collapse
- KINDS =
%w[model controller job mailer helper service policy component view route schema migration test spec config lib unknown].freeze
- PREFIX_MAP =
{ "app/models/" => "model", "app/controllers/" => "controller", "app/jobs/" => "job", "app/mailers/" => "mailer", "app/helpers/" => "helper", "app/services/" => "service", "app/policies/" => "policy", "app/components/" => "component", "app/views/" => "view" }.freeze
Class Method Summary collapse
Class Method Details
.classify(path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rail_verdict/rails_context/classifier.rb', line 20 def self.classify(path) normalized = normalize(path) return "unknown" if normalized.empty? PREFIX_MAP.each do |prefix, kind| return kind if normalized.start_with?(prefix) end case normalized when "config/routes.rb" "route" when "db/schema.rb" "schema" when /\Adb\/migrate\// "migration" when /\Atest\// "test" when /\Aspec\// "spec" when /\Aconfig\// "config" when /\Alib\// "lib" else "unknown" end end |