repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
bfoz/geometry | lib/geometry/polyline.rb | Geometry.Polyline.close! | def close!
unless @edges.empty?
# NOTE: parallel? is use here instead of collinear? because the
# edges are connected, and will therefore be collinear if
# they're parallel
if closed?
if @edges.first.parallel?(@edges.last)
unshift_edge Edge.new(@edges.last.first, shift_edge.last)
end
elsif
closing_edge = Edge.new(@edges.last.last, @edges.first.first)
# If the closing edge is collinear with the last edge, then
# simply extened the last edge to fill the gap
if @edges.last.parallel?(closing_edge)
closing_edge = Edge.new(pop_edge.first, @edges.first.first)
end
# Check that the new closing_edge isn't zero-length
if closing_edge.first != closing_edge.last
# If the closing edge is collinear with the first edge, then
# extend the first edge "backwards" to fill the gap
if @edges.first.parallel?(closing_edge)
unshift_edge Edge.new(closing_edge.first, shift_edge.last)
else
push_edge closing_edge
end
end
end
end
self
end | ruby | def close!
unless @edges.empty?
# NOTE: parallel? is use here instead of collinear? because the
# edges are connected, and will therefore be collinear if
# they're parallel
if closed?
if @edges.first.parallel?(@edges.last)
unshift_edge Edge.new(@edges.last.first, shift_edge.last)
end
elsif
closing_edge = Edge.new(@edges.last.last, @edges.first.first)
# If the closing edge is collinear with the last edge, then
# simply extened the last edge to fill the gap
if @edges.last.parallel?(closing_edge)
closing_edge = Edge.new(pop_edge.first, @edges.first.first)
end
# Check that the new closing_edge isn't zero-length
if closing_edge.first != closing_edge.last
# If the closing edge is collinear with the first edge, then
# extend the first edge "backwards" to fill the gap
if @edges.first.parallel?(closing_edge)
unshift_edge Edge.new(closing_edge.first, shift_edge.last)
else
push_edge closing_edge
end
end
end
end
self
end | [
"def",
"close!",
"unless",
"@edges",
".",
"empty?",
"if",
"closed?",
"if",
"@edges",
".",
"first",
".",
"parallel?",
"(",
"@edges",
".",
"last",
")",
"unshift_edge",
"Edge",
".",
"new",
"(",
"@edges",
".",
"last",
".",
"first",
",",
"shift_edge",
".",
"last",
")",
"end",
"elsif",
"closing_edge",
"=",
"Edge",
".",
"new",
"(",
"@edges",
".",
"last",
".",
"last",
",",
"@edges",
".",
"first",
".",
"first",
")",
"if",
"@edges",
".",
"last",
".",
"parallel?",
"(",
"closing_edge",
")",
"closing_edge",
"=",
"Edge",
".",
"new",
"(",
"pop_edge",
".",
"first",
",",
"@edges",
".",
"first",
".",
"first",
")",
"end",
"if",
"closing_edge",
".",
"first",
"!=",
"closing_edge",
".",
"last",
"if",
"@edges",
".",
"first",
".",
"parallel?",
"(",
"closing_edge",
")",
"unshift_edge",
"Edge",
".",
"new",
"(",
"closing_edge",
".",
"first",
",",
"shift_edge",
".",
"last",
")",
"else",
"push_edge",
"closing_edge",
"end",
"end",
"end",
"end",
"self",
"end"
] | Close the receiver and return it
@return [Polyline] the receiver after closing | [
"Close",
"the",
"receiver",
"and",
"return",
"it"
] | 3054ccba59f184c172be52a6f0b7cf4a33f617a5 | https://github.com/bfoz/geometry/blob/3054ccba59f184c172be52a6f0b7cf4a33f617a5/lib/geometry/polyline.rb#L127-L159 | train |
bfoz/geometry | lib/geometry/polyline.rb | Geometry.Polyline.bisector_map | def bisector_map
winding = 0
tangent_loop.each_cons(2).map do |v1,v2|
k = v1[0]*v2[1] - v1[1]*v2[0] # z-component of v1 x v2
winding += k
if v1 == v2 # collinear, same direction?
bisector = Vector[-v1[1], v1[0]]
block_given? ? (bisector * yield(bisector, 1)) : bisector
elsif 0 == k # collinear, reverse direction
nil
else
bisector_y = (v2[1] - v1[1])/k
# If v1 or v2 happens to be horizontal, then the other one must be used when calculating
# the x-component of the bisector (to avoid a divide by zero). But, comparing floats
# with zero is problematic, so use the one with the largest y-component instead checking
# for a y-component equal to zero.
v = (v2[1].abs > v1[1].abs) ? v2 : v1
bisector = Vector[(v[0]*bisector_y - 1)/v[1], bisector_y]
block_given? ? (bisector * yield(bisector, k)) : bisector
end
end
end | ruby | def bisector_map
winding = 0
tangent_loop.each_cons(2).map do |v1,v2|
k = v1[0]*v2[1] - v1[1]*v2[0] # z-component of v1 x v2
winding += k
if v1 == v2 # collinear, same direction?
bisector = Vector[-v1[1], v1[0]]
block_given? ? (bisector * yield(bisector, 1)) : bisector
elsif 0 == k # collinear, reverse direction
nil
else
bisector_y = (v2[1] - v1[1])/k
# If v1 or v2 happens to be horizontal, then the other one must be used when calculating
# the x-component of the bisector (to avoid a divide by zero). But, comparing floats
# with zero is problematic, so use the one with the largest y-component instead checking
# for a y-component equal to zero.
v = (v2[1].abs > v1[1].abs) ? v2 : v1
bisector = Vector[(v[0]*bisector_y - 1)/v[1], bisector_y]
block_given? ? (bisector * yield(bisector, k)) : bisector
end
end
end | [
"def",
"bisector_map",
"winding",
"=",
"0",
"tangent_loop",
".",
"each_cons",
"(",
"2",
")",
".",
"map",
"do",
"|",
"v1",
",",
"v2",
"|",
"k",
"=",
"v1",
"[",
"0",
"]",
"*",
"v2",
"[",
"1",
"]",
"-",
"v1",
"[",
"1",
"]",
"*",
"v2",
"[",
"0",
"]",
"winding",
"+=",
"k",
"if",
"v1",
"==",
"v2",
"bisector",
"=",
"Vector",
"[",
"-",
"v1",
"[",
"1",
"]",
",",
"v1",
"[",
"0",
"]",
"]",
"block_given?",
"?",
"(",
"bisector",
"*",
"yield",
"(",
"bisector",
",",
"1",
")",
")",
":",
"bisector",
"elsif",
"0",
"==",
"k",
"nil",
"else",
"bisector_y",
"=",
"(",
"v2",
"[",
"1",
"]",
"-",
"v1",
"[",
"1",
"]",
")",
"/",
"k",
"v",
"=",
"(",
"v2",
"[",
"1",
"]",
".",
"abs",
">",
"v1",
"[",
"1",
"]",
".",
"abs",
")",
"?",
"v2",
":",
"v1",
"bisector",
"=",
"Vector",
"[",
"(",
"v",
"[",
"0",
"]",
"*",
"bisector_y",
"-",
"1",
")",
"/",
"v",
"[",
"1",
"]",
",",
"bisector_y",
"]",
"block_given?",
"?",
"(",
"bisector",
"*",
"yield",
"(",
"bisector",
",",
"k",
")",
")",
":",
"bisector",
"end",
"end",
"end"
] | Generate bisectors and k values with an optional mapping block
@note If the {Polyline} isn't closed (the normal case), then the first and
last vertices will be given bisectors that are perpendicular to themselves.
@return [Array<Vector>] the unit {Vector}s representing the angle bisector of each vertex | [
"Generate",
"bisectors",
"and",
"k",
"values",
"with",
"an",
"optional",
"mapping",
"block"
] | 3054ccba59f184c172be52a6f0b7cf4a33f617a5 | https://github.com/bfoz/geometry/blob/3054ccba59f184c172be52a6f0b7cf4a33f617a5/lib/geometry/polyline.rb#L281-L304 | train |
bfoz/geometry | lib/geometry/polyline.rb | Geometry.Polyline.tangent_loop | def tangent_loop
edges.map {|e| e.direction }.tap do |tangents|
# Generating a bisector for each vertex requires an edge on both sides of each vertex.
# Obviously, the first and last vertices each have only a single adjacent edge, unless the
# Polyline happens to be closed (like a Polygon). When not closed, duplicate the
# first and last direction vectors to fake the adjacent edges. This causes the first and last
# edges to have bisectors that are perpendicular to themselves.
if closed?
# Prepend the last direction vector so that the last edge can be used to find the bisector for the first vertex
tangents.unshift tangents.last
else
# Duplicate the first and last direction vectors to compensate for not having edges adjacent to the first and last vertices
tangents.unshift(tangents.first)
tangents.push(tangents.last)
end
end
end | ruby | def tangent_loop
edges.map {|e| e.direction }.tap do |tangents|
# Generating a bisector for each vertex requires an edge on both sides of each vertex.
# Obviously, the first and last vertices each have only a single adjacent edge, unless the
# Polyline happens to be closed (like a Polygon). When not closed, duplicate the
# first and last direction vectors to fake the adjacent edges. This causes the first and last
# edges to have bisectors that are perpendicular to themselves.
if closed?
# Prepend the last direction vector so that the last edge can be used to find the bisector for the first vertex
tangents.unshift tangents.last
else
# Duplicate the first and last direction vectors to compensate for not having edges adjacent to the first and last vertices
tangents.unshift(tangents.first)
tangents.push(tangents.last)
end
end
end | [
"def",
"tangent_loop",
"edges",
".",
"map",
"{",
"|",
"e",
"|",
"e",
".",
"direction",
"}",
".",
"tap",
"do",
"|",
"tangents",
"|",
"if",
"closed?",
"tangents",
".",
"unshift",
"tangents",
".",
"last",
"else",
"tangents",
".",
"unshift",
"(",
"tangents",
".",
"first",
")",
"tangents",
".",
"push",
"(",
"tangents",
".",
"last",
")",
"end",
"end",
"end"
] | Generate the tangents and fake a circular buffer while accounting for closedness
@return [Array<Vector>] the tangents | [
"Generate",
"the",
"tangents",
"and",
"fake",
"a",
"circular",
"buffer",
"while",
"accounting",
"for",
"closedness"
] | 3054ccba59f184c172be52a6f0b7cf4a33f617a5 | https://github.com/bfoz/geometry/blob/3054ccba59f184c172be52a6f0b7cf4a33f617a5/lib/geometry/polyline.rb#L317-L333 | train |
bfoz/geometry | lib/geometry/polyline.rb | Geometry.Polyline.find_next_intersection | def find_next_intersection(edges, i, e)
for j in i..(edges.count-1)
e2 = edges[j][:edge]
next if !e2 || e.connected?(e2)
intersection = e.intersection(e2)
return [intersection, j] if intersection
end
nil
end | ruby | def find_next_intersection(edges, i, e)
for j in i..(edges.count-1)
e2 = edges[j][:edge]
next if !e2 || e.connected?(e2)
intersection = e.intersection(e2)
return [intersection, j] if intersection
end
nil
end | [
"def",
"find_next_intersection",
"(",
"edges",
",",
"i",
",",
"e",
")",
"for",
"j",
"in",
"i",
"..",
"(",
"edges",
".",
"count",
"-",
"1",
")",
"e2",
"=",
"edges",
"[",
"j",
"]",
"[",
":edge",
"]",
"next",
"if",
"!",
"e2",
"||",
"e",
".",
"connected?",
"(",
"e2",
")",
"intersection",
"=",
"e",
".",
"intersection",
"(",
"e2",
")",
"return",
"[",
"intersection",
",",
"j",
"]",
"if",
"intersection",
"end",
"nil",
"end"
] | Find the next edge that intersects with e, starting at index i | [
"Find",
"the",
"next",
"edge",
"that",
"intersects",
"with",
"e",
"starting",
"at",
"index",
"i"
] | 3054ccba59f184c172be52a6f0b7cf4a33f617a5 | https://github.com/bfoz/geometry/blob/3054ccba59f184c172be52a6f0b7cf4a33f617a5/lib/geometry/polyline.rb#L336-L344 | train |
bfoz/geometry | lib/geometry/polyline.rb | Geometry.Polyline.find_last_intersection | def find_last_intersection(edges, i, e)
intersection, intersection_at = nil, nil
for j in i..(edges.count-1)
e2 = edges[j][:edge]
next if !e2 || e.connected?(e2)
_intersection = e.intersection(e2)
intersection, intersection_at = _intersection, j if _intersection
end
[intersection, intersection_at]
end | ruby | def find_last_intersection(edges, i, e)
intersection, intersection_at = nil, nil
for j in i..(edges.count-1)
e2 = edges[j][:edge]
next if !e2 || e.connected?(e2)
_intersection = e.intersection(e2)
intersection, intersection_at = _intersection, j if _intersection
end
[intersection, intersection_at]
end | [
"def",
"find_last_intersection",
"(",
"edges",
",",
"i",
",",
"e",
")",
"intersection",
",",
"intersection_at",
"=",
"nil",
",",
"nil",
"for",
"j",
"in",
"i",
"..",
"(",
"edges",
".",
"count",
"-",
"1",
")",
"e2",
"=",
"edges",
"[",
"j",
"]",
"[",
":edge",
"]",
"next",
"if",
"!",
"e2",
"||",
"e",
".",
"connected?",
"(",
"e2",
")",
"_intersection",
"=",
"e",
".",
"intersection",
"(",
"e2",
")",
"intersection",
",",
"intersection_at",
"=",
"_intersection",
",",
"j",
"if",
"_intersection",
"end",
"[",
"intersection",
",",
"intersection_at",
"]",
"end"
] | Find the last edge that intersects with e, starting at index i | [
"Find",
"the",
"last",
"edge",
"that",
"intersects",
"with",
"e",
"starting",
"at",
"index",
"i"
] | 3054ccba59f184c172be52a6f0b7cf4a33f617a5 | https://github.com/bfoz/geometry/blob/3054ccba59f184c172be52a6f0b7cf4a33f617a5/lib/geometry/polyline.rb#L347-L356 | train |
paddor/cztop | lib/cztop/config.rb | CZTop.Config.[] | def [](path, default = "")
ptr = ffi_delegate.get(path, default)
return nil if ptr.null?
ptr.read_string
end | ruby | def [](path, default = "")
ptr = ffi_delegate.get(path, default)
return nil if ptr.null?
ptr.read_string
end | [
"def",
"[]",
"(",
"path",
",",
"default",
"=",
"\"\"",
")",
"ptr",
"=",
"ffi_delegate",
".",
"get",
"(",
"path",
",",
"default",
")",
"return",
"nil",
"if",
"ptr",
".",
"null?",
"ptr",
".",
"read_string",
"end"
] | Get the value of the current config item.
@param path [String, #to_s] path to config item
@param default [String, #to_s] default value to return if config item
doesn't exist
@return [String]
@return [default] if config item doesn't exist
@note The default value is not returned when the config item exists but
just doesn't have a value. In that case, it'll return the empty
string. | [
"Get",
"the",
"value",
"of",
"the",
"current",
"config",
"item",
"."
] | d20ee44775d05b60f40fffd1287a9b01270ab853 | https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/config.rb#L95-L99 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.9/xmlrpc/create.rb | XMLRPC.Create.methodResponse | def methodResponse(is_ret, *params)
if is_ret
resp = params.collect do |param|
@writer.ele("param", conv2value(param))
end
resp = [@writer.ele("params", *resp)]
else
if params.size != 1 or params[0] === XMLRPC::FaultException
raise ArgumentError, "no valid fault-structure given"
end
resp = @writer.ele("fault", conv2value(params[0].to_h))
end
tree = @writer.document(
@writer.pi("xml", 'version="1.0"'),
@writer.ele("methodResponse", resp)
)
@writer.document_to_str(tree) + "\n"
end | ruby | def methodResponse(is_ret, *params)
if is_ret
resp = params.collect do |param|
@writer.ele("param", conv2value(param))
end
resp = [@writer.ele("params", *resp)]
else
if params.size != 1 or params[0] === XMLRPC::FaultException
raise ArgumentError, "no valid fault-structure given"
end
resp = @writer.ele("fault", conv2value(params[0].to_h))
end
tree = @writer.document(
@writer.pi("xml", 'version="1.0"'),
@writer.ele("methodResponse", resp)
)
@writer.document_to_str(tree) + "\n"
end | [
"def",
"methodResponse",
"(",
"is_ret",
",",
"*",
"params",
")",
"if",
"is_ret",
"resp",
"=",
"params",
".",
"collect",
"do",
"|",
"param",
"|",
"@writer",
".",
"ele",
"(",
"\"param\"",
",",
"conv2value",
"(",
"param",
")",
")",
"end",
"resp",
"=",
"[",
"@writer",
".",
"ele",
"(",
"\"params\"",
",",
"*",
"resp",
")",
"]",
"else",
"if",
"params",
".",
"size",
"!=",
"1",
"or",
"params",
"[",
"0",
"]",
"===",
"XMLRPC",
"::",
"FaultException",
"raise",
"ArgumentError",
",",
"\"no valid fault-structure given\"",
"end",
"resp",
"=",
"@writer",
".",
"ele",
"(",
"\"fault\"",
",",
"conv2value",
"(",
"params",
"[",
"0",
"]",
".",
"to_h",
")",
")",
"end",
"tree",
"=",
"@writer",
".",
"document",
"(",
"@writer",
".",
"pi",
"(",
"\"xml\"",
",",
"'version=\"1.0\"'",
")",
",",
"@writer",
".",
"ele",
"(",
"\"methodResponse\"",
",",
"resp",
")",
")",
"@writer",
".",
"document_to_str",
"(",
"tree",
")",
"+",
"\"\\n\"",
"end"
] | generates a XML-RPC methodResponse document
if is_ret == false then the params array must
contain only one element, which is a structure
of a fault return-value.
if is_ret == true then a normal
return-value of all the given params is created. | [
"generates",
"a",
"XML",
"-",
"RPC",
"methodResponse",
"document"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/xmlrpc/create.rb#L144-L166 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/fragments.rb | SM.LineCollection.add_list_start_and_ends | def add_list_start_and_ends
level = 0
res = []
type_stack = []
@fragments.each do |fragment|
# $stderr.puts "#{level} : #{fragment.class.name} : #{fragment.level}"
new_level = fragment.level
while (level < new_level)
level += 1
type = fragment.type
res << ListStart.new(level, fragment.param, type) if type
type_stack.push type
# $stderr.puts "Start: #{level}"
end
while level > new_level
type = type_stack.pop
res << ListEnd.new(level, type) if type
level -= 1
# $stderr.puts "End: #{level}, #{type}"
end
res << fragment
level = fragment.level
end
level.downto(1) do |i|
type = type_stack.pop
res << ListEnd.new(i, type) if type
end
@fragments = res
end | ruby | def add_list_start_and_ends
level = 0
res = []
type_stack = []
@fragments.each do |fragment|
# $stderr.puts "#{level} : #{fragment.class.name} : #{fragment.level}"
new_level = fragment.level
while (level < new_level)
level += 1
type = fragment.type
res << ListStart.new(level, fragment.param, type) if type
type_stack.push type
# $stderr.puts "Start: #{level}"
end
while level > new_level
type = type_stack.pop
res << ListEnd.new(level, type) if type
level -= 1
# $stderr.puts "End: #{level}, #{type}"
end
res << fragment
level = fragment.level
end
level.downto(1) do |i|
type = type_stack.pop
res << ListEnd.new(i, type) if type
end
@fragments = res
end | [
"def",
"add_list_start_and_ends",
"level",
"=",
"0",
"res",
"=",
"[",
"]",
"type_stack",
"=",
"[",
"]",
"@fragments",
".",
"each",
"do",
"|",
"fragment",
"|",
"new_level",
"=",
"fragment",
".",
"level",
"while",
"(",
"level",
"<",
"new_level",
")",
"level",
"+=",
"1",
"type",
"=",
"fragment",
".",
"type",
"res",
"<<",
"ListStart",
".",
"new",
"(",
"level",
",",
"fragment",
".",
"param",
",",
"type",
")",
"if",
"type",
"type_stack",
".",
"push",
"type",
"end",
"while",
"level",
">",
"new_level",
"type",
"=",
"type_stack",
".",
"pop",
"res",
"<<",
"ListEnd",
".",
"new",
"(",
"level",
",",
"type",
")",
"if",
"type",
"level",
"-=",
"1",
"end",
"res",
"<<",
"fragment",
"level",
"=",
"fragment",
".",
"level",
"end",
"level",
".",
"downto",
"(",
"1",
")",
"do",
"|",
"i",
"|",
"type",
"=",
"type_stack",
".",
"pop",
"res",
"<<",
"ListEnd",
".",
"new",
"(",
"i",
",",
"type",
")",
"if",
"type",
"end",
"@fragments",
"=",
"res",
"end"
] | List nesting is implicit given the level of
Make it explicit, just to make life a tad
easier for the output processors | [
"List",
"nesting",
"is",
"implicit",
"given",
"the",
"level",
"of",
"Make",
"it",
"explicit",
"just",
"to",
"make",
"life",
"a",
"tad",
"easier",
"for",
"the",
"output",
"processors"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/fragments.rb#L239-L271 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/packagetask.rb | Rake.PackageTask.init | def init(name, version)
@name = name
@version = version
@package_files = Rake::FileList.new
@package_dir = 'pkg'
@need_tar = false
@need_tar_gz = false
@need_tar_bz2 = false
@need_zip = false
@tar_command = 'tar'
@zip_command = 'zip'
end | ruby | def init(name, version)
@name = name
@version = version
@package_files = Rake::FileList.new
@package_dir = 'pkg'
@need_tar = false
@need_tar_gz = false
@need_tar_bz2 = false
@need_zip = false
@tar_command = 'tar'
@zip_command = 'zip'
end | [
"def",
"init",
"(",
"name",
",",
"version",
")",
"@name",
"=",
"name",
"@version",
"=",
"version",
"@package_files",
"=",
"Rake",
"::",
"FileList",
".",
"new",
"@package_dir",
"=",
"'pkg'",
"@need_tar",
"=",
"false",
"@need_tar_gz",
"=",
"false",
"@need_tar_bz2",
"=",
"false",
"@need_zip",
"=",
"false",
"@tar_command",
"=",
"'tar'",
"@zip_command",
"=",
"'zip'",
"end"
] | Create a Package Task with the given name and version.
Initialization that bypasses the "yield self" and "define" step. | [
"Create",
"a",
"Package",
"Task",
"with",
"the",
"given",
"name",
"and",
"version",
".",
"Initialization",
"that",
"bypasses",
"the",
"yield",
"self",
"and",
"define",
"step",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/packagetask.rb#L85-L96 | train |
maintux/esx | lib/esx.rb | ESX.Host.create_vm | def create_vm(specification)
spec = specification
spec[:cpus] = (specification[:cpus] || 1).to_i
spec[:cpu_cores] = (specification[:cpu_cores] || 1).to_i
spec[:guest_id] = specification[:guest_id] || 'otherGuest'
spec[:hw_version] = (specification[:hw_version] || 8).to_i
if specification[:disk_size]
spec[:disk_size] = (specification[:disk_size].to_i * 1024)
else
spec[:disk_size] = 4194304
end
spec[:memory] = (specification[:memory] || 128).to_i
if specification[:datastore]
spec[:datastore] = "[#{specification[:datastore]}]"
else
spec[:datastore] = '[datastore1]'
end
vm_cfg = {
:name => spec[:vm_name],
:guestId => spec[:guest_id],
:files => { :vmPathName => spec[:datastore] },
:numCPUs => spec[:cpus],
:numCoresPerSocket => spec[:cpu_cores],
:memoryMB => spec[:memory],
:deviceChange => [
{
:operation => :add,
:device => RbVmomi::VIM.VirtualLsiLogicController(
:key => 1000,
:busNumber => 0,
:sharedBus => :noSharing)
}
],
:version => 'vmx-'+spec[:hw_version].to_s.rjust(2,'0'),
:extraConfig => [
{
:key => 'bios.bootOrder',
:value => 'ethernet0'
}
]
}
#Add multiple nics
nics_count = 0
if spec[:nics]
spec[:nics].each do |nic_spec|
vm_cfg[:deviceChange].push(
{
:operation => :add,
:device => RbVmomi::VIM.VirtualE1000(create_net_dev(nics_count, nic_spec))
}
)
nics_count += 1
end
end
# VMDK provided, replace the empty vmdk
vm_cfg[:deviceChange].push(create_disk_spec(:disk_file => spec[:disk_file],
:disk_type => spec[:disk_type],
:disk_size => spec[:disk_size],
:datastore => spec[:datastore]))
unless @free_license
VM.wrap(@_datacenter.vmFolder.CreateVM_Task(:config => vm_cfg, :pool => @_datacenter.hostFolder.children.first.resourcePool).wait_for_completion,self)
else
gem_root = Gem::Specification.find_by_name("esx").gem_dir
template_path = File.join(gem_root, 'templates', 'vmx_template.erb')
spec[:guest_id] = convert_guest_id_for_vmdk(spec[:guest_id])
erb = ERB.new File.read(template_path)
vmx = erb.result binding
tmp_vmx = Tempfile.new 'vmx'
tmp_vmx.write vmx
tmp_vmx.close
ds = spec[:datastore]||'datastore1'
ds = ds.gsub('[','').gsub(']','')
vmx_path = "/vmfs/volumes/#{ds}/#{spec[:vm_name]}/#{spec[:vm_name]}.vmx"
remote_command "mkdir -p #{File.dirname(vmx_path)}"
upload_file tmp_vmx.path, vmx_path
remote_command "vim-cmd solo/registervm #{vmx_path}"
VM.wrap(@_datacenter.find_vm(spec[:vm_name]),self)
end
end | ruby | def create_vm(specification)
spec = specification
spec[:cpus] = (specification[:cpus] || 1).to_i
spec[:cpu_cores] = (specification[:cpu_cores] || 1).to_i
spec[:guest_id] = specification[:guest_id] || 'otherGuest'
spec[:hw_version] = (specification[:hw_version] || 8).to_i
if specification[:disk_size]
spec[:disk_size] = (specification[:disk_size].to_i * 1024)
else
spec[:disk_size] = 4194304
end
spec[:memory] = (specification[:memory] || 128).to_i
if specification[:datastore]
spec[:datastore] = "[#{specification[:datastore]}]"
else
spec[:datastore] = '[datastore1]'
end
vm_cfg = {
:name => spec[:vm_name],
:guestId => spec[:guest_id],
:files => { :vmPathName => spec[:datastore] },
:numCPUs => spec[:cpus],
:numCoresPerSocket => spec[:cpu_cores],
:memoryMB => spec[:memory],
:deviceChange => [
{
:operation => :add,
:device => RbVmomi::VIM.VirtualLsiLogicController(
:key => 1000,
:busNumber => 0,
:sharedBus => :noSharing)
}
],
:version => 'vmx-'+spec[:hw_version].to_s.rjust(2,'0'),
:extraConfig => [
{
:key => 'bios.bootOrder',
:value => 'ethernet0'
}
]
}
#Add multiple nics
nics_count = 0
if spec[:nics]
spec[:nics].each do |nic_spec|
vm_cfg[:deviceChange].push(
{
:operation => :add,
:device => RbVmomi::VIM.VirtualE1000(create_net_dev(nics_count, nic_spec))
}
)
nics_count += 1
end
end
# VMDK provided, replace the empty vmdk
vm_cfg[:deviceChange].push(create_disk_spec(:disk_file => spec[:disk_file],
:disk_type => spec[:disk_type],
:disk_size => spec[:disk_size],
:datastore => spec[:datastore]))
unless @free_license
VM.wrap(@_datacenter.vmFolder.CreateVM_Task(:config => vm_cfg, :pool => @_datacenter.hostFolder.children.first.resourcePool).wait_for_completion,self)
else
gem_root = Gem::Specification.find_by_name("esx").gem_dir
template_path = File.join(gem_root, 'templates', 'vmx_template.erb')
spec[:guest_id] = convert_guest_id_for_vmdk(spec[:guest_id])
erb = ERB.new File.read(template_path)
vmx = erb.result binding
tmp_vmx = Tempfile.new 'vmx'
tmp_vmx.write vmx
tmp_vmx.close
ds = spec[:datastore]||'datastore1'
ds = ds.gsub('[','').gsub(']','')
vmx_path = "/vmfs/volumes/#{ds}/#{spec[:vm_name]}/#{spec[:vm_name]}.vmx"
remote_command "mkdir -p #{File.dirname(vmx_path)}"
upload_file tmp_vmx.path, vmx_path
remote_command "vim-cmd solo/registervm #{vmx_path}"
VM.wrap(@_datacenter.find_vm(spec[:vm_name]),self)
end
end | [
"def",
"create_vm",
"(",
"specification",
")",
"spec",
"=",
"specification",
"spec",
"[",
":cpus",
"]",
"=",
"(",
"specification",
"[",
":cpus",
"]",
"||",
"1",
")",
".",
"to_i",
"spec",
"[",
":cpu_cores",
"]",
"=",
"(",
"specification",
"[",
":cpu_cores",
"]",
"||",
"1",
")",
".",
"to_i",
"spec",
"[",
":guest_id",
"]",
"=",
"specification",
"[",
":guest_id",
"]",
"||",
"'otherGuest'",
"spec",
"[",
":hw_version",
"]",
"=",
"(",
"specification",
"[",
":hw_version",
"]",
"||",
"8",
")",
".",
"to_i",
"if",
"specification",
"[",
":disk_size",
"]",
"spec",
"[",
":disk_size",
"]",
"=",
"(",
"specification",
"[",
":disk_size",
"]",
".",
"to_i",
"*",
"1024",
")",
"else",
"spec",
"[",
":disk_size",
"]",
"=",
"4194304",
"end",
"spec",
"[",
":memory",
"]",
"=",
"(",
"specification",
"[",
":memory",
"]",
"||",
"128",
")",
".",
"to_i",
"if",
"specification",
"[",
":datastore",
"]",
"spec",
"[",
":datastore",
"]",
"=",
"\"[#{specification[:datastore]}]\"",
"else",
"spec",
"[",
":datastore",
"]",
"=",
"'[datastore1]'",
"end",
"vm_cfg",
"=",
"{",
":name",
"=>",
"spec",
"[",
":vm_name",
"]",
",",
":guestId",
"=>",
"spec",
"[",
":guest_id",
"]",
",",
":files",
"=>",
"{",
":vmPathName",
"=>",
"spec",
"[",
":datastore",
"]",
"}",
",",
":numCPUs",
"=>",
"spec",
"[",
":cpus",
"]",
",",
":numCoresPerSocket",
"=>",
"spec",
"[",
":cpu_cores",
"]",
",",
":memoryMB",
"=>",
"spec",
"[",
":memory",
"]",
",",
":deviceChange",
"=>",
"[",
"{",
":operation",
"=>",
":add",
",",
":device",
"=>",
"RbVmomi",
"::",
"VIM",
".",
"VirtualLsiLogicController",
"(",
":key",
"=>",
"1000",
",",
":busNumber",
"=>",
"0",
",",
":sharedBus",
"=>",
":noSharing",
")",
"}",
"]",
",",
":version",
"=>",
"'vmx-'",
"+",
"spec",
"[",
":hw_version",
"]",
".",
"to_s",
".",
"rjust",
"(",
"2",
",",
"'0'",
")",
",",
":extraConfig",
"=>",
"[",
"{",
":key",
"=>",
"'bios.bootOrder'",
",",
":value",
"=>",
"'ethernet0'",
"}",
"]",
"}",
"nics_count",
"=",
"0",
"if",
"spec",
"[",
":nics",
"]",
"spec",
"[",
":nics",
"]",
".",
"each",
"do",
"|",
"nic_spec",
"|",
"vm_cfg",
"[",
":deviceChange",
"]",
".",
"push",
"(",
"{",
":operation",
"=>",
":add",
",",
":device",
"=>",
"RbVmomi",
"::",
"VIM",
".",
"VirtualE1000",
"(",
"create_net_dev",
"(",
"nics_count",
",",
"nic_spec",
")",
")",
"}",
")",
"nics_count",
"+=",
"1",
"end",
"end",
"vm_cfg",
"[",
":deviceChange",
"]",
".",
"push",
"(",
"create_disk_spec",
"(",
":disk_file",
"=>",
"spec",
"[",
":disk_file",
"]",
",",
":disk_type",
"=>",
"spec",
"[",
":disk_type",
"]",
",",
":disk_size",
"=>",
"spec",
"[",
":disk_size",
"]",
",",
":datastore",
"=>",
"spec",
"[",
":datastore",
"]",
")",
")",
"unless",
"@free_license",
"VM",
".",
"wrap",
"(",
"@_datacenter",
".",
"vmFolder",
".",
"CreateVM_Task",
"(",
":config",
"=>",
"vm_cfg",
",",
":pool",
"=>",
"@_datacenter",
".",
"hostFolder",
".",
"children",
".",
"first",
".",
"resourcePool",
")",
".",
"wait_for_completion",
",",
"self",
")",
"else",
"gem_root",
"=",
"Gem",
"::",
"Specification",
".",
"find_by_name",
"(",
"\"esx\"",
")",
".",
"gem_dir",
"template_path",
"=",
"File",
".",
"join",
"(",
"gem_root",
",",
"'templates'",
",",
"'vmx_template.erb'",
")",
"spec",
"[",
":guest_id",
"]",
"=",
"convert_guest_id_for_vmdk",
"(",
"spec",
"[",
":guest_id",
"]",
")",
"erb",
"=",
"ERB",
".",
"new",
"File",
".",
"read",
"(",
"template_path",
")",
"vmx",
"=",
"erb",
".",
"result",
"binding",
"tmp_vmx",
"=",
"Tempfile",
".",
"new",
"'vmx'",
"tmp_vmx",
".",
"write",
"vmx",
"tmp_vmx",
".",
"close",
"ds",
"=",
"spec",
"[",
":datastore",
"]",
"||",
"'datastore1'",
"ds",
"=",
"ds",
".",
"gsub",
"(",
"'['",
",",
"''",
")",
".",
"gsub",
"(",
"']'",
",",
"''",
")",
"vmx_path",
"=",
"\"/vmfs/volumes/#{ds}/#{spec[:vm_name]}/#{spec[:vm_name]}.vmx\"",
"remote_command",
"\"mkdir -p #{File.dirname(vmx_path)}\"",
"upload_file",
"tmp_vmx",
".",
"path",
",",
"vmx_path",
"remote_command",
"\"vim-cmd solo/registervm #{vmx_path}\"",
"VM",
".",
"wrap",
"(",
"@_datacenter",
".",
"find_vm",
"(",
"spec",
"[",
":vm_name",
"]",
")",
",",
"self",
")",
"end",
"end"
] | Create a Virtual Machine
Requires a Hash with the following keys:
{
:vm_name => name, (string, required)
:cpus => 1, #(int, optional)
:guest_id => 'otherGuest', #(string, optional)
:disk_size => 4096, #(in MB, optional)
:memory => 128, #(in MB, optional)
:datastore => datastore1 #(string, optional)
:disk_file => path to vmdk inside datastore (optional)
:disk_type => flat, sparse (default flat)
:hw_version => 8 #(int, optional)
}
supported guest_id list:
http://pubs.vmware.com/vsphere-50/index.jsp?topic=/com.vmware.wssdk.apiref.doc_50/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html
Default values above. | [
"Create",
"a",
"Virtual",
"Machine"
] | ac02f2ef1b6294dfaa811fe638250cb3c000eeb6 | https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L126-L207 | train |
maintux/esx | lib/esx.rb | ESX.Host.host_info | def host_info
[
@_host.summary.config.product.fullName,
@_host.summary.config.product.apiType,
@_host.summary.config.product.apiVersion,
@_host.summary.config.product.osType,
@_host.summary.config.product.productLineId,
@_host.summary.config.product.vendor,
@_host.summary.config.product.version
]
end | ruby | def host_info
[
@_host.summary.config.product.fullName,
@_host.summary.config.product.apiType,
@_host.summary.config.product.apiVersion,
@_host.summary.config.product.osType,
@_host.summary.config.product.productLineId,
@_host.summary.config.product.vendor,
@_host.summary.config.product.version
]
end | [
"def",
"host_info",
"[",
"@_host",
".",
"summary",
".",
"config",
".",
"product",
".",
"fullName",
",",
"@_host",
".",
"summary",
".",
"config",
".",
"product",
".",
"apiType",
",",
"@_host",
".",
"summary",
".",
"config",
".",
"product",
".",
"apiVersion",
",",
"@_host",
".",
"summary",
".",
"config",
".",
"product",
".",
"osType",
",",
"@_host",
".",
"summary",
".",
"config",
".",
"product",
".",
"productLineId",
",",
"@_host",
".",
"summary",
".",
"config",
".",
"product",
".",
"vendor",
",",
"@_host",
".",
"summary",
".",
"config",
".",
"product",
".",
"version",
"]",
"end"
] | Return product info as an array of strings containing
fullName, apiType, apiVersion, osType, productLineId, vendor, version | [
"Return",
"product",
"info",
"as",
"an",
"array",
"of",
"strings",
"containing"
] | ac02f2ef1b6294dfaa811fe638250cb3c000eeb6 | https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L234-L244 | train |
maintux/esx | lib/esx.rb | ESX.Host.remote_command | def remote_command(cmd)
output = ""
Net::SSH.start(@address, @user, :password => @password) do |ssh|
output = ssh.exec! cmd
end
output
end | ruby | def remote_command(cmd)
output = ""
Net::SSH.start(@address, @user, :password => @password) do |ssh|
output = ssh.exec! cmd
end
output
end | [
"def",
"remote_command",
"(",
"cmd",
")",
"output",
"=",
"\"\"",
"Net",
"::",
"SSH",
".",
"start",
"(",
"@address",
",",
"@user",
",",
":password",
"=>",
"@password",
")",
"do",
"|",
"ssh",
"|",
"output",
"=",
"ssh",
".",
"exec!",
"cmd",
"end",
"output",
"end"
] | Run a command in the ESX host via SSH | [
"Run",
"a",
"command",
"in",
"the",
"ESX",
"host",
"via",
"SSH"
] | ac02f2ef1b6294dfaa811fe638250cb3c000eeb6 | https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L272-L278 | train |
maintux/esx | lib/esx.rb | ESX.Host.copy_from_template | def copy_from_template(template_disk, destination)
Log.debug "Copying from template #{template_disk} to #{destination}"
raise "Template does not exist" if not template_exist?(template_disk)
source = File.join(@templates_dir, File.basename(template_disk))
Net::SSH.start(@address, @user, :password => @password) do |ssh|
Log.debug "Clone disk #{source} to #{destination}"
Log.debug ssh.exec!("vmkfstools -i #{source} --diskformat thin #{destination} 2>&1")
end
end | ruby | def copy_from_template(template_disk, destination)
Log.debug "Copying from template #{template_disk} to #{destination}"
raise "Template does not exist" if not template_exist?(template_disk)
source = File.join(@templates_dir, File.basename(template_disk))
Net::SSH.start(@address, @user, :password => @password) do |ssh|
Log.debug "Clone disk #{source} to #{destination}"
Log.debug ssh.exec!("vmkfstools -i #{source} --diskformat thin #{destination} 2>&1")
end
end | [
"def",
"copy_from_template",
"(",
"template_disk",
",",
"destination",
")",
"Log",
".",
"debug",
"\"Copying from template #{template_disk} to #{destination}\"",
"raise",
"\"Template does not exist\"",
"if",
"not",
"template_exist?",
"(",
"template_disk",
")",
"source",
"=",
"File",
".",
"join",
"(",
"@templates_dir",
",",
"File",
".",
"basename",
"(",
"template_disk",
")",
")",
"Net",
"::",
"SSH",
".",
"start",
"(",
"@address",
",",
"@user",
",",
":password",
"=>",
"@password",
")",
"do",
"|",
"ssh",
"|",
"Log",
".",
"debug",
"\"Clone disk #{source} to #{destination}\"",
"Log",
".",
"debug",
"ssh",
".",
"exec!",
"(",
"\"vmkfstools -i #{source} --diskformat thin #{destination} 2>&1\"",
")",
"end",
"end"
] | Expects vmdk source file path and destination path
copy_from_template "/home/fooser/my.vmdk", "/vmfs/volumes/datastore1/foovm/foovm.vmdk"
Destination directory must exist otherwise rises exception | [
"Expects",
"vmdk",
"source",
"file",
"path",
"and",
"destination",
"path"
] | ac02f2ef1b6294dfaa811fe638250cb3c000eeb6 | https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L356-L364 | train |
maintux/esx | lib/esx.rb | ESX.Host.import_disk | def import_disk(source, destination, print_progress = false, params = {})
use_template = params[:use_template] || false
if use_template
Log.debug "import_disk :use_template => true"
if !template_exist?(source)
Log.debug "import_disk, template does not exist, importing."
import_template(source, { :print_progress => print_progress })
end
copy_from_template(source, destination)
else
import_disk_convert source, destination, print_progress
end
end | ruby | def import_disk(source, destination, print_progress = false, params = {})
use_template = params[:use_template] || false
if use_template
Log.debug "import_disk :use_template => true"
if !template_exist?(source)
Log.debug "import_disk, template does not exist, importing."
import_template(source, { :print_progress => print_progress })
end
copy_from_template(source, destination)
else
import_disk_convert source, destination, print_progress
end
end | [
"def",
"import_disk",
"(",
"source",
",",
"destination",
",",
"print_progress",
"=",
"false",
",",
"params",
"=",
"{",
"}",
")",
"use_template",
"=",
"params",
"[",
":use_template",
"]",
"||",
"false",
"if",
"use_template",
"Log",
".",
"debug",
"\"import_disk :use_template => true\"",
"if",
"!",
"template_exist?",
"(",
"source",
")",
"Log",
".",
"debug",
"\"import_disk, template does not exist, importing.\"",
"import_template",
"(",
"source",
",",
"{",
":print_progress",
"=>",
"print_progress",
"}",
")",
"end",
"copy_from_template",
"(",
"source",
",",
"destination",
")",
"else",
"import_disk_convert",
"source",
",",
"destination",
",",
"print_progress",
"end",
"end"
] | Imports a VMDK
if params has :use_template => true, the disk is saved as a template in
@templates_dir and cloned from there.
Destination directory must exist otherwise rises exception | [
"Imports",
"a",
"VMDK"
] | ac02f2ef1b6294dfaa811fe638250cb3c000eeb6 | https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L374-L386 | train |
maintux/esx | lib/esx.rb | ESX.Host.import_disk_convert | def import_disk_convert(source, destination, print_progress = false)
tmp_dest = destination + ".tmp"
Net::SSH.start(@address, @user, :password => @password) do |ssh|
if not (ssh.exec! "ls #{destination} 2>/dev/null").nil?
raise Exception.new("Destination file #{destination} already exists")
end
Log.info "Uploading file... (#{File.basename(source)})" if print_progress
ssh.scp.upload!(source, tmp_dest) do |ch, name, sent, total|
if print_progress
print "\rProgress: #{(sent.to_f * 100 / total.to_f).to_i}%"
end
end
if print_progress
Log.info "Converting disk..."
ssh.exec "vmkfstools -i #{tmp_dest} --diskformat thin #{destination}; rm -f #{tmp_dest}"
else
ssh.exec "vmkfstools -i #{tmp_dest} --diskformat thin #{destination} >/dev/null 2>&1; rm -f #{tmp_dest}"
end
end
end | ruby | def import_disk_convert(source, destination, print_progress = false)
tmp_dest = destination + ".tmp"
Net::SSH.start(@address, @user, :password => @password) do |ssh|
if not (ssh.exec! "ls #{destination} 2>/dev/null").nil?
raise Exception.new("Destination file #{destination} already exists")
end
Log.info "Uploading file... (#{File.basename(source)})" if print_progress
ssh.scp.upload!(source, tmp_dest) do |ch, name, sent, total|
if print_progress
print "\rProgress: #{(sent.to_f * 100 / total.to_f).to_i}%"
end
end
if print_progress
Log.info "Converting disk..."
ssh.exec "vmkfstools -i #{tmp_dest} --diskformat thin #{destination}; rm -f #{tmp_dest}"
else
ssh.exec "vmkfstools -i #{tmp_dest} --diskformat thin #{destination} >/dev/null 2>&1; rm -f #{tmp_dest}"
end
end
end | [
"def",
"import_disk_convert",
"(",
"source",
",",
"destination",
",",
"print_progress",
"=",
"false",
")",
"tmp_dest",
"=",
"destination",
"+",
"\".tmp\"",
"Net",
"::",
"SSH",
".",
"start",
"(",
"@address",
",",
"@user",
",",
":password",
"=>",
"@password",
")",
"do",
"|",
"ssh",
"|",
"if",
"not",
"(",
"ssh",
".",
"exec!",
"\"ls #{destination} 2>/dev/null\"",
")",
".",
"nil?",
"raise",
"Exception",
".",
"new",
"(",
"\"Destination file #{destination} already exists\"",
")",
"end",
"Log",
".",
"info",
"\"Uploading file... (#{File.basename(source)})\"",
"if",
"print_progress",
"ssh",
".",
"scp",
".",
"upload!",
"(",
"source",
",",
"tmp_dest",
")",
"do",
"|",
"ch",
",",
"name",
",",
"sent",
",",
"total",
"|",
"if",
"print_progress",
"print",
"\"\\rProgress: #{(sent.to_f * 100 / total.to_f).to_i}%\"",
"end",
"end",
"if",
"print_progress",
"Log",
".",
"info",
"\"Converting disk...\"",
"ssh",
".",
"exec",
"\"vmkfstools -i #{tmp_dest} --diskformat thin #{destination}; rm -f #{tmp_dest}\"",
"else",
"ssh",
".",
"exec",
"\"vmkfstools -i #{tmp_dest} --diskformat thin #{destination} >/dev/null 2>&1; rm -f #{tmp_dest}\"",
"end",
"end",
"end"
] | This method does all the heavy lifting when importing the disk.
It also converts the imported VMDK to thin format | [
"This",
"method",
"does",
"all",
"the",
"heavy",
"lifting",
"when",
"importing",
"the",
"disk",
".",
"It",
"also",
"converts",
"the",
"imported",
"VMDK",
"to",
"thin",
"format"
] | ac02f2ef1b6294dfaa811fe638250cb3c000eeb6 | https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L392-L411 | train |
maintux/esx | lib/esx.rb | ESX.Host.create_disk_spec | def create_disk_spec(params)
disk_type = params[:disk_type] || :flat
disk_file = params[:disk_file]
if disk_type == :sparse and disk_file.nil?
raise Exception.new("Creating sparse disks in ESX is not supported. Use an existing image.")
end
disk_size = params[:disk_size]
datastore = params[:datastore]
datastore = datastore + " #{disk_file}" if not disk_file.nil?
spec = {}
if disk_type == :sparse
spec = {
:operation => :add,
:device => RbVmomi::VIM.VirtualDisk(
:key => 0,
:backing => RbVmomi::VIM.VirtualDiskSparseVer2BackingInfo(
:fileName => datastore,
:diskMode => :persistent),
:controllerKey => 1000,
:unitNumber => 0,
:capacityInKB => disk_size)
}
else
spec = {
:operation => :add,
:device => RbVmomi::VIM.VirtualDisk(
:key => 0,
:backing => RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo(
:fileName => datastore,
:diskMode => :persistent),
:controllerKey => 1000,
:unitNumber => 0,
:capacityInKB => disk_size)
}
end
spec[:fileOperation] = :create if disk_file.nil?
spec
end | ruby | def create_disk_spec(params)
disk_type = params[:disk_type] || :flat
disk_file = params[:disk_file]
if disk_type == :sparse and disk_file.nil?
raise Exception.new("Creating sparse disks in ESX is not supported. Use an existing image.")
end
disk_size = params[:disk_size]
datastore = params[:datastore]
datastore = datastore + " #{disk_file}" if not disk_file.nil?
spec = {}
if disk_type == :sparse
spec = {
:operation => :add,
:device => RbVmomi::VIM.VirtualDisk(
:key => 0,
:backing => RbVmomi::VIM.VirtualDiskSparseVer2BackingInfo(
:fileName => datastore,
:diskMode => :persistent),
:controllerKey => 1000,
:unitNumber => 0,
:capacityInKB => disk_size)
}
else
spec = {
:operation => :add,
:device => RbVmomi::VIM.VirtualDisk(
:key => 0,
:backing => RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo(
:fileName => datastore,
:diskMode => :persistent),
:controllerKey => 1000,
:unitNumber => 0,
:capacityInKB => disk_size)
}
end
spec[:fileOperation] = :create if disk_file.nil?
spec
end | [
"def",
"create_disk_spec",
"(",
"params",
")",
"disk_type",
"=",
"params",
"[",
":disk_type",
"]",
"||",
":flat",
"disk_file",
"=",
"params",
"[",
":disk_file",
"]",
"if",
"disk_type",
"==",
":sparse",
"and",
"disk_file",
".",
"nil?",
"raise",
"Exception",
".",
"new",
"(",
"\"Creating sparse disks in ESX is not supported. Use an existing image.\"",
")",
"end",
"disk_size",
"=",
"params",
"[",
":disk_size",
"]",
"datastore",
"=",
"params",
"[",
":datastore",
"]",
"datastore",
"=",
"datastore",
"+",
"\" #{disk_file}\"",
"if",
"not",
"disk_file",
".",
"nil?",
"spec",
"=",
"{",
"}",
"if",
"disk_type",
"==",
":sparse",
"spec",
"=",
"{",
":operation",
"=>",
":add",
",",
":device",
"=>",
"RbVmomi",
"::",
"VIM",
".",
"VirtualDisk",
"(",
":key",
"=>",
"0",
",",
":backing",
"=>",
"RbVmomi",
"::",
"VIM",
".",
"VirtualDiskSparseVer2BackingInfo",
"(",
":fileName",
"=>",
"datastore",
",",
":diskMode",
"=>",
":persistent",
")",
",",
":controllerKey",
"=>",
"1000",
",",
":unitNumber",
"=>",
"0",
",",
":capacityInKB",
"=>",
"disk_size",
")",
"}",
"else",
"spec",
"=",
"{",
":operation",
"=>",
":add",
",",
":device",
"=>",
"RbVmomi",
"::",
"VIM",
".",
"VirtualDisk",
"(",
":key",
"=>",
"0",
",",
":backing",
"=>",
"RbVmomi",
"::",
"VIM",
".",
"VirtualDiskFlatVer2BackingInfo",
"(",
":fileName",
"=>",
"datastore",
",",
":diskMode",
"=>",
":persistent",
")",
",",
":controllerKey",
"=>",
"1000",
",",
":unitNumber",
"=>",
"0",
",",
":capacityInKB",
"=>",
"disk_size",
")",
"}",
"end",
"spec",
"[",
":fileOperation",
"]",
"=",
":create",
"if",
"disk_file",
".",
"nil?",
"spec",
"end"
] | disk_file
datastore
disk_size
disk_type | [
"disk_file",
"datastore",
"disk_size",
"disk_type"
] | ac02f2ef1b6294dfaa811fe638250cb3c000eeb6 | https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L424-L461 | train |
maintux/esx | lib/esx.rb | ESX.VM.destroy | def destroy
#disks = vm_object.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
unless host.free_license
vm_object.Destroy_Task.wait_for_completion
else
host.remote_command "vim-cmd vmsvc/power.off #{vmid}"
host.remote_command "vim-cmd vmsvc/destroy #{vmid}"
end
end | ruby | def destroy
#disks = vm_object.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
unless host.free_license
vm_object.Destroy_Task.wait_for_completion
else
host.remote_command "vim-cmd vmsvc/power.off #{vmid}"
host.remote_command "vim-cmd vmsvc/destroy #{vmid}"
end
end | [
"def",
"destroy",
"unless",
"host",
".",
"free_license",
"vm_object",
".",
"Destroy_Task",
".",
"wait_for_completion",
"else",
"host",
".",
"remote_command",
"\"vim-cmd vmsvc/power.off #{vmid}\"",
"host",
".",
"remote_command",
"\"vim-cmd vmsvc/destroy #{vmid}\"",
"end",
"end"
] | Destroy the VirtualMaching removing it from the inventory
and deleting the disk files | [
"Destroy",
"the",
"VirtualMaching",
"removing",
"it",
"from",
"the",
"inventory",
"and",
"deleting",
"the",
"disk",
"files"
] | ac02f2ef1b6294dfaa811fe638250cb3c000eeb6 | https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L524-L532 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_formatter.rb | RI.AttributeFormatter.write_attribute_text | def write_attribute_text(prefix, line)
print prefix
line.each do |achar|
print achar.char
end
puts
end | ruby | def write_attribute_text(prefix, line)
print prefix
line.each do |achar|
print achar.char
end
puts
end | [
"def",
"write_attribute_text",
"(",
"prefix",
",",
"line",
")",
"print",
"prefix",
"line",
".",
"each",
"do",
"|",
"achar",
"|",
"print",
"achar",
".",
"char",
"end",
"puts",
"end"
] | overridden in specific formatters | [
"overridden",
"in",
"specific",
"formatters"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_formatter.rb#L331-L337 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_formatter.rb | RI.OverstrikeFormatter.bold_print | def bold_print(text)
text.split(//).each do |ch|
print ch, BS, ch
end
end | ruby | def bold_print(text)
text.split(//).each do |ch|
print ch, BS, ch
end
end | [
"def",
"bold_print",
"(",
"text",
")",
"text",
".",
"split",
"(",
"/",
"/",
")",
".",
"each",
"do",
"|",
"ch",
"|",
"print",
"ch",
",",
"BS",
",",
"ch",
"end",
"end"
] | draw a string in bold | [
"draw",
"a",
"string",
"in",
"bold"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_formatter.rb#L390-L394 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_formatter.rb | RI.SimpleFormatter.display_heading | def display_heading(text, level, indent)
text = strip_attributes(text)
case level
when 1
puts "= " + text.upcase
when 2
puts "-- " + text
else
print indent, text, "\n"
end
end | ruby | def display_heading(text, level, indent)
text = strip_attributes(text)
case level
when 1
puts "= " + text.upcase
when 2
puts "-- " + text
else
print indent, text, "\n"
end
end | [
"def",
"display_heading",
"(",
"text",
",",
"level",
",",
"indent",
")",
"text",
"=",
"strip_attributes",
"(",
"text",
")",
"case",
"level",
"when",
"1",
"puts",
"\"= \"",
"+",
"text",
".",
"upcase",
"when",
"2",
"puts",
"\"-- \"",
"+",
"text",
"else",
"print",
"indent",
",",
"text",
",",
"\"\\n\"",
"end",
"end"
] | Place heading level indicators inline with heading. | [
"Place",
"heading",
"level",
"indicators",
"inline",
"with",
"heading",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_formatter.rb#L633-L643 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/request.rb | Rack.Request.POST | def POST
if @env["rack.request.form_input"].eql? @env["rack.input"]
@env["rack.request.form_hash"]
elsif form_data? || parseable_data?
@env["rack.request.form_input"] = @env["rack.input"]
unless @env["rack.request.form_hash"] =
Utils::Multipart.parse_multipart(env)
form_vars = @env["rack.input"].read
# Fix for Safari Ajax postings that always append \0
form_vars.sub!(/\0\z/, '')
@env["rack.request.form_vars"] = form_vars
@env["rack.request.form_hash"] = Utils.parse_nested_query(form_vars)
@env["rack.input"].rewind
end
@env["rack.request.form_hash"]
else
{}
end
end | ruby | def POST
if @env["rack.request.form_input"].eql? @env["rack.input"]
@env["rack.request.form_hash"]
elsif form_data? || parseable_data?
@env["rack.request.form_input"] = @env["rack.input"]
unless @env["rack.request.form_hash"] =
Utils::Multipart.parse_multipart(env)
form_vars = @env["rack.input"].read
# Fix for Safari Ajax postings that always append \0
form_vars.sub!(/\0\z/, '')
@env["rack.request.form_vars"] = form_vars
@env["rack.request.form_hash"] = Utils.parse_nested_query(form_vars)
@env["rack.input"].rewind
end
@env["rack.request.form_hash"]
else
{}
end
end | [
"def",
"POST",
"if",
"@env",
"[",
"\"rack.request.form_input\"",
"]",
".",
"eql?",
"@env",
"[",
"\"rack.input\"",
"]",
"@env",
"[",
"\"rack.request.form_hash\"",
"]",
"elsif",
"form_data?",
"||",
"parseable_data?",
"@env",
"[",
"\"rack.request.form_input\"",
"]",
"=",
"@env",
"[",
"\"rack.input\"",
"]",
"unless",
"@env",
"[",
"\"rack.request.form_hash\"",
"]",
"=",
"Utils",
"::",
"Multipart",
".",
"parse_multipart",
"(",
"env",
")",
"form_vars",
"=",
"@env",
"[",
"\"rack.input\"",
"]",
".",
"read",
"form_vars",
".",
"sub!",
"(",
"/",
"\\0",
"\\z",
"/",
",",
"''",
")",
"@env",
"[",
"\"rack.request.form_vars\"",
"]",
"=",
"form_vars",
"@env",
"[",
"\"rack.request.form_hash\"",
"]",
"=",
"Utils",
".",
"parse_nested_query",
"(",
"form_vars",
")",
"@env",
"[",
"\"rack.input\"",
"]",
".",
"rewind",
"end",
"@env",
"[",
"\"rack.request.form_hash\"",
"]",
"else",
"{",
"}",
"end",
"end"
] | Returns the data recieved in the request body.
This method support both application/x-www-form-urlencoded and
multipart/form-data. | [
"Returns",
"the",
"data",
"recieved",
"in",
"the",
"request",
"body",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/request.rb#L127-L148 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/request.rb | Rack.Request.url | def url
url = scheme + "://"
url << host
if scheme == "https" && port != 443 ||
scheme == "http" && port != 80
url << ":#{port}"
end
url << fullpath
url
end | ruby | def url
url = scheme + "://"
url << host
if scheme == "https" && port != 443 ||
scheme == "http" && port != 80
url << ":#{port}"
end
url << fullpath
url
end | [
"def",
"url",
"url",
"=",
"scheme",
"+",
"\"://\"",
"url",
"<<",
"host",
"if",
"scheme",
"==",
"\"https\"",
"&&",
"port",
"!=",
"443",
"||",
"scheme",
"==",
"\"http\"",
"&&",
"port",
"!=",
"80",
"url",
"<<",
"\":#{port}\"",
"end",
"url",
"<<",
"fullpath",
"url",
"end"
] | Tries to return a remake of the original request URL as a string. | [
"Tries",
"to",
"return",
"a",
"remake",
"of",
"the",
"original",
"request",
"URL",
"as",
"a",
"string",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/request.rb#L204-L216 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb | DRb.DRbProtocol.open | def open(uri, config, first=true)
@protocol.each do |prot|
begin
return prot.open(uri, config)
rescue DRbBadScheme
rescue DRbConnError
raise($!)
rescue
raise(DRbConnError, "#{uri} - #{$!.inspect}")
end
end
if first && (config[:auto_load] != false)
auto_load(uri, config)
return open(uri, config, false)
end
raise DRbBadURI, 'can\'t parse uri:' + uri
end | ruby | def open(uri, config, first=true)
@protocol.each do |prot|
begin
return prot.open(uri, config)
rescue DRbBadScheme
rescue DRbConnError
raise($!)
rescue
raise(DRbConnError, "#{uri} - #{$!.inspect}")
end
end
if first && (config[:auto_load] != false)
auto_load(uri, config)
return open(uri, config, false)
end
raise DRbBadURI, 'can\'t parse uri:' + uri
end | [
"def",
"open",
"(",
"uri",
",",
"config",
",",
"first",
"=",
"true",
")",
"@protocol",
".",
"each",
"do",
"|",
"prot",
"|",
"begin",
"return",
"prot",
".",
"open",
"(",
"uri",
",",
"config",
")",
"rescue",
"DRbBadScheme",
"rescue",
"DRbConnError",
"raise",
"(",
"$!",
")",
"rescue",
"raise",
"(",
"DRbConnError",
",",
"\"#{uri} - #{$!.inspect}\"",
")",
"end",
"end",
"if",
"first",
"&&",
"(",
"config",
"[",
":auto_load",
"]",
"!=",
"false",
")",
"auto_load",
"(",
"uri",
",",
"config",
")",
"return",
"open",
"(",
"uri",
",",
"config",
",",
"false",
")",
"end",
"raise",
"DRbBadURI",
",",
"'can\\'t parse uri:'",
"+",
"uri",
"end"
] | Open a client connection to +uri+ with the configuration +config+.
The DRbProtocol module asks each registered protocol in turn to
try to open the URI. Each protocol signals that it does not handle that
URI by raising a DRbBadScheme error. If no protocol recognises the
URI, then a DRbBadURI error is raised. If a protocol accepts the
URI, but an error occurs in opening it, a DRbConnError is raised. | [
"Open",
"a",
"client",
"connection",
"to",
"+",
"uri",
"+",
"with",
"the",
"configuration",
"+",
"config",
"+",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L758-L774 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb | DRb.DRbProtocol.open_server | def open_server(uri, config, first=true)
@protocol.each do |prot|
begin
return prot.open_server(uri, config)
rescue DRbBadScheme
end
end
if first && (config[:auto_load] != false)
auto_load(uri, config)
return open_server(uri, config, false)
end
raise DRbBadURI, 'can\'t parse uri:' + uri
end | ruby | def open_server(uri, config, first=true)
@protocol.each do |prot|
begin
return prot.open_server(uri, config)
rescue DRbBadScheme
end
end
if first && (config[:auto_load] != false)
auto_load(uri, config)
return open_server(uri, config, false)
end
raise DRbBadURI, 'can\'t parse uri:' + uri
end | [
"def",
"open_server",
"(",
"uri",
",",
"config",
",",
"first",
"=",
"true",
")",
"@protocol",
".",
"each",
"do",
"|",
"prot",
"|",
"begin",
"return",
"prot",
".",
"open_server",
"(",
"uri",
",",
"config",
")",
"rescue",
"DRbBadScheme",
"end",
"end",
"if",
"first",
"&&",
"(",
"config",
"[",
":auto_load",
"]",
"!=",
"false",
")",
"auto_load",
"(",
"uri",
",",
"config",
")",
"return",
"open_server",
"(",
"uri",
",",
"config",
",",
"false",
")",
"end",
"raise",
"DRbBadURI",
",",
"'can\\'t parse uri:'",
"+",
"uri",
"end"
] | Open a server listening for connections at +uri+ with
configuration +config+.
The DRbProtocol module asks each registered protocol in turn to
try to open a server at the URI. Each protocol signals that it does
not handle that URI by raising a DRbBadScheme error. If no protocol
recognises the URI, then a DRbBadURI error is raised. If a protocol
accepts the URI, but an error occurs in opening it, the underlying
error is passed on to the caller. | [
"Open",
"a",
"server",
"listening",
"for",
"connections",
"at",
"+",
"uri",
"+",
"with",
"configuration",
"+",
"config",
"+",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L786-L798 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb | DRb.DRbTCPSocket.send_request | def send_request(ref, msg_id, arg, b)
@msg.send_request(stream, ref, msg_id, arg, b)
end | ruby | def send_request(ref, msg_id, arg, b)
@msg.send_request(stream, ref, msg_id, arg, b)
end | [
"def",
"send_request",
"(",
"ref",
",",
"msg_id",
",",
"arg",
",",
"b",
")",
"@msg",
".",
"send_request",
"(",
"stream",
",",
"ref",
",",
"msg_id",
",",
"arg",
",",
"b",
")",
"end"
] | On the client side, send a request to the server. | [
"On",
"the",
"client",
"side",
"send",
"a",
"request",
"to",
"the",
"server",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L937-L939 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb | DRb.DRbObject.method_missing | def method_missing(msg_id, *a, &b)
if DRb.here?(@uri)
obj = DRb.to_obj(@ref)
DRb.current_server.check_insecure_method(obj, msg_id)
return obj.__send__(msg_id, *a, &b)
end
succ, result = self.class.with_friend(@uri) do
DRbConn.open(@uri) do |conn|
conn.send_message(self, msg_id, a, b)
end
end
if succ
return result
elsif DRbUnknown === result
raise result
else
bt = self.class.prepare_backtrace(@uri, result)
result.set_backtrace(bt + caller)
raise result
end
end | ruby | def method_missing(msg_id, *a, &b)
if DRb.here?(@uri)
obj = DRb.to_obj(@ref)
DRb.current_server.check_insecure_method(obj, msg_id)
return obj.__send__(msg_id, *a, &b)
end
succ, result = self.class.with_friend(@uri) do
DRbConn.open(@uri) do |conn|
conn.send_message(self, msg_id, a, b)
end
end
if succ
return result
elsif DRbUnknown === result
raise result
else
bt = self.class.prepare_backtrace(@uri, result)
result.set_backtrace(bt + caller)
raise result
end
end | [
"def",
"method_missing",
"(",
"msg_id",
",",
"*",
"a",
",",
"&",
"b",
")",
"if",
"DRb",
".",
"here?",
"(",
"@uri",
")",
"obj",
"=",
"DRb",
".",
"to_obj",
"(",
"@ref",
")",
"DRb",
".",
"current_server",
".",
"check_insecure_method",
"(",
"obj",
",",
"msg_id",
")",
"return",
"obj",
".",
"__send__",
"(",
"msg_id",
",",
"*",
"a",
",",
"&",
"b",
")",
"end",
"succ",
",",
"result",
"=",
"self",
".",
"class",
".",
"with_friend",
"(",
"@uri",
")",
"do",
"DRbConn",
".",
"open",
"(",
"@uri",
")",
"do",
"|",
"conn",
"|",
"conn",
".",
"send_message",
"(",
"self",
",",
"msg_id",
",",
"a",
",",
"b",
")",
"end",
"end",
"if",
"succ",
"return",
"result",
"elsif",
"DRbUnknown",
"===",
"result",
"raise",
"result",
"else",
"bt",
"=",
"self",
".",
"class",
".",
"prepare_backtrace",
"(",
"@uri",
",",
"result",
")",
"result",
".",
"set_backtrace",
"(",
"bt",
"+",
"caller",
")",
"raise",
"result",
"end",
"end"
] | Routes method calls to the referenced object. | [
"Routes",
"method",
"calls",
"to",
"the",
"referenced",
"object",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L1114-L1136 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb | DRb.DRbServer.stop_service | def stop_service
DRb.remove_server(self)
if Thread.current['DRb'] && Thread.current['DRb']['server'] == self
Thread.current['DRb']['stop_service'] = true
else
@thread.kill
end
end | ruby | def stop_service
DRb.remove_server(self)
if Thread.current['DRb'] && Thread.current['DRb']['server'] == self
Thread.current['DRb']['stop_service'] = true
else
@thread.kill
end
end | [
"def",
"stop_service",
"DRb",
".",
"remove_server",
"(",
"self",
")",
"if",
"Thread",
".",
"current",
"[",
"'DRb'",
"]",
"&&",
"Thread",
".",
"current",
"[",
"'DRb'",
"]",
"[",
"'server'",
"]",
"==",
"self",
"Thread",
".",
"current",
"[",
"'DRb'",
"]",
"[",
"'stop_service'",
"]",
"=",
"true",
"else",
"@thread",
".",
"kill",
"end",
"end"
] | Stop this server. | [
"Stop",
"this",
"server",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L1427-L1434 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb | DRb.DRbServer.to_obj | def to_obj(ref)
return front if ref.nil?
return front[ref.to_s] if DRbURIOption === ref
@idconv.to_obj(ref)
end | ruby | def to_obj(ref)
return front if ref.nil?
return front[ref.to_s] if DRbURIOption === ref
@idconv.to_obj(ref)
end | [
"def",
"to_obj",
"(",
"ref",
")",
"return",
"front",
"if",
"ref",
".",
"nil?",
"return",
"front",
"[",
"ref",
".",
"to_s",
"]",
"if",
"DRbURIOption",
"===",
"ref",
"@idconv",
".",
"to_obj",
"(",
"ref",
")",
"end"
] | Convert a dRuby reference to the local object it refers to. | [
"Convert",
"a",
"dRuby",
"reference",
"to",
"the",
"local",
"object",
"it",
"refers",
"to",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L1437-L1441 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb | DRb.DRbServer.check_insecure_method | def check_insecure_method(obj, msg_id)
return true if Proc === obj && msg_id == :__drb_yield
raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class
raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id)
if obj.private_methods.include?(msg_id.to_s)
desc = any_to_s(obj)
raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
elsif obj.protected_methods.include?(msg_id.to_s)
desc = any_to_s(obj)
raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
else
true
end
end | ruby | def check_insecure_method(obj, msg_id)
return true if Proc === obj && msg_id == :__drb_yield
raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class
raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id)
if obj.private_methods.include?(msg_id.to_s)
desc = any_to_s(obj)
raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
elsif obj.protected_methods.include?(msg_id.to_s)
desc = any_to_s(obj)
raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
else
true
end
end | [
"def",
"check_insecure_method",
"(",
"obj",
",",
"msg_id",
")",
"return",
"true",
"if",
"Proc",
"===",
"obj",
"&&",
"msg_id",
"==",
":__drb_yield",
"raise",
"(",
"ArgumentError",
",",
"\"#{any_to_s(msg_id)} is not a symbol\"",
")",
"unless",
"Symbol",
"==",
"msg_id",
".",
"class",
"raise",
"(",
"SecurityError",
",",
"\"insecure method `#{msg_id}'\"",
")",
"if",
"insecure_method?",
"(",
"msg_id",
")",
"if",
"obj",
".",
"private_methods",
".",
"include?",
"(",
"msg_id",
".",
"to_s",
")",
"desc",
"=",
"any_to_s",
"(",
"obj",
")",
"raise",
"NoMethodError",
",",
"\"private method `#{msg_id}' called for #{desc}\"",
"elsif",
"obj",
".",
"protected_methods",
".",
"include?",
"(",
"msg_id",
".",
"to_s",
")",
"desc",
"=",
"any_to_s",
"(",
"obj",
")",
"raise",
"NoMethodError",
",",
"\"protected method `#{msg_id}' called for #{desc}\"",
"else",
"true",
"end",
"end"
] | Check that a method is callable via dRuby.
+obj+ is the object we want to invoke the method on. +msg_id+ is the
method name, as a Symbol.
If the method is an insecure method (see #insecure_method?) a
SecurityError is thrown. If the method is private or undefined,
a NameError is thrown. | [
"Check",
"that",
"a",
"method",
"is",
"callable",
"via",
"dRuby",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L1505-L1519 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb | DRb.DRbServer.main_loop | def main_loop
Thread.start(@protocol.accept) do |client|
@grp.add Thread.current
Thread.current['DRb'] = { 'client' => client ,
'server' => self }
loop do
begin
succ = false
invoke_method = InvokeMethod.new(self, client)
succ, result = invoke_method.perform
if !succ && verbose
p result
result.backtrace.each do |x|
puts x
end
end
client.send_reply(succ, result) rescue nil
ensure
client.close unless succ
if Thread.current['DRb']['stop_service']
Thread.new { stop_service }
end
break unless succ
end
end
end
end | ruby | def main_loop
Thread.start(@protocol.accept) do |client|
@grp.add Thread.current
Thread.current['DRb'] = { 'client' => client ,
'server' => self }
loop do
begin
succ = false
invoke_method = InvokeMethod.new(self, client)
succ, result = invoke_method.perform
if !succ && verbose
p result
result.backtrace.each do |x|
puts x
end
end
client.send_reply(succ, result) rescue nil
ensure
client.close unless succ
if Thread.current['DRb']['stop_service']
Thread.new { stop_service }
end
break unless succ
end
end
end
end | [
"def",
"main_loop",
"Thread",
".",
"start",
"(",
"@protocol",
".",
"accept",
")",
"do",
"|",
"client",
"|",
"@grp",
".",
"add",
"Thread",
".",
"current",
"Thread",
".",
"current",
"[",
"'DRb'",
"]",
"=",
"{",
"'client'",
"=>",
"client",
",",
"'server'",
"=>",
"self",
"}",
"loop",
"do",
"begin",
"succ",
"=",
"false",
"invoke_method",
"=",
"InvokeMethod",
".",
"new",
"(",
"self",
",",
"client",
")",
"succ",
",",
"result",
"=",
"invoke_method",
".",
"perform",
"if",
"!",
"succ",
"&&",
"verbose",
"p",
"result",
"result",
".",
"backtrace",
".",
"each",
"do",
"|",
"x",
"|",
"puts",
"x",
"end",
"end",
"client",
".",
"send_reply",
"(",
"succ",
",",
"result",
")",
"rescue",
"nil",
"ensure",
"client",
".",
"close",
"unless",
"succ",
"if",
"Thread",
".",
"current",
"[",
"'DRb'",
"]",
"[",
"'stop_service'",
"]",
"Thread",
".",
"new",
"{",
"stop_service",
"}",
"end",
"break",
"unless",
"succ",
"end",
"end",
"end",
"end"
] | The main loop performed by a DRbServer's internal thread.
Accepts a connection from a client, and starts up its own
thread to handle it. This thread loops, receiving requests
from the client, invoking them on a local object, and
returning responses, until the client closes the connection
or a local method call fails. | [
"The",
"main",
"loop",
"performed",
"by",
"a",
"DRbServer",
"s",
"internal",
"thread",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L1618-L1644 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7-java/lib/jdbc_adapter/jdbc_postgre.rb | ::JdbcSpec.PostgreSQL.supports_standard_conforming_strings? | def supports_standard_conforming_strings?
# Temporarily set the client message level above error to prevent unintentional
# error messages in the logs when working on a PostgreSQL database server that
# does not support standard conforming strings.
client_min_messages_old = client_min_messages
self.client_min_messages = 'panic'
# postgres-pr does not raise an exception when client_min_messages is set higher
# than error and "SHOW standard_conforming_strings" fails, but returns an empty
# PGresult instead.
has_support = select('SHOW standard_conforming_strings').to_a[0][0] rescue false
self.client_min_messages = client_min_messages_old
has_support
end | ruby | def supports_standard_conforming_strings?
# Temporarily set the client message level above error to prevent unintentional
# error messages in the logs when working on a PostgreSQL database server that
# does not support standard conforming strings.
client_min_messages_old = client_min_messages
self.client_min_messages = 'panic'
# postgres-pr does not raise an exception when client_min_messages is set higher
# than error and "SHOW standard_conforming_strings" fails, but returns an empty
# PGresult instead.
has_support = select('SHOW standard_conforming_strings').to_a[0][0] rescue false
self.client_min_messages = client_min_messages_old
has_support
end | [
"def",
"supports_standard_conforming_strings?",
"client_min_messages_old",
"=",
"client_min_messages",
"self",
".",
"client_min_messages",
"=",
"'panic'",
"has_support",
"=",
"select",
"(",
"'SHOW standard_conforming_strings'",
")",
".",
"to_a",
"[",
"0",
"]",
"[",
"0",
"]",
"rescue",
"false",
"self",
".",
"client_min_messages",
"=",
"client_min_messages_old",
"has_support",
"end"
] | Does PostgreSQL support standard conforming strings? | [
"Does",
"PostgreSQL",
"support",
"standard",
"conforming",
"strings?"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7-java/lib/jdbc_adapter/jdbc_postgre.rb#L120-L133 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rdoctask.rb | Rake.RDocTask.define | def define
if rdoc_task_name != "rdoc"
desc "Build the RDOC HTML Files"
else
desc "Build the #{rdoc_task_name} HTML Files"
end
task rdoc_task_name
desc "Force a rebuild of the RDOC files"
task rerdoc_task_name => [clobber_task_name, rdoc_task_name]
desc "Remove rdoc products"
task clobber_task_name do
rm_r rdoc_dir rescue nil
end
task :clobber => [clobber_task_name]
directory @rdoc_dir
task rdoc_task_name => [rdoc_target]
file rdoc_target => @rdoc_files + [Rake.application.rakefile] do
rm_r @rdoc_dir rescue nil
@before_running_rdoc.call if @before_running_rdoc
args = option_list + @rdoc_files
if @external
argstring = args.join(' ')
sh %{ruby -Ivendor vendor/rd #{argstring}}
else
require 'rdoc/rdoc'
RDoc::RDoc.new.document(args)
end
end
self
end | ruby | def define
if rdoc_task_name != "rdoc"
desc "Build the RDOC HTML Files"
else
desc "Build the #{rdoc_task_name} HTML Files"
end
task rdoc_task_name
desc "Force a rebuild of the RDOC files"
task rerdoc_task_name => [clobber_task_name, rdoc_task_name]
desc "Remove rdoc products"
task clobber_task_name do
rm_r rdoc_dir rescue nil
end
task :clobber => [clobber_task_name]
directory @rdoc_dir
task rdoc_task_name => [rdoc_target]
file rdoc_target => @rdoc_files + [Rake.application.rakefile] do
rm_r @rdoc_dir rescue nil
@before_running_rdoc.call if @before_running_rdoc
args = option_list + @rdoc_files
if @external
argstring = args.join(' ')
sh %{ruby -Ivendor vendor/rd #{argstring}}
else
require 'rdoc/rdoc'
RDoc::RDoc.new.document(args)
end
end
self
end | [
"def",
"define",
"if",
"rdoc_task_name",
"!=",
"\"rdoc\"",
"desc",
"\"Build the RDOC HTML Files\"",
"else",
"desc",
"\"Build the #{rdoc_task_name} HTML Files\"",
"end",
"task",
"rdoc_task_name",
"desc",
"\"Force a rebuild of the RDOC files\"",
"task",
"rerdoc_task_name",
"=>",
"[",
"clobber_task_name",
",",
"rdoc_task_name",
"]",
"desc",
"\"Remove rdoc products\"",
"task",
"clobber_task_name",
"do",
"rm_r",
"rdoc_dir",
"rescue",
"nil",
"end",
"task",
":clobber",
"=>",
"[",
"clobber_task_name",
"]",
"directory",
"@rdoc_dir",
"task",
"rdoc_task_name",
"=>",
"[",
"rdoc_target",
"]",
"file",
"rdoc_target",
"=>",
"@rdoc_files",
"+",
"[",
"Rake",
".",
"application",
".",
"rakefile",
"]",
"do",
"rm_r",
"@rdoc_dir",
"rescue",
"nil",
"@before_running_rdoc",
".",
"call",
"if",
"@before_running_rdoc",
"args",
"=",
"option_list",
"+",
"@rdoc_files",
"if",
"@external",
"argstring",
"=",
"args",
".",
"join",
"(",
"' '",
")",
"sh",
"%{ruby -Ivendor vendor/rd #{argstring}}",
"else",
"require",
"'rdoc/rdoc'",
"RDoc",
"::",
"RDoc",
".",
"new",
".",
"document",
"(",
"args",
")",
"end",
"end",
"self",
"end"
] | Create an RDoc task with the given name. See the RDocTask class overview
for documentation.
Create the tasks defined by this task lib. | [
"Create",
"an",
"RDoc",
"task",
"with",
"the",
"given",
"name",
".",
"See",
"the",
"RDocTask",
"class",
"overview",
"for",
"documentation",
".",
"Create",
"the",
"tasks",
"defined",
"by",
"this",
"task",
"lib",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rdoctask.rb#L111-L144 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/runit/assert.rb | RUNIT.Assert.assert_match | def assert_match(actual_string, expected_re, message="")
_wrap_assertion {
full_message = build_message(message, "Expected <?> to match <?>", actual_string, expected_re)
assert_block(full_message) {
expected_re =~ actual_string
}
Regexp.last_match
}
end | ruby | def assert_match(actual_string, expected_re, message="")
_wrap_assertion {
full_message = build_message(message, "Expected <?> to match <?>", actual_string, expected_re)
assert_block(full_message) {
expected_re =~ actual_string
}
Regexp.last_match
}
end | [
"def",
"assert_match",
"(",
"actual_string",
",",
"expected_re",
",",
"message",
"=",
"\"\"",
")",
"_wrap_assertion",
"{",
"full_message",
"=",
"build_message",
"(",
"message",
",",
"\"Expected <?> to match <?>\"",
",",
"actual_string",
",",
"expected_re",
")",
"assert_block",
"(",
"full_message",
")",
"{",
"expected_re",
"=~",
"actual_string",
"}",
"Regexp",
".",
"last_match",
"}",
"end"
] | To deal with the fact that RubyUnit does not check that the
regular expression is, indeed, a regular expression, if it is
not, we do our own assertion using the same semantics as
RubyUnit | [
"To",
"deal",
"with",
"the",
"fact",
"that",
"RubyUnit",
"does",
"not",
"check",
"that",
"the",
"regular",
"expression",
"is",
"indeed",
"a",
"regular",
"expression",
"if",
"it",
"is",
"not",
"we",
"do",
"our",
"own",
"assertion",
"using",
"the",
"same",
"semantics",
"as",
"RubyUnit"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/runit/assert.rb#L23-L31 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/gempackagetask.rb | Rake.GemPackageTask.init | def init(gem)
super(gem.name, gem.version)
@gem_spec = gem
@package_files += gem_spec.files if gem_spec.files
end | ruby | def init(gem)
super(gem.name, gem.version)
@gem_spec = gem
@package_files += gem_spec.files if gem_spec.files
end | [
"def",
"init",
"(",
"gem",
")",
"super",
"(",
"gem",
".",
"name",
",",
"gem",
".",
"version",
")",
"@gem_spec",
"=",
"gem",
"@package_files",
"+=",
"gem_spec",
".",
"files",
"if",
"gem_spec",
".",
"files",
"end"
] | Create a GEM Package task library. Automatically define the gem
if a block is given. If no block is supplied, then +define+
needs to be called to define the task.
Initialization tasks without the "yield self" or define
operations. | [
"Create",
"a",
"GEM",
"Package",
"task",
"library",
".",
"Automatically",
"define",
"the",
"gem",
"if",
"a",
"block",
"is",
"given",
".",
"If",
"no",
"block",
"is",
"supplied",
"then",
"+",
"define",
"+",
"needs",
"to",
"be",
"called",
"to",
"define",
"the",
"task",
".",
"Initialization",
"tasks",
"without",
"the",
"yield",
"self",
"or",
"define",
"operations",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/gempackagetask.rb#L64-L68 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/xml_mini/rexml.rb | ActiveSupport.XmlMini_REXML.parse | def parse(string)
require 'rexml/document' unless defined?(REXML::Document)
doc = REXML::Document.new(string)
merge_element!({}, doc.root)
end | ruby | def parse(string)
require 'rexml/document' unless defined?(REXML::Document)
doc = REXML::Document.new(string)
merge_element!({}, doc.root)
end | [
"def",
"parse",
"(",
"string",
")",
"require",
"'rexml/document'",
"unless",
"defined?",
"(",
"REXML",
"::",
"Document",
")",
"doc",
"=",
"REXML",
"::",
"Document",
".",
"new",
"(",
"string",
")",
"merge_element!",
"(",
"{",
"}",
",",
"doc",
".",
"root",
")",
"end"
] | Parse an XML Document string into a simple hash
Same as XmlSimple::xml_in but doesn't shoot itself in the foot,
and uses the defaults from ActiveSupport
string::
XML Document string to parse | [
"Parse",
"an",
"XML",
"Document",
"string",
"into",
"a",
"simple",
"hash"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/xml_mini/rexml.rb#L15-L19 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/to_html.rb | SM.ToHtml.init_tags | def init_tags
@attr_tags = [
InlineTag.new(SM::Attribute.bitmap_for(:BOLD), "<b>", "</b>"),
InlineTag.new(SM::Attribute.bitmap_for(:TT), "<tt>", "</tt>"),
InlineTag.new(SM::Attribute.bitmap_for(:EM), "<em>", "</em>"),
]
end | ruby | def init_tags
@attr_tags = [
InlineTag.new(SM::Attribute.bitmap_for(:BOLD), "<b>", "</b>"),
InlineTag.new(SM::Attribute.bitmap_for(:TT), "<tt>", "</tt>"),
InlineTag.new(SM::Attribute.bitmap_for(:EM), "<em>", "</em>"),
]
end | [
"def",
"init_tags",
"@attr_tags",
"=",
"[",
"InlineTag",
".",
"new",
"(",
"SM",
"::",
"Attribute",
".",
"bitmap_for",
"(",
":BOLD",
")",
",",
"\"<b>\"",
",",
"\"</b>\"",
")",
",",
"InlineTag",
".",
"new",
"(",
"SM",
"::",
"Attribute",
".",
"bitmap_for",
"(",
":TT",
")",
",",
"\"<tt>\"",
",",
"\"</tt>\"",
")",
",",
"InlineTag",
".",
"new",
"(",
"SM",
"::",
"Attribute",
".",
"bitmap_for",
"(",
":EM",
")",
",",
"\"<em>\"",
",",
"\"</em>\"",
")",
",",
"]",
"end"
] | Set up the standard mapping of attributes to HTML tags | [
"Set",
"up",
"the",
"standard",
"mapping",
"of",
"attributes",
"to",
"HTML",
"tags"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/to_html.rb#L28-L34 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/to_html.rb | SM.ToHtml.add_tag | def add_tag(name, start, stop)
@attr_tags << InlineTag.new(SM::Attribute.bitmap_for(name), start, stop)
end | ruby | def add_tag(name, start, stop)
@attr_tags << InlineTag.new(SM::Attribute.bitmap_for(name), start, stop)
end | [
"def",
"add_tag",
"(",
"name",
",",
"start",
",",
"stop",
")",
"@attr_tags",
"<<",
"InlineTag",
".",
"new",
"(",
"SM",
"::",
"Attribute",
".",
"bitmap_for",
"(",
"name",
")",
",",
"start",
",",
"stop",
")",
"end"
] | Add a new set of HTML tags for an attribute. We allow
separate start and end tags for flexibility | [
"Add",
"a",
"new",
"set",
"of",
"HTML",
"tags",
"for",
"an",
"attribute",
".",
"We",
"allow",
"separate",
"start",
"and",
"end",
"tags",
"for",
"flexibility"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/to_html.rb#L40-L42 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/net/http.rb | Net.HTTPHeader.set_form_data | def set_form_data(params, sep = '&')
self.body = params.map {|k,v| "#{urlencode(k.to_s)}=#{urlencode(v.to_s)}" }.join(sep)
self.content_type = 'application/x-www-form-urlencoded'
end | ruby | def set_form_data(params, sep = '&')
self.body = params.map {|k,v| "#{urlencode(k.to_s)}=#{urlencode(v.to_s)}" }.join(sep)
self.content_type = 'application/x-www-form-urlencoded'
end | [
"def",
"set_form_data",
"(",
"params",
",",
"sep",
"=",
"'&'",
")",
"self",
".",
"body",
"=",
"params",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"\"#{urlencode(k.to_s)}=#{urlencode(v.to_s)}\"",
"}",
".",
"join",
"(",
"sep",
")",
"self",
".",
"content_type",
"=",
"'application/x-www-form-urlencoded'",
"end"
] | Set header fields and a body from HTML form data.
+params+ should be a Hash containing HTML form data.
Optional argument +sep+ means data record separator.
This method also set Content-Type: header field to
application/x-www-form-urlencoded. | [
"Set",
"header",
"fields",
"and",
"a",
"body",
"from",
"HTML",
"form",
"data",
".",
"+",
"params",
"+",
"should",
"be",
"a",
"Hash",
"containing",
"HTML",
"form",
"data",
".",
"Optional",
"argument",
"+",
"sep",
"+",
"means",
"data",
"record",
"separator",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/net/http.rb#L1432-L1435 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rinda/rinda.rb | Rinda.Tuple.each | def each # FIXME
if Hash === @tuple
@tuple.each { |k, v| yield(k, v) }
else
@tuple.each_with_index { |v, k| yield(k, v) }
end
end | ruby | def each # FIXME
if Hash === @tuple
@tuple.each { |k, v| yield(k, v) }
else
@tuple.each_with_index { |v, k| yield(k, v) }
end
end | [
"def",
"each",
"if",
"Hash",
"===",
"@tuple",
"@tuple",
".",
"each",
"{",
"|",
"k",
",",
"v",
"|",
"yield",
"(",
"k",
",",
"v",
")",
"}",
"else",
"@tuple",
".",
"each_with_index",
"{",
"|",
"v",
",",
"k",
"|",
"yield",
"(",
"k",
",",
"v",
")",
"}",
"end",
"end"
] | Iterate through the tuple, yielding the index or key, and the
value, thus ensuring arrays are iterated similarly to hashes. | [
"Iterate",
"through",
"the",
"tuple",
"yielding",
"the",
"index",
"or",
"key",
"and",
"the",
"value",
"thus",
"ensuring",
"arrays",
"are",
"iterated",
"similarly",
"to",
"hashes",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/rinda.rb#L84-L90 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rinda/rinda.rb | Rinda.Tuple.init_with_ary | def init_with_ary(ary)
@tuple = Array.new(ary.size)
@tuple.size.times do |i|
@tuple[i] = ary[i]
end
end | ruby | def init_with_ary(ary)
@tuple = Array.new(ary.size)
@tuple.size.times do |i|
@tuple[i] = ary[i]
end
end | [
"def",
"init_with_ary",
"(",
"ary",
")",
"@tuple",
"=",
"Array",
".",
"new",
"(",
"ary",
".",
"size",
")",
"@tuple",
".",
"size",
".",
"times",
"do",
"|",
"i",
"|",
"@tuple",
"[",
"i",
"]",
"=",
"ary",
"[",
"i",
"]",
"end",
"end"
] | Munges +ary+ into a valid Tuple. | [
"Munges",
"+",
"ary",
"+",
"into",
"a",
"valid",
"Tuple",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/rinda.rb#L107-L112 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rinda/rinda.rb | Rinda.Tuple.init_with_hash | def init_with_hash(hash)
@tuple = Hash.new
hash.each do |k, v|
raise InvalidHashTupleKey unless String === k
@tuple[k] = v
end
end | ruby | def init_with_hash(hash)
@tuple = Hash.new
hash.each do |k, v|
raise InvalidHashTupleKey unless String === k
@tuple[k] = v
end
end | [
"def",
"init_with_hash",
"(",
"hash",
")",
"@tuple",
"=",
"Hash",
".",
"new",
"hash",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"raise",
"InvalidHashTupleKey",
"unless",
"String",
"===",
"k",
"@tuple",
"[",
"k",
"]",
"=",
"v",
"end",
"end"
] | Ensures +hash+ is a valid Tuple. | [
"Ensures",
"+",
"hash",
"+",
"is",
"a",
"valid",
"Tuple",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/rinda.rb#L117-L123 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/xsd/datatypes.rb | XSD.XSDFloat.narrow32bit | def narrow32bit(f)
if f.nan? || f.infinite?
f
elsif f.abs < MIN_POSITIVE_SINGLE
XSDFloat.positive?(f) ? POSITIVE_ZERO : NEGATIVE_ZERO
else
f
end
end | ruby | def narrow32bit(f)
if f.nan? || f.infinite?
f
elsif f.abs < MIN_POSITIVE_SINGLE
XSDFloat.positive?(f) ? POSITIVE_ZERO : NEGATIVE_ZERO
else
f
end
end | [
"def",
"narrow32bit",
"(",
"f",
")",
"if",
"f",
".",
"nan?",
"||",
"f",
".",
"infinite?",
"f",
"elsif",
"f",
".",
"abs",
"<",
"MIN_POSITIVE_SINGLE",
"XSDFloat",
".",
"positive?",
"(",
"f",
")",
"?",
"POSITIVE_ZERO",
":",
"NEGATIVE_ZERO",
"else",
"f",
"end",
"end"
] | Convert to single-precision 32-bit floating point value. | [
"Convert",
"to",
"single",
"-",
"precision",
"32",
"-",
"bit",
"floating",
"point",
"value",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/xsd/datatypes.rb#L352-L360 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/xsd/datatypes.rb | XSD.XSDHexBinary.set_encoded | def set_encoded(value)
if /^[0-9a-fA-F]*$/ !~ value
raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
end
@data = String.new(value).strip
@is_nil = false
end | ruby | def set_encoded(value)
if /^[0-9a-fA-F]*$/ !~ value
raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
end
@data = String.new(value).strip
@is_nil = false
end | [
"def",
"set_encoded",
"(",
"value",
")",
"if",
"/",
"/",
"!~",
"value",
"raise",
"ValueSpaceError",
".",
"new",
"(",
"\"#{ type }: cannot accept '#{ value }'.\"",
")",
"end",
"@data",
"=",
"String",
".",
"new",
"(",
"value",
")",
".",
"strip",
"@is_nil",
"=",
"false",
"end"
] | String in Ruby could be a binary. | [
"String",
"in",
"Ruby",
"could",
"be",
"a",
"binary",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/xsd/datatypes.rb#L880-L886 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/rescuable.rb | ActiveSupport.Rescuable.rescue_with_handler | def rescue_with_handler(exception)
if handler = handler_for_rescue(exception)
handler.arity != 0 ? handler.call(exception) : handler.call
true # don't rely on the return value of the handler
end
end | ruby | def rescue_with_handler(exception)
if handler = handler_for_rescue(exception)
handler.arity != 0 ? handler.call(exception) : handler.call
true # don't rely on the return value of the handler
end
end | [
"def",
"rescue_with_handler",
"(",
"exception",
")",
"if",
"handler",
"=",
"handler_for_rescue",
"(",
"exception",
")",
"handler",
".",
"arity",
"!=",
"0",
"?",
"handler",
".",
"call",
"(",
"exception",
")",
":",
"handler",
".",
"call",
"true",
"end",
"end"
] | Tries to rescue the exception by looking up and calling a registered handler. | [
"Tries",
"to",
"rescue",
"the",
"exception",
"by",
"looking",
"up",
"and",
"calling",
"a",
"registered",
"handler",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/rescuable.rb#L71-L76 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/preprocess.rb | SM.PreProcess.handle | def handle(text)
text.gsub!(/^([ \t#]*):(\w+):\s*(.+)?\n/) do
prefix = $1
directive = $2.downcase
param = $3
case directive
when "include"
filename = param.split[0]
include_file(filename, prefix)
else
yield(directive, param)
end
end
end | ruby | def handle(text)
text.gsub!(/^([ \t#]*):(\w+):\s*(.+)?\n/) do
prefix = $1
directive = $2.downcase
param = $3
case directive
when "include"
filename = param.split[0]
include_file(filename, prefix)
else
yield(directive, param)
end
end
end | [
"def",
"handle",
"(",
"text",
")",
"text",
".",
"gsub!",
"(",
"/",
"\\t",
"\\w",
"\\s",
"\\n",
"/",
")",
"do",
"prefix",
"=",
"$1",
"directive",
"=",
"$2",
".",
"downcase",
"param",
"=",
"$3",
"case",
"directive",
"when",
"\"include\"",
"filename",
"=",
"param",
".",
"split",
"[",
"0",
"]",
"include_file",
"(",
"filename",
",",
"prefix",
")",
"else",
"yield",
"(",
"directive",
",",
"param",
")",
"end",
"end",
"end"
] | Look for common options in a chunk of text. Options that
we don't handle are passed back to our caller
as |directive, param| | [
"Look",
"for",
"common",
"options",
"in",
"a",
"chunk",
"of",
"text",
".",
"Options",
"that",
"we",
"don",
"t",
"handle",
"are",
"passed",
"back",
"to",
"our",
"caller",
"as",
"|directive",
"param|"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/preprocess.rb#L20-L35 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/preprocess.rb | SM.PreProcess.include_file | def include_file(name, indent)
if (full_name = find_include_file(name))
content = File.open(full_name) {|f| f.read}
# strip leading '#'s, but only if all lines start with them
if content =~ /^[^#]/
content.gsub(/^/, indent)
else
content.gsub(/^#?/, indent)
end
else
$stderr.puts "Couldn't find file to include: '#{name}'"
''
end
end | ruby | def include_file(name, indent)
if (full_name = find_include_file(name))
content = File.open(full_name) {|f| f.read}
# strip leading '#'s, but only if all lines start with them
if content =~ /^[^#]/
content.gsub(/^/, indent)
else
content.gsub(/^#?/, indent)
end
else
$stderr.puts "Couldn't find file to include: '#{name}'"
''
end
end | [
"def",
"include_file",
"(",
"name",
",",
"indent",
")",
"if",
"(",
"full_name",
"=",
"find_include_file",
"(",
"name",
")",
")",
"content",
"=",
"File",
".",
"open",
"(",
"full_name",
")",
"{",
"|",
"f",
"|",
"f",
".",
"read",
"}",
"if",
"content",
"=~",
"/",
"/",
"content",
".",
"gsub",
"(",
"/",
"/",
",",
"indent",
")",
"else",
"content",
".",
"gsub",
"(",
"/",
"/",
",",
"indent",
")",
"end",
"else",
"$stderr",
".",
"puts",
"\"Couldn't find file to include: '#{name}'\"",
"''",
"end",
"end"
] | Include a file, indenting it correctly | [
"Include",
"a",
"file",
"indenting",
"it",
"correctly"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/preprocess.rb#L43-L56 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/preprocess.rb | SM.PreProcess.find_include_file | def find_include_file(name)
to_search = [ File.dirname(@input_file_name) ].concat @include_path
to_search.each do |dir|
full_name = File.join(dir, name)
stat = File.stat(full_name) rescue next
return full_name if stat.readable?
end
nil
end | ruby | def find_include_file(name)
to_search = [ File.dirname(@input_file_name) ].concat @include_path
to_search.each do |dir|
full_name = File.join(dir, name)
stat = File.stat(full_name) rescue next
return full_name if stat.readable?
end
nil
end | [
"def",
"find_include_file",
"(",
"name",
")",
"to_search",
"=",
"[",
"File",
".",
"dirname",
"(",
"@input_file_name",
")",
"]",
".",
"concat",
"@include_path",
"to_search",
".",
"each",
"do",
"|",
"dir",
"|",
"full_name",
"=",
"File",
".",
"join",
"(",
"dir",
",",
"name",
")",
"stat",
"=",
"File",
".",
"stat",
"(",
"full_name",
")",
"rescue",
"next",
"return",
"full_name",
"if",
"stat",
".",
"readable?",
"end",
"nil",
"end"
] | Look for the given file in the directory containing the current
file, and then in each of the directories specified in the
RDOC_INCLUDE path | [
"Look",
"for",
"the",
"given",
"file",
"in",
"the",
"directory",
"containing",
"the",
"current",
"file",
"and",
"then",
"in",
"each",
"of",
"the",
"directories",
"specified",
"in",
"the",
"RDOC_INCLUDE",
"path"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/preprocess.rb#L62-L70 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb | RDoc.Fortran95parser.parse_subprogram | def parse_subprogram(subprogram, params, comment, code,
before_contains=nil, function=nil, prefix=nil)
subprogram.singleton = false
prefix = "" if !prefix
arguments = params.sub(/\(/, "").sub(/\)/, "").split(",") if params
args_comment, params_opt =
find_arguments(arguments, code.sub(/^s*?contains\s*?(!.*?)?$.*/im, ""),
nil, nil, true)
params_opt = "( " + params_opt + " ) " if params_opt
subprogram.params = params_opt || ""
namelist_comment = find_namelists(code, before_contains)
block_comment = find_comments comment
if function
subprogram.comment = "<b><em> Function </em></b> :: <em>#{prefix}</em>\n"
else
subprogram.comment = "<b><em> Subroutine </em></b> :: <em>#{prefix}</em>\n"
end
subprogram.comment << args_comment if args_comment
subprogram.comment << block_comment if block_comment
subprogram.comment << namelist_comment if namelist_comment
# For output source code
subprogram.start_collecting_tokens
subprogram.add_token Token.new(1,1).set_text(code)
subprogram
end | ruby | def parse_subprogram(subprogram, params, comment, code,
before_contains=nil, function=nil, prefix=nil)
subprogram.singleton = false
prefix = "" if !prefix
arguments = params.sub(/\(/, "").sub(/\)/, "").split(",") if params
args_comment, params_opt =
find_arguments(arguments, code.sub(/^s*?contains\s*?(!.*?)?$.*/im, ""),
nil, nil, true)
params_opt = "( " + params_opt + " ) " if params_opt
subprogram.params = params_opt || ""
namelist_comment = find_namelists(code, before_contains)
block_comment = find_comments comment
if function
subprogram.comment = "<b><em> Function </em></b> :: <em>#{prefix}</em>\n"
else
subprogram.comment = "<b><em> Subroutine </em></b> :: <em>#{prefix}</em>\n"
end
subprogram.comment << args_comment if args_comment
subprogram.comment << block_comment if block_comment
subprogram.comment << namelist_comment if namelist_comment
# For output source code
subprogram.start_collecting_tokens
subprogram.add_token Token.new(1,1).set_text(code)
subprogram
end | [
"def",
"parse_subprogram",
"(",
"subprogram",
",",
"params",
",",
"comment",
",",
"code",
",",
"before_contains",
"=",
"nil",
",",
"function",
"=",
"nil",
",",
"prefix",
"=",
"nil",
")",
"subprogram",
".",
"singleton",
"=",
"false",
"prefix",
"=",
"\"\"",
"if",
"!",
"prefix",
"arguments",
"=",
"params",
".",
"sub",
"(",
"/",
"\\(",
"/",
",",
"\"\"",
")",
".",
"sub",
"(",
"/",
"\\)",
"/",
",",
"\"\"",
")",
".",
"split",
"(",
"\",\"",
")",
"if",
"params",
"args_comment",
",",
"params_opt",
"=",
"find_arguments",
"(",
"arguments",
",",
"code",
".",
"sub",
"(",
"/",
"\\s",
"/im",
",",
"\"\"",
")",
",",
"nil",
",",
"nil",
",",
"true",
")",
"params_opt",
"=",
"\"( \"",
"+",
"params_opt",
"+",
"\" ) \"",
"if",
"params_opt",
"subprogram",
".",
"params",
"=",
"params_opt",
"||",
"\"\"",
"namelist_comment",
"=",
"find_namelists",
"(",
"code",
",",
"before_contains",
")",
"block_comment",
"=",
"find_comments",
"comment",
"if",
"function",
"subprogram",
".",
"comment",
"=",
"\"<b><em> Function </em></b> :: <em>#{prefix}</em>\\n\"",
"else",
"subprogram",
".",
"comment",
"=",
"\"<b><em> Subroutine </em></b> :: <em>#{prefix}</em>\\n\"",
"end",
"subprogram",
".",
"comment",
"<<",
"args_comment",
"if",
"args_comment",
"subprogram",
".",
"comment",
"<<",
"block_comment",
"if",
"block_comment",
"subprogram",
".",
"comment",
"<<",
"namelist_comment",
"if",
"namelist_comment",
"subprogram",
".",
"start_collecting_tokens",
"subprogram",
".",
"add_token",
"Token",
".",
"new",
"(",
"1",
",",
"1",
")",
".",
"set_text",
"(",
"code",
")",
"subprogram",
"end"
] | End of parse_program_or_module
Parse arguments, comment, code of subroutine and function.
Return AnyMethod object. | [
"End",
"of",
"parse_program_or_module"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1007-L1034 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb | RDoc.Fortran95parser.collect_first_comment | def collect_first_comment(body)
comment = ""
not_comment = ""
comment_start = false
comment_end = false
body.split("\n").each{ |line|
if comment_end
not_comment << line
not_comment << "\n"
elsif /^\s*?!\s?(.*)$/i =~ line
comment_start = true
comment << $1
comment << "\n"
elsif /^\s*?$/i =~ line
comment_end = true if comment_start && COMMENTS_ARE_UPPER
else
comment_end = true
not_comment << line
not_comment << "\n"
end
}
return comment, not_comment
end | ruby | def collect_first_comment(body)
comment = ""
not_comment = ""
comment_start = false
comment_end = false
body.split("\n").each{ |line|
if comment_end
not_comment << line
not_comment << "\n"
elsif /^\s*?!\s?(.*)$/i =~ line
comment_start = true
comment << $1
comment << "\n"
elsif /^\s*?$/i =~ line
comment_end = true if comment_start && COMMENTS_ARE_UPPER
else
comment_end = true
not_comment << line
not_comment << "\n"
end
}
return comment, not_comment
end | [
"def",
"collect_first_comment",
"(",
"body",
")",
"comment",
"=",
"\"\"",
"not_comment",
"=",
"\"\"",
"comment_start",
"=",
"false",
"comment_end",
"=",
"false",
"body",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"each",
"{",
"|",
"line",
"|",
"if",
"comment_end",
"not_comment",
"<<",
"line",
"not_comment",
"<<",
"\"\\n\"",
"elsif",
"/",
"\\s",
"\\s",
"/i",
"=~",
"line",
"comment_start",
"=",
"true",
"comment",
"<<",
"$1",
"comment",
"<<",
"\"\\n\"",
"elsif",
"/",
"\\s",
"/i",
"=~",
"line",
"comment_end",
"=",
"true",
"if",
"comment_start",
"&&",
"COMMENTS_ARE_UPPER",
"else",
"comment_end",
"=",
"true",
"not_comment",
"<<",
"line",
"not_comment",
"<<",
"\"\\n\"",
"end",
"}",
"return",
"comment",
",",
"not_comment",
"end"
] | Collect comment for file entity | [
"Collect",
"comment",
"for",
"file",
"entity"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1039-L1061 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb | RDoc.Fortran95parser.find_namelists | def find_namelists(text, before_contains=nil)
return nil if !text
result = ""
lines = "#{text}"
before_contains = "" if !before_contains
while lines =~ /^\s*?namelist\s+\/\s*?(\w+)\s*?\/([\s\w\,]+)$/i
lines = $~.post_match
nml_comment = COMMENTS_ARE_UPPER ?
find_comments($~.pre_match) : find_comments($~.post_match)
nml_name = $1
nml_args = $2.split(",")
result << "\n\n=== NAMELIST <tt><b>" + nml_name + "</tt></b>\n\n"
result << nml_comment + "\n" if nml_comment
if lines.split("\n")[0] =~ /^\//i
lines = "namelist " + lines
end
result << find_arguments(nml_args, "#{text}" + "\n" + before_contains)
end
return result
end | ruby | def find_namelists(text, before_contains=nil)
return nil if !text
result = ""
lines = "#{text}"
before_contains = "" if !before_contains
while lines =~ /^\s*?namelist\s+\/\s*?(\w+)\s*?\/([\s\w\,]+)$/i
lines = $~.post_match
nml_comment = COMMENTS_ARE_UPPER ?
find_comments($~.pre_match) : find_comments($~.post_match)
nml_name = $1
nml_args = $2.split(",")
result << "\n\n=== NAMELIST <tt><b>" + nml_name + "</tt></b>\n\n"
result << nml_comment + "\n" if nml_comment
if lines.split("\n")[0] =~ /^\//i
lines = "namelist " + lines
end
result << find_arguments(nml_args, "#{text}" + "\n" + before_contains)
end
return result
end | [
"def",
"find_namelists",
"(",
"text",
",",
"before_contains",
"=",
"nil",
")",
"return",
"nil",
"if",
"!",
"text",
"result",
"=",
"\"\"",
"lines",
"=",
"\"#{text}\"",
"before_contains",
"=",
"\"\"",
"if",
"!",
"before_contains",
"while",
"lines",
"=~",
"/",
"\\s",
"\\s",
"\\/",
"\\s",
"\\w",
"\\s",
"\\/",
"\\s",
"\\w",
"\\,",
"/i",
"lines",
"=",
"$~",
".",
"post_match",
"nml_comment",
"=",
"COMMENTS_ARE_UPPER",
"?",
"find_comments",
"(",
"$~",
".",
"pre_match",
")",
":",
"find_comments",
"(",
"$~",
".",
"post_match",
")",
"nml_name",
"=",
"$1",
"nml_args",
"=",
"$2",
".",
"split",
"(",
"\",\"",
")",
"result",
"<<",
"\"\\n\\n=== NAMELIST <tt><b>\"",
"+",
"nml_name",
"+",
"\"</tt></b>\\n\\n\"",
"result",
"<<",
"nml_comment",
"+",
"\"\\n\"",
"if",
"nml_comment",
"if",
"lines",
".",
"split",
"(",
"\"\\n\"",
")",
"[",
"0",
"]",
"=~",
"/",
"\\/",
"/i",
"lines",
"=",
"\"namelist \"",
"+",
"lines",
"end",
"result",
"<<",
"find_arguments",
"(",
"nml_args",
",",
"\"#{text}\"",
"+",
"\"\\n\"",
"+",
"before_contains",
")",
"end",
"return",
"result",
"end"
] | Return comments of definitions of namelists | [
"Return",
"comments",
"of",
"definitions",
"of",
"namelists"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1123-L1142 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb | RDoc.Fortran95parser.find_comments | def find_comments text
return "" unless text
lines = text.split("\n")
lines.reverse! if COMMENTS_ARE_UPPER
comment_block = Array.new
lines.each do |line|
break if line =~ /^\s*?\w/ || line =~ /^\s*?$/
if COMMENTS_ARE_UPPER
comment_block.unshift line.sub(/^\s*?!\s?/,"")
else
comment_block.push line.sub(/^\s*?!\s?/,"")
end
end
nice_lines = comment_block.join("\n").split "\n\s*?\n"
nice_lines[0] ||= ""
nice_lines.shift
end | ruby | def find_comments text
return "" unless text
lines = text.split("\n")
lines.reverse! if COMMENTS_ARE_UPPER
comment_block = Array.new
lines.each do |line|
break if line =~ /^\s*?\w/ || line =~ /^\s*?$/
if COMMENTS_ARE_UPPER
comment_block.unshift line.sub(/^\s*?!\s?/,"")
else
comment_block.push line.sub(/^\s*?!\s?/,"")
end
end
nice_lines = comment_block.join("\n").split "\n\s*?\n"
nice_lines[0] ||= ""
nice_lines.shift
end | [
"def",
"find_comments",
"text",
"return",
"\"\"",
"unless",
"text",
"lines",
"=",
"text",
".",
"split",
"(",
"\"\\n\"",
")",
"lines",
".",
"reverse!",
"if",
"COMMENTS_ARE_UPPER",
"comment_block",
"=",
"Array",
".",
"new",
"lines",
".",
"each",
"do",
"|",
"line",
"|",
"break",
"if",
"line",
"=~",
"/",
"\\s",
"\\w",
"/",
"||",
"line",
"=~",
"/",
"\\s",
"/",
"if",
"COMMENTS_ARE_UPPER",
"comment_block",
".",
"unshift",
"line",
".",
"sub",
"(",
"/",
"\\s",
"\\s",
"/",
",",
"\"\"",
")",
"else",
"comment_block",
".",
"push",
"line",
".",
"sub",
"(",
"/",
"\\s",
"\\s",
"/",
",",
"\"\"",
")",
"end",
"end",
"nice_lines",
"=",
"comment_block",
".",
"join",
"(",
"\"\\n\"",
")",
".",
"split",
"\"\\n\\s*?\\n\"",
"nice_lines",
"[",
"0",
"]",
"||=",
"\"\"",
"nice_lines",
".",
"shift",
"end"
] | Comments just after module or subprogram, or arguments are
returned. If "COMMENTS_ARE_UPPER" is true, comments just before
modules or subprograms are returned | [
"Comments",
"just",
"after",
"module",
"or",
"subprogram",
"or",
"arguments",
"are",
"returned",
".",
"If",
"COMMENTS_ARE_UPPER",
"is",
"true",
"comments",
"just",
"before",
"modules",
"or",
"subprograms",
"are",
"returned"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1149-L1165 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb | RDoc.Fortran95parser.initialize_public_method | def initialize_public_method(method, parent)
return if !method || !parent
new_meth = AnyMethod.new("External Alias for module", method.name)
new_meth.singleton = method.singleton
new_meth.params = method.params.clone
new_meth.comment = remove_trailing_alias(method.comment.clone)
new_meth.comment << "\n\n#{EXTERNAL_ALIAS_MES} #{parent.strip.chomp}\##{method.name}"
return new_meth
end | ruby | def initialize_public_method(method, parent)
return if !method || !parent
new_meth = AnyMethod.new("External Alias for module", method.name)
new_meth.singleton = method.singleton
new_meth.params = method.params.clone
new_meth.comment = remove_trailing_alias(method.comment.clone)
new_meth.comment << "\n\n#{EXTERNAL_ALIAS_MES} #{parent.strip.chomp}\##{method.name}"
return new_meth
end | [
"def",
"initialize_public_method",
"(",
"method",
",",
"parent",
")",
"return",
"if",
"!",
"method",
"||",
"!",
"parent",
"new_meth",
"=",
"AnyMethod",
".",
"new",
"(",
"\"External Alias for module\"",
",",
"method",
".",
"name",
")",
"new_meth",
".",
"singleton",
"=",
"method",
".",
"singleton",
"new_meth",
".",
"params",
"=",
"method",
".",
"params",
".",
"clone",
"new_meth",
".",
"comment",
"=",
"remove_trailing_alias",
"(",
"method",
".",
"comment",
".",
"clone",
")",
"new_meth",
".",
"comment",
"<<",
"\"\\n\\n#{EXTERNAL_ALIAS_MES} #{parent.strip.chomp}\\##{method.name}\"",
"return",
"new_meth",
"end"
] | Create method for internal alias | [
"Create",
"method",
"for",
"internal",
"alias"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1177-L1187 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb | RDoc.Fortran95parser.initialize_external_method | def initialize_external_method(new, old, params, file, comment, token=nil,
internal=nil, nolink=nil)
return nil unless new || old
if internal
external_alias_header = "#{INTERNAL_ALIAS_MES} "
external_alias_text = external_alias_header + old
elsif file
external_alias_header = "#{EXTERNAL_ALIAS_MES} "
external_alias_text = external_alias_header + file + "#" + old
else
return nil
end
external_meth = AnyMethod.new(external_alias_text, new)
external_meth.singleton = false
external_meth.params = params
external_comment = remove_trailing_alias(comment) + "\n\n" if comment
external_meth.comment = external_comment || ""
if nolink && token
external_meth.start_collecting_tokens
external_meth.add_token Token.new(1,1).set_text(token)
else
external_meth.comment << external_alias_text
end
return external_meth
end | ruby | def initialize_external_method(new, old, params, file, comment, token=nil,
internal=nil, nolink=nil)
return nil unless new || old
if internal
external_alias_header = "#{INTERNAL_ALIAS_MES} "
external_alias_text = external_alias_header + old
elsif file
external_alias_header = "#{EXTERNAL_ALIAS_MES} "
external_alias_text = external_alias_header + file + "#" + old
else
return nil
end
external_meth = AnyMethod.new(external_alias_text, new)
external_meth.singleton = false
external_meth.params = params
external_comment = remove_trailing_alias(comment) + "\n\n" if comment
external_meth.comment = external_comment || ""
if nolink && token
external_meth.start_collecting_tokens
external_meth.add_token Token.new(1,1).set_text(token)
else
external_meth.comment << external_alias_text
end
return external_meth
end | [
"def",
"initialize_external_method",
"(",
"new",
",",
"old",
",",
"params",
",",
"file",
",",
"comment",
",",
"token",
"=",
"nil",
",",
"internal",
"=",
"nil",
",",
"nolink",
"=",
"nil",
")",
"return",
"nil",
"unless",
"new",
"||",
"old",
"if",
"internal",
"external_alias_header",
"=",
"\"#{INTERNAL_ALIAS_MES} \"",
"external_alias_text",
"=",
"external_alias_header",
"+",
"old",
"elsif",
"file",
"external_alias_header",
"=",
"\"#{EXTERNAL_ALIAS_MES} \"",
"external_alias_text",
"=",
"external_alias_header",
"+",
"file",
"+",
"\"#\"",
"+",
"old",
"else",
"return",
"nil",
"end",
"external_meth",
"=",
"AnyMethod",
".",
"new",
"(",
"external_alias_text",
",",
"new",
")",
"external_meth",
".",
"singleton",
"=",
"false",
"external_meth",
".",
"params",
"=",
"params",
"external_comment",
"=",
"remove_trailing_alias",
"(",
"comment",
")",
"+",
"\"\\n\\n\"",
"if",
"comment",
"external_meth",
".",
"comment",
"=",
"external_comment",
"||",
"\"\"",
"if",
"nolink",
"&&",
"token",
"external_meth",
".",
"start_collecting_tokens",
"external_meth",
".",
"add_token",
"Token",
".",
"new",
"(",
"1",
",",
"1",
")",
".",
"set_text",
"(",
"token",
")",
"else",
"external_meth",
".",
"comment",
"<<",
"external_alias_text",
"end",
"return",
"external_meth",
"end"
] | Create method for external alias
If argument "internal" is true, file is ignored. | [
"Create",
"method",
"for",
"external",
"alias"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1194-L1220 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb | RDoc.Fortran95parser.check_external_aliases | def check_external_aliases(subname, params, comment, test=nil)
@@external_aliases.each{ |alias_item|
if subname == alias_item["old_name"] ||
subname.upcase == alias_item["old_name"].upcase &&
@options.ignore_case
new_meth = initialize_external_method(alias_item["new_name"],
subname, params, @file_name,
comment)
new_meth.visibility = alias_item["visibility"]
progress "e"
@stats.num_methods += 1
alias_item["file_or_module"].add_method(new_meth)
if !alias_item["file_or_module"].include_requires?(@file_name, @options.ignore_case)
alias_item["file_or_module"].add_require(Require.new(@file_name, ""))
end
end
}
end | ruby | def check_external_aliases(subname, params, comment, test=nil)
@@external_aliases.each{ |alias_item|
if subname == alias_item["old_name"] ||
subname.upcase == alias_item["old_name"].upcase &&
@options.ignore_case
new_meth = initialize_external_method(alias_item["new_name"],
subname, params, @file_name,
comment)
new_meth.visibility = alias_item["visibility"]
progress "e"
@stats.num_methods += 1
alias_item["file_or_module"].add_method(new_meth)
if !alias_item["file_or_module"].include_requires?(@file_name, @options.ignore_case)
alias_item["file_or_module"].add_require(Require.new(@file_name, ""))
end
end
}
end | [
"def",
"check_external_aliases",
"(",
"subname",
",",
"params",
",",
"comment",
",",
"test",
"=",
"nil",
")",
"@@external_aliases",
".",
"each",
"{",
"|",
"alias_item",
"|",
"if",
"subname",
"==",
"alias_item",
"[",
"\"old_name\"",
"]",
"||",
"subname",
".",
"upcase",
"==",
"alias_item",
"[",
"\"old_name\"",
"]",
".",
"upcase",
"&&",
"@options",
".",
"ignore_case",
"new_meth",
"=",
"initialize_external_method",
"(",
"alias_item",
"[",
"\"new_name\"",
"]",
",",
"subname",
",",
"params",
",",
"@file_name",
",",
"comment",
")",
"new_meth",
".",
"visibility",
"=",
"alias_item",
"[",
"\"visibility\"",
"]",
"progress",
"\"e\"",
"@stats",
".",
"num_methods",
"+=",
"1",
"alias_item",
"[",
"\"file_or_module\"",
"]",
".",
"add_method",
"(",
"new_meth",
")",
"if",
"!",
"alias_item",
"[",
"\"file_or_module\"",
"]",
".",
"include_requires?",
"(",
"@file_name",
",",
"@options",
".",
"ignore_case",
")",
"alias_item",
"[",
"\"file_or_module\"",
"]",
".",
"add_require",
"(",
"Require",
".",
"new",
"(",
"@file_name",
",",
"\"\"",
")",
")",
"end",
"end",
"}",
"end"
] | Check external aliases | [
"Check",
"external",
"aliases"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1328-L1348 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb | RDoc.Fortran95parser.united_to_one_line | def united_to_one_line(f90src)
return "" unless f90src
lines = f90src.split("\n")
previous_continuing = false
now_continuing = false
body = ""
lines.each{ |line|
words = line.split("")
next if words.empty? && previous_continuing
commentout = false
brank_flag = true ; brank_char = ""
squote = false ; dquote = false
ignore = false
words.collect! { |char|
if previous_continuing && brank_flag
now_continuing = true
ignore = true
case char
when "!" ; break
when " " ; brank_char << char ; next ""
when "&"
brank_flag = false
now_continuing = false
next ""
else
brank_flag = false
now_continuing = false
ignore = false
next brank_char + char
end
end
ignore = false
if now_continuing
next ""
elsif !(squote) && !(dquote) && !(commentout)
case char
when "!" ; commentout = true ; next char
when "\""; dquote = true ; next char
when "\'"; squote = true ; next char
when "&" ; now_continuing = true ; next ""
else next char
end
elsif commentout
next char
elsif squote
case char
when "\'"; squote = false ; next char
else next char
end
elsif dquote
case char
when "\""; dquote = false ; next char
else next char
end
end
}
if !ignore && !previous_continuing || !brank_flag
if previous_continuing
body << words.join("")
else
body << "\n" + words.join("")
end
end
previous_continuing = now_continuing ? true : nil
now_continuing = nil
}
return body
end | ruby | def united_to_one_line(f90src)
return "" unless f90src
lines = f90src.split("\n")
previous_continuing = false
now_continuing = false
body = ""
lines.each{ |line|
words = line.split("")
next if words.empty? && previous_continuing
commentout = false
brank_flag = true ; brank_char = ""
squote = false ; dquote = false
ignore = false
words.collect! { |char|
if previous_continuing && brank_flag
now_continuing = true
ignore = true
case char
when "!" ; break
when " " ; brank_char << char ; next ""
when "&"
brank_flag = false
now_continuing = false
next ""
else
brank_flag = false
now_continuing = false
ignore = false
next brank_char + char
end
end
ignore = false
if now_continuing
next ""
elsif !(squote) && !(dquote) && !(commentout)
case char
when "!" ; commentout = true ; next char
when "\""; dquote = true ; next char
when "\'"; squote = true ; next char
when "&" ; now_continuing = true ; next ""
else next char
end
elsif commentout
next char
elsif squote
case char
when "\'"; squote = false ; next char
else next char
end
elsif dquote
case char
when "\""; dquote = false ; next char
else next char
end
end
}
if !ignore && !previous_continuing || !brank_flag
if previous_continuing
body << words.join("")
else
body << "\n" + words.join("")
end
end
previous_continuing = now_continuing ? true : nil
now_continuing = nil
}
return body
end | [
"def",
"united_to_one_line",
"(",
"f90src",
")",
"return",
"\"\"",
"unless",
"f90src",
"lines",
"=",
"f90src",
".",
"split",
"(",
"\"\\n\"",
")",
"previous_continuing",
"=",
"false",
"now_continuing",
"=",
"false",
"body",
"=",
"\"\"",
"lines",
".",
"each",
"{",
"|",
"line",
"|",
"words",
"=",
"line",
".",
"split",
"(",
"\"\"",
")",
"next",
"if",
"words",
".",
"empty?",
"&&",
"previous_continuing",
"commentout",
"=",
"false",
"brank_flag",
"=",
"true",
";",
"brank_char",
"=",
"\"\"",
"squote",
"=",
"false",
";",
"dquote",
"=",
"false",
"ignore",
"=",
"false",
"words",
".",
"collect!",
"{",
"|",
"char",
"|",
"if",
"previous_continuing",
"&&",
"brank_flag",
"now_continuing",
"=",
"true",
"ignore",
"=",
"true",
"case",
"char",
"when",
"\"!\"",
";",
"break",
"when",
"\" \"",
";",
"brank_char",
"<<",
"char",
";",
"next",
"\"\"",
"when",
"\"&\"",
"brank_flag",
"=",
"false",
"now_continuing",
"=",
"false",
"next",
"\"\"",
"else",
"brank_flag",
"=",
"false",
"now_continuing",
"=",
"false",
"ignore",
"=",
"false",
"next",
"brank_char",
"+",
"char",
"end",
"end",
"ignore",
"=",
"false",
"if",
"now_continuing",
"next",
"\"\"",
"elsif",
"!",
"(",
"squote",
")",
"&&",
"!",
"(",
"dquote",
")",
"&&",
"!",
"(",
"commentout",
")",
"case",
"char",
"when",
"\"!\"",
";",
"commentout",
"=",
"true",
";",
"next",
"char",
"when",
"\"\\\"\"",
";",
"dquote",
"=",
"true",
";",
"next",
"char",
"when",
"\"\\'\"",
";",
"squote",
"=",
"true",
";",
"next",
"char",
"when",
"\"&\"",
";",
"now_continuing",
"=",
"true",
";",
"next",
"\"\"",
"else",
"next",
"char",
"end",
"elsif",
"commentout",
"next",
"char",
"elsif",
"squote",
"case",
"char",
"when",
"\"\\'\"",
";",
"squote",
"=",
"false",
";",
"next",
"char",
"else",
"next",
"char",
"end",
"elsif",
"dquote",
"case",
"char",
"when",
"\"\\\"\"",
";",
"dquote",
"=",
"false",
";",
"next",
"char",
"else",
"next",
"char",
"end",
"end",
"}",
"if",
"!",
"ignore",
"&&",
"!",
"previous_continuing",
"||",
"!",
"brank_flag",
"if",
"previous_continuing",
"body",
"<<",
"words",
".",
"join",
"(",
"\"\"",
")",
"else",
"body",
"<<",
"\"\\n\"",
"+",
"words",
".",
"join",
"(",
"\"\"",
")",
"end",
"end",
"previous_continuing",
"=",
"now_continuing",
"?",
"true",
":",
"nil",
"now_continuing",
"=",
"nil",
"}",
"return",
"body",
"end"
] | Continuous lines are united.
Comments in continuous lines are removed. | [
"Continuous",
"lines",
"are",
"united",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1387-L1455 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb | RDoc.Fortran95parser.continuous_line? | def continuous_line?(line)
continuous = false
if /&\s*?(!.*)?$/ =~ line
continuous = true
if comment_out?($~.pre_match)
continuous = false
end
end
return continuous
end | ruby | def continuous_line?(line)
continuous = false
if /&\s*?(!.*)?$/ =~ line
continuous = true
if comment_out?($~.pre_match)
continuous = false
end
end
return continuous
end | [
"def",
"continuous_line?",
"(",
"line",
")",
"continuous",
"=",
"false",
"if",
"/",
"\\s",
"/",
"=~",
"line",
"continuous",
"=",
"true",
"if",
"comment_out?",
"(",
"$~",
".",
"pre_match",
")",
"continuous",
"=",
"false",
"end",
"end",
"return",
"continuous",
"end"
] | Continuous line checker | [
"Continuous",
"line",
"checker"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1461-L1470 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb | RDoc.Fortran95parser.comment_out? | def comment_out?(line)
return nil unless line
commentout = false
squote = false ; dquote = false
line.split("").each { |char|
if !(squote) && !(dquote)
case char
when "!" ; commentout = true ; break
when "\""; dquote = true
when "\'"; squote = true
else next
end
elsif squote
case char
when "\'"; squote = false
else next
end
elsif dquote
case char
when "\""; dquote = false
else next
end
end
}
return commentout
end | ruby | def comment_out?(line)
return nil unless line
commentout = false
squote = false ; dquote = false
line.split("").each { |char|
if !(squote) && !(dquote)
case char
when "!" ; commentout = true ; break
when "\""; dquote = true
when "\'"; squote = true
else next
end
elsif squote
case char
when "\'"; squote = false
else next
end
elsif dquote
case char
when "\""; dquote = false
else next
end
end
}
return commentout
end | [
"def",
"comment_out?",
"(",
"line",
")",
"return",
"nil",
"unless",
"line",
"commentout",
"=",
"false",
"squote",
"=",
"false",
";",
"dquote",
"=",
"false",
"line",
".",
"split",
"(",
"\"\"",
")",
".",
"each",
"{",
"|",
"char",
"|",
"if",
"!",
"(",
"squote",
")",
"&&",
"!",
"(",
"dquote",
")",
"case",
"char",
"when",
"\"!\"",
";",
"commentout",
"=",
"true",
";",
"break",
"when",
"\"\\\"\"",
";",
"dquote",
"=",
"true",
"when",
"\"\\'\"",
";",
"squote",
"=",
"true",
"else",
"next",
"end",
"elsif",
"squote",
"case",
"char",
"when",
"\"\\'\"",
";",
"squote",
"=",
"false",
"else",
"next",
"end",
"elsif",
"dquote",
"case",
"char",
"when",
"\"\\\"\"",
";",
"dquote",
"=",
"false",
"else",
"next",
"end",
"end",
"}",
"return",
"commentout",
"end"
] | Comment out checker | [
"Comment",
"out",
"checker"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1475-L1500 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb | RDoc.Fortran95parser.semicolon_to_linefeed | def semicolon_to_linefeed(text)
return "" unless text
lines = text.split("\n")
lines.collect!{ |line|
words = line.split("")
commentout = false
squote = false ; dquote = false
words.collect! { |char|
if !(squote) && !(dquote) && !(commentout)
case char
when "!" ; commentout = true ; next char
when "\""; dquote = true ; next char
when "\'"; squote = true ; next char
when ";" ; "\n"
else next char
end
elsif commentout
next char
elsif squote
case char
when "\'"; squote = false ; next char
else next char
end
elsif dquote
case char
when "\""; dquote = false ; next char
else next char
end
end
}
words.join("")
}
return lines.join("\n")
end | ruby | def semicolon_to_linefeed(text)
return "" unless text
lines = text.split("\n")
lines.collect!{ |line|
words = line.split("")
commentout = false
squote = false ; dquote = false
words.collect! { |char|
if !(squote) && !(dquote) && !(commentout)
case char
when "!" ; commentout = true ; next char
when "\""; dquote = true ; next char
when "\'"; squote = true ; next char
when ";" ; "\n"
else next char
end
elsif commentout
next char
elsif squote
case char
when "\'"; squote = false ; next char
else next char
end
elsif dquote
case char
when "\""; dquote = false ; next char
else next char
end
end
}
words.join("")
}
return lines.join("\n")
end | [
"def",
"semicolon_to_linefeed",
"(",
"text",
")",
"return",
"\"\"",
"unless",
"text",
"lines",
"=",
"text",
".",
"split",
"(",
"\"\\n\"",
")",
"lines",
".",
"collect!",
"{",
"|",
"line",
"|",
"words",
"=",
"line",
".",
"split",
"(",
"\"\"",
")",
"commentout",
"=",
"false",
"squote",
"=",
"false",
";",
"dquote",
"=",
"false",
"words",
".",
"collect!",
"{",
"|",
"char",
"|",
"if",
"!",
"(",
"squote",
")",
"&&",
"!",
"(",
"dquote",
")",
"&&",
"!",
"(",
"commentout",
")",
"case",
"char",
"when",
"\"!\"",
";",
"commentout",
"=",
"true",
";",
"next",
"char",
"when",
"\"\\\"\"",
";",
"dquote",
"=",
"true",
";",
"next",
"char",
"when",
"\"\\'\"",
";",
"squote",
"=",
"true",
";",
"next",
"char",
"when",
"\";\"",
";",
"\"\\n\"",
"else",
"next",
"char",
"end",
"elsif",
"commentout",
"next",
"char",
"elsif",
"squote",
"case",
"char",
"when",
"\"\\'\"",
";",
"squote",
"=",
"false",
";",
"next",
"char",
"else",
"next",
"char",
"end",
"elsif",
"dquote",
"case",
"char",
"when",
"\"\\\"\"",
";",
"dquote",
"=",
"false",
";",
"next",
"char",
"else",
"next",
"char",
"end",
"end",
"}",
"words",
".",
"join",
"(",
"\"\"",
")",
"}",
"return",
"lines",
".",
"join",
"(",
"\"\\n\"",
")",
"end"
] | Semicolons are replaced to line feed. | [
"Semicolons",
"are",
"replaced",
"to",
"line",
"feed",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1505-L1538 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb | RDoc.Fortran95parser.remove_empty_head_lines | def remove_empty_head_lines(text)
return "" unless text
lines = text.split("\n")
header = true
lines.delete_if{ |line|
header = false if /\S/ =~ line
header && /^\s*?$/ =~ line
}
lines.join("\n")
end | ruby | def remove_empty_head_lines(text)
return "" unless text
lines = text.split("\n")
header = true
lines.delete_if{ |line|
header = false if /\S/ =~ line
header && /^\s*?$/ =~ line
}
lines.join("\n")
end | [
"def",
"remove_empty_head_lines",
"(",
"text",
")",
"return",
"\"\"",
"unless",
"text",
"lines",
"=",
"text",
".",
"split",
"(",
"\"\\n\"",
")",
"header",
"=",
"true",
"lines",
".",
"delete_if",
"{",
"|",
"line",
"|",
"header",
"=",
"false",
"if",
"/",
"\\S",
"/",
"=~",
"line",
"header",
"&&",
"/",
"\\s",
"/",
"=~",
"line",
"}",
"lines",
".",
"join",
"(",
"\"\\n\"",
")",
"end"
] | Empty lines in header are removed | [
"Empty",
"lines",
"in",
"header",
"are",
"removed"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1619-L1628 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb | Zlib.ZStream.end | def end
unless ready? then
warn "attempt to close uninitialized stream; ignored."
return nil
end
if in_stream? then
warn "attempt to close unfinished zstream; reset forced"
reset
end
reset_input
err = Zlib.send @func_end, pointer
Zlib.handle_error err, message
@flags = 0
# HACK this may be wrong
@output = nil
@next_out.free unless @next_out.nil?
@next_out = nil
nil
end | ruby | def end
unless ready? then
warn "attempt to close uninitialized stream; ignored."
return nil
end
if in_stream? then
warn "attempt to close unfinished zstream; reset forced"
reset
end
reset_input
err = Zlib.send @func_end, pointer
Zlib.handle_error err, message
@flags = 0
# HACK this may be wrong
@output = nil
@next_out.free unless @next_out.nil?
@next_out = nil
nil
end | [
"def",
"end",
"unless",
"ready?",
"then",
"warn",
"\"attempt to close uninitialized stream; ignored.\"",
"return",
"nil",
"end",
"if",
"in_stream?",
"then",
"warn",
"\"attempt to close unfinished zstream; reset forced\"",
"reset",
"end",
"reset_input",
"err",
"=",
"Zlib",
".",
"send",
"@func_end",
",",
"pointer",
"Zlib",
".",
"handle_error",
"err",
",",
"message",
"@flags",
"=",
"0",
"@output",
"=",
"nil",
"@next_out",
".",
"free",
"unless",
"@next_out",
".",
"nil?",
"@next_out",
"=",
"nil",
"nil",
"end"
] | Closes the stream. All operations on the closed stream will raise an
exception. | [
"Closes",
"the",
"stream",
".",
"All",
"operations",
"on",
"the",
"closed",
"stream",
"will",
"raise",
"an",
"exception",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb#L319-L344 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb | Zlib.ZStream.reset | def reset
err = Zlib.send @func_reset, pointer
Zlib.handle_error err, message
@flags = READY
reset_input
end | ruby | def reset
err = Zlib.send @func_reset, pointer
Zlib.handle_error err, message
@flags = READY
reset_input
end | [
"def",
"reset",
"err",
"=",
"Zlib",
".",
"send",
"@func_reset",
",",
"pointer",
"Zlib",
".",
"handle_error",
"err",
",",
"message",
"@flags",
"=",
"READY",
"reset_input",
"end"
] | Resets and initializes the stream. All data in both input and output
buffer are discarded. | [
"Resets",
"and",
"initializes",
"the",
"stream",
".",
"All",
"data",
"in",
"both",
"input",
"and",
"output",
"buffer",
"are",
"discarded",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb#L415-L423 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb | Zlib.Deflate.do_deflate | def do_deflate(data, flush)
if data.nil? then
run '', Zlib::FINISH
else
data = StringValue data
if flush != Zlib::NO_FLUSH or not data.empty? then # prevent BUF_ERROR
run data, flush
end
end
end | ruby | def do_deflate(data, flush)
if data.nil? then
run '', Zlib::FINISH
else
data = StringValue data
if flush != Zlib::NO_FLUSH or not data.empty? then # prevent BUF_ERROR
run data, flush
end
end
end | [
"def",
"do_deflate",
"(",
"data",
",",
"flush",
")",
"if",
"data",
".",
"nil?",
"then",
"run",
"''",
",",
"Zlib",
"::",
"FINISH",
"else",
"data",
"=",
"StringValue",
"data",
"if",
"flush",
"!=",
"Zlib",
"::",
"NO_FLUSH",
"or",
"not",
"data",
".",
"empty?",
"then",
"run",
"data",
",",
"flush",
"end",
"end",
"end"
] | Performs the deflate operation and leaves the compressed data in the
output buffer | [
"Performs",
"the",
"deflate",
"operation",
"and",
"leaves",
"the",
"compressed",
"data",
"in",
"the",
"output",
"buffer"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb#L654-L664 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb | Zlib.Deflate.params | def params(level, strategy)
err = Zlib.deflateParams pointer, level, strategy
raise Zlib::BufError, 'buffer expansion not implemented' if
err == Zlib::BUF_ERROR
Zlib.handle_error err, message
nil
end | ruby | def params(level, strategy)
err = Zlib.deflateParams pointer, level, strategy
raise Zlib::BufError, 'buffer expansion not implemented' if
err == Zlib::BUF_ERROR
Zlib.handle_error err, message
nil
end | [
"def",
"params",
"(",
"level",
",",
"strategy",
")",
"err",
"=",
"Zlib",
".",
"deflateParams",
"pointer",
",",
"level",
",",
"strategy",
"raise",
"Zlib",
"::",
"BufError",
",",
"'buffer expansion not implemented'",
"if",
"err",
"==",
"Zlib",
"::",
"BUF_ERROR",
"Zlib",
".",
"handle_error",
"err",
",",
"message",
"nil",
"end"
] | Changes the parameters of the deflate stream. See zlib.h for details.
The output from the stream by changing the params is preserved in output
buffer. | [
"Changes",
"the",
"parameters",
"of",
"the",
"deflate",
"stream",
".",
"See",
"zlib",
".",
"h",
"for",
"details",
".",
"The",
"output",
"from",
"the",
"stream",
"by",
"changing",
"the",
"params",
"is",
"preserved",
"in",
"output",
"buffer",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb#L692-L701 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb | Zlib.GzipReader.check_footer | def check_footer
@zstream.flags |= Zlib::GzipFile::FOOTER_FINISHED
footer = @zstream.input.slice! 0, 8
rest = @io.read 8 - footer.length
footer << rest if rest
raise NoFooter, 'footer is not found' unless footer.length == 8
crc, length = footer.unpack 'VV'
@zstream[:total_in] += 8 # to rewind correctly
raise CRCError, 'invalid compressed data -- crc error' unless @crc == crc
raise LengthError, 'invalid compressed data -- length error' unless
length == @zstream.total_out
end | ruby | def check_footer
@zstream.flags |= Zlib::GzipFile::FOOTER_FINISHED
footer = @zstream.input.slice! 0, 8
rest = @io.read 8 - footer.length
footer << rest if rest
raise NoFooter, 'footer is not found' unless footer.length == 8
crc, length = footer.unpack 'VV'
@zstream[:total_in] += 8 # to rewind correctly
raise CRCError, 'invalid compressed data -- crc error' unless @crc == crc
raise LengthError, 'invalid compressed data -- length error' unless
length == @zstream.total_out
end | [
"def",
"check_footer",
"@zstream",
".",
"flags",
"|=",
"Zlib",
"::",
"GzipFile",
"::",
"FOOTER_FINISHED",
"footer",
"=",
"@zstream",
".",
"input",
".",
"slice!",
"0",
",",
"8",
"rest",
"=",
"@io",
".",
"read",
"8",
"-",
"footer",
".",
"length",
"footer",
"<<",
"rest",
"if",
"rest",
"raise",
"NoFooter",
",",
"'footer is not found'",
"unless",
"footer",
".",
"length",
"==",
"8",
"crc",
",",
"length",
"=",
"footer",
".",
"unpack",
"'VV'",
"@zstream",
"[",
":total_in",
"]",
"+=",
"8",
"raise",
"CRCError",
",",
"'invalid compressed data -- crc error'",
"unless",
"@crc",
"==",
"crc",
"raise",
"LengthError",
",",
"'invalid compressed data -- length error'",
"unless",
"length",
"==",
"@zstream",
".",
"total_out",
"end"
] | HACK use a buffer class
Creates a GzipReader object associated with +io+. The GzipReader object
reads gzipped data from +io+, and parses/decompresses them. At least,
+io+ must have a +read+ method that behaves same as the +read+ method in
IO class.
If the gzip file header is incorrect, raises an Zlib::GzipFile::Error
exception. | [
"HACK",
"use",
"a",
"buffer",
"class"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb#L961-L978 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb | Zlib.GzipWriter.make_header | def make_header
flags = 0
extra_flags = 0
flags |= Zlib::GzipFile::FLAG_ORIG_NAME if @orig_name
flags |= Zlib::GzipFile::FLAG_COMMENT if @comment
extra_flags |= Zlib::GzipFile::EXTRAFLAG_FAST if
@level == Zlib::BEST_SPEED
extra_flags |= Zlib::GzipFile::EXTRAFLAG_SLOW if
@level == Zlib::BEST_COMPRESSION
header = [
Zlib::GzipFile::MAGIC1, # byte 0
Zlib::GzipFile::MAGIC2, # byte 1
Zlib::GzipFile::METHOD_DEFLATE, # byte 2
flags, # byte 3
@mtime.to_i, # bytes 4-7
extra_flags, # byte 8
@os_code # byte 9
].pack 'CCCCVCC'
@io.write header
@io.write "#{@orig_name}\0" if @orig_name
@io.write "#{@comment}\0" if @comment
@zstream.flags |= Zlib::GzipFile::HEADER_FINISHED
end | ruby | def make_header
flags = 0
extra_flags = 0
flags |= Zlib::GzipFile::FLAG_ORIG_NAME if @orig_name
flags |= Zlib::GzipFile::FLAG_COMMENT if @comment
extra_flags |= Zlib::GzipFile::EXTRAFLAG_FAST if
@level == Zlib::BEST_SPEED
extra_flags |= Zlib::GzipFile::EXTRAFLAG_SLOW if
@level == Zlib::BEST_COMPRESSION
header = [
Zlib::GzipFile::MAGIC1, # byte 0
Zlib::GzipFile::MAGIC2, # byte 1
Zlib::GzipFile::METHOD_DEFLATE, # byte 2
flags, # byte 3
@mtime.to_i, # bytes 4-7
extra_flags, # byte 8
@os_code # byte 9
].pack 'CCCCVCC'
@io.write header
@io.write "#{@orig_name}\0" if @orig_name
@io.write "#{@comment}\0" if @comment
@zstream.flags |= Zlib::GzipFile::HEADER_FINISHED
end | [
"def",
"make_header",
"flags",
"=",
"0",
"extra_flags",
"=",
"0",
"flags",
"|=",
"Zlib",
"::",
"GzipFile",
"::",
"FLAG_ORIG_NAME",
"if",
"@orig_name",
"flags",
"|=",
"Zlib",
"::",
"GzipFile",
"::",
"FLAG_COMMENT",
"if",
"@comment",
"extra_flags",
"|=",
"Zlib",
"::",
"GzipFile",
"::",
"EXTRAFLAG_FAST",
"if",
"@level",
"==",
"Zlib",
"::",
"BEST_SPEED",
"extra_flags",
"|=",
"Zlib",
"::",
"GzipFile",
"::",
"EXTRAFLAG_SLOW",
"if",
"@level",
"==",
"Zlib",
"::",
"BEST_COMPRESSION",
"header",
"=",
"[",
"Zlib",
"::",
"GzipFile",
"::",
"MAGIC1",
",",
"Zlib",
"::",
"GzipFile",
"::",
"MAGIC2",
",",
"Zlib",
"::",
"GzipFile",
"::",
"METHOD_DEFLATE",
",",
"flags",
",",
"@mtime",
".",
"to_i",
",",
"extra_flags",
",",
"@os_code",
"]",
".",
"pack",
"'CCCCVCC'",
"@io",
".",
"write",
"header",
"@io",
".",
"write",
"\"#{@orig_name}\\0\"",
"if",
"@orig_name",
"@io",
".",
"write",
"\"#{@comment}\\0\"",
"if",
"@comment",
"@zstream",
".",
"flags",
"|=",
"Zlib",
"::",
"GzipFile",
"::",
"HEADER_FINISHED",
"end"
] | Writes out a gzip header | [
"Writes",
"out",
"a",
"gzip",
"header"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb#L1178-L1207 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb | Zlib.GzipWriter.make_footer | def make_footer
footer = [
@crc, # bytes 0-3
@zstream.total_in, # bytes 4-7
].pack 'VV'
@io.write footer
@zstream.flags |= Zlib::GzipFile::FOOTER_FINISHED
end | ruby | def make_footer
footer = [
@crc, # bytes 0-3
@zstream.total_in, # bytes 4-7
].pack 'VV'
@io.write footer
@zstream.flags |= Zlib::GzipFile::FOOTER_FINISHED
end | [
"def",
"make_footer",
"footer",
"=",
"[",
"@crc",
",",
"@zstream",
".",
"total_in",
",",
"]",
".",
"pack",
"'VV'",
"@io",
".",
"write",
"footer",
"@zstream",
".",
"flags",
"|=",
"Zlib",
"::",
"GzipFile",
"::",
"FOOTER_FINISHED",
"end"
] | Writes out a gzip footer | [
"Writes",
"out",
"a",
"gzip",
"footer"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb#L1212-L1221 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb | Zlib.GzipWriter.write | def write(data)
make_header unless header_finished?
data = String data
if data.length > 0 or sync? then
@crc = Zlib.crc32_c @crc, data, data.length
flush = sync? ? Zlib::SYNC_FLUSH : Zlib::NO_FLUSH
@zstream.run data, flush
end
write_raw
end | ruby | def write(data)
make_header unless header_finished?
data = String data
if data.length > 0 or sync? then
@crc = Zlib.crc32_c @crc, data, data.length
flush = sync? ? Zlib::SYNC_FLUSH : Zlib::NO_FLUSH
@zstream.run data, flush
end
write_raw
end | [
"def",
"write",
"(",
"data",
")",
"make_header",
"unless",
"header_finished?",
"data",
"=",
"String",
"data",
"if",
"data",
".",
"length",
">",
"0",
"or",
"sync?",
"then",
"@crc",
"=",
"Zlib",
".",
"crc32_c",
"@crc",
",",
"data",
",",
"data",
".",
"length",
"flush",
"=",
"sync?",
"?",
"Zlib",
"::",
"SYNC_FLUSH",
":",
"Zlib",
"::",
"NO_FLUSH",
"@zstream",
".",
"run",
"data",
",",
"flush",
"end",
"write_raw",
"end"
] | Same as IO. | [
"Same",
"as",
"IO",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb#L1241-L1255 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb | Zlib.Inflate.<< | def <<(string)
string = StringValue string unless string.nil?
if finished? then
unless string.nil? then
@input ||= ''
@input << string
end
else
run string, Zlib::SYNC_FLUSH
end
end | ruby | def <<(string)
string = StringValue string unless string.nil?
if finished? then
unless string.nil? then
@input ||= ''
@input << string
end
else
run string, Zlib::SYNC_FLUSH
end
end | [
"def",
"<<",
"(",
"string",
")",
"string",
"=",
"StringValue",
"string",
"unless",
"string",
".",
"nil?",
"if",
"finished?",
"then",
"unless",
"string",
".",
"nil?",
"then",
"@input",
"||=",
"''",
"@input",
"<<",
"string",
"end",
"else",
"run",
"string",
",",
"Zlib",
"::",
"SYNC_FLUSH",
"end",
"end"
] | Creates a new inflate stream for decompression. See zlib.h for details
of the argument. If +window_bits+ is +nil+, the default value is used.
Inputs +string+ into the inflate stream just like Zlib::Inflate#inflate,
but returns the Zlib::Inflate object itself. The output from the stream
is preserved in output buffer. | [
"Creates",
"a",
"new",
"inflate",
"stream",
"for",
"decompression",
".",
"See",
"zlib",
".",
"h",
"for",
"details",
"of",
"the",
"argument",
".",
"If",
"+",
"window_bits",
"+",
"is",
"+",
"nil",
"+",
"the",
"default",
"value",
"is",
"used",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/platform/i386-solaris/zlib.rb#L1327-L1338 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rexml/element.rb | REXML.Element.each_with_something | def each_with_something( test, max=0, name=nil )
num = 0
child=nil
@elements.each( name ){ |child|
yield child if test.call(child) and num += 1
return if max>0 and num == max
}
end | ruby | def each_with_something( test, max=0, name=nil )
num = 0
child=nil
@elements.each( name ){ |child|
yield child if test.call(child) and num += 1
return if max>0 and num == max
}
end | [
"def",
"each_with_something",
"(",
"test",
",",
"max",
"=",
"0",
",",
"name",
"=",
"nil",
")",
"num",
"=",
"0",
"child",
"=",
"nil",
"@elements",
".",
"each",
"(",
"name",
")",
"{",
"|",
"child",
"|",
"yield",
"child",
"if",
"test",
".",
"call",
"(",
"child",
")",
"and",
"num",
"+=",
"1",
"return",
"if",
"max",
">",
"0",
"and",
"num",
"==",
"max",
"}",
"end"
] | A private helper method | [
"A",
"private",
"helper",
"method"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rexml/element.rb#L705-L712 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.9/xmlrpc/server.rb | XMLRPC.BasicServer.check_arity | def check_arity(obj, n_args)
ary = obj.arity
if ary >= 0
n_args == ary
else
n_args >= (ary+1).abs
end
end | ruby | def check_arity(obj, n_args)
ary = obj.arity
if ary >= 0
n_args == ary
else
n_args >= (ary+1).abs
end
end | [
"def",
"check_arity",
"(",
"obj",
",",
"n_args",
")",
"ary",
"=",
"obj",
".",
"arity",
"if",
"ary",
">=",
"0",
"n_args",
"==",
"ary",
"else",
"n_args",
">=",
"(",
"ary",
"+",
"1",
")",
".",
"abs",
"end",
"end"
] | returns true, if the arity of "obj" matches | [
"returns",
"true",
"if",
"the",
"arity",
"of",
"obj",
"matches"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/xmlrpc/server.rb#L354-L362 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/site_ruby/1.8/rubygems/security.rb | Gem::Security.Policy.verify_gem | def verify_gem(signature, data, chain, time = Time.now)
Gem.ensure_ssl_available
cert_class = OpenSSL::X509::Certificate
exc = Gem::Security::Exception
chain ||= []
chain = chain.map{ |str| cert_class.new(str) }
signer, ch_len = chain[-1], chain.size
# make sure signature is valid
if @verify_data
# get digest algorithm (TODO: this should be configurable)
dgst = @opt[:dgst_algo]
# verify the data signature (this is the most important part, so don't
# screw it up :D)
v = signer.public_key.verify(dgst.new, signature, data)
raise exc, "Invalid Gem Signature" unless v
# make sure the signer is valid
if @verify_signer
# make sure the signing cert is valid right now
v = signer.check_validity(nil, time)
raise exc, "Invalid Signature: #{v[:desc]}" unless v[:is_valid]
end
end
# make sure the certificate chain is valid
if @verify_chain
# iterate down over the chain and verify each certificate against it's
# issuer
(ch_len - 1).downto(1) do |i|
issuer, cert = chain[i - 1, 2]
v = cert.check_validity(issuer, time)
raise exc, "%s: cert = '%s', error = '%s'" % [
'Invalid Signing Chain', cert.subject, v[:desc]
] unless v[:is_valid]
end
# verify root of chain
if @verify_root
# make sure root is self-signed
root = chain[0]
raise exc, "%s: %s (subject = '%s', issuer = '%s')" % [
'Invalid Signing Chain Root',
'Subject does not match Issuer for Gem Signing Chain',
root.subject.to_s,
root.issuer.to_s,
] unless root.issuer.to_s == root.subject.to_s
# make sure root is valid
v = root.check_validity(root, time)
raise exc, "%s: cert = '%s', error = '%s'" % [
'Invalid Signing Chain Root', root.subject, v[:desc]
] unless v[:is_valid]
# verify that the chain root is trusted
if @only_trusted
# get digest algorithm, calculate checksum of root.subject
algo = @opt[:dgst_algo]
path = Gem::Security::Policy.trusted_cert_path(root, @opt)
# check to make sure trusted path exists
raise exc, "%s: cert = '%s', error = '%s'" % [
'Untrusted Signing Chain Root',
root.subject.to_s,
"path \"#{path}\" does not exist",
] unless File.exist?(path)
# load calculate digest from saved cert file
save_cert = OpenSSL::X509::Certificate.new(File.read(path))
save_dgst = algo.digest(save_cert.public_key.to_s)
# create digest of public key
pkey_str = root.public_key.to_s
cert_dgst = algo.digest(pkey_str)
# now compare the two digests, raise exception
# if they don't match
raise exc, "%s: %s (saved = '%s', root = '%s')" % [
'Invalid Signing Chain Root',
"Saved checksum doesn't match root checksum",
save_dgst, cert_dgst,
] unless save_dgst == cert_dgst
end
end
# return the signing chain
chain.map { |cert| cert.subject }
end
end | ruby | def verify_gem(signature, data, chain, time = Time.now)
Gem.ensure_ssl_available
cert_class = OpenSSL::X509::Certificate
exc = Gem::Security::Exception
chain ||= []
chain = chain.map{ |str| cert_class.new(str) }
signer, ch_len = chain[-1], chain.size
# make sure signature is valid
if @verify_data
# get digest algorithm (TODO: this should be configurable)
dgst = @opt[:dgst_algo]
# verify the data signature (this is the most important part, so don't
# screw it up :D)
v = signer.public_key.verify(dgst.new, signature, data)
raise exc, "Invalid Gem Signature" unless v
# make sure the signer is valid
if @verify_signer
# make sure the signing cert is valid right now
v = signer.check_validity(nil, time)
raise exc, "Invalid Signature: #{v[:desc]}" unless v[:is_valid]
end
end
# make sure the certificate chain is valid
if @verify_chain
# iterate down over the chain and verify each certificate against it's
# issuer
(ch_len - 1).downto(1) do |i|
issuer, cert = chain[i - 1, 2]
v = cert.check_validity(issuer, time)
raise exc, "%s: cert = '%s', error = '%s'" % [
'Invalid Signing Chain', cert.subject, v[:desc]
] unless v[:is_valid]
end
# verify root of chain
if @verify_root
# make sure root is self-signed
root = chain[0]
raise exc, "%s: %s (subject = '%s', issuer = '%s')" % [
'Invalid Signing Chain Root',
'Subject does not match Issuer for Gem Signing Chain',
root.subject.to_s,
root.issuer.to_s,
] unless root.issuer.to_s == root.subject.to_s
# make sure root is valid
v = root.check_validity(root, time)
raise exc, "%s: cert = '%s', error = '%s'" % [
'Invalid Signing Chain Root', root.subject, v[:desc]
] unless v[:is_valid]
# verify that the chain root is trusted
if @only_trusted
# get digest algorithm, calculate checksum of root.subject
algo = @opt[:dgst_algo]
path = Gem::Security::Policy.trusted_cert_path(root, @opt)
# check to make sure trusted path exists
raise exc, "%s: cert = '%s', error = '%s'" % [
'Untrusted Signing Chain Root',
root.subject.to_s,
"path \"#{path}\" does not exist",
] unless File.exist?(path)
# load calculate digest from saved cert file
save_cert = OpenSSL::X509::Certificate.new(File.read(path))
save_dgst = algo.digest(save_cert.public_key.to_s)
# create digest of public key
pkey_str = root.public_key.to_s
cert_dgst = algo.digest(pkey_str)
# now compare the two digests, raise exception
# if they don't match
raise exc, "%s: %s (saved = '%s', root = '%s')" % [
'Invalid Signing Chain Root',
"Saved checksum doesn't match root checksum",
save_dgst, cert_dgst,
] unless save_dgst == cert_dgst
end
end
# return the signing chain
chain.map { |cert| cert.subject }
end
end | [
"def",
"verify_gem",
"(",
"signature",
",",
"data",
",",
"chain",
",",
"time",
"=",
"Time",
".",
"now",
")",
"Gem",
".",
"ensure_ssl_available",
"cert_class",
"=",
"OpenSSL",
"::",
"X509",
"::",
"Certificate",
"exc",
"=",
"Gem",
"::",
"Security",
"::",
"Exception",
"chain",
"||=",
"[",
"]",
"chain",
"=",
"chain",
".",
"map",
"{",
"|",
"str",
"|",
"cert_class",
".",
"new",
"(",
"str",
")",
"}",
"signer",
",",
"ch_len",
"=",
"chain",
"[",
"-",
"1",
"]",
",",
"chain",
".",
"size",
"if",
"@verify_data",
"dgst",
"=",
"@opt",
"[",
":dgst_algo",
"]",
"v",
"=",
"signer",
".",
"public_key",
".",
"verify",
"(",
"dgst",
".",
"new",
",",
"signature",
",",
"data",
")",
"raise",
"exc",
",",
"\"Invalid Gem Signature\"",
"unless",
"v",
"if",
"@verify_signer",
"v",
"=",
"signer",
".",
"check_validity",
"(",
"nil",
",",
"time",
")",
"raise",
"exc",
",",
"\"Invalid Signature: #{v[:desc]}\"",
"unless",
"v",
"[",
":is_valid",
"]",
"end",
"end",
"if",
"@verify_chain",
"(",
"ch_len",
"-",
"1",
")",
".",
"downto",
"(",
"1",
")",
"do",
"|",
"i",
"|",
"issuer",
",",
"cert",
"=",
"chain",
"[",
"i",
"-",
"1",
",",
"2",
"]",
"v",
"=",
"cert",
".",
"check_validity",
"(",
"issuer",
",",
"time",
")",
"raise",
"exc",
",",
"\"%s: cert = '%s', error = '%s'\"",
"%",
"[",
"'Invalid Signing Chain'",
",",
"cert",
".",
"subject",
",",
"v",
"[",
":desc",
"]",
"]",
"unless",
"v",
"[",
":is_valid",
"]",
"end",
"if",
"@verify_root",
"root",
"=",
"chain",
"[",
"0",
"]",
"raise",
"exc",
",",
"\"%s: %s (subject = '%s', issuer = '%s')\"",
"%",
"[",
"'Invalid Signing Chain Root'",
",",
"'Subject does not match Issuer for Gem Signing Chain'",
",",
"root",
".",
"subject",
".",
"to_s",
",",
"root",
".",
"issuer",
".",
"to_s",
",",
"]",
"unless",
"root",
".",
"issuer",
".",
"to_s",
"==",
"root",
".",
"subject",
".",
"to_s",
"v",
"=",
"root",
".",
"check_validity",
"(",
"root",
",",
"time",
")",
"raise",
"exc",
",",
"\"%s: cert = '%s', error = '%s'\"",
"%",
"[",
"'Invalid Signing Chain Root'",
",",
"root",
".",
"subject",
",",
"v",
"[",
":desc",
"]",
"]",
"unless",
"v",
"[",
":is_valid",
"]",
"if",
"@only_trusted",
"algo",
"=",
"@opt",
"[",
":dgst_algo",
"]",
"path",
"=",
"Gem",
"::",
"Security",
"::",
"Policy",
".",
"trusted_cert_path",
"(",
"root",
",",
"@opt",
")",
"raise",
"exc",
",",
"\"%s: cert = '%s', error = '%s'\"",
"%",
"[",
"'Untrusted Signing Chain Root'",
",",
"root",
".",
"subject",
".",
"to_s",
",",
"\"path \\\"#{path}\\\" does not exist\"",
",",
"]",
"unless",
"File",
".",
"exist?",
"(",
"path",
")",
"save_cert",
"=",
"OpenSSL",
"::",
"X509",
"::",
"Certificate",
".",
"new",
"(",
"File",
".",
"read",
"(",
"path",
")",
")",
"save_dgst",
"=",
"algo",
".",
"digest",
"(",
"save_cert",
".",
"public_key",
".",
"to_s",
")",
"pkey_str",
"=",
"root",
".",
"public_key",
".",
"to_s",
"cert_dgst",
"=",
"algo",
".",
"digest",
"(",
"pkey_str",
")",
"raise",
"exc",
",",
"\"%s: %s (saved = '%s', root = '%s')\"",
"%",
"[",
"'Invalid Signing Chain Root'",
",",
"\"Saved checksum doesn't match root checksum\"",
",",
"save_dgst",
",",
"cert_dgst",
",",
"]",
"unless",
"save_dgst",
"==",
"cert_dgst",
"end",
"end",
"chain",
".",
"map",
"{",
"|",
"cert",
"|",
"cert",
".",
"subject",
"}",
"end",
"end"
] | Verify that the gem data with the given signature and signing chain
matched this security policy at the specified time. | [
"Verify",
"that",
"the",
"gem",
"data",
"with",
"the",
"given",
"signature",
"and",
"signing",
"chain",
"matched",
"this",
"security",
"policy",
"at",
"the",
"specified",
"time",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/site_ruby/1.8/rubygems/security.rb#L419-L509 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.9/yaml/yamlnode.rb | YAML.YamlNode.transform | def transform
t = nil
if @value.is_a? Hash
t = {}
@value.each { |k,v|
t[ k ] = v[1].transform
}
elsif @value.is_a? Array
t = []
@value.each { |v|
t.push v.transform
}
else
t = @value
end
YAML.transfer_method( @type_id, t )
end | ruby | def transform
t = nil
if @value.is_a? Hash
t = {}
@value.each { |k,v|
t[ k ] = v[1].transform
}
elsif @value.is_a? Array
t = []
@value.each { |v|
t.push v.transform
}
else
t = @value
end
YAML.transfer_method( @type_id, t )
end | [
"def",
"transform",
"t",
"=",
"nil",
"if",
"@value",
".",
"is_a?",
"Hash",
"t",
"=",
"{",
"}",
"@value",
".",
"each",
"{",
"|",
"k",
",",
"v",
"|",
"t",
"[",
"k",
"]",
"=",
"v",
"[",
"1",
"]",
".",
"transform",
"}",
"elsif",
"@value",
".",
"is_a?",
"Array",
"t",
"=",
"[",
"]",
"@value",
".",
"each",
"{",
"|",
"v",
"|",
"t",
".",
"push",
"v",
".",
"transform",
"}",
"else",
"t",
"=",
"@value",
"end",
"YAML",
".",
"transfer_method",
"(",
"@type_id",
",",
"t",
")",
"end"
] | Transform this node fully into a native type | [
"Transform",
"this",
"node",
"fully",
"into",
"a",
"native",
"type"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/yaml/yamlnode.rb#L34-L50 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb | RDoc.RubyParser.collect_first_comment | def collect_first_comment
skip_tkspace
res = ''
first_line = true
tk = get_tk
while tk.kind_of?(TkCOMMENT)
if first_line && /\A#!/ =~ tk.text
skip_tkspace
tk = get_tk
elsif first_line && /\A#\s*-\*-/ =~ tk.text
first_line = false
skip_tkspace
tk = get_tk
else
first_line = false
res << tk.text << "\n"
tk = get_tk
if tk.kind_of? TkNL
skip_tkspace(false)
tk = get_tk
end
end
end
unget_tk(tk)
res
end | ruby | def collect_first_comment
skip_tkspace
res = ''
first_line = true
tk = get_tk
while tk.kind_of?(TkCOMMENT)
if first_line && /\A#!/ =~ tk.text
skip_tkspace
tk = get_tk
elsif first_line && /\A#\s*-\*-/ =~ tk.text
first_line = false
skip_tkspace
tk = get_tk
else
first_line = false
res << tk.text << "\n"
tk = get_tk
if tk.kind_of? TkNL
skip_tkspace(false)
tk = get_tk
end
end
end
unget_tk(tk)
res
end | [
"def",
"collect_first_comment",
"skip_tkspace",
"res",
"=",
"''",
"first_line",
"=",
"true",
"tk",
"=",
"get_tk",
"while",
"tk",
".",
"kind_of?",
"(",
"TkCOMMENT",
")",
"if",
"first_line",
"&&",
"/",
"\\A",
"/",
"=~",
"tk",
".",
"text",
"skip_tkspace",
"tk",
"=",
"get_tk",
"elsif",
"first_line",
"&&",
"/",
"\\A",
"\\s",
"\\*",
"/",
"=~",
"tk",
".",
"text",
"first_line",
"=",
"false",
"skip_tkspace",
"tk",
"=",
"get_tk",
"else",
"first_line",
"=",
"false",
"res",
"<<",
"tk",
".",
"text",
"<<",
"\"\\n\"",
"tk",
"=",
"get_tk",
"if",
"tk",
".",
"kind_of?",
"TkNL",
"skip_tkspace",
"(",
"false",
")",
"tk",
"=",
"get_tk",
"end",
"end",
"end",
"unget_tk",
"(",
"tk",
")",
"res",
"end"
] | Look for the first comment in a file that isn't
a shebang line. | [
"Look",
"for",
"the",
"first",
"comment",
"in",
"a",
"file",
"that",
"isn",
"t",
"a",
"shebang",
"line",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb#L1542-L1568 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb | RDoc.RubyParser.parse_method_parameters | def parse_method_parameters(method)
res = parse_method_or_yield_parameters(method)
res = "(" + res + ")" unless res[0] == ?(
method.params = res unless method.params
if method.block_params.nil?
skip_tkspace(false)
read_documentation_modifiers(method, METHOD_MODIFIERS)
end
end | ruby | def parse_method_parameters(method)
res = parse_method_or_yield_parameters(method)
res = "(" + res + ")" unless res[0] == ?(
method.params = res unless method.params
if method.block_params.nil?
skip_tkspace(false)
read_documentation_modifiers(method, METHOD_MODIFIERS)
end
end | [
"def",
"parse_method_parameters",
"(",
"method",
")",
"res",
"=",
"parse_method_or_yield_parameters",
"(",
"method",
")",
"res",
"=",
"\"(\"",
"+",
"res",
"+",
"\")\"",
"unless",
"res",
"[",
"0",
"]",
"==",
"?(",
"method",
".",
"params",
"=",
"res",
"unless",
"method",
".",
"params",
"if",
"method",
".",
"block_params",
".",
"nil?",
"skip_tkspace",
"(",
"false",
")",
"read_documentation_modifiers",
"(",
"method",
",",
"METHOD_MODIFIERS",
")",
"end",
"end"
] | Capture the method's parameters. Along the way,
look for a comment containing
# yields: ....
and add this as the block_params for the method | [
"Capture",
"the",
"method",
"s",
"parameters",
".",
"Along",
"the",
"way",
"look",
"for",
"a",
"comment",
"containing"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb#L2016-L2024 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb | RDoc.RubyParser.skip_optional_do_after_expression | def skip_optional_do_after_expression
skip_tkspace(false)
tk = get_tk
case tk
when TkLPAREN, TkfLPAREN
end_token = TkRPAREN
else
end_token = TkNL
end
nest = 0
@scanner.instance_eval{@continue = false}
loop do
puts("\nWhile: #{tk}, #{@scanner.continue} " +
"#{@scanner.lex_state} #{nest}") if $DEBUG
case tk
when TkSEMICOLON
break
when TkLPAREN, TkfLPAREN
nest += 1
when TkDO
break if nest.zero?
when end_token
if end_token == TkRPAREN
nest -= 1
break if @scanner.lex_state == EXPR_END and nest.zero?
else
break unless @scanner.continue
end
end
tk = get_tk
end
skip_tkspace(false)
if peek_tk.kind_of? TkDO
get_tk
end
end | ruby | def skip_optional_do_after_expression
skip_tkspace(false)
tk = get_tk
case tk
when TkLPAREN, TkfLPAREN
end_token = TkRPAREN
else
end_token = TkNL
end
nest = 0
@scanner.instance_eval{@continue = false}
loop do
puts("\nWhile: #{tk}, #{@scanner.continue} " +
"#{@scanner.lex_state} #{nest}") if $DEBUG
case tk
when TkSEMICOLON
break
when TkLPAREN, TkfLPAREN
nest += 1
when TkDO
break if nest.zero?
when end_token
if end_token == TkRPAREN
nest -= 1
break if @scanner.lex_state == EXPR_END and nest.zero?
else
break unless @scanner.continue
end
end
tk = get_tk
end
skip_tkspace(false)
if peek_tk.kind_of? TkDO
get_tk
end
end | [
"def",
"skip_optional_do_after_expression",
"skip_tkspace",
"(",
"false",
")",
"tk",
"=",
"get_tk",
"case",
"tk",
"when",
"TkLPAREN",
",",
"TkfLPAREN",
"end_token",
"=",
"TkRPAREN",
"else",
"end_token",
"=",
"TkNL",
"end",
"nest",
"=",
"0",
"@scanner",
".",
"instance_eval",
"{",
"@continue",
"=",
"false",
"}",
"loop",
"do",
"puts",
"(",
"\"\\nWhile: #{tk}, #{@scanner.continue} \"",
"+",
"\"#{@scanner.lex_state} #{nest}\"",
")",
"if",
"$DEBUG",
"case",
"tk",
"when",
"TkSEMICOLON",
"break",
"when",
"TkLPAREN",
",",
"TkfLPAREN",
"nest",
"+=",
"1",
"when",
"TkDO",
"break",
"if",
"nest",
".",
"zero?",
"when",
"end_token",
"if",
"end_token",
"==",
"TkRPAREN",
"nest",
"-=",
"1",
"break",
"if",
"@scanner",
".",
"lex_state",
"==",
"EXPR_END",
"and",
"nest",
".",
"zero?",
"else",
"break",
"unless",
"@scanner",
".",
"continue",
"end",
"end",
"tk",
"=",
"get_tk",
"end",
"skip_tkspace",
"(",
"false",
")",
"if",
"peek_tk",
".",
"kind_of?",
"TkDO",
"get_tk",
"end",
"end"
] | while, until, and for have an optional | [
"while",
"until",
"and",
"for",
"have",
"an",
"optional"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb#L2088-L2125 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb | RDoc.RubyParser.get_class_specification | def get_class_specification
tk = get_tk
return "self" if tk.kind_of?(TkSELF)
res = ""
while tk.kind_of?(TkCOLON2) ||
tk.kind_of?(TkCOLON3) ||
tk.kind_of?(TkCONSTANT)
res += tk.text
tk = get_tk
end
unget_tk(tk)
skip_tkspace(false)
get_tkread # empty out read buffer
tk = get_tk
case tk
when TkNL, TkCOMMENT, TkSEMICOLON
unget_tk(tk)
return res
end
res += parse_call_parameters(tk)
res
end | ruby | def get_class_specification
tk = get_tk
return "self" if tk.kind_of?(TkSELF)
res = ""
while tk.kind_of?(TkCOLON2) ||
tk.kind_of?(TkCOLON3) ||
tk.kind_of?(TkCONSTANT)
res += tk.text
tk = get_tk
end
unget_tk(tk)
skip_tkspace(false)
get_tkread # empty out read buffer
tk = get_tk
case tk
when TkNL, TkCOMMENT, TkSEMICOLON
unget_tk(tk)
return res
end
res += parse_call_parameters(tk)
res
end | [
"def",
"get_class_specification",
"tk",
"=",
"get_tk",
"return",
"\"self\"",
"if",
"tk",
".",
"kind_of?",
"(",
"TkSELF",
")",
"res",
"=",
"\"\"",
"while",
"tk",
".",
"kind_of?",
"(",
"TkCOLON2",
")",
"||",
"tk",
".",
"kind_of?",
"(",
"TkCOLON3",
")",
"||",
"tk",
".",
"kind_of?",
"(",
"TkCONSTANT",
")",
"res",
"+=",
"tk",
".",
"text",
"tk",
"=",
"get_tk",
"end",
"unget_tk",
"(",
"tk",
")",
"skip_tkspace",
"(",
"false",
")",
"get_tkread",
"tk",
"=",
"get_tk",
"case",
"tk",
"when",
"TkNL",
",",
"TkCOMMENT",
",",
"TkSEMICOLON",
"unget_tk",
"(",
"tk",
")",
"return",
"res",
"end",
"res",
"+=",
"parse_call_parameters",
"(",
"tk",
")",
"res",
"end"
] | Return a superclass, which can be either a constant
of an expression | [
"Return",
"a",
"superclass",
"which",
"can",
"be",
"either",
"a",
"constant",
"of",
"an",
"expression"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb#L2130-L2158 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb | RDoc.RubyParser.get_constant | def get_constant
res = ""
skip_tkspace(false)
tk = get_tk
while tk.kind_of?(TkCOLON2) ||
tk.kind_of?(TkCOLON3) ||
tk.kind_of?(TkCONSTANT)
res += tk.text
tk = get_tk
end
# if res.empty?
# warn("Unexpected token #{tk} in constant")
# end
unget_tk(tk)
res
end | ruby | def get_constant
res = ""
skip_tkspace(false)
tk = get_tk
while tk.kind_of?(TkCOLON2) ||
tk.kind_of?(TkCOLON3) ||
tk.kind_of?(TkCONSTANT)
res += tk.text
tk = get_tk
end
# if res.empty?
# warn("Unexpected token #{tk} in constant")
# end
unget_tk(tk)
res
end | [
"def",
"get_constant",
"res",
"=",
"\"\"",
"skip_tkspace",
"(",
"false",
")",
"tk",
"=",
"get_tk",
"while",
"tk",
".",
"kind_of?",
"(",
"TkCOLON2",
")",
"||",
"tk",
".",
"kind_of?",
"(",
"TkCOLON3",
")",
"||",
"tk",
".",
"kind_of?",
"(",
"TkCONSTANT",
")",
"res",
"+=",
"tk",
".",
"text",
"tk",
"=",
"get_tk",
"end",
"unget_tk",
"(",
"tk",
")",
"res",
"end"
] | Parse a constant, which might be qualified by
one or more class or module names | [
"Parse",
"a",
"constant",
"which",
"might",
"be",
"qualified",
"by",
"one",
"or",
"more",
"class",
"or",
"module",
"names"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb#L2202-L2220 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb | RDoc.RubyParser.get_constant_with_optional_parens | def get_constant_with_optional_parens
skip_tkspace(false)
nest = 0
while (tk = peek_tk).kind_of?(TkLPAREN) || tk.kind_of?(TkfLPAREN)
get_tk
skip_tkspace(true)
nest += 1
end
name = get_constant
while nest > 0
skip_tkspace(true)
tk = get_tk
nest -= 1 if tk.kind_of?(TkRPAREN)
end
name
end | ruby | def get_constant_with_optional_parens
skip_tkspace(false)
nest = 0
while (tk = peek_tk).kind_of?(TkLPAREN) || tk.kind_of?(TkfLPAREN)
get_tk
skip_tkspace(true)
nest += 1
end
name = get_constant
while nest > 0
skip_tkspace(true)
tk = get_tk
nest -= 1 if tk.kind_of?(TkRPAREN)
end
name
end | [
"def",
"get_constant_with_optional_parens",
"skip_tkspace",
"(",
"false",
")",
"nest",
"=",
"0",
"while",
"(",
"tk",
"=",
"peek_tk",
")",
".",
"kind_of?",
"(",
"TkLPAREN",
")",
"||",
"tk",
".",
"kind_of?",
"(",
"TkfLPAREN",
")",
"get_tk",
"skip_tkspace",
"(",
"true",
")",
"nest",
"+=",
"1",
"end",
"name",
"=",
"get_constant",
"while",
"nest",
">",
"0",
"skip_tkspace",
"(",
"true",
")",
"tk",
"=",
"get_tk",
"nest",
"-=",
"1",
"if",
"tk",
".",
"kind_of?",
"(",
"TkRPAREN",
")",
"end",
"name",
"end"
] | Get a constant that may be surrounded by parens | [
"Get",
"a",
"constant",
"that",
"may",
"be",
"surrounded",
"by",
"parens"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb#L2224-L2241 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb | RDoc.RubyParser.read_directive | def read_directive(allowed)
tk = get_tk
puts "directive: #{tk.inspect}" if $DEBUG
result = nil
if tk.kind_of?(TkCOMMENT)
if tk.text =~ /\s*:?(\w+):\s*(.*)/
directive = $1.downcase
if allowed.include?(directive)
result = [directive, $2]
end
end
else
unget_tk(tk)
end
result
end | ruby | def read_directive(allowed)
tk = get_tk
puts "directive: #{tk.inspect}" if $DEBUG
result = nil
if tk.kind_of?(TkCOMMENT)
if tk.text =~ /\s*:?(\w+):\s*(.*)/
directive = $1.downcase
if allowed.include?(directive)
result = [directive, $2]
end
end
else
unget_tk(tk)
end
result
end | [
"def",
"read_directive",
"(",
"allowed",
")",
"tk",
"=",
"get_tk",
"puts",
"\"directive: #{tk.inspect}\"",
"if",
"$DEBUG",
"result",
"=",
"nil",
"if",
"tk",
".",
"kind_of?",
"(",
"TkCOMMENT",
")",
"if",
"tk",
".",
"text",
"=~",
"/",
"\\s",
"\\w",
"\\s",
"/",
"directive",
"=",
"$1",
".",
"downcase",
"if",
"allowed",
".",
"include?",
"(",
"directive",
")",
"result",
"=",
"[",
"directive",
",",
"$2",
"]",
"end",
"end",
"else",
"unget_tk",
"(",
"tk",
")",
"end",
"result",
"end"
] | Directives are modifier comments that can appear after class, module,
or method names. For example
def fred # :yields: a, b
or
class SM # :nodoc:
we return the directive name and any parameters as a two element array | [
"Directives",
"are",
"modifier",
"comments",
"that",
"can",
"appear",
"after",
"class",
"module",
"or",
"method",
"names",
".",
"For",
"example"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_rb.rb#L2254-L2269 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/soap/wsdlDriver.rb | SOAP.WSDLDriverFactory.create_driver | def create_driver(servicename = nil, portname = nil)
warn("WSDLDriverFactory#create_driver is depricated. Use create_rpc_driver instead.")
port = find_port(servicename, portname)
WSDLDriver.new(@wsdl, port, nil)
end | ruby | def create_driver(servicename = nil, portname = nil)
warn("WSDLDriverFactory#create_driver is depricated. Use create_rpc_driver instead.")
port = find_port(servicename, portname)
WSDLDriver.new(@wsdl, port, nil)
end | [
"def",
"create_driver",
"(",
"servicename",
"=",
"nil",
",",
"portname",
"=",
"nil",
")",
"warn",
"(",
"\"WSDLDriverFactory#create_driver is depricated. Use create_rpc_driver instead.\"",
")",
"port",
"=",
"find_port",
"(",
"servicename",
",",
"portname",
")",
"WSDLDriver",
".",
"new",
"(",
"@wsdl",
",",
"port",
",",
"nil",
")",
"end"
] | depricated old interface | [
"depricated",
"old",
"interface"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/soap/wsdlDriver.rb#L45-L49 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb | Generators.MarkUp.markup | def markup(str, remove_para=false)
return '' unless str
unless defined? @markup
@markup = SM::SimpleMarkup.new
# class names, variable names, or instance variables
@markup.add_special(/(
\w+(::\w+)*[.\#]\w+(\([\.\w+\*\/\+\-\=\<\>]+\))? # A::B.meth(**) (for operator in Fortran95)
| \#\w+(\([.\w\*\/\+\-\=\<\>]+\))? # meth(**) (for operator in Fortran95)
| \b([A-Z]\w*(::\w+)*[.\#]\w+) # A::B.meth
| \b([A-Z]\w+(::\w+)*) # A::B..
| \#\w+[!?=]? # #meth_name
| \b\w+([_\/\.]+\w+)*[!?=]? # meth_name
)/x,
:CROSSREF)
# external hyperlinks
@markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)
# and links of the form <text>[<url>]
@markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\.\S+?\])/, :TIDYLINK)
# @markup.add_special(/\b(\S+?\[\S+?\.\S+?\])/, :TIDYLINK)
end
unless defined? @html_formatter
@html_formatter = HyperlinkHtml.new(self.path, self)
end
# Convert leading comment markers to spaces, but only
# if all non-blank lines have them
if str =~ /^(?>\s*)[^\#]/
content = str
else
content = str.gsub(/^\s*(#+)/) { $1.tr('#',' ') }
end
res = @markup.convert(content, @html_formatter)
if remove_para
res.sub!(/^<p>/, '')
res.sub!(/<\/p>$/, '')
end
res
end | ruby | def markup(str, remove_para=false)
return '' unless str
unless defined? @markup
@markup = SM::SimpleMarkup.new
# class names, variable names, or instance variables
@markup.add_special(/(
\w+(::\w+)*[.\#]\w+(\([\.\w+\*\/\+\-\=\<\>]+\))? # A::B.meth(**) (for operator in Fortran95)
| \#\w+(\([.\w\*\/\+\-\=\<\>]+\))? # meth(**) (for operator in Fortran95)
| \b([A-Z]\w*(::\w+)*[.\#]\w+) # A::B.meth
| \b([A-Z]\w+(::\w+)*) # A::B..
| \#\w+[!?=]? # #meth_name
| \b\w+([_\/\.]+\w+)*[!?=]? # meth_name
)/x,
:CROSSREF)
# external hyperlinks
@markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)
# and links of the form <text>[<url>]
@markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\.\S+?\])/, :TIDYLINK)
# @markup.add_special(/\b(\S+?\[\S+?\.\S+?\])/, :TIDYLINK)
end
unless defined? @html_formatter
@html_formatter = HyperlinkHtml.new(self.path, self)
end
# Convert leading comment markers to spaces, but only
# if all non-blank lines have them
if str =~ /^(?>\s*)[^\#]/
content = str
else
content = str.gsub(/^\s*(#+)/) { $1.tr('#',' ') }
end
res = @markup.convert(content, @html_formatter)
if remove_para
res.sub!(/^<p>/, '')
res.sub!(/<\/p>$/, '')
end
res
end | [
"def",
"markup",
"(",
"str",
",",
"remove_para",
"=",
"false",
")",
"return",
"''",
"unless",
"str",
"unless",
"defined?",
"@markup",
"@markup",
"=",
"SM",
"::",
"SimpleMarkup",
".",
"new",
"@markup",
".",
"add_special",
"(",
"/",
"\\w",
"\\w",
"\\#",
"\\w",
"\\(",
"\\.",
"\\w",
"\\*",
"\\/",
"\\+",
"\\-",
"\\=",
"\\<",
"\\>",
"\\)",
"\\#",
"\\w",
"\\(",
"\\w",
"\\*",
"\\/",
"\\+",
"\\-",
"\\=",
"\\<",
"\\>",
"\\)",
"\\b",
"\\w",
"\\w",
"\\#",
"\\w",
"\\b",
"\\w",
"\\w",
"\\#",
"\\w",
"\\b",
"\\w",
"\\/",
"\\.",
"\\w",
"/x",
",",
":CROSSREF",
")",
"@markup",
".",
"add_special",
"(",
"/",
"\\.",
"\\S",
"\\w",
"/",
",",
":HYPERLINK",
")",
"@markup",
".",
"add_special",
"(",
"/",
"\\{",
"\\}",
"\\b",
"\\S",
"\\[",
"\\S",
"\\.",
"\\S",
"\\]",
"/",
",",
":TIDYLINK",
")",
"end",
"unless",
"defined?",
"@html_formatter",
"@html_formatter",
"=",
"HyperlinkHtml",
".",
"new",
"(",
"self",
".",
"path",
",",
"self",
")",
"end",
"if",
"str",
"=~",
"/",
"\\s",
"\\#",
"/",
"content",
"=",
"str",
"else",
"content",
"=",
"str",
".",
"gsub",
"(",
"/",
"\\s",
"/",
")",
"{",
"$1",
".",
"tr",
"(",
"'#'",
",",
"' '",
")",
"}",
"end",
"res",
"=",
"@markup",
".",
"convert",
"(",
"content",
",",
"@html_formatter",
")",
"if",
"remove_para",
"res",
".",
"sub!",
"(",
"/",
"/",
",",
"''",
")",
"res",
".",
"sub!",
"(",
"/",
"\\/",
"/",
",",
"''",
")",
"end",
"res",
"end"
] | Convert a string in markup format into HTML. We keep a cached
SimpleMarkup object lying around after the first time we're
called per object. | [
"Convert",
"a",
"string",
"in",
"markup",
"format",
"into",
"HTML",
".",
"We",
"keep",
"a",
"cached",
"SimpleMarkup",
"object",
"lying",
"around",
"after",
"the",
"first",
"time",
"we",
"re",
"called",
"per",
"object",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb#L209-L252 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb | Generators.ContextUser.build_method_detail_list | def build_method_detail_list(section)
outer = []
methods = @methods.sort
for singleton in [true, false]
for vis in [ :public, :protected, :private ]
res = []
methods.each do |m|
if m.section == section and
m.document_self and
m.visibility == vis and
m.singleton == singleton
row = {}
if m.call_seq
row["callseq"] = m.call_seq.gsub(/->/, '→')
else
row["name"] = CGI.escapeHTML(m.name)
row["params"] = m.params
end
desc = m.description.strip
row["m_desc"] = desc unless desc.empty?
row["aref"] = m.aref
row["visibility"] = m.visibility.to_s
alias_names = []
m.aliases.each do |other|
if other.viewer # won't be if the alias is private
alias_names << {
'name' => other.name,
'aref' => other.viewer.as_href(path)
}
end
end
unless alias_names.empty?
row["aka"] = alias_names
end
if @options.inline_source
code = m.source_code
row["sourcecode"] = code if code
else
code = m.src_url
if code
row["codeurl"] = code
row["imgurl"] = m.img_url
end
end
res << row
end
end
if res.size > 0
outer << {
"type" => vis.to_s.capitalize,
"category" => singleton ? "Class" : "Instance",
"methods" => res
}
end
end
end
outer
end | ruby | def build_method_detail_list(section)
outer = []
methods = @methods.sort
for singleton in [true, false]
for vis in [ :public, :protected, :private ]
res = []
methods.each do |m|
if m.section == section and
m.document_self and
m.visibility == vis and
m.singleton == singleton
row = {}
if m.call_seq
row["callseq"] = m.call_seq.gsub(/->/, '→')
else
row["name"] = CGI.escapeHTML(m.name)
row["params"] = m.params
end
desc = m.description.strip
row["m_desc"] = desc unless desc.empty?
row["aref"] = m.aref
row["visibility"] = m.visibility.to_s
alias_names = []
m.aliases.each do |other|
if other.viewer # won't be if the alias is private
alias_names << {
'name' => other.name,
'aref' => other.viewer.as_href(path)
}
end
end
unless alias_names.empty?
row["aka"] = alias_names
end
if @options.inline_source
code = m.source_code
row["sourcecode"] = code if code
else
code = m.src_url
if code
row["codeurl"] = code
row["imgurl"] = m.img_url
end
end
res << row
end
end
if res.size > 0
outer << {
"type" => vis.to_s.capitalize,
"category" => singleton ? "Class" : "Instance",
"methods" => res
}
end
end
end
outer
end | [
"def",
"build_method_detail_list",
"(",
"section",
")",
"outer",
"=",
"[",
"]",
"methods",
"=",
"@methods",
".",
"sort",
"for",
"singleton",
"in",
"[",
"true",
",",
"false",
"]",
"for",
"vis",
"in",
"[",
":public",
",",
":protected",
",",
":private",
"]",
"res",
"=",
"[",
"]",
"methods",
".",
"each",
"do",
"|",
"m",
"|",
"if",
"m",
".",
"section",
"==",
"section",
"and",
"m",
".",
"document_self",
"and",
"m",
".",
"visibility",
"==",
"vis",
"and",
"m",
".",
"singleton",
"==",
"singleton",
"row",
"=",
"{",
"}",
"if",
"m",
".",
"call_seq",
"row",
"[",
"\"callseq\"",
"]",
"=",
"m",
".",
"call_seq",
".",
"gsub",
"(",
"/",
"/",
",",
"'→'",
")",
"else",
"row",
"[",
"\"name\"",
"]",
"=",
"CGI",
".",
"escapeHTML",
"(",
"m",
".",
"name",
")",
"row",
"[",
"\"params\"",
"]",
"=",
"m",
".",
"params",
"end",
"desc",
"=",
"m",
".",
"description",
".",
"strip",
"row",
"[",
"\"m_desc\"",
"]",
"=",
"desc",
"unless",
"desc",
".",
"empty?",
"row",
"[",
"\"aref\"",
"]",
"=",
"m",
".",
"aref",
"row",
"[",
"\"visibility\"",
"]",
"=",
"m",
".",
"visibility",
".",
"to_s",
"alias_names",
"=",
"[",
"]",
"m",
".",
"aliases",
".",
"each",
"do",
"|",
"other",
"|",
"if",
"other",
".",
"viewer",
"alias_names",
"<<",
"{",
"'name'",
"=>",
"other",
".",
"name",
",",
"'aref'",
"=>",
"other",
".",
"viewer",
".",
"as_href",
"(",
"path",
")",
"}",
"end",
"end",
"unless",
"alias_names",
".",
"empty?",
"row",
"[",
"\"aka\"",
"]",
"=",
"alias_names",
"end",
"if",
"@options",
".",
"inline_source",
"code",
"=",
"m",
".",
"source_code",
"row",
"[",
"\"sourcecode\"",
"]",
"=",
"code",
"if",
"code",
"else",
"code",
"=",
"m",
".",
"src_url",
"if",
"code",
"row",
"[",
"\"codeurl\"",
"]",
"=",
"code",
"row",
"[",
"\"imgurl\"",
"]",
"=",
"m",
".",
"img_url",
"end",
"end",
"res",
"<<",
"row",
"end",
"end",
"if",
"res",
".",
"size",
">",
"0",
"outer",
"<<",
"{",
"\"type\"",
"=>",
"vis",
".",
"to_s",
".",
"capitalize",
",",
"\"category\"",
"=>",
"singleton",
"?",
"\"Class\"",
":",
"\"Instance\"",
",",
"\"methods\"",
"=>",
"res",
"}",
"end",
"end",
"end",
"outer",
"end"
] | Build an array of arrays of method details. The outer array has up
to six entries, public, private, and protected for both class
methods, the other for instance methods. The inner arrays contain
a hash for each method | [
"Build",
"an",
"array",
"of",
"arrays",
"of",
"method",
"details",
".",
"The",
"outer",
"array",
"has",
"up",
"to",
"six",
"entries",
"public",
"private",
"and",
"protected",
"for",
"both",
"class",
"methods",
"the",
"other",
"for",
"instance",
"methods",
".",
"The",
"inner",
"arrays",
"contain",
"a",
"hash",
"for",
"each",
"method"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb#L432-L492 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb | Generators.ContextUser.build_class_list | def build_class_list(level, from, section, infile=nil)
res = ""
prefix = " ::" * level;
from.modules.sort.each do |mod|
next unless mod.section == section
next if infile && !mod.defined_in?(infile)
if mod.document_self
res <<
prefix <<
"Module " <<
href(url(mod.viewer.path), "link", mod.full_name) <<
"<br />\n" <<
build_class_list(level + 1, mod, section, infile)
end
end
from.classes.sort.each do |cls|
next unless cls.section == section
next if infile && !cls.defined_in?(infile)
if cls.document_self
res <<
prefix <<
"Class " <<
href(url(cls.viewer.path), "link", cls.full_name) <<
"<br />\n" <<
build_class_list(level + 1, cls, section, infile)
end
end
res
end | ruby | def build_class_list(level, from, section, infile=nil)
res = ""
prefix = " ::" * level;
from.modules.sort.each do |mod|
next unless mod.section == section
next if infile && !mod.defined_in?(infile)
if mod.document_self
res <<
prefix <<
"Module " <<
href(url(mod.viewer.path), "link", mod.full_name) <<
"<br />\n" <<
build_class_list(level + 1, mod, section, infile)
end
end
from.classes.sort.each do |cls|
next unless cls.section == section
next if infile && !cls.defined_in?(infile)
if cls.document_self
res <<
prefix <<
"Class " <<
href(url(cls.viewer.path), "link", cls.full_name) <<
"<br />\n" <<
build_class_list(level + 1, cls, section, infile)
end
end
res
end | [
"def",
"build_class_list",
"(",
"level",
",",
"from",
",",
"section",
",",
"infile",
"=",
"nil",
")",
"res",
"=",
"\"\"",
"prefix",
"=",
"\" ::\"",
"*",
"level",
";",
"from",
".",
"modules",
".",
"sort",
".",
"each",
"do",
"|",
"mod",
"|",
"next",
"unless",
"mod",
".",
"section",
"==",
"section",
"next",
"if",
"infile",
"&&",
"!",
"mod",
".",
"defined_in?",
"(",
"infile",
")",
"if",
"mod",
".",
"document_self",
"res",
"<<",
"prefix",
"<<",
"\"Module \"",
"<<",
"href",
"(",
"url",
"(",
"mod",
".",
"viewer",
".",
"path",
")",
",",
"\"link\"",
",",
"mod",
".",
"full_name",
")",
"<<",
"\"<br />\\n\"",
"<<",
"build_class_list",
"(",
"level",
"+",
"1",
",",
"mod",
",",
"section",
",",
"infile",
")",
"end",
"end",
"from",
".",
"classes",
".",
"sort",
".",
"each",
"do",
"|",
"cls",
"|",
"next",
"unless",
"cls",
".",
"section",
"==",
"section",
"next",
"if",
"infile",
"&&",
"!",
"cls",
".",
"defined_in?",
"(",
"infile",
")",
"if",
"cls",
".",
"document_self",
"res",
"<<",
"prefix",
"<<",
"\"Class \"",
"<<",
"href",
"(",
"url",
"(",
"cls",
".",
"viewer",
".",
"path",
")",
",",
"\"link\"",
",",
"cls",
".",
"full_name",
")",
"<<",
"\"<br />\\n\"",
"<<",
"build_class_list",
"(",
"level",
"+",
"1",
",",
"cls",
",",
"section",
",",
"infile",
")",
"end",
"end",
"res",
"end"
] | Build the structured list of classes and modules contained
in this context. | [
"Build",
"the",
"structured",
"list",
"of",
"classes",
"and",
"modules",
"contained",
"in",
"this",
"context",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb#L497-L528 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb | Generators.HTMLGenerator.load_html_template | def load_html_template
template = @options.template
unless template =~ %r{/|\\}
template = File.join("rdoc/generators/template",
@options.generator.key, template)
end
require template
extend RDoc::Page
rescue LoadError
$stderr.puts "Could not find HTML template '#{template}'"
exit 99
end | ruby | def load_html_template
template = @options.template
unless template =~ %r{/|\\}
template = File.join("rdoc/generators/template",
@options.generator.key, template)
end
require template
extend RDoc::Page
rescue LoadError
$stderr.puts "Could not find HTML template '#{template}'"
exit 99
end | [
"def",
"load_html_template",
"template",
"=",
"@options",
".",
"template",
"unless",
"template",
"=~",
"%r{",
"\\\\",
"}",
"template",
"=",
"File",
".",
"join",
"(",
"\"rdoc/generators/template\"",
",",
"@options",
".",
"generator",
".",
"key",
",",
"template",
")",
"end",
"require",
"template",
"extend",
"RDoc",
"::",
"Page",
"rescue",
"LoadError",
"$stderr",
".",
"puts",
"\"Could not find HTML template '#{template}'\"",
"exit",
"99",
"end"
] | Load up the HTML template specified in the options.
If the template name contains a slash, use it literally | [
"Load",
"up",
"the",
"HTML",
"template",
"specified",
"in",
"the",
"options",
".",
"If",
"the",
"template",
"name",
"contains",
"a",
"slash",
"use",
"it",
"literally"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb#L1206-L1217 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb | Generators.HTMLGenerator.write_style_sheet | def write_style_sheet
template = TemplatePage.new(RDoc::Page::STYLE)
unless @options.css
File.open(CSS_NAME, "w") do |f|
values = { "fonts" => RDoc::Page::FONTS }
template.write_html_on(f, values)
end
end
end | ruby | def write_style_sheet
template = TemplatePage.new(RDoc::Page::STYLE)
unless @options.css
File.open(CSS_NAME, "w") do |f|
values = { "fonts" => RDoc::Page::FONTS }
template.write_html_on(f, values)
end
end
end | [
"def",
"write_style_sheet",
"template",
"=",
"TemplatePage",
".",
"new",
"(",
"RDoc",
"::",
"Page",
"::",
"STYLE",
")",
"unless",
"@options",
".",
"css",
"File",
".",
"open",
"(",
"CSS_NAME",
",",
"\"w\"",
")",
"do",
"|",
"f",
"|",
"values",
"=",
"{",
"\"fonts\"",
"=>",
"RDoc",
"::",
"Page",
"::",
"FONTS",
"}",
"template",
".",
"write_html_on",
"(",
"f",
",",
"values",
")",
"end",
"end",
"end"
] | Write out the style sheet used by the main frames | [
"Write",
"out",
"the",
"style",
"sheet",
"used",
"by",
"the",
"main",
"frames"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb#L1223-L1231 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb | Generators.HTMLGenerator.main_url | def main_url
main_page = @options.main_page
ref = nil
if main_page
ref = AllReferences[main_page]
if ref
ref = ref.path
else
$stderr.puts "Could not find main page #{main_page}"
end
end
unless ref
for file in @files
if file.document_self
ref = file.path
break
end
end
end
unless ref
$stderr.puts "Couldn't find anything to document"
$stderr.puts "Perhaps you've used :stopdoc: in all classes"
exit(1)
end
ref
end | ruby | def main_url
main_page = @options.main_page
ref = nil
if main_page
ref = AllReferences[main_page]
if ref
ref = ref.path
else
$stderr.puts "Could not find main page #{main_page}"
end
end
unless ref
for file in @files
if file.document_self
ref = file.path
break
end
end
end
unless ref
$stderr.puts "Couldn't find anything to document"
$stderr.puts "Perhaps you've used :stopdoc: in all classes"
exit(1)
end
ref
end | [
"def",
"main_url",
"main_page",
"=",
"@options",
".",
"main_page",
"ref",
"=",
"nil",
"if",
"main_page",
"ref",
"=",
"AllReferences",
"[",
"main_page",
"]",
"if",
"ref",
"ref",
"=",
"ref",
".",
"path",
"else",
"$stderr",
".",
"puts",
"\"Could not find main page #{main_page}\"",
"end",
"end",
"unless",
"ref",
"for",
"file",
"in",
"@files",
"if",
"file",
".",
"document_self",
"ref",
"=",
"file",
".",
"path",
"break",
"end",
"end",
"end",
"unless",
"ref",
"$stderr",
".",
"puts",
"\"Couldn't find anything to document\"",
"$stderr",
".",
"puts",
"\"Perhaps you've used :stopdoc: in all classes\"",
"exit",
"(",
"1",
")",
"end",
"ref",
"end"
] | return the url of the main page | [
"return",
"the",
"url",
"of",
"the",
"main",
"page"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb#L1361-L1389 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb | Generators.HTMLGeneratorInOne.generate_xml | def generate_xml
values = {
'charset' => @options.charset,
'files' => gen_into(@files),
'classes' => gen_into(@classes),
'title' => CGI.escapeHTML(@options.title),
}
# this method is defined in the template file
write_extra_pages if defined? write_extra_pages
template = TemplatePage.new(RDoc::Page::ONE_PAGE)
if @options.op_name
opfile = File.open(@options.op_name, "w")
else
opfile = $stdout
end
template.write_html_on(opfile, values)
end | ruby | def generate_xml
values = {
'charset' => @options.charset,
'files' => gen_into(@files),
'classes' => gen_into(@classes),
'title' => CGI.escapeHTML(@options.title),
}
# this method is defined in the template file
write_extra_pages if defined? write_extra_pages
template = TemplatePage.new(RDoc::Page::ONE_PAGE)
if @options.op_name
opfile = File.open(@options.op_name, "w")
else
opfile = $stdout
end
template.write_html_on(opfile, values)
end | [
"def",
"generate_xml",
"values",
"=",
"{",
"'charset'",
"=>",
"@options",
".",
"charset",
",",
"'files'",
"=>",
"gen_into",
"(",
"@files",
")",
",",
"'classes'",
"=>",
"gen_into",
"(",
"@classes",
")",
",",
"'title'",
"=>",
"CGI",
".",
"escapeHTML",
"(",
"@options",
".",
"title",
")",
",",
"}",
"write_extra_pages",
"if",
"defined?",
"write_extra_pages",
"template",
"=",
"TemplatePage",
".",
"new",
"(",
"RDoc",
"::",
"Page",
"::",
"ONE_PAGE",
")",
"if",
"@options",
".",
"op_name",
"opfile",
"=",
"File",
".",
"open",
"(",
"@options",
".",
"op_name",
",",
"\"w\"",
")",
"else",
"opfile",
"=",
"$stdout",
"end",
"template",
".",
"write_html_on",
"(",
"opfile",
",",
"values",
")",
"end"
] | Generate all the HTML. For the one-file case, we generate
all the information in to one big hash | [
"Generate",
"all",
"the",
"HTML",
".",
"For",
"the",
"one",
"-",
"file",
"case",
"we",
"generate",
"all",
"the",
"information",
"in",
"to",
"one",
"big",
"hash"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/html_generator.rb#L1451-L1470 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.9/rdoc/diagram.rb | RDoc.Diagram.draw | def draw
unless @options.quiet
$stderr.print "Diagrams: "
$stderr.flush
end
@info.each_with_index do |i, file_count|
@done_modules = {}
@local_names = find_names(i)
@global_names = []
@global_graph = graph = DOT::Digraph.new('name' => 'TopLevel',
'fontname' => FONT,
'fontsize' => '8',
'bgcolor' => 'lightcyan1',
'compound' => 'true')
# it's a little hack %) i'm too lazy to create a separate class
# for default node
graph << DOT::Node.new('name' => 'node',
'fontname' => FONT,
'color' => 'black',
'fontsize' => 8)
i.modules.each do |mod|
draw_module(mod, graph, true, i.file_relative_name)
end
add_classes(i, graph, i.file_relative_name)
i.diagram = convert_to_png("f_#{file_count}", graph)
# now go through and document each top level class and
# module independently
i.modules.each_with_index do |mod, count|
@done_modules = {}
@local_names = find_names(mod)
@global_names = []
@global_graph = graph = DOT::Digraph.new('name' => 'TopLevel',
'fontname' => FONT,
'fontsize' => '8',
'bgcolor' => 'lightcyan1',
'compound' => 'true')
graph << DOT::Node.new('name' => 'node',
'fontname' => FONT,
'color' => 'black',
'fontsize' => 8)
draw_module(mod, graph, true)
mod.diagram = convert_to_png("m_#{file_count}_#{count}",
graph)
end
end
$stderr.puts unless @options.quiet
end | ruby | def draw
unless @options.quiet
$stderr.print "Diagrams: "
$stderr.flush
end
@info.each_with_index do |i, file_count|
@done_modules = {}
@local_names = find_names(i)
@global_names = []
@global_graph = graph = DOT::Digraph.new('name' => 'TopLevel',
'fontname' => FONT,
'fontsize' => '8',
'bgcolor' => 'lightcyan1',
'compound' => 'true')
# it's a little hack %) i'm too lazy to create a separate class
# for default node
graph << DOT::Node.new('name' => 'node',
'fontname' => FONT,
'color' => 'black',
'fontsize' => 8)
i.modules.each do |mod|
draw_module(mod, graph, true, i.file_relative_name)
end
add_classes(i, graph, i.file_relative_name)
i.diagram = convert_to_png("f_#{file_count}", graph)
# now go through and document each top level class and
# module independently
i.modules.each_with_index do |mod, count|
@done_modules = {}
@local_names = find_names(mod)
@global_names = []
@global_graph = graph = DOT::Digraph.new('name' => 'TopLevel',
'fontname' => FONT,
'fontsize' => '8',
'bgcolor' => 'lightcyan1',
'compound' => 'true')
graph << DOT::Node.new('name' => 'node',
'fontname' => FONT,
'color' => 'black',
'fontsize' => 8)
draw_module(mod, graph, true)
mod.diagram = convert_to_png("m_#{file_count}_#{count}",
graph)
end
end
$stderr.puts unless @options.quiet
end | [
"def",
"draw",
"unless",
"@options",
".",
"quiet",
"$stderr",
".",
"print",
"\"Diagrams: \"",
"$stderr",
".",
"flush",
"end",
"@info",
".",
"each_with_index",
"do",
"|",
"i",
",",
"file_count",
"|",
"@done_modules",
"=",
"{",
"}",
"@local_names",
"=",
"find_names",
"(",
"i",
")",
"@global_names",
"=",
"[",
"]",
"@global_graph",
"=",
"graph",
"=",
"DOT",
"::",
"Digraph",
".",
"new",
"(",
"'name'",
"=>",
"'TopLevel'",
",",
"'fontname'",
"=>",
"FONT",
",",
"'fontsize'",
"=>",
"'8'",
",",
"'bgcolor'",
"=>",
"'lightcyan1'",
",",
"'compound'",
"=>",
"'true'",
")",
"graph",
"<<",
"DOT",
"::",
"Node",
".",
"new",
"(",
"'name'",
"=>",
"'node'",
",",
"'fontname'",
"=>",
"FONT",
",",
"'color'",
"=>",
"'black'",
",",
"'fontsize'",
"=>",
"8",
")",
"i",
".",
"modules",
".",
"each",
"do",
"|",
"mod",
"|",
"draw_module",
"(",
"mod",
",",
"graph",
",",
"true",
",",
"i",
".",
"file_relative_name",
")",
"end",
"add_classes",
"(",
"i",
",",
"graph",
",",
"i",
".",
"file_relative_name",
")",
"i",
".",
"diagram",
"=",
"convert_to_png",
"(",
"\"f_#{file_count}\"",
",",
"graph",
")",
"i",
".",
"modules",
".",
"each_with_index",
"do",
"|",
"mod",
",",
"count",
"|",
"@done_modules",
"=",
"{",
"}",
"@local_names",
"=",
"find_names",
"(",
"mod",
")",
"@global_names",
"=",
"[",
"]",
"@global_graph",
"=",
"graph",
"=",
"DOT",
"::",
"Digraph",
".",
"new",
"(",
"'name'",
"=>",
"'TopLevel'",
",",
"'fontname'",
"=>",
"FONT",
",",
"'fontsize'",
"=>",
"'8'",
",",
"'bgcolor'",
"=>",
"'lightcyan1'",
",",
"'compound'",
"=>",
"'true'",
")",
"graph",
"<<",
"DOT",
"::",
"Node",
".",
"new",
"(",
"'name'",
"=>",
"'node'",
",",
"'fontname'",
"=>",
"FONT",
",",
"'color'",
"=>",
"'black'",
",",
"'fontsize'",
"=>",
"8",
")",
"draw_module",
"(",
"mod",
",",
"graph",
",",
"true",
")",
"mod",
".",
"diagram",
"=",
"convert_to_png",
"(",
"\"m_#{file_count}_#{count}\"",
",",
"graph",
")",
"end",
"end",
"$stderr",
".",
"puts",
"unless",
"@options",
".",
"quiet",
"end"
] | Pass in the set of top level objects. The method also creates the
subdirectory to hold the images
Draw the diagrams. We traverse the files, drawing a diagram for each. We
also traverse each top-level class and module in that file drawing a
diagram for these too. | [
"Pass",
"in",
"the",
"set",
"of",
"top",
"level",
"objects",
".",
"The",
"method",
"also",
"creates",
"the",
"subdirectory",
"to",
"hold",
"the",
"images"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/diagram.rb#L50-L103 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rdoc/code_objects.rb | RDoc.Context.find_symbol | def find_symbol(symbol, method=nil)
result = nil
case symbol
when /^::(.*)/
result = toplevel.find_symbol($1)
when /::/
modules = symbol.split(/::/)
unless modules.empty?
module_name = modules.shift
result = find_module_named(module_name)
if result
modules.each do |module_name|
result = result.find_module_named(module_name)
break unless result
end
end
end
else
# if a method is specified, then we're definitely looking for
# a module, otherwise it could be any symbol
if method
result = find_module_named(symbol)
else
result = find_local_symbol(symbol)
if result.nil?
if symbol =~ /^[A-Z]/
result = parent
while result && result.name != symbol
result = result.parent
end
end
end
end
end
if result && method
if !result.respond_to?(:find_local_symbol)
p result.name
p method
fail
end
result = result.find_local_symbol(method)
end
result
end | ruby | def find_symbol(symbol, method=nil)
result = nil
case symbol
when /^::(.*)/
result = toplevel.find_symbol($1)
when /::/
modules = symbol.split(/::/)
unless modules.empty?
module_name = modules.shift
result = find_module_named(module_name)
if result
modules.each do |module_name|
result = result.find_module_named(module_name)
break unless result
end
end
end
else
# if a method is specified, then we're definitely looking for
# a module, otherwise it could be any symbol
if method
result = find_module_named(symbol)
else
result = find_local_symbol(symbol)
if result.nil?
if symbol =~ /^[A-Z]/
result = parent
while result && result.name != symbol
result = result.parent
end
end
end
end
end
if result && method
if !result.respond_to?(:find_local_symbol)
p result.name
p method
fail
end
result = result.find_local_symbol(method)
end
result
end | [
"def",
"find_symbol",
"(",
"symbol",
",",
"method",
"=",
"nil",
")",
"result",
"=",
"nil",
"case",
"symbol",
"when",
"/",
"/",
"result",
"=",
"toplevel",
".",
"find_symbol",
"(",
"$1",
")",
"when",
"/",
"/",
"modules",
"=",
"symbol",
".",
"split",
"(",
"/",
"/",
")",
"unless",
"modules",
".",
"empty?",
"module_name",
"=",
"modules",
".",
"shift",
"result",
"=",
"find_module_named",
"(",
"module_name",
")",
"if",
"result",
"modules",
".",
"each",
"do",
"|",
"module_name",
"|",
"result",
"=",
"result",
".",
"find_module_named",
"(",
"module_name",
")",
"break",
"unless",
"result",
"end",
"end",
"end",
"else",
"if",
"method",
"result",
"=",
"find_module_named",
"(",
"symbol",
")",
"else",
"result",
"=",
"find_local_symbol",
"(",
"symbol",
")",
"if",
"result",
".",
"nil?",
"if",
"symbol",
"=~",
"/",
"/",
"result",
"=",
"parent",
"while",
"result",
"&&",
"result",
".",
"name",
"!=",
"symbol",
"result",
"=",
"result",
".",
"parent",
"end",
"end",
"end",
"end",
"end",
"if",
"result",
"&&",
"method",
"if",
"!",
"result",
".",
"respond_to?",
"(",
":find_local_symbol",
")",
"p",
"result",
".",
"name",
"p",
"method",
"fail",
"end",
"result",
"=",
"result",
".",
"find_local_symbol",
"(",
"method",
")",
"end",
"result",
"end"
] | allow us to sort modules by name
Look up the given symbol. If method is non-nil, then
we assume the symbol references a module that
contains that method | [
"allow",
"us",
"to",
"sort",
"modules",
"by",
"name",
"Look",
"up",
"the",
"given",
"symbol",
".",
"If",
"method",
"is",
"non",
"-",
"nil",
"then",
"we",
"assume",
"the",
"symbol",
"references",
"a",
"module",
"that",
"contains",
"that",
"method"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/code_objects.rb#L377-L420 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb | ActiveSupport.MessageVerifier.secure_compare | def secure_compare(a, b)
if a.length == b.length
result = 0
for i in 0..(a.length - 1)
result |= a[i] ^ b[i]
end
result == 0
else
false
end
end | ruby | def secure_compare(a, b)
if a.length == b.length
result = 0
for i in 0..(a.length - 1)
result |= a[i] ^ b[i]
end
result == 0
else
false
end
end | [
"def",
"secure_compare",
"(",
"a",
",",
"b",
")",
"if",
"a",
".",
"length",
"==",
"b",
".",
"length",
"result",
"=",
"0",
"for",
"i",
"in",
"0",
"..",
"(",
"a",
".",
"length",
"-",
"1",
")",
"result",
"|=",
"a",
"[",
"i",
"]",
"^",
"b",
"[",
"i",
"]",
"end",
"result",
"==",
"0",
"else",
"false",
"end",
"end"
] | constant-time comparison algorithm to prevent timing attacks | [
"constant",
"-",
"time",
"comparison",
"algorithm",
"to",
"prevent",
"timing",
"attacks"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb#L42-L52 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.9/rss/parser.rb | RSS.ListenerMixin.parse_pi_content | def parse_pi_content(content)
params = {}
content.scan(CONTENT_PATTERN) do |name, quote, value|
params[name] = value
end
params
end | ruby | def parse_pi_content(content)
params = {}
content.scan(CONTENT_PATTERN) do |name, quote, value|
params[name] = value
end
params
end | [
"def",
"parse_pi_content",
"(",
"content",
")",
"params",
"=",
"{",
"}",
"content",
".",
"scan",
"(",
"CONTENT_PATTERN",
")",
"do",
"|",
"name",
",",
"quote",
",",
"value",
"|",
"params",
"[",
"name",
"]",
"=",
"value",
"end",
"params",
"end"
] | Extract the first name="value" pair from content.
Works with single quotes according to the constant
CONTENT_PATTERN. Return a Hash. | [
"Extract",
"the",
"first",
"name",
"=",
"value",
"pair",
"from",
"content",
".",
"Works",
"with",
"single",
"quotes",
"according",
"to",
"the",
"constant",
"CONTENT_PATTERN",
".",
"Return",
"a",
"Hash",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rss/parser.rb#L379-L385 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.9/rss/parser.rb | RSS.Parser.normalize_rss | def normalize_rss(rss)
return rss if maybe_xml?(rss)
uri = to_uri(rss)
if uri.respond_to?(:read)
uri.read
elsif !rss.tainted? and File.readable?(rss)
File.open(rss) {|f| f.read}
else
rss
end
end | ruby | def normalize_rss(rss)
return rss if maybe_xml?(rss)
uri = to_uri(rss)
if uri.respond_to?(:read)
uri.read
elsif !rss.tainted? and File.readable?(rss)
File.open(rss) {|f| f.read}
else
rss
end
end | [
"def",
"normalize_rss",
"(",
"rss",
")",
"return",
"rss",
"if",
"maybe_xml?",
"(",
"rss",
")",
"uri",
"=",
"to_uri",
"(",
"rss",
")",
"if",
"uri",
".",
"respond_to?",
"(",
":read",
")",
"uri",
".",
"read",
"elsif",
"!",
"rss",
".",
"tainted?",
"and",
"File",
".",
"readable?",
"(",
"rss",
")",
"File",
".",
"open",
"(",
"rss",
")",
"{",
"|",
"f",
"|",
"f",
".",
"read",
"}",
"else",
"rss",
"end",
"end"
] | Try to get the XML associated with +rss+.
Return +rss+ if it already looks like XML, or treat it as a URI,
or a file to get the XML, | [
"Try",
"to",
"get",
"the",
"XML",
"associated",
"with",
"+",
"rss",
"+",
".",
"Return",
"+",
"rss",
"+",
"if",
"it",
"already",
"looks",
"like",
"XML",
"or",
"treat",
"it",
"as",
"a",
"URI",
"or",
"a",
"file",
"to",
"get",
"the",
"XML"
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rss/parser.rb#L97-L109 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rcov-0.9.8-java/lib/rcov/rcovtask.rb | Rcov.RcovTask.define | def define
lib_path = @libs.join(File::PATH_SEPARATOR)
actual_name = Hash === name ? name.keys.first : name
unless Rake.application.last_comment
desc "Analyze code coverage with tests" +
(@name==:rcov ? "" : " for #{actual_name}")
end
task @name do
run_code = ''
RakeFileUtils.verbose(@verbose) do
run_code =
case rcov_path
when nil, ''
"-S rcov"
else %!"#{rcov_path}"!
end
ruby_opts = @ruby_opts.clone
ruby_opts.push( "-I#{lib_path}" )
ruby_opts.push run_code
ruby_opts.push( "-w" ) if @warning
ruby ruby_opts.join(" ") + " " + option_list +
%[ -o "#{@output_dir}" ] +
file_list.collect { |fn| %["#{fn}"] }.join(' ')
end
end
desc "Remove rcov products for #{actual_name}"
task paste("clobber_", actual_name) do
rm_r @output_dir rescue nil
end
clobber_task = paste("clobber_", actual_name)
task :clobber => [clobber_task]
task actual_name => clobber_task
self
end | ruby | def define
lib_path = @libs.join(File::PATH_SEPARATOR)
actual_name = Hash === name ? name.keys.first : name
unless Rake.application.last_comment
desc "Analyze code coverage with tests" +
(@name==:rcov ? "" : " for #{actual_name}")
end
task @name do
run_code = ''
RakeFileUtils.verbose(@verbose) do
run_code =
case rcov_path
when nil, ''
"-S rcov"
else %!"#{rcov_path}"!
end
ruby_opts = @ruby_opts.clone
ruby_opts.push( "-I#{lib_path}" )
ruby_opts.push run_code
ruby_opts.push( "-w" ) if @warning
ruby ruby_opts.join(" ") + " " + option_list +
%[ -o "#{@output_dir}" ] +
file_list.collect { |fn| %["#{fn}"] }.join(' ')
end
end
desc "Remove rcov products for #{actual_name}"
task paste("clobber_", actual_name) do
rm_r @output_dir rescue nil
end
clobber_task = paste("clobber_", actual_name)
task :clobber => [clobber_task]
task actual_name => clobber_task
self
end | [
"def",
"define",
"lib_path",
"=",
"@libs",
".",
"join",
"(",
"File",
"::",
"PATH_SEPARATOR",
")",
"actual_name",
"=",
"Hash",
"===",
"name",
"?",
"name",
".",
"keys",
".",
"first",
":",
"name",
"unless",
"Rake",
".",
"application",
".",
"last_comment",
"desc",
"\"Analyze code coverage with tests\"",
"+",
"(",
"@name",
"==",
":rcov",
"?",
"\"\"",
":",
"\" for #{actual_name}\"",
")",
"end",
"task",
"@name",
"do",
"run_code",
"=",
"''",
"RakeFileUtils",
".",
"verbose",
"(",
"@verbose",
")",
"do",
"run_code",
"=",
"case",
"rcov_path",
"when",
"nil",
",",
"''",
"\"-S rcov\"",
"else",
"%!\"#{rcov_path}\"!",
"end",
"ruby_opts",
"=",
"@ruby_opts",
".",
"clone",
"ruby_opts",
".",
"push",
"(",
"\"-I#{lib_path}\"",
")",
"ruby_opts",
".",
"push",
"run_code",
"ruby_opts",
".",
"push",
"(",
"\"-w\"",
")",
"if",
"@warning",
"ruby",
"ruby_opts",
".",
"join",
"(",
"\" \"",
")",
"+",
"\" \"",
"+",
"option_list",
"+",
"%[ -o \"#{@output_dir}\" ]",
"+",
"file_list",
".",
"collect",
"{",
"|",
"fn",
"|",
"%[\"#{fn}\"]",
"}",
".",
"join",
"(",
"' '",
")",
"end",
"end",
"desc",
"\"Remove rcov products for #{actual_name}\"",
"task",
"paste",
"(",
"\"clobber_\"",
",",
"actual_name",
")",
"do",
"rm_r",
"@output_dir",
"rescue",
"nil",
"end",
"clobber_task",
"=",
"paste",
"(",
"\"clobber_\"",
",",
"actual_name",
")",
"task",
":clobber",
"=>",
"[",
"clobber_task",
"]",
"task",
"actual_name",
"=>",
"clobber_task",
"self",
"end"
] | Create a testing task.
Create the tasks defined by this task lib. | [
"Create",
"a",
"testing",
"task",
".",
"Create",
"the",
"tasks",
"defined",
"by",
"this",
"task",
"lib",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rcov-0.9.8-java/lib/rcov/rcovtask.rb#L98-L134 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.9/rdoc/rdoc.rb | RDoc.RDoc.update_output_dir | def update_output_dir(op_dir, time)
File.open(output_flag_file(op_dir), "w") {|f| f.puts time.rfc2822 }
end | ruby | def update_output_dir(op_dir, time)
File.open(output_flag_file(op_dir), "w") {|f| f.puts time.rfc2822 }
end | [
"def",
"update_output_dir",
"(",
"op_dir",
",",
"time",
")",
"File",
".",
"open",
"(",
"output_flag_file",
"(",
"op_dir",
")",
",",
"\"w\"",
")",
"{",
"|",
"f",
"|",
"f",
".",
"puts",
"time",
".",
"rfc2822",
"}",
"end"
] | Update the flag file in an output directory. | [
"Update",
"the",
"flag",
"file",
"in",
"an",
"output",
"directory",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/rdoc.rb#L105-L107 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.9/rdoc/rdoc.rb | RDoc.RDoc.normalized_file_list | def normalized_file_list(options, relative_files, force_doc = false,
exclude_pattern = nil)
file_list = []
relative_files.each do |rel_file_name|
next if exclude_pattern && exclude_pattern =~ rel_file_name
stat = File.stat(rel_file_name)
case type = stat.ftype
when "file"
next if @last_created and stat.mtime < @last_created
if force_doc or ::RDoc::Parser.can_parse(rel_file_name) then
file_list << rel_file_name.sub(/^\.\//, '')
end
when "directory"
next if rel_file_name == "CVS" || rel_file_name == ".svn"
dot_doc = File.join(rel_file_name, DOT_DOC_FILENAME)
if File.file?(dot_doc)
file_list.concat(parse_dot_doc_file(rel_file_name, dot_doc, options))
else
file_list.concat(list_files_in_directory(rel_file_name, options))
end
else
raise RDoc::Error, "I can't deal with a #{type} #{rel_file_name}"
end
end
file_list
end | ruby | def normalized_file_list(options, relative_files, force_doc = false,
exclude_pattern = nil)
file_list = []
relative_files.each do |rel_file_name|
next if exclude_pattern && exclude_pattern =~ rel_file_name
stat = File.stat(rel_file_name)
case type = stat.ftype
when "file"
next if @last_created and stat.mtime < @last_created
if force_doc or ::RDoc::Parser.can_parse(rel_file_name) then
file_list << rel_file_name.sub(/^\.\//, '')
end
when "directory"
next if rel_file_name == "CVS" || rel_file_name == ".svn"
dot_doc = File.join(rel_file_name, DOT_DOC_FILENAME)
if File.file?(dot_doc)
file_list.concat(parse_dot_doc_file(rel_file_name, dot_doc, options))
else
file_list.concat(list_files_in_directory(rel_file_name, options))
end
else
raise RDoc::Error, "I can't deal with a #{type} #{rel_file_name}"
end
end
file_list
end | [
"def",
"normalized_file_list",
"(",
"options",
",",
"relative_files",
",",
"force_doc",
"=",
"false",
",",
"exclude_pattern",
"=",
"nil",
")",
"file_list",
"=",
"[",
"]",
"relative_files",
".",
"each",
"do",
"|",
"rel_file_name",
"|",
"next",
"if",
"exclude_pattern",
"&&",
"exclude_pattern",
"=~",
"rel_file_name",
"stat",
"=",
"File",
".",
"stat",
"(",
"rel_file_name",
")",
"case",
"type",
"=",
"stat",
".",
"ftype",
"when",
"\"file\"",
"next",
"if",
"@last_created",
"and",
"stat",
".",
"mtime",
"<",
"@last_created",
"if",
"force_doc",
"or",
"::",
"RDoc",
"::",
"Parser",
".",
"can_parse",
"(",
"rel_file_name",
")",
"then",
"file_list",
"<<",
"rel_file_name",
".",
"sub",
"(",
"/",
"\\.",
"\\/",
"/",
",",
"''",
")",
"end",
"when",
"\"directory\"",
"next",
"if",
"rel_file_name",
"==",
"\"CVS\"",
"||",
"rel_file_name",
"==",
"\".svn\"",
"dot_doc",
"=",
"File",
".",
"join",
"(",
"rel_file_name",
",",
"DOT_DOC_FILENAME",
")",
"if",
"File",
".",
"file?",
"(",
"dot_doc",
")",
"file_list",
".",
"concat",
"(",
"parse_dot_doc_file",
"(",
"rel_file_name",
",",
"dot_doc",
",",
"options",
")",
")",
"else",
"file_list",
".",
"concat",
"(",
"list_files_in_directory",
"(",
"rel_file_name",
",",
"options",
")",
")",
"end",
"else",
"raise",
"RDoc",
"::",
"Error",
",",
"\"I can't deal with a #{type} #{rel_file_name}\"",
"end",
"end",
"file_list",
"end"
] | Given a list of files and directories, create a list of all the Ruby
files they contain.
If +force_doc+ is true we always add the given files, if false, only
add files that we guarantee we can parse. It is true when looking at
files given on the command line, false when recursing through
subdirectories.
The effect of this is that if you want a file with a non-standard
extension parsed, you must name it explicitly. | [
"Given",
"a",
"list",
"of",
"files",
"and",
"directories",
"create",
"a",
"list",
"of",
"all",
"the",
"Ruby",
"files",
"they",
"contain",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/rdoc.rb#L146-L174 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.9/rdoc/rdoc.rb | RDoc.RDoc.list_files_in_directory | def list_files_in_directory(dir, options)
files = Dir.glob File.join(dir, "*")
normalized_file_list options, files, false, options.exclude
end | ruby | def list_files_in_directory(dir, options)
files = Dir.glob File.join(dir, "*")
normalized_file_list options, files, false, options.exclude
end | [
"def",
"list_files_in_directory",
"(",
"dir",
",",
"options",
")",
"files",
"=",
"Dir",
".",
"glob",
"File",
".",
"join",
"(",
"dir",
",",
"\"*\"",
")",
"normalized_file_list",
"options",
",",
"files",
",",
"false",
",",
"options",
".",
"exclude",
"end"
] | Return a list of the files to be processed in a directory. We know that
this directory doesn't have a .document file, so we're looking for real
files. However we may well contain subdirectories which must be tested
for .document files. | [
"Return",
"a",
"list",
"of",
"the",
"files",
"to",
"be",
"processed",
"in",
"a",
"directory",
".",
"We",
"know",
"that",
"this",
"directory",
"doesn",
"t",
"have",
"a",
".",
"document",
"file",
"so",
"we",
"re",
"looking",
"for",
"real",
"files",
".",
"However",
"we",
"may",
"well",
"contain",
"subdirectories",
"which",
"must",
"be",
"tested",
"for",
".",
"document",
"files",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/rdoc.rb#L182-L186 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.9/rdoc/rdoc.rb | RDoc.RDoc.parse_files | def parse_files(options)
@stats = Stats.new options.verbosity
files = options.files
files = ["."] if files.empty?
file_list = normalized_file_list(options, files, true, options.exclude)
return [] if file_list.empty?
file_info = []
file_list.each do |filename|
@stats.add_file filename
content = if RUBY_VERSION >= '1.9' then
File.open(filename, "r:ascii-8bit") { |f| f.read }
else
File.read filename
end
if defined? Encoding then
if /coding:\s*(\S+)/ =~ content[/\A(?:.*\n){0,2}/]
if enc = ::Encoding.find($1)
content.force_encoding(enc)
end
end
end
top_level = ::RDoc::TopLevel.new filename
parser = ::RDoc::Parser.for top_level, filename, content, options,
@stats
file_info << parser.scan
end
file_info
end | ruby | def parse_files(options)
@stats = Stats.new options.verbosity
files = options.files
files = ["."] if files.empty?
file_list = normalized_file_list(options, files, true, options.exclude)
return [] if file_list.empty?
file_info = []
file_list.each do |filename|
@stats.add_file filename
content = if RUBY_VERSION >= '1.9' then
File.open(filename, "r:ascii-8bit") { |f| f.read }
else
File.read filename
end
if defined? Encoding then
if /coding:\s*(\S+)/ =~ content[/\A(?:.*\n){0,2}/]
if enc = ::Encoding.find($1)
content.force_encoding(enc)
end
end
end
top_level = ::RDoc::TopLevel.new filename
parser = ::RDoc::Parser.for top_level, filename, content, options,
@stats
file_info << parser.scan
end
file_info
end | [
"def",
"parse_files",
"(",
"options",
")",
"@stats",
"=",
"Stats",
".",
"new",
"options",
".",
"verbosity",
"files",
"=",
"options",
".",
"files",
"files",
"=",
"[",
"\".\"",
"]",
"if",
"files",
".",
"empty?",
"file_list",
"=",
"normalized_file_list",
"(",
"options",
",",
"files",
",",
"true",
",",
"options",
".",
"exclude",
")",
"return",
"[",
"]",
"if",
"file_list",
".",
"empty?",
"file_info",
"=",
"[",
"]",
"file_list",
".",
"each",
"do",
"|",
"filename",
"|",
"@stats",
".",
"add_file",
"filename",
"content",
"=",
"if",
"RUBY_VERSION",
">=",
"'1.9'",
"then",
"File",
".",
"open",
"(",
"filename",
",",
"\"r:ascii-8bit\"",
")",
"{",
"|",
"f",
"|",
"f",
".",
"read",
"}",
"else",
"File",
".",
"read",
"filename",
"end",
"if",
"defined?",
"Encoding",
"then",
"if",
"/",
"\\s",
"\\S",
"/",
"=~",
"content",
"[",
"/",
"\\A",
"\\n",
"/",
"]",
"if",
"enc",
"=",
"::",
"Encoding",
".",
"find",
"(",
"$1",
")",
"content",
".",
"force_encoding",
"(",
"enc",
")",
"end",
"end",
"end",
"top_level",
"=",
"::",
"RDoc",
"::",
"TopLevel",
".",
"new",
"filename",
"parser",
"=",
"::",
"RDoc",
"::",
"Parser",
".",
"for",
"top_level",
",",
"filename",
",",
"content",
",",
"options",
",",
"@stats",
"file_info",
"<<",
"parser",
".",
"scan",
"end",
"file_info",
"end"
] | Parse each file on the command line, recursively entering directories. | [
"Parse",
"each",
"file",
"on",
"the",
"command",
"line",
"recursively",
"entering",
"directories",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/rdoc.rb#L191-L229 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.9/rdoc/rdoc.rb | RDoc.RDoc.document | def document(argv)
TopLevel::reset
@options = Options.new GENERATORS
@options.parse argv
@last_created = nil
unless @options.all_one_file then
@last_created = setup_output_dir @options.op_dir, @options.force_update
end
start_time = Time.now
file_info = parse_files @options
@options.title = "RDoc Documentation"
if file_info.empty?
$stderr.puts "\nNo newer files." unless @options.quiet
else
@gen = @options.generator
$stderr.puts "\nGenerating #{@gen.key.upcase}..." unless @options.quiet
require @gen.file_name
gen_class = ::RDoc::Generator.const_get @gen.class_name
@gen = gen_class.for @options
pwd = Dir.pwd
Dir.chdir @options.op_dir unless @options.all_one_file
begin
Diagram.new(file_info, @options).draw if @options.diagram
@gen.generate(file_info)
update_output_dir(".", start_time)
ensure
Dir.chdir(pwd)
end
end
unless @options.quiet
puts
@stats.print
end
end | ruby | def document(argv)
TopLevel::reset
@options = Options.new GENERATORS
@options.parse argv
@last_created = nil
unless @options.all_one_file then
@last_created = setup_output_dir @options.op_dir, @options.force_update
end
start_time = Time.now
file_info = parse_files @options
@options.title = "RDoc Documentation"
if file_info.empty?
$stderr.puts "\nNo newer files." unless @options.quiet
else
@gen = @options.generator
$stderr.puts "\nGenerating #{@gen.key.upcase}..." unless @options.quiet
require @gen.file_name
gen_class = ::RDoc::Generator.const_get @gen.class_name
@gen = gen_class.for @options
pwd = Dir.pwd
Dir.chdir @options.op_dir unless @options.all_one_file
begin
Diagram.new(file_info, @options).draw if @options.diagram
@gen.generate(file_info)
update_output_dir(".", start_time)
ensure
Dir.chdir(pwd)
end
end
unless @options.quiet
puts
@stats.print
end
end | [
"def",
"document",
"(",
"argv",
")",
"TopLevel",
"::",
"reset",
"@options",
"=",
"Options",
".",
"new",
"GENERATORS",
"@options",
".",
"parse",
"argv",
"@last_created",
"=",
"nil",
"unless",
"@options",
".",
"all_one_file",
"then",
"@last_created",
"=",
"setup_output_dir",
"@options",
".",
"op_dir",
",",
"@options",
".",
"force_update",
"end",
"start_time",
"=",
"Time",
".",
"now",
"file_info",
"=",
"parse_files",
"@options",
"@options",
".",
"title",
"=",
"\"RDoc Documentation\"",
"if",
"file_info",
".",
"empty?",
"$stderr",
".",
"puts",
"\"\\nNo newer files.\"",
"unless",
"@options",
".",
"quiet",
"else",
"@gen",
"=",
"@options",
".",
"generator",
"$stderr",
".",
"puts",
"\"\\nGenerating #{@gen.key.upcase}...\"",
"unless",
"@options",
".",
"quiet",
"require",
"@gen",
".",
"file_name",
"gen_class",
"=",
"::",
"RDoc",
"::",
"Generator",
".",
"const_get",
"@gen",
".",
"class_name",
"@gen",
"=",
"gen_class",
".",
"for",
"@options",
"pwd",
"=",
"Dir",
".",
"pwd",
"Dir",
".",
"chdir",
"@options",
".",
"op_dir",
"unless",
"@options",
".",
"all_one_file",
"begin",
"Diagram",
".",
"new",
"(",
"file_info",
",",
"@options",
")",
".",
"draw",
"if",
"@options",
".",
"diagram",
"@gen",
".",
"generate",
"(",
"file_info",
")",
"update_output_dir",
"(",
"\".\"",
",",
"start_time",
")",
"ensure",
"Dir",
".",
"chdir",
"(",
"pwd",
")",
"end",
"end",
"unless",
"@options",
".",
"quiet",
"puts",
"@stats",
".",
"print",
"end",
"end"
] | Format up one or more files according to the given arguments.
For simplicity, _argv_ is an array of strings, equivalent to the strings
that would be passed on the command line. (This isn't a coincidence, as
we _do_ pass in ARGV when running interactively). For a list of options,
see rdoc/rdoc.rb. By default, output will be stored in a directory
called +doc+ below the current directory, so make sure you're somewhere
writable before invoking.
Throws: RDoc::Error on error | [
"Format",
"up",
"one",
"or",
"more",
"files",
"according",
"to",
"the",
"given",
"arguments",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/rdoc.rb#L243-L290 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.8/rss/utils.rb | RSS.Utils.new_with_value_if_need | def new_with_value_if_need(klass, value)
if value.is_a?(klass)
value
else
klass.new(value)
end
end | ruby | def new_with_value_if_need(klass, value)
if value.is_a?(klass)
value
else
klass.new(value)
end
end | [
"def",
"new_with_value_if_need",
"(",
"klass",
",",
"value",
")",
"if",
"value",
".",
"is_a?",
"(",
"klass",
")",
"value",
"else",
"klass",
".",
"new",
"(",
"value",
")",
"end",
"end"
] | If +value+ is an instance of class +klass+, return it, else
create a new instance of +klass+ with value +value+. | [
"If",
"+",
"value",
"+",
"is",
"an",
"instance",
"of",
"class",
"+",
"klass",
"+",
"return",
"it",
"else",
"create",
"a",
"new",
"instance",
"of",
"+",
"klass",
"+",
"with",
"value",
"+",
"value",
"+",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rss/utils.rb#L27-L33 | train |
ThoughtWorksStudios/oauth2_provider | tools/jruby-1.5.1/lib/ruby/1.9/rdoc/code_objects.rb | RDoc.Context.methods_matching | def methods_matching(methods, singleton = false)
count = 0
@method_list.each do |m|
if methods.include? m.name and m.singleton == singleton then
yield m
count += 1
end
end
return if count == methods.size || singleton
# perhaps we need to look at attributes
@attributes.each do |a|
yield a if methods.include? a.name
end
end | ruby | def methods_matching(methods, singleton = false)
count = 0
@method_list.each do |m|
if methods.include? m.name and m.singleton == singleton then
yield m
count += 1
end
end
return if count == methods.size || singleton
# perhaps we need to look at attributes
@attributes.each do |a|
yield a if methods.include? a.name
end
end | [
"def",
"methods_matching",
"(",
"methods",
",",
"singleton",
"=",
"false",
")",
"count",
"=",
"0",
"@method_list",
".",
"each",
"do",
"|",
"m",
"|",
"if",
"methods",
".",
"include?",
"m",
".",
"name",
"and",
"m",
".",
"singleton",
"==",
"singleton",
"then",
"yield",
"m",
"count",
"+=",
"1",
"end",
"end",
"return",
"if",
"count",
"==",
"methods",
".",
"size",
"||",
"singleton",
"@attributes",
".",
"each",
"do",
"|",
"a",
"|",
"yield",
"a",
"if",
"methods",
".",
"include?",
"a",
".",
"name",
"end",
"end"
] | Yields Method and Attr entries matching the list of names in +methods+.
Attributes are only returned when +singleton+ is false. | [
"Yields",
"Method",
"and",
"Attr",
"entries",
"matching",
"the",
"list",
"of",
"names",
"in",
"+",
"methods",
"+",
".",
"Attributes",
"are",
"only",
"returned",
"when",
"+",
"singleton",
"+",
"is",
"false",
"."
] | d54702f194edd05389968cf8947465860abccc5d | https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/code_objects.rb#L249-L266 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.