Module: Qdocs::Helpers

Included in:
Base::Const, Base::Method
Defined in:
lib/qdocs.rb

Instance Method Summary collapse

Instance Method Details

#find_constant(const) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# 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) ⇒ Object



25
26
27
# File 'lib/qdocs.rb', line 25

def own_methods(methods)
  methods - Object.methods
end

#params_to_hash(params) ⇒ Object



29
30
31
32
33
34
35
# 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) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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) ⇒ Object



19
20
21
22
23
# 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