Module: Evil::Client::Names

Extended by:
Names
Included in:
Names
Defined in:
lib/evil/client/names.rb

Overview

Utility to remove unnecessary methods from instances to clear a namespace

Constant Summary collapse

FORBIDDEN =

List of preserved methods. They also couldn’t be used as names of operations/scopes/options to avoid name conflicts.

%i[
  basic_auth
  class
  datetime
  hash
  inspect
  instance_exec
  instance_variable_get
  instance_variable_set
  key_auth
  logger
  logger
  object_id
  operation
  operations
  options
  schema
  scope
  scopes
  self
  send
  settings
  singleton_class
  tap
  to_s
  to_str
  token_auth
].freeze
FORMAT =

Matches whether a name can be used in operations/scopes/options

/^[a-z]([a-z\d_])*[a-z\d]$/

Instance Method Summary collapse

Instance Method Details

#clean(klass) ⇒ nil

Removes unused instance methods inherited from [Object] from given class

Parameters:

  • klass (Class)

Returns:

  • (nil)


15
16
17
18
# File 'lib/evil/client/names.rb', line 15

def clean(klass)
  (klass.instance_methods - BasicObject.instance_methods - FORBIDDEN)
    .each { |m| klass.send(:undef_method, m) if m[FORMAT] } && nil
end