<commit_before>namespace :praxis do

  desc 'List routes, format=json or table, default table'
  task :routes, [:format] => [:environment] do |t, args|
    require 'terminal-table'

    table = Terminal::Table.new title: "Routes",
    headings:  [
      "Version", "Path", "Verb",
      "Resource", "Action", "Implementation", "Name", "Primary"
    ]

    rows = []
    Praxis::Application.instance.resource_definitions.each do |resource_definition|
      resource_definition.actions.each do |name, action|
        method = begin
          m = resource_definition.controller.instance_method(name)
        rescue
          nil
        end

        method_name = method ? "#{method.owner.name}##{method.name}" : 'n/a'

        if action.routes.empty?
          raise "No routes defined for #{resource_definition.name}##{name}."
        end

        action.routes.each do |route|
          rows << {
            resource: resource_definition.name,
            version: route.version,
            verb: route.verb,
            path: route.path,
            action: name,
            implementation: method_name,
            name: route.name,
            primary: (action.primary_route == route ? 'yes' : '')
          }
        end
      end
    end

    case args[:format] || "table"
    when "json"
      puts JSON.pretty_generate(rows)
    when "table"
      rows.each do |row|
        table.add_row(row.values_at(:version, :path, :verb, :resource,
                                    :action, :implementation, :name, :primary))
      end
      puts table
    else
      raise "unknown output format: #{args[:format]}"
    end

  end
end<commit_msg>Show meaningful error when routes aren't defined (updated). Fixes #80.<commit_after>namespace :praxis do

  desc 'List routes, format=json or table, default table'
  task :routes, [:format] => [:environment] do |t, args|
    require 'terminal-table'

    table = Terminal::Table.new title: "Routes",
    headings:  [
      "Version", "Path", "Verb",
      "Resource", "Action", "Implementation", "Name", "Primary"
    ]

    rows = []
    Praxis::Application.instance.resource_definitions.each do |resource_definition|
      resource_definition.actions.each do |name, action|
        method = begin
          m = resource_definition.controller.instance_method(name)
        rescue
          nil
        end

        method_name = method ? "#{method.owner.name}##{method.name}" : 'n/a'

        row = {
          resource: resource_definition.name,
          action: name,
          implementation: method_name,
        }

        if action.routes.empty?
          warn "Warning: No routes defined for #{resource_definition.name}##{name}."
          rows << row
        else
          action.routes.each do |route|
            rows << row.merge({
              version: route.version,
              verb: route.verb,
              path: route.path,
              name: route.name,
              primary: (action.primary_route == route ? 'yes' : '')
            })
        end
      end
    end
  end

    case args[:format] || "table"
    when "json"
      puts JSON.pretty_generate(rows)
    when "table"
      rows.each do |row|
        table.add_row(row.values_at(:version, :path, :verb, :resource,
                                    :action, :implementation, :name, :primary))
      end
      puts table
    else
      raise "unknown output format: #{args[:format]}"
    end

  end
end
{'fraction_non_alphanumeric': 0.11958102996799534, 'fraction_numerical': 0.0005819028222286878, 'mean_word_length': 2.037102473498233, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1044924', 'n_tokens_mistral': 988, 'n_tokens_neox': 973, 'n_words': 250}