class Peeky::Api

API has factory and creational patterns for easy usage of the Peeky reflection system

Public Instance Methods

build_class_info(instance, lazy: true) click to toggle source

Build a {Peeky::ClassInfo} structure based around a ruby class instance.

ClassInfo stores information about the instance of a class that is passed in including methods, attr_accessors attr_readers and attr_writers.

@param instance [Object] instance of class to gather information about (required) @param lazy [TrueClass] lazy load method and parameter information, laze: is optional, defaults to true

# File lib/peeky/api.rb, line 22
def build_class_info(instance, lazy: true)
  ci = Peeky::ClassInfo.new(instance)
  ci.load unless lazy
  ci
end
class_renderer(key) click to toggle source

Get a class renderer by :key

TODO: Refactor to a configurable system @param key [String] key is a shortcut to a specific Peeky::Renderer that handles class_info (required)

# File lib/peeky/api.rb, line 69
def class_renderer(key)
  case key
  when :class_debug
    Peeky::Renderer::ClassDebugRender
  when :class_interface
    Peeky::Renderer::ClassInterfaceRender
  when :class_interface_yard
    Peeky::Renderer::ClassInterfaceYardRender
  else
    raise "Unknown class renderer: #{key}"
  end
end
method_renderer(key) click to toggle source

Get a method renderer by :key

TODO: Refactor to a configurable system @param key [String] key is a shortcut to a specific Peeky::Render that handles method_info (required)

# File lib/peeky/api.rb, line 52
def method_renderer(key)
  case key
  when :signature
    Peeky::Renderer::MethodSignatureRender
  when :signature_with_debug
    Peeky::Renderer::MethodSignatureWithDebugRender
  when :call_minimum_params
    Peeky::Renderer::MethodCallMinimumParamsRender
  else
    raise "Unknown method renderer: #{key}"
  end
end
render_class(render_key, class_info: nil, instance: nil, **_opts) click to toggle source

Render a class using a predefined class renderer

^1: One of class_info and instance must supplied, they are mutually exclusive to each other.

@param render_key [Symbol] class render key (required) @param class_info [Object] class_info: is optional^1, defaults to nil @param instance [Object] instance: is optional^1, defaults to nil @param _opts [<key: value>…] **_opts - list of key/values that can help configure render

# File lib/peeky/api.rb, line 37
def render_class(render_key, class_info: nil, instance: nil, **_opts)
  raise 'Call render_class with class_info OR instance.' if class_info.nil? && instance.nil?
  raise 'Call render_class with class_info OR instance, these parameters are mutually exclusive' if !class_info.nil? && !instance.nil?

  renderer = class_renderer(render_key)

  class_info = Peeky::ClassInfo.new(instance) if class_info.nil?

  renderer.new(class_info).render
end