Class: Reflexive::Application

Inherits:
Sinatra::Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/reflexive/application.rb

Constant Summary

Constants included from Helpers

Helpers::CODERAY_ENCODER_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#constant_name, #constants_links, #constants_list, #constants_table, #filter_existing_constants, #full_name_link_to_method, #highlight_file, #instance_methods_table, #just_methods_table, #link_to_file, #link_to_method, #load_and_highlight, #methods_table, #new_link_to_method, #new_methods_table, #shorten_file_path, #truncate

Methods included from RoutingHelpers

#apidock_path, #class_method_definition_path, #constant_lookup_path, constant_path, #dashboard_path, #file_path, #instance_method_definition_path, #load_path_lookup_path, #method_call_path, #method_definition_path, #method_documentation_path, #method_path, #new_method_definition_path, new_method_path, #up_path

Class Method Details

.action(path, &block) ⇒ Object



56
57
58
# File 'lib/reflexive/application.rb', line 56

def self.action(path, &block)
  get("/reflexive/#{ path }", &block)
end

.default_url_prefixObject



48
49
50
# File 'lib/reflexive/application.rb', line 48

def default_url_prefix
  "http://localhost:3000"
end

.rootObject



43
44
45
46
# File 'lib/reflexive/application.rb', line 43

def root
  require "pathname"
  Pathname("../../../").expand_path(__FILE__)
end

Instance Method Details

#definition_action(klass, level, name) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/reflexive/application.rb', line 104

def definition_action(klass, level, name)
  find_klass(klass)
  @method_name = name
  @path, @line = @klass.send(level == :class ? :method : :instance_method, @method_name).source_location
  if @path.include?("(eval)")
    e "#{ name } #{ level } method was generated using `eval' function and can't be browsed"
  else
    @source = highlight_file(@path, :highlight_lines => [@line])
    erb :methods_definition
  end
end

#e(message) ⇒ Object



66
67
68
69
# File 'lib/reflexive/application.rb', line 66

def e(message)
  @message = message
  erb :error
end

#method_lookup_action(klass, level, name) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/reflexive/application.rb', line 138

def method_lookup_action(klass, level, name)
  lookup = MethodLookup.new(klass: klass, level: level, name: name)
  if definitions = lookup.definitions
    if definitions.size == 1
      redirect(new_method_definition_path(*definitions[0]) + "#highlighted")
    else
      @definitions, @klass, @level, @name, @last_resort_lookup_used =
              definitions, klass, level, name, lookup.last_resort_lookup_used?
      erb :methods_choose
    end
  elsif documentations = lookup.documentations
    if documentations.size == 1
      redirect(method_documentation_path(*documentations[0]))
    else
      raise ArgumentError, "don't know how to handle multiple documentations"
    end
  else
    e "failed to find `#{ name }' #{ level } method for #{ klass }"
  end
  #
  # e "failed to find `#{ method }' instance method for #{ klass }"
end