Rakefile 1.71 KB
Newer Older
1
#!/usr/bin/env rake
2
require "bundler/gem_tasks"
3

4
require "rspec/core/rake_task"
5 6
RSpec::Core::RakeTask.new

7 8 9
task :test => :spec

begin
10
  require "rubocop/rake_task"
11
  RuboCop::RakeTask.new
12 13
rescue LoadError
  task :rubocop do
14
    $stderr.puts "RuboCop is disabled"
15 16 17
  end
end

18
require "yardstick/rake/measurement"
19
Yardstick::Rake::Measurement.new do |measurement|
20
  measurement.output = "measurement/report.txt"
21 22
end

23
require "yardstick/rake/verify"
24 25
Yardstick::Rake::Verify.new do |verify|
  verify.require_exact_threshold = false
26
  verify.threshold = 55
27 28
end

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
task :generate_status_codes do
  require "http"
  require "nokogiri"

  url = "http://www.iana.org/assignments/http-status-codes/http-status-codes.xml"
  xml = Nokogiri::XML HTTP.get url
  arr = xml.xpath("//xmlns:record").reduce [] do |a, e|
    code = e.xpath("xmlns:value").text.to_s
    desc = e.xpath("xmlns:description").text.to_s

    next a if "Unassigned" == desc || "(Unused)" == desc

    a << "#{code} => #{desc.inspect}"
  end

  File.open("./lib/http/response/status/reasons.rb", "w") do |io|
    io.puts <<-TPL.gsub(/^[ ]{6}/, "")
      # AUTO-GENERATED FILE, DO NOT CHANGE IT MANUALLY

      require "delegate"

      module HTTP
        class Response
          class Status < ::Delegator
            # Code to Reason map
            #
            # @example Usage
            #
            #   REASONS[400] # => "Bad Request"
            #   REASONS[414] # => "Request-URI Too Long"
            #
            # @return [Hash<Fixnum => String>]
            REASONS = {
              #{arr.join ",\n              "}
            }.each { |_, v| v.freeze }.freeze
          end
        end
      end
    TPL
  end
end

71
task :default => [:spec, :rubocop, :verify_measurements]