Module: MixinBot::CLIHelpers

Included in:
CLI, UtilsCLI
Defined in:
lib/mixin_bot/cli/base.rb

Overview

Registry and predicates for mixinbot ‘call` / `list` commands.

Constant Summary collapse

API_EXCLUDED_METHODS =
%i[
  initialize
  client
  config
  utils
  client_id
  access_token
  sign_authentication_token
  sign_authentication_token_without_body
  sign_authentication_token_with_request_id
  encode_raw_transaction
  decode_raw_transaction
  generate_trace_from_hash
  encode_raw_transaction_native
  decode_raw_transaction_native
  warn_legacy_mixin_api!
  ensure_mixin_command_exist
  command?
].freeze
INTERACTIVE_API_METHODS =
%i[
  start_blaze_connect
  blaze
  upload_attachment
].freeze

Class Method Summary collapse

Class Method Details

.api_callable_methodsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mixin_bot/cli/base.rb', line 36

def api_callable_methods
  methods = MixinBot::API.instance_methods(false)
  MixinBot::API.included_modules.each do |mod|
    next unless mod.name&.start_with?('MixinBot::API::')

    methods.concat(mod.instance_methods(false))
  end

  methods
    .map(&:to_sym)
    .uniq
    .select { |m| api_method_callable?(m) }
    .sort
end

.api_method_callable?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
# File 'lib/mixin_bot/cli/base.rb', line 51

def api_method_callable?(method_name)
  sym = method_name.to_sym
  return false if API_EXCLUDED_METHODS.include?(sym)
  return false if INTERACTIVE_API_METHODS.include?(sym)

  MixinBot::API.method_defined?(sym) &&
    !sym.to_s.start_with?('_')
end

.api_method_owner(method_name) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/mixin_bot/cli/base.rb', line 64

def api_method_owner(method_name)
  sym = method_name.to_sym
  return 'MixinBot::API' if MixinBot::API.method_defined?(sym, false)

  MixinBot::API.included_modules.find do |mod|
    mod.name&.start_with?('MixinBot::API::') && mod.method_defined?(sym, false)
  end&.name || 'MixinBot::API'
end

.grouped_api_methodsObject



73
74
75
# File 'lib/mixin_bot/cli/base.rb', line 73

def grouped_api_methods
  api_callable_methods.group_by { |m| api_method_owner(m) }.sort_by { |k, _| k }
end

.utils_callable_methodsObject



60
61
62
# File 'lib/mixin_bot/cli/base.rb', line 60

def utils_callable_methods
  MixinBot::Utils.singleton_methods(false).sort
end