class Logux::RakeTasks
Constants
- ACTIONS_HEAD
- ACTIONS_NAMESPACE
- CHANNELS_HEAD
- CHANNELS_NAMESPACE
Attributes
fail_on_error[RW]
formatters[RW]
name[RW]
options[RW]
patterns[RW]
requires[RW]
verbose[RW]
Public Class Methods
new(name = :logux)
click to toggle source
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# File lib/logux/rake_tasks.rb, line 23 def initialize(name = :logux) setup(name) namespace(name) do desc 'Lists all Logux action types' task(:actions, [:actions_path]) do |_, task_args| task_args.with_defaults(actions_path: default_actions_path) require_all(task_args.actions_path) report(ACTIONS_HEAD, action_types) end desc 'Lists all Logux channel' task(:channels, [:channels_path]) do |_, task_args| task_args.with_defaults(channels_path: default_channels_path) require_all(task_args.channels_path) report(CHANNELS_HEAD, channels) end end end
Protected Instance Methods
default_actions_path()
click to toggle source
rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# File lib/logux/rake_tasks.rb, line 45 def default_actions_path File.join(Dir.pwd, '**', 'actions') end
default_channels_path()
click to toggle source
# File lib/logux/rake_tasks.rb, line 49 def default_channels_path File.join(Dir.pwd, '**', 'channels') end
Private Instance Methods
action_methods(klass)
click to toggle source
# File lib/logux/rake_tasks.rb, line 80 def action_methods(klass) prefix = action_type(klass) klass.instance_methods(false).sort.map do |action| [[prefix, action].join('/'), [klass.name, action].join('#')] end end
action_type(klass)
click to toggle source
# File lib/logux/rake_tasks.rb, line 87 def action_type(klass) strip_namespace(klass, ACTIONS_NAMESPACE) end
action_types()
click to toggle source
# File lib/logux/rake_tasks.rb, line 75 def action_types classes = descendants_of(::Logux::ActionController).sort_by(&:name) classes.flat_map { |klass| action_methods(klass) } end
channel(klass)
click to toggle source
# File lib/logux/rake_tasks.rb, line 98 def channel(klass) strip_namespace(klass, CHANNELS_NAMESPACE) end
channels()
click to toggle source
# File lib/logux/rake_tasks.rb, line 91 def channels classes = descendants_of(::Logux::ChannelController) classes.select(&:name).sort_by(&:name).map do |klass| [channel(klass), klass] end end
descendants_of(parent)
click to toggle source
# File lib/logux/rake_tasks.rb, line 106 def descendants_of(parent) ObjectSpace.each_object(Class).select { |klass| klass < parent } end
report(header, items)
click to toggle source
# File lib/logux/rake_tasks.rb, line 110 def report(header, items) output = header + items first_column_length = output.map(&:first).max_by(&:length).length output.each do |entity, klass_name| puts "#{entity.rjust(first_column_length, ' ')} #{klass_name}" end end
require_all(path)
click to toggle source
# File lib/logux/rake_tasks.rb, line 69 def require_all(path) Dir[File.join(path, '**', '*.rb')].each do |file| require file end end
setup(name)
click to toggle source
# File lib/logux/rake_tasks.rb, line 55 def setup(name) @name = name @verbose = true @fail_on_error = true @patterns = [] @requires = [] @options = [] @formatters = [] end
strip_namespace(klass, namespace)
click to toggle source
# File lib/logux/rake_tasks.rb, line 102 def strip_namespace(klass, namespace) klass.name.gsub(/^#{namespace}::/, '').underscore end