Sha256: 5b58ec327ae3f02a271c67cf03be046be7c93499bf6d5d4423427a6c0a608956

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

# rubocop:disable Metrics/BlockLength
namespace :logux do
  desc 'Lists all Logux action types'
  task actions: :environment do
    Dir[Rails.root.join('app', 'logux', 'actions', '**', '*.rb')].each do |file|
      require file
    end

    output = [%w[action.type Class#method]]
    Logux::ActionController.descendants.sort_by(&:name).each do |klass|
      klass.instance_methods(false).sort.each do |action|
        output << [
          "#{klass.name.gsub(/^Actions::/, '').underscore}/#{action}",
          "#{klass.name}##{action}"
        ]
      end
    end

    first_column_length = output.map(&:first).max_by(&:length).length
    output.each do |action, klass_name|
      puts "#{action.rjust(first_column_length, ' ')} #{klass_name}"
    end
  end

  desc 'Lists all Logux channels'
  task channels: :environment do
    path = Rails.root.join('app', 'logux', 'channels', '**', '*.rb')
    Dir[path].each { |file| require file }

    output = [%w[channel Class]]
    Logux::ChannelController.descendants.map(&:name).sort.each do |klass_name|
      output << [
        klass_name.gsub(/^Channels::/, '').underscore,
        klass_name
      ]
    end

    first_column_length = output.map(&:first).max_by(&:length).length
    output.each do |channel, klass_name|
      puts "#{channel.rjust(first_column_length, ' ')} #{klass_name}"
    end
  end
end
# rubocop:enable Metrics/BlockLength

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logux_rails-0.1.0 lib/tasks/logux_tasks.rake