Module: Qdocs

Defined in:
lib/qdocs.rb,
lib/qdocs/server.rb,
lib/qdocs/version.rb,
lib/qdocs/active_record.rb

Defined Under Namespace

Modules: ActiveRecord, Base, Helpers Classes: InvalidArgumentError, Server, UnknownClassError, UnknownMethodError, UnknownMethodTypeError, UnknownPatternError

Constant Summary collapse

METHOD_REGEXP =
/(?:[a-zA-Z_]+|\[\])[?!=]?/.freeze
CONST_REGEXP =
/[[:upper:]]\w*(?:::[[:upper:]]\w*)*/.freeze
Handler =
if Object.const_defined? :ActiveRecord
  require_relative "qdocs/active_record"
  Qdocs::ActiveRecord
else
  Qdocs::Base
end
VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.load_env(dir_level = nil) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/qdocs.rb', line 196

def self.load_env(dir_level = nil)
  check_dir = dir_level || ["."]
  project_top_level = Pathname(File.join(*check_dir, "Gemfile")).exist? ||
                      Pathname(File.join(*check_dir, ".git")).exist?
  if project_top_level && Pathname(File.join(*check_dir, "config", "environment.rb")).exist?
    require File.join(*check_dir, "config", "environment.rb")
  elsif project_top_level
    # no op - no env to load
  else
    dir_level ||= []
    dir_level << ".."
    Qdocs.load_env(dir_level)
  end
end

.lookup(input) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/qdocs.rb', line 220

def self.lookup(input)
  case input
  when /\A([[:lower:]](?:#{METHOD_REGEXP})?)\z/
    Handler::Method.new(input).show(Object, $1, :instance)
  when /\A(#{CONST_REGEXP})\.(#{METHOD_REGEXP})\z/
    Handler::Method.new(input).show($1, $2, :singleton)
  when /\A(#{CONST_REGEXP})#(#{METHOD_REGEXP})\z/
    Handler::Method.new(input).show($1, $2, :instance)
  when /\A(#{CONST_REGEXP})\z/
    Handler::Const.new(input).show($1)
  when %r{\A(#{CONST_REGEXP})/([^/]+)/\z}
    Handler::Method.new(input).index($1, Regexp.new($2))
  else
    raise UnknownPatternError, "Unrecognised pattern #{input}"
  end
end