forked from ably/ably-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
66 lines (56 loc) · 1.95 KB
/
Rakefile
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
require 'rubygems'
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'json'
require 'yard'
YARD::Rake::YardocTask.new
begin
require 'rspec/core/rake_task'
rspec_task = RSpec::Core::RakeTask.new(:spec)
task :default => :spec
namespace :doc do
desc 'Generate Markdown Specification from the RSpec public API tests'
task :spec do
ENV['PROTOCOL'] = 'json'
rspec_task.rspec_opts = %w(
--require ./spec/support/markdown_spec_formatter
--order defined
--tag ~api_private
--format documentation
--format Ably::RSpec::MarkdownSpecFormatter
).join(' ')
Rake::Task[:spec].invoke
end
end
desc 'Generate error code constants from ably-common: https://github.com/ably/ably-common/issues/32'
task :generate_error_codes do
errors_json_path = File.join(File.dirname(__FILE__), 'lib/submodules/ably-common/protocol/errors.json')
module_path = File.join(File.dirname(__FILE__), 'lib/ably/modules/exception_codes.rb')
max_length = 0
errors = JSON.parse(File.read(errors_json_path)).each_with_object({}) do |(key, val), hash|
hash[key] = val.split(/\s+/).map { |d| d.upcase.gsub(/[^a-zA-Z]+/, '') }.join('_')
end.each do |code, const_name|
max_length = [const_name.length, max_length].max
end.map do |code, const_name|
" #{const_name.ljust(max_length, ' ')} = #{code}"
end.join("\n")
module_content = <<-EOF
# This file is generated by running `rake :generate_error_codes`
# Do not manually modify this file
# Generated at: #{Time.now.utc}
#
module Ably
module Exceptions
module Codes
#{errors}
end
end
end
EOF
File.open(module_path, 'w') { |file| file.write module_content }
puts "Error code constants have been generated into #{module_path}"
puts "Warning: Search for any constants referenced in this library if their name has changed as a result of this constant generation!"
end
rescue LoadError
# RSpec not available
end