module Qdocs::Helpers

Public Instance Methods

find_constant(const) click to toggle source
# File lib/qdocs.rb, line 37
def find_constant(const)
  case const
  when Symbol, String
    Object.const_get const
  else
    const
  end
rescue NameError
  raise UnknownClassError, "Unknown constant #{const}"
end
own_methods(methods) click to toggle source
# File lib/qdocs.rb, line 25
def own_methods(methods)
  methods - Object.methods
end
params_to_hash(params) click to toggle source
# File lib/qdocs.rb, line 29
def params_to_hash(params)
  hsh = {}
  params.each_with_index do |prm, i|
    hsh[prm[1] || "unnamed_arg_#{i}"] = prm[0]
  end
  hsh
end
render_response(const, type, attrs) click to toggle source
# File lib/qdocs.rb, line 48
def render_response(const, type, attrs)
  const_name = if const.is_a?(Class) || const.is_a?(Module)
      const.name
    elsif instance_of?(Class) || const.instance_of?(Module)
      const.inspect
    else
      const.to_s
    end
  {
    original_input: @original_input,
    constant: {
      name: const_name,
      type: const.class.name,
    },
    query_type: type,
    attributes: attrs,
  }
end
source_location_to_str(source_location) click to toggle source
# File lib/qdocs.rb, line 19
def source_location_to_str(source_location)
  if source_location && source_location.length == 2
    "#{source_location[0]}:#{source_location[1]}"
  end
end