File: Rakefile

package info (click to toggle)
ruby-sinatra 4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,932 kB
  • sloc: ruby: 17,700; sh: 25; makefile: 8
file content (74 lines) | stat: -rw-r--r-- 2,047 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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