Class: BitClust::Request

Inherits:
Object show all
Includes:
NameUtils
Defined in:
lib/bitclust/requesthandler.rb

Direct Known Subclasses

RackRequest

Constant Summary

Constants included from NameUtils

NameUtils::CHAR_TO_MARK, NameUtils::CHAR_TO_NAME, NameUtils::CLASS_NAME_RE, NameUtils::CLASS_PATH_RE, NameUtils::CONST_PATH_RE, NameUtils::CONST_RE, NameUtils::GVAR_RE, NameUtils::LIBNAME_RE, NameUtils::MARK_TO_CHAR, NameUtils::MARK_TO_NAME, NameUtils::METHOD_NAME_RE, NameUtils::METHOD_SPEC_RE, NameUtils::MID, NameUtils::NAME_TO_CHAR, NameUtils::NAME_TO_MARK, NameUtils::TYPEMARK_RE

Instance Method Summary collapse

Methods included from NameUtils

build_method_id, classid2name, classname2id, classname?, decodeid, decodename_fs, decodename_url, encodeid, encodename_fs, encodename_rdocurl, encodename_url, functionname?, gvarname?, html_filename, libid2name, libname2id, libname?, method_spec?, methodid2classid, methodid2libid, methodid2mname, methodid2specparts, methodid2specstring, methodid2typechar, methodid2typemark, methodid2typename, methodname?, split_method_id, split_method_spec, typechar2mark, typechar2name, typechar?, typemark2char, typemark2name, typemark?, typename2char, typename2mark, typename?

Constructor Details

#initialize(wreq) ⇒ Request

Returns a new instance of Request.


136
137
138
# File 'lib/bitclust/requesthandler.rb', line 136

def initialize(wreq)
  @wreq = wreq
end

Instance Method Details

#ancestors_levelObject


239
240
241
242
243
244
245
246
# File 'lib/bitclust/requesthandler.rb', line 239

def ancestors_level
  ret = query['a'].to_i
  if ret < 0
    0
  else
    ret
  end
end

#class?Boolean

Returns:

  • (Boolean)

144
145
146
# File 'lib/bitclust/requesthandler.rb', line 144

def class?
  type_id() == :class
end

#class_nameObject


168
169
170
171
172
173
174
175
176
177
# File 'lib/bitclust/requesthandler.rb', line 168

def class_name
  raise '#class_name called but not class request' unless class?
  id = type_param()
  return nil unless id
  name = classid2name(id)
  unless classname?(name)
    raise InvalidKey, "invalid class name: #{name.inspect}"
  end
  name
end

#defined_type?Boolean

Returns:

  • (Boolean)

209
210
211
212
213
214
215
216
217
# File 'lib/bitclust/requesthandler.rb', line 209

def defined_type?
  type, param = parse_path_info()
  case type
  when 'library', 'class', 'method', 'function', 'search', 'opensearchdescription'
    true
  else
    false
  end
end

#doc_nameObject


152
153
154
155
# File 'lib/bitclust/requesthandler.rb', line 152

def doc_name
  name = path_info.sub(%r!\A/!, '')
  name unless name.empty?
end

#full_uriObject


252
253
254
# File 'lib/bitclust/requesthandler.rb', line 252

def full_uri
  @wreq.request_uri
end

#function?Boolean

Returns:

  • (Boolean)

224
225
226
# File 'lib/bitclust/requesthandler.rb', line 224

def function?
  type_id() == :function
end

#function_nameObject


228
229
230
231
232
233
234
235
236
237
# File 'lib/bitclust/requesthandler.rb', line 228

def function_name
  raise '#function_name called but not function request' unless function?
  id = type_param()
  return nil unless id
  name = id
  unless functionname?(name)
    raise InvalidKey, "invalid function name: #{name.inspect}"
  end
  name
end

#library?Boolean

Returns:

  • (Boolean)

140
141
142
# File 'lib/bitclust/requesthandler.rb', line 140

def library?
  type_id() == :library
end

#library_nameObject


157
158
159
160
161
162
163
164
165
166
# File 'lib/bitclust/requesthandler.rb', line 157

def library_name
  raise '#library_name called but not library request' unless library?
  id = type_param()
  return nil unless id
  name = libid2name(id)
  unless libname?(name)
    raise InvalidKey, "invalid library name: #{name.inspect}"
  end
  name
end

#method?Boolean

Returns:

  • (Boolean)

148
149
150
# File 'lib/bitclust/requesthandler.rb', line 148

def method?
  type_id() == :method
end

#method_specObject

Raises:


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/bitclust/requesthandler.rb', line 179

def method_spec
  return nil unless method?
  param = type_param()
  return nil unless param
  cid, typechar, mencoded = param.split('/', 3)
  raise InvalidKey, 'missing class name' unless cid
  raise InvalidKey, 'missing type name' unless typechar
  raise InvalidKey, 'missing method name' unless mencoded
  unless typechar?(typechar)
    raise InvalidKey, "invalid method-type ID: #{typechar.inspect}"
  end
  cname = classid2name(cid)
  tmark = typechar2mark(typechar)
  mname = decodename_url(mencoded)
  unless classname?(cname)
    raise InvalidKey, "invalid class name: #{cname.inspect}"
  end
  case tmark
  when '$'
    unless gvarname?('$' + mname)
      raise InvalidKey, "invalid variable name: #{('$' + mname).inspect}"
    end
  when '.', '#', '.#', '::'
    unless methodname?(mname)
      raise InvalidKey, "invalid method name: #{mname.inspect}"
    end
  end
  MethodSpec.new(cname, tmark, mname)
end

#queryObject


248
249
250
# File 'lib/bitclust/requesthandler.rb', line 248

def query
  @wreq.query
end

#type_idObject


219
220
221
222
# File 'lib/bitclust/requesthandler.rb', line 219

def type_id
  type, param = parse_path_info()
  type.intern if type
end