Sha256: 89ef28bc7335b35ae7d1c577dfb41d44093c5293a458fa32609adb94ca2af527
Contents?: true
Size: 1.89 KB
Versions: 1
Compression:
Stored size: 1.89 KB
Contents
# frozen_string_literal: true # largely from https://github.com/aki017/slack-ruby-gem require 'json-schema' require 'erubis' namespace :slack do namespace :real_time do namespace :api do REAL_TIME_EVENTS_MARKER = '### RealTime Events' desc 'Update Real Time API.' task update: [:git_update] do event_schema = JSON.parse(File.read('lib/slack/real_time/api/schema/event.json')) dirglob = 'lib/slack/web/api/slack-api-ref/events/**/*.json' events = Dir.glob(dirglob).each_with_object({}) do |path, result| name = File.basename(path, '.json') parsed = JSON.parse(File.read(path)) JSON::Validator.validate(event_schema, parsed, insert_defaults: true) next if %w[message hello].include?(name) result[name] = parsed end event_handler_template = Erubis::Eruby.new(File.read('lib/slack/real_time/api/templates/event_handler.erb')) Dir.glob('lib/slack/real_time/stores/**/*.rb').each do |store_file| next if File.basename(store_file) == 'base.rb' STDOUT.write "#{File.basename(store_file)}:" store_file_contents = File.read(store_file) events.each_pair do |event_name, event_data| if store_file_contents.include?("on :#{event_name} do") STDOUT.write('.') else STDOUT.write('x') rendered_event_handler = event_handler_template.result( name: event_data['name'], desc: event_data['desc'] ) store_file_contents.gsub!( REAL_TIME_EVENTS_MARKER, REAL_TIME_EVENTS_MARKER + "\n\n" + rendered_event_handler.rstrip ) end end File.write(store_file, store_file_contents) puts ' done.' end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
slack-ruby-client-1.1.0 | lib/tasks/real_time.rake |