Sha256: adafa016a8e71a0eaf5e2b76241df91e5d5676af4959d727856cfb6371411ee3

Contents?: true

Size: 2 KB

Versions: 16

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path('lib', __dir__)

begin
  require 'bundler'
  Bundler::GemHelper.install_tasks
rescue LoadError => e
  warn e
end

desc 'run specs'
task(:spec) { ruby '-S rspec' }

namespace :doc do
  task :readmes do
    Dir.glob 'lib/rack/protection/*.rb' do |file|
      excluded_files = %w[lib/rack/protection/base.rb lib/rack/protection/version.rb]
      next if excluded_files.include?(file)

      doc  = File.read(file)[/^  module Protection(\n)+(    #[^\n]*\n)*/m].scan(/^ *#(?!#) ?(.*)\n/).join("\n")
      file = "doc/#{file[4..-4].tr('/_', '-')}.rdoc"
      Dir.mkdir 'doc' unless File.directory? 'doc'
      puts "writing #{file}"
      File.open(file, 'w') { |f| f << doc }
    end
  end

  task :index do
    doc = File.read('README.md')
    file = 'doc/rack-protection-readme.md'
    Dir.mkdir 'doc' unless File.directory? 'doc'
    puts "writing #{file}"
    File.open(file, 'w') { |f| f << doc }
  end

  task all: %i[readmes index]
end

desc 'generate documentation'
task doc: 'doc:all'

desc 'generate gemspec'
task 'rack-protection.gemspec' do
  require 'rack/protection/version'
  content = File.binread 'rack-protection.gemspec'

  # fetch data
  fields = {
    authors: `git shortlog -sn`.force_encoding('utf-8').scan(/[^\d\s].*/),
    email: ['mail@zzak.io', 'konstantin.haase@gmail.com'],
    files: %w[License README.md Rakefile Gemfile rack-protection.gemspec] + Dir['lib/**/*']
  }

  # insert data
  fields.each do |field, values|
    updated = "  s.#{field} = ["
    updated << values.map { |v| "\n    %p" % v }.join(',')
    updated << "\n  ]"
    content.sub!(/  s\.#{field} = \[\n(    .*\n)*  \]/, updated)
  end

  # set version
  content.sub! /(s\.version.*=\s+).*/, "\\1\"#{Rack::Protection::VERSION}\""

  # escape unicode
  content.gsub!(/./) { |c| c.bytesize > 1 ? "\\u{#{c.codepoints.first.to_s(16)}}" : c }

  File.open('rack-protection.gemspec', 'w') { |f| f << content }
end

task gemspec: 'rack-protection.gemspec'
task default: :spec
task test: :spec

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
rack-protection-4.1.1 Rakefile
rack-protection-4.1.0 Rakefile
rack-protection-4.0.0 Rakefile
rack-protection-3.2.0 Rakefile
rack-protection-3.1.0 Rakefile
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.5/Rakefile
rack-protection-3.0.6 Rakefile
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.5/Rakefile
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.5/Rakefile
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.5/Rakefile
rack-protection-3.0.5 Rakefile
rack-protection-3.0.4 Rakefile
rack-protection-3.0.3 Rakefile
rack-protection-3.0.2 Rakefile
rack-protection-3.0.1 Rakefile
rack-protection-3.0.0 Rakefile