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
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/rdoc/code_objects.rb
RDoc.Context.find_module_named
def find_module_named(name) # First check the enclosed modules, then check the module itself, # then check the enclosing modules (this mirrors the check done by # the Ruby parser) res = @modules[name] || @classes[name] return res if res return self if self.name == name find_enclosing_module_named(name) end
ruby
def find_module_named(name) # First check the enclosed modules, then check the module itself, # then check the enclosing modules (this mirrors the check done by # the Ruby parser) res = @modules[name] || @classes[name] return res if res return self if self.name == name find_enclosing_module_named(name) end
[ "def", "find_module_named", "(", "name", ")", "res", "=", "@modules", "[", "name", "]", "||", "@classes", "[", "name", "]", "return", "res", "if", "res", "return", "self", "if", "self", ".", "name", "==", "name", "find_enclosing_module_named", "(", "name", ")", "end" ]
Find a named module
[ "Find", "a", "named", "module" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/code_objects.rb#L429-L437
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/rdoc/code_objects.rb
RDoc.TopLevel.add_class_or_module
def add_class_or_module(collection, class_type, name, superclass) cls = collection[name] if cls then cls.superclass = superclass unless cls.module? puts "Reusing class/module #{cls.full_name}" if $DEBUG_RDOC else if class_type == NormalModule then all = @@all_modules else all = @@all_classes end cls = all[name] if !cls then cls = class_type.new name, superclass all[name] = cls unless @done_documenting else # If the class has been encountered already, check that its # superclass has been set (it may not have been, depending on # the context in which it was encountered). if class_type == NormalClass if !cls.superclass then cls.superclass = superclass end end end collection[name] = cls unless @done_documenting cls.parent = self end cls end
ruby
def add_class_or_module(collection, class_type, name, superclass) cls = collection[name] if cls then cls.superclass = superclass unless cls.module? puts "Reusing class/module #{cls.full_name}" if $DEBUG_RDOC else if class_type == NormalModule then all = @@all_modules else all = @@all_classes end cls = all[name] if !cls then cls = class_type.new name, superclass all[name] = cls unless @done_documenting else # If the class has been encountered already, check that its # superclass has been set (it may not have been, depending on # the context in which it was encountered). if class_type == NormalClass if !cls.superclass then cls.superclass = superclass end end end collection[name] = cls unless @done_documenting cls.parent = self end cls end
[ "def", "add_class_or_module", "(", "collection", ",", "class_type", ",", "name", ",", "superclass", ")", "cls", "=", "collection", "[", "name", "]", "if", "cls", "then", "cls", ".", "superclass", "=", "superclass", "unless", "cls", ".", "module?", "puts", "\"Reusing class/module #{cls.full_name}\"", "if", "$DEBUG_RDOC", "else", "if", "class_type", "==", "NormalModule", "then", "all", "=", "@@all_modules", "else", "all", "=", "@@all_classes", "end", "cls", "=", "all", "[", "name", "]", "if", "!", "cls", "then", "cls", "=", "class_type", ".", "new", "name", ",", "superclass", "all", "[", "name", "]", "=", "cls", "unless", "@done_documenting", "else", "if", "class_type", "==", "NormalClass", "if", "!", "cls", ".", "superclass", "then", "cls", ".", "superclass", "=", "superclass", "end", "end", "end", "collection", "[", "name", "]", "=", "cls", "unless", "@done_documenting", "cls", ".", "parent", "=", "self", "end", "cls", "end" ]
Adding a class or module to a TopLevel is special, as we only want one copy of a particular top-level class. For example, if both file A and file B implement class C, we only want one ClassModule object for C. This code arranges to share classes and modules between files.
[ "Adding", "a", "class", "or", "module", "to", "a", "TopLevel", "is", "special", "as", "we", "only", "want", "one", "copy", "of", "a", "particular", "top", "-", "level", "class", ".", "For", "example", "if", "both", "file", "A", "and", "file", "B", "implement", "class", "C", "we", "only", "want", "one", "ClassModule", "object", "for", "C", ".", "This", "code", "arranges", "to", "share", "classes", "and", "modules", "between", "files", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/code_objects.rb#L618-L653
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/rdoc/code_objects.rb
RDoc.ClassModule.superclass
def superclass raise NoMethodError, "#{full_name} is a module" if module? scope = self begin superclass = scope.classes.find { |c| c.name == @superclass } return superclass.full_name if superclass scope = scope.parent end until scope.nil? or TopLevel === scope @superclass end
ruby
def superclass raise NoMethodError, "#{full_name} is a module" if module? scope = self begin superclass = scope.classes.find { |c| c.name == @superclass } return superclass.full_name if superclass scope = scope.parent end until scope.nil? or TopLevel === scope @superclass end
[ "def", "superclass", "raise", "NoMethodError", ",", "\"#{full_name} is a module\"", "if", "module?", "scope", "=", "self", "begin", "superclass", "=", "scope", ".", "classes", ".", "find", "{", "|", "c", "|", "c", ".", "name", "==", "@superclass", "}", "return", "superclass", ".", "full_name", "if", "superclass", "scope", "=", "scope", ".", "parent", "end", "until", "scope", ".", "nil?", "or", "TopLevel", "===", "scope", "@superclass", "end" ]
Get the superclass of this class. Attempts to retrieve the superclass' real name by following module nesting.
[ "Get", "the", "superclass", "of", "this", "class", ".", "Attempts", "to", "retrieve", "the", "superclass", "real", "name", "by", "following", "module", "nesting", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/code_objects.rb#L748-L761
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/response.rb
Rack.Response.write
def write(str) s = str.to_s @length += Rack::Utils.bytesize(s) @writer.call s header["Content-Length"] = @length.to_s str end
ruby
def write(str) s = str.to_s @length += Rack::Utils.bytesize(s) @writer.call s header["Content-Length"] = @length.to_s str end
[ "def", "write", "(", "str", ")", "s", "=", "str", ".", "to_s", "@length", "+=", "Rack", "::", "Utils", ".", "bytesize", "(", "s", ")", "@writer", ".", "call", "s", "header", "[", "\"Content-Length\"", "]", "=", "@length", ".", "to_s", "str", "end" ]
Append to body and update Content-Length. NOTE: Do not mix #write and direct #body access!
[ "Append", "to", "body", "and", "update", "Content", "-", "Length", "." ]
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/response.rb#L125-L132
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rexml/attribute.rb
REXML.Attribute.to_s
def to_s return @normalized if @normalized doctype = nil if @element doc = @element.document doctype = doc.doctype if doc end @normalized = Text::normalize( @unnormalized, doctype ) @unnormalized = nil @normalized end
ruby
def to_s return @normalized if @normalized doctype = nil if @element doc = @element.document doctype = doc.doctype if doc end @normalized = Text::normalize( @unnormalized, doctype ) @unnormalized = nil @normalized end
[ "def", "to_s", "return", "@normalized", "if", "@normalized", "doctype", "=", "nil", "if", "@element", "doc", "=", "@element", ".", "document", "doctype", "=", "doc", ".", "doctype", "if", "doc", "end", "@normalized", "=", "Text", "::", "normalize", "(", "@unnormalized", ",", "doctype", ")", "@unnormalized", "=", "nil", "@normalized", "end" ]
Returns the attribute value, with entities replaced
[ "Returns", "the", "attribute", "value", "with", "entities", "replaced" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rexml/attribute.rb#L114-L126
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rexml/attribute.rb
REXML.Attribute.value
def value return @unnormalized if @unnormalized doctype = nil if @element doc = @element.document doctype = doc.doctype if doc end @unnormalized = Text::unnormalize( @normalized, doctype ) @normalized = nil @unnormalized end
ruby
def value return @unnormalized if @unnormalized doctype = nil if @element doc = @element.document doctype = doc.doctype if doc end @unnormalized = Text::unnormalize( @normalized, doctype ) @normalized = nil @unnormalized end
[ "def", "value", "return", "@unnormalized", "if", "@unnormalized", "doctype", "=", "nil", "if", "@element", "doc", "=", "@element", ".", "document", "doctype", "=", "doc", ".", "doctype", "if", "doc", "end", "@unnormalized", "=", "Text", "::", "unnormalize", "(", "@normalized", ",", "doctype", ")", "@normalized", "=", "nil", "@unnormalized", "end" ]
Returns the UNNORMALIZED value of this attribute. That is, entities have been expanded to their values
[ "Returns", "the", "UNNORMALIZED", "value", "of", "this", "attribute", ".", "That", "is", "entities", "have", "been", "expanded", "to", "their", "values" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rexml/attribute.rb#L130-L140
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb
Rake.TaskManager.resolve_args_with_dependencies
def resolve_args_with_dependencies(args, hash) # :nodoc: fail "Task Argument Error" if hash.size != 1 key, value = hash.map { |k, v| [k,v] }.first if args.empty? task_name = key arg_names = [] deps = value elsif key == :needs task_name = args.shift arg_names = args deps = value else task_name = args.shift arg_names = key deps = value end deps = [deps] unless deps.respond_to?(:to_ary) [task_name, arg_names, deps] end
ruby
def resolve_args_with_dependencies(args, hash) # :nodoc: fail "Task Argument Error" if hash.size != 1 key, value = hash.map { |k, v| [k,v] }.first if args.empty? task_name = key arg_names = [] deps = value elsif key == :needs task_name = args.shift arg_names = args deps = value else task_name = args.shift arg_names = key deps = value end deps = [deps] unless deps.respond_to?(:to_ary) [task_name, arg_names, deps] end
[ "def", "resolve_args_with_dependencies", "(", "args", ",", "hash", ")", "fail", "\"Task Argument Error\"", "if", "hash", ".", "size", "!=", "1", "key", ",", "value", "=", "hash", ".", "map", "{", "|", "k", ",", "v", "|", "[", "k", ",", "v", "]", "}", ".", "first", "if", "args", ".", "empty?", "task_name", "=", "key", "arg_names", "=", "[", "]", "deps", "=", "value", "elsif", "key", "==", ":needs", "task_name", "=", "args", ".", "shift", "arg_names", "=", "args", "deps", "=", "value", "else", "task_name", "=", "args", ".", "shift", "arg_names", "=", "key", "deps", "=", "value", "end", "deps", "=", "[", "deps", "]", "unless", "deps", ".", "respond_to?", "(", ":to_ary", ")", "[", "task_name", ",", "arg_names", ",", "deps", "]", "end" ]
Resolve task arguments for a task or rule when there are dependencies declared. The patterns recognized by this argument resolving function are: task :t => [:d] task :t, [a] => [:d] task :t, :needs => [:d] (deprecated) task :t, :a, :needs => [:d] (deprecated)
[ "Resolve", "task", "arguments", "for", "a", "task", "or", "rule", "when", "there", "are", "dependencies", "declared", "." ]
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.rb#L1777-L1795
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb
Rake.Application.top_level
def top_level standard_exception_handling do if options.show_tasks display_tasks_and_comments elsif options.show_prereqs display_prerequisites else top_level_tasks.each { |task_name| invoke_task(task_name) } end end end
ruby
def top_level standard_exception_handling do if options.show_tasks display_tasks_and_comments elsif options.show_prereqs display_prerequisites else top_level_tasks.each { |task_name| invoke_task(task_name) } end end end
[ "def", "top_level", "standard_exception_handling", "do", "if", "options", ".", "show_tasks", "display_tasks_and_comments", "elsif", "options", ".", "show_prereqs", "display_prerequisites", "else", "top_level_tasks", ".", "each", "{", "|", "task_name", "|", "invoke_task", "(", "task_name", ")", "}", "end", "end", "end" ]
Run the top level tasks of a Rake application.
[ "Run", "the", "top", "level", "tasks", "of", "a", "Rake", "application", "." ]
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.rb#L2022-L2032
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/ri_generator.rb
Generators.RIGenerator.method_list
def method_list(cls) list = cls.method_list unless @options.show_all list = list.find_all do |m| m.visibility == :public || m.visibility == :protected || m.force_documentation end end c = [] i = [] list.sort.each do |m| if m.singleton c << m else i << m end end return c,i end
ruby
def method_list(cls) list = cls.method_list unless @options.show_all list = list.find_all do |m| m.visibility == :public || m.visibility == :protected || m.force_documentation end end c = [] i = [] list.sort.each do |m| if m.singleton c << m else i << m end end return c,i end
[ "def", "method_list", "(", "cls", ")", "list", "=", "cls", ".", "method_list", "unless", "@options", ".", "show_all", "list", "=", "list", ".", "find_all", "do", "|", "m", "|", "m", ".", "visibility", "==", ":public", "||", "m", ".", "visibility", "==", ":protected", "||", "m", ".", "force_documentation", "end", "end", "c", "=", "[", "]", "i", "=", "[", "]", "list", ".", "sort", ".", "each", "do", "|", "m", "|", "if", "m", ".", "singleton", "c", "<<", "m", "else", "i", "<<", "m", "end", "end", "return", "c", ",", "i", "end" ]
return a list of class and instance methods that we'll be documenting
[ "return", "a", "list", "of", "class", "and", "instance", "methods", "that", "we", "ll", "be", "documenting" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/ri_generator.rb#L171-L189
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rcov-0.9.8-java/lib/rcov/differential_analyzer.rb
Rcov.DifferentialAnalyzer.reset
def reset @@mutex.synchronize do if self.class.hook_level == 0 # Unfortunately there's no way to report this as covered with rcov: # if we run the tests under rcov self.class.hook_level will be >= 1 ! # It is however executed when we run the tests normally. Rcov::RCOV__.send(@reset_meth) @start_raw_data = data_default @end_raw_data = data_default else @start_raw_data = @end_raw_data = raw_data_absolute end @raw_data_relative = data_default @aggregated_data = data_default end end
ruby
def reset @@mutex.synchronize do if self.class.hook_level == 0 # Unfortunately there's no way to report this as covered with rcov: # if we run the tests under rcov self.class.hook_level will be >= 1 ! # It is however executed when we run the tests normally. Rcov::RCOV__.send(@reset_meth) @start_raw_data = data_default @end_raw_data = data_default else @start_raw_data = @end_raw_data = raw_data_absolute end @raw_data_relative = data_default @aggregated_data = data_default end end
[ "def", "reset", "@@mutex", ".", "synchronize", "do", "if", "self", ".", "class", ".", "hook_level", "==", "0", "Rcov", "::", "RCOV__", ".", "send", "(", "@reset_meth", ")", "@start_raw_data", "=", "data_default", "@end_raw_data", "=", "data_default", "else", "@start_raw_data", "=", "@end_raw_data", "=", "raw_data_absolute", "end", "@raw_data_relative", "=", "data_default", "@aggregated_data", "=", "data_default", "end", "end" ]
Remove the data collected so far. Further collection will start from scratch.
[ "Remove", "the", "data", "collected", "so", "far", ".", "Further", "collection", "will", "start", "from", "scratch", "." ]
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/differential_analyzer.rb#L57-L72
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/net/ftp.rb
Net.FTP.putbinaryfile
def putbinaryfile(localfile, remotefile = File.basename(localfile), blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data if @resume begin rest_offset = size(remotefile) rescue Net::FTPPermError rest_offset = nil end else rest_offset = nil end f = open(localfile) begin f.binmode storbinary("STOR " + remotefile, f, blocksize, rest_offset, &block) ensure f.close end end
ruby
def putbinaryfile(localfile, remotefile = File.basename(localfile), blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data if @resume begin rest_offset = size(remotefile) rescue Net::FTPPermError rest_offset = nil end else rest_offset = nil end f = open(localfile) begin f.binmode storbinary("STOR " + remotefile, f, blocksize, rest_offset, &block) ensure f.close end end
[ "def", "putbinaryfile", "(", "localfile", ",", "remotefile", "=", "File", ".", "basename", "(", "localfile", ")", ",", "blocksize", "=", "DEFAULT_BLOCKSIZE", ",", "&", "block", ")", "if", "@resume", "begin", "rest_offset", "=", "size", "(", "remotefile", ")", "rescue", "Net", "::", "FTPPermError", "rest_offset", "=", "nil", "end", "else", "rest_offset", "=", "nil", "end", "f", "=", "open", "(", "localfile", ")", "begin", "f", ".", "binmode", "storbinary", "(", "\"STOR \"", "+", "remotefile", ",", "f", ",", "blocksize", ",", "rest_offset", ",", "&", "block", ")", "ensure", "f", ".", "close", "end", "end" ]
Transfers +localfile+ to the server in binary mode, storing the result in +remotefile+. If a block is supplied, calls it, passing in the transmitted data in +blocksize+ chunks.
[ "Transfers", "+", "localfile", "+", "to", "the", "server", "in", "binary", "mode", "storing", "the", "result", "in", "+", "remotefile", "+", ".", "If", "a", "block", "is", "supplied", "calls", "it", "passing", "in", "the", "transmitted", "data", "in", "+", "blocksize", "+", "chunks", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/net/ftp.rb#L602-L620
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_cache.rb
RI.ClassEntry.load_from
def load_from(dir) Dir.foreach(dir) do |name| next if name =~ /^\./ # convert from external to internal form, and # extract the instance/class flag if name =~ /^(.*?)-(c|i).yaml$/ external_name = $1 is_class_method = $2 == "c" internal_name = RiWriter.external_to_internal(external_name) list = is_class_method ? @class_methods : @instance_methods path = File.join(dir, name) list << MethodEntry.new(path, internal_name, is_class_method, self) else full_name = File.join(dir, name) if File.directory?(full_name) inf_class = @inferior_classes.find {|c| c.name == name } if inf_class inf_class.add_path(full_name) else inf_class = ClassEntry.new(full_name, name, self) @inferior_classes << inf_class end inf_class.load_from(full_name) end end end end
ruby
def load_from(dir) Dir.foreach(dir) do |name| next if name =~ /^\./ # convert from external to internal form, and # extract the instance/class flag if name =~ /^(.*?)-(c|i).yaml$/ external_name = $1 is_class_method = $2 == "c" internal_name = RiWriter.external_to_internal(external_name) list = is_class_method ? @class_methods : @instance_methods path = File.join(dir, name) list << MethodEntry.new(path, internal_name, is_class_method, self) else full_name = File.join(dir, name) if File.directory?(full_name) inf_class = @inferior_classes.find {|c| c.name == name } if inf_class inf_class.add_path(full_name) else inf_class = ClassEntry.new(full_name, name, self) @inferior_classes << inf_class end inf_class.load_from(full_name) end end end end
[ "def", "load_from", "(", "dir", ")", "Dir", ".", "foreach", "(", "dir", ")", "do", "|", "name", "|", "next", "if", "name", "=~", "/", "\\.", "/", "if", "name", "=~", "/", "/", "external_name", "=", "$1", "is_class_method", "=", "$2", "==", "\"c\"", "internal_name", "=", "RiWriter", ".", "external_to_internal", "(", "external_name", ")", "list", "=", "is_class_method", "?", "@class_methods", ":", "@instance_methods", "path", "=", "File", ".", "join", "(", "dir", ",", "name", ")", "list", "<<", "MethodEntry", ".", "new", "(", "path", ",", "internal_name", ",", "is_class_method", ",", "self", ")", "else", "full_name", "=", "File", ".", "join", "(", "dir", ",", "name", ")", "if", "File", ".", "directory?", "(", "full_name", ")", "inf_class", "=", "@inferior_classes", ".", "find", "{", "|", "c", "|", "c", ".", "name", "==", "name", "}", "if", "inf_class", "inf_class", ".", "add_path", "(", "full_name", ")", "else", "inf_class", "=", "ClassEntry", ".", "new", "(", "full_name", ",", "name", ",", "self", ")", "@inferior_classes", "<<", "inf_class", "end", "inf_class", ".", "load_from", "(", "full_name", ")", "end", "end", "end", "end" ]
read in our methods and any classes and modules in our namespace. Methods are stored in files called name-c|i.yaml, where the 'name' portion is the external form of the method name and the c|i is a class|instance flag
[ "read", "in", "our", "methods", "and", "any", "classes", "and", "modules", "in", "our", "namespace", ".", "Methods", "are", "stored", "in", "files", "called", "name", "-", "c|i", ".", "yaml", "where", "the", "name", "portion", "is", "the", "external", "form", "of", "the", "method", "name", "and", "the", "c|i", "is", "a", "class|instance", "flag" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_cache.rb#L30-L58
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_cache.rb
RI.ClassEntry.recursively_find_methods_matching
def recursively_find_methods_matching(name, is_class_method) res = local_methods_matching(name, is_class_method) @inferior_classes.each do |c| res.concat(c.recursively_find_methods_matching(name, is_class_method)) end res end
ruby
def recursively_find_methods_matching(name, is_class_method) res = local_methods_matching(name, is_class_method) @inferior_classes.each do |c| res.concat(c.recursively_find_methods_matching(name, is_class_method)) end res end
[ "def", "recursively_find_methods_matching", "(", "name", ",", "is_class_method", ")", "res", "=", "local_methods_matching", "(", "name", ",", "is_class_method", ")", "@inferior_classes", ".", "each", "do", "|", "c", "|", "res", ".", "concat", "(", "c", ".", "recursively_find_methods_matching", "(", "name", ",", "is_class_method", ")", ")", "end", "res", "end" ]
Find methods matching 'name' in ourselves and in any classes we contain
[ "Find", "methods", "matching", "name", "in", "ourselves", "and", "in", "any", "classes", "we", "contain" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_cache.rb#L85-L91
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_cache.rb
RI.ClassEntry.all_method_names
def all_method_names res = @class_methods.map {|m| m.full_name } @instance_methods.each {|m| res << m.full_name} res end
ruby
def all_method_names res = @class_methods.map {|m| m.full_name } @instance_methods.each {|m| res << m.full_name} res end
[ "def", "all_method_names", "res", "=", "@class_methods", ".", "map", "{", "|", "m", "|", "m", ".", "full_name", "}", "@instance_methods", ".", "each", "{", "|", "m", "|", "res", "<<", "m", ".", "full_name", "}", "res", "end" ]
Return a list of all out method names
[ "Return", "a", "list", "of", "all", "out", "method", "names" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_cache.rb#L102-L106
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_cache.rb
RI.ClassEntry.local_methods_matching
def local_methods_matching(name, is_class_method) list = case is_class_method when nil then @class_methods + @instance_methods when true then @class_methods when false then @instance_methods else fail "Unknown is_class_method: #{is_class_method.inspect}" end list.find_all {|m| m.name; m.name[name]} end
ruby
def local_methods_matching(name, is_class_method) list = case is_class_method when nil then @class_methods + @instance_methods when true then @class_methods when false then @instance_methods else fail "Unknown is_class_method: #{is_class_method.inspect}" end list.find_all {|m| m.name; m.name[name]} end
[ "def", "local_methods_matching", "(", "name", ",", "is_class_method", ")", "list", "=", "case", "is_class_method", "when", "nil", "then", "@class_methods", "+", "@instance_methods", "when", "true", "then", "@class_methods", "when", "false", "then", "@instance_methods", "else", "fail", "\"Unknown is_class_method: #{is_class_method.inspect}\"", "end", "list", ".", "find_all", "{", "|", "m", "|", "m", ".", "name", ";", "m", ".", "name", "[", "name", "]", "}", "end" ]
Return a list of all our methods matching a given string. Is +is_class_methods+ if 'nil', we don't care if the method is a class method or not, otherwise we only return those methods that match
[ "Return", "a", "list", "of", "all", "our", "methods", "matching", "a", "given", "string", ".", "Is", "+", "is_class_methods", "+", "if", "nil", "we", "don", "t", "care", "if", "the", "method", "is", "a", "class", "method", "or", "not", "otherwise", "we", "only", "return", "those", "methods", "that", "match" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_cache.rb#L114-L124
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/rdoc/generator.rb
RDoc::Generator.MarkUp.markup
def markup(str, remove_para = false) return '' unless str # Convert leading comment markers to spaces, but only if all non-blank # lines have them if str =~ /^(?>\s*)[^\#]/ then content = str else content = str.gsub(/^\s*(#+)/) { $1.tr '#', ' ' } end res = formatter.convert content if remove_para then res.sub!(/^<p>/, '') res.sub!(/<\/p>$/, '') end res end
ruby
def markup(str, remove_para = false) return '' unless str # Convert leading comment markers to spaces, but only if all non-blank # lines have them if str =~ /^(?>\s*)[^\#]/ then content = str else content = str.gsub(/^\s*(#+)/) { $1.tr '#', ' ' } end res = formatter.convert content if remove_para then res.sub!(/^<p>/, '') res.sub!(/<\/p>$/, '') end res end
[ "def", "markup", "(", "str", ",", "remove_para", "=", "false", ")", "return", "''", "unless", "str", "if", "str", "=~", "/", "\\s", "\\#", "/", "then", "content", "=", "str", "else", "content", "=", "str", ".", "gsub", "(", "/", "\\s", "/", ")", "{", "$1", ".", "tr", "'#'", ",", "' '", "}", "end", "res", "=", "formatter", ".", "convert", "content", "if", "remove_para", "then", "res", ".", "sub!", "(", "/", "/", ",", "''", ")", "res", ".", "sub!", "(", "/", "\\/", "/", ",", "''", ")", "end", "res", "end" ]
Convert a string in markup format into HTML.
[ "Convert", "a", "string", "in", "markup", "format", "into", "HTML", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/generator.rb#L59-L78
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/rdoc/generator.rb
RDoc::Generator.Context.as_href
def as_href(from_path) if @options.all_one_file "#" + path else RDoc::Markup::ToHtml.gen_relative_url from_path, path end end
ruby
def as_href(from_path) if @options.all_one_file "#" + path else RDoc::Markup::ToHtml.gen_relative_url from_path, path end end
[ "def", "as_href", "(", "from_path", ")", "if", "@options", ".", "all_one_file", "\"#\"", "+", "path", "else", "RDoc", "::", "Markup", "::", "ToHtml", ".", "gen_relative_url", "from_path", ",", "path", "end", "end" ]
Returns a reference to outselves to be used as an href= the form depends on whether we're all in one file or in multiple files
[ "Returns", "a", "reference", "to", "outselves", "to", "be", "used", "as", "an", "href", "=", "the", "form", "depends", "on", "whether", "we", "re", "all", "in", "one", "file", "or", "in", "multiple", "files" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/generator.rb#L179-L185
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/rdoc/generator.rb
RDoc::Generator.Context.collect_methods
def collect_methods list = @context.method_list unless @options.show_all then list = list.select do |m| m.visibility == :public or m.visibility == :protected or m.force_documentation end end @methods = list.collect do |m| RDoc::Generator::Method.new m, self, @options end end
ruby
def collect_methods list = @context.method_list unless @options.show_all then list = list.select do |m| m.visibility == :public or m.visibility == :protected or m.force_documentation end end @methods = list.collect do |m| RDoc::Generator::Method.new m, self, @options end end
[ "def", "collect_methods", "list", "=", "@context", ".", "method_list", "unless", "@options", ".", "show_all", "then", "list", "=", "list", ".", "select", "do", "|", "m", "|", "m", ".", "visibility", "==", ":public", "or", "m", ".", "visibility", "==", ":protected", "or", "m", ".", "force_documentation", "end", "end", "@methods", "=", "list", ".", "collect", "do", "|", "m", "|", "RDoc", "::", "Generator", "::", "Method", ".", "new", "m", ",", "self", ",", "@options", "end", "end" ]
Create a list of Method objects for each method in the corresponding context object. If the @options.show_all variable is set (corresponding to the <tt>--all</tt> option, we include all methods, otherwise just the public ones.
[ "Create", "a", "list", "of", "Method", "objects", "for", "each", "method", "in", "the", "corresponding", "context", "object", ".", "If", "the" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/generator.rb#L193-L207
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/rdoc/generator.rb
RDoc::Generator.Context.add_table_of_sections
def add_table_of_sections toc = [] @context.sections.each do |section| if section.title then toc << { 'secname' => section.title, 'href' => section.sequence } end end @values['toc'] = toc unless toc.empty? end
ruby
def add_table_of_sections toc = [] @context.sections.each do |section| if section.title then toc << { 'secname' => section.title, 'href' => section.sequence } end end @values['toc'] = toc unless toc.empty? end
[ "def", "add_table_of_sections", "toc", "=", "[", "]", "@context", ".", "sections", ".", "each", "do", "|", "section", "|", "if", "section", ".", "title", "then", "toc", "<<", "{", "'secname'", "=>", "section", ".", "title", ",", "'href'", "=>", "section", ".", "sequence", "}", "end", "end", "@values", "[", "'toc'", "]", "=", "toc", "unless", "toc", ".", "empty?", "end" ]
create table of contents if we contain sections
[ "create", "table", "of", "contents", "if", "we", "contain", "sections" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/generator.rb#L462-L474
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/rdoc/generator.rb
RDoc::Generator.Class.http_url
def http_url(full_name, prefix) path = full_name.dup path.gsub!(/<<\s*(\w*)/, 'from-\1') if path['<<'] ::File.join(prefix, path.split("::")) + ".html" end
ruby
def http_url(full_name, prefix) path = full_name.dup path.gsub!(/<<\s*(\w*)/, 'from-\1') if path['<<'] ::File.join(prefix, path.split("::")) + ".html" end
[ "def", "http_url", "(", "full_name", ",", "prefix", ")", "path", "=", "full_name", ".", "dup", "path", ".", "gsub!", "(", "/", "\\s", "\\w", "/", ",", "'from-\\1'", ")", "if", "path", "[", "'<<'", "]", "::", "File", ".", "join", "(", "prefix", ",", "path", ".", "split", "(", "\"::\"", ")", ")", "+", "\".html\"", "end" ]
Returns the relative file name to store this class in, which is also its url
[ "Returns", "the", "relative", "file", "name", "to", "store", "this", "class", "in", "which", "is", "also", "its", "url" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/rdoc/generator.rb#L512-L518
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/tools/const_generator.rb
FFI.ConstGenerator.to_ruby
def to_ruby @constants.sort_by { |name,| name }.map do |name, constant| if constant.value.nil? then "# #{name} not available" else constant.to_ruby end end.join "\n" end
ruby
def to_ruby @constants.sort_by { |name,| name }.map do |name, constant| if constant.value.nil? then "# #{name} not available" else constant.to_ruby end end.join "\n" end
[ "def", "to_ruby", "@constants", ".", "sort_by", "{", "|", "name", ",", "|", "name", "}", ".", "map", "do", "|", "name", ",", "constant", "|", "if", "constant", ".", "value", ".", "nil?", "then", "\"# #{name} not available\"", "else", "constant", ".", "to_ruby", "end", "end", ".", "join", "\"\\n\"", "end" ]
Outputs values for discovered constants. If the constant's value was not discovered it is not omitted.
[ "Outputs", "values", "for", "discovered", "constants", ".", "If", "the", "constant", "s", "value", "was", "not", "discovered", "it", "is", "not", "omitted", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/tools/const_generator.rb#L130-L138
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_descriptions.rb
RI.ModuleDescription.merge_in
def merge_in(old) merge(@class_methods, old.class_methods) merge(@instance_methods, old.instance_methods) merge(@attributes, old.attributes) merge(@constants, old.constants) merge(@includes, old.includes) if @comment.nil? || @comment.empty? @comment = old.comment else unless old.comment.nil? or old.comment.empty? then @comment << SM::Flow::RULE.new @comment.concat old.comment end end end
ruby
def merge_in(old) merge(@class_methods, old.class_methods) merge(@instance_methods, old.instance_methods) merge(@attributes, old.attributes) merge(@constants, old.constants) merge(@includes, old.includes) if @comment.nil? || @comment.empty? @comment = old.comment else unless old.comment.nil? or old.comment.empty? then @comment << SM::Flow::RULE.new @comment.concat old.comment end end end
[ "def", "merge_in", "(", "old", ")", "merge", "(", "@class_methods", ",", "old", ".", "class_methods", ")", "merge", "(", "@instance_methods", ",", "old", ".", "instance_methods", ")", "merge", "(", "@attributes", ",", "old", ".", "attributes", ")", "merge", "(", "@constants", ",", "old", ".", "constants", ")", "merge", "(", "@includes", ",", "old", ".", "includes", ")", "if", "@comment", ".", "nil?", "||", "@comment", ".", "empty?", "@comment", "=", "old", ".", "comment", "else", "unless", "old", ".", "comment", ".", "nil?", "or", "old", ".", "comment", ".", "empty?", "then", "@comment", "<<", "SM", "::", "Flow", "::", "RULE", ".", "new", "@comment", ".", "concat", "old", ".", "comment", "end", "end", "end" ]
merge in another class desscription into this one
[ "merge", "in", "another", "class", "desscription", "into", "this", "one" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_descriptions.rb#L89-L103
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/irb/workspace.rb
IRB.WorkSpace.filter_backtrace
def filter_backtrace(bt) case IRB.conf[:CONTEXT_MODE] when 0 return nil if bt =~ /\(irb_local_binding\)/ when 1 if(bt =~ %r!/tmp/irb-binding! or bt =~ %r!irb/.*\.rb! or bt =~ /irb\.rb/) return nil end when 2 return nil if bt =~ /irb\/.*\.rb/ when 3 return nil if bt =~ /irb\/.*\.rb/ bt.sub!(/:\s*in `irb_binding'/){""} end bt end
ruby
def filter_backtrace(bt) case IRB.conf[:CONTEXT_MODE] when 0 return nil if bt =~ /\(irb_local_binding\)/ when 1 if(bt =~ %r!/tmp/irb-binding! or bt =~ %r!irb/.*\.rb! or bt =~ /irb\.rb/) return nil end when 2 return nil if bt =~ /irb\/.*\.rb/ when 3 return nil if bt =~ /irb\/.*\.rb/ bt.sub!(/:\s*in `irb_binding'/){""} end bt end
[ "def", "filter_backtrace", "(", "bt", ")", "case", "IRB", ".", "conf", "[", ":CONTEXT_MODE", "]", "when", "0", "return", "nil", "if", "bt", "=~", "/", "\\(", "\\)", "/", "when", "1", "if", "(", "bt", "=~", "%r!", "!", "or", "bt", "=~", "%r!", "\\.", "!", "or", "bt", "=~", "/", "\\.", "/", ")", "return", "nil", "end", "when", "2", "return", "nil", "if", "bt", "=~", "/", "\\/", "\\.", "/", "when", "3", "return", "nil", "if", "bt", "=~", "/", "\\/", "\\.", "/", "bt", ".", "sub!", "(", "/", "\\s", "/", ")", "{", "\"\"", "}", "end", "bt", "end" ]
error message manipulator
[ "error", "message", "manipulator" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/irb/workspace.rb#L85-L102
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_reader.rb
RI.RiReader.get_method
def get_method(method_entry) path = method_entry.path_name File.open(path) { |f| RI::Description.deserialize(f) } end
ruby
def get_method(method_entry) path = method_entry.path_name File.open(path) { |f| RI::Description.deserialize(f) } end
[ "def", "get_method", "(", "method_entry", ")", "path", "=", "method_entry", ".", "path_name", "File", ".", "open", "(", "path", ")", "{", "|", "f", "|", "RI", "::", "Description", ".", "deserialize", "(", "f", ")", "}", "end" ]
return the MethodDescription for a given MethodEntry by deserializing the YAML
[ "return", "the", "MethodDescription", "for", "a", "given", "MethodEntry", "by", "deserializing", "the", "YAML" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_reader.rb#L44-L47
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_reader.rb
RI.RiReader.get_class
def get_class(class_entry) result = nil for path in class_entry.path_names path = RiWriter.class_desc_path(path, class_entry) desc = File.open(path) {|f| RI::Description.deserialize(f) } if result result.merge_in(desc) else result = desc end end result end
ruby
def get_class(class_entry) result = nil for path in class_entry.path_names path = RiWriter.class_desc_path(path, class_entry) desc = File.open(path) {|f| RI::Description.deserialize(f) } if result result.merge_in(desc) else result = desc end end result end
[ "def", "get_class", "(", "class_entry", ")", "result", "=", "nil", "for", "path", "in", "class_entry", ".", "path_names", "path", "=", "RiWriter", ".", "class_desc_path", "(", "path", ",", "class_entry", ")", "desc", "=", "File", ".", "open", "(", "path", ")", "{", "|", "f", "|", "RI", "::", "Description", ".", "deserialize", "(", "f", ")", "}", "if", "result", "result", ".", "merge_in", "(", "desc", ")", "else", "result", "=", "desc", "end", "end", "result", "end" ]
Return a class description
[ "Return", "a", "class", "description" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_reader.rb#L50-L62
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_options.rb
RI.Options.parse
def parse(args) old_argv = ARGV.dup ARGV.replace(args) begin go = GetoptLong.new(*OptionList.options) go.quiet = true go.each do |opt, arg| case opt when "--help" then OptionList.usage when "--version" then show_version when "--list-names" then @list_names = true when "--no-pager" then @use_stdout = true when "--classes" then @list_classes = true when "--java" then @java_classes = true when "--system" then @use_system = true when "--site" then @use_site = true when "--home" then @use_home = true when "--gems" then @use_gems = true when "--doc-dir" if File.directory?(arg) @doc_dirs << arg else $stderr.puts "Invalid directory: #{arg}" exit 1 end when "--format" @formatter = RI::TextFormatter.for(arg) unless @formatter $stderr.print "Invalid formatter (should be one of " $stderr.puts RI::TextFormatter.list + ")" exit 1 end when "--width" begin @width = Integer(arg) rescue $stderr.puts "Invalid width: '#{arg}'" exit 1 end end end rescue GetoptLong::InvalidOption, GetoptLong::MissingArgument => error OptionList.error(error.message) end end
ruby
def parse(args) old_argv = ARGV.dup ARGV.replace(args) begin go = GetoptLong.new(*OptionList.options) go.quiet = true go.each do |opt, arg| case opt when "--help" then OptionList.usage when "--version" then show_version when "--list-names" then @list_names = true when "--no-pager" then @use_stdout = true when "--classes" then @list_classes = true when "--java" then @java_classes = true when "--system" then @use_system = true when "--site" then @use_site = true when "--home" then @use_home = true when "--gems" then @use_gems = true when "--doc-dir" if File.directory?(arg) @doc_dirs << arg else $stderr.puts "Invalid directory: #{arg}" exit 1 end when "--format" @formatter = RI::TextFormatter.for(arg) unless @formatter $stderr.print "Invalid formatter (should be one of " $stderr.puts RI::TextFormatter.list + ")" exit 1 end when "--width" begin @width = Integer(arg) rescue $stderr.puts "Invalid width: '#{arg}'" exit 1 end end end rescue GetoptLong::InvalidOption, GetoptLong::MissingArgument => error OptionList.error(error.message) end end
[ "def", "parse", "(", "args", ")", "old_argv", "=", "ARGV", ".", "dup", "ARGV", ".", "replace", "(", "args", ")", "begin", "go", "=", "GetoptLong", ".", "new", "(", "*", "OptionList", ".", "options", ")", "go", ".", "quiet", "=", "true", "go", ".", "each", "do", "|", "opt", ",", "arg", "|", "case", "opt", "when", "\"--help\"", "then", "OptionList", ".", "usage", "when", "\"--version\"", "then", "show_version", "when", "\"--list-names\"", "then", "@list_names", "=", "true", "when", "\"--no-pager\"", "then", "@use_stdout", "=", "true", "when", "\"--classes\"", "then", "@list_classes", "=", "true", "when", "\"--java\"", "then", "@java_classes", "=", "true", "when", "\"--system\"", "then", "@use_system", "=", "true", "when", "\"--site\"", "then", "@use_site", "=", "true", "when", "\"--home\"", "then", "@use_home", "=", "true", "when", "\"--gems\"", "then", "@use_gems", "=", "true", "when", "\"--doc-dir\"", "if", "File", ".", "directory?", "(", "arg", ")", "@doc_dirs", "<<", "arg", "else", "$stderr", ".", "puts", "\"Invalid directory: #{arg}\"", "exit", "1", "end", "when", "\"--format\"", "@formatter", "=", "RI", "::", "TextFormatter", ".", "for", "(", "arg", ")", "unless", "@formatter", "$stderr", ".", "print", "\"Invalid formatter (should be one of \"", "$stderr", ".", "puts", "RI", "::", "TextFormatter", ".", "list", "+", "\")\"", "exit", "1", "end", "when", "\"--width\"", "begin", "@width", "=", "Integer", "(", "arg", ")", "rescue", "$stderr", ".", "puts", "\"Invalid width: '#{arg}'\"", "exit", "1", "end", "end", "end", "rescue", "GetoptLong", "::", "InvalidOption", ",", "GetoptLong", "::", "MissingArgument", "=>", "error", "OptionList", ".", "error", "(", "error", ".", "message", ")", "end", "end" ]
Parse command line options.
[ "Parse", "command", "line", "options", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_options.rb#L250-L304
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/rdoc.rb
RDoc.RDoc.parse_files
def parse_files(options) file_info = [] files = options.files files = ["."] if files.empty? file_list = normalized_file_list(options, files, true) file_list.each do |fn| $stderr.printf("\n%35s: ", File.basename(fn)) unless options.quiet content = File.open(fn, "r") {|f| f.read} top_level = TopLevel.new(fn) parser = ParserFactory.parser_for(top_level, fn, content, options, @stats) file_info << parser.scan @stats.num_files += 1 end file_info end
ruby
def parse_files(options) file_info = [] files = options.files files = ["."] if files.empty? file_list = normalized_file_list(options, files, true) file_list.each do |fn| $stderr.printf("\n%35s: ", File.basename(fn)) unless options.quiet content = File.open(fn, "r") {|f| f.read} top_level = TopLevel.new(fn) parser = ParserFactory.parser_for(top_level, fn, content, options, @stats) file_info << parser.scan @stats.num_files += 1 end file_info end
[ "def", "parse_files", "(", "options", ")", "file_info", "=", "[", "]", "files", "=", "options", ".", "files", "files", "=", "[", "\".\"", "]", "if", "files", ".", "empty?", "file_list", "=", "normalized_file_list", "(", "options", ",", "files", ",", "true", ")", "file_list", ".", "each", "do", "|", "fn", "|", "$stderr", ".", "printf", "(", "\"\\n%35s: \"", ",", "File", ".", "basename", "(", "fn", ")", ")", "unless", "options", ".", "quiet", "content", "=", "File", ".", "open", "(", "fn", ",", "\"r\"", ")", "{", "|", "f", "|", "f", ".", "read", "}", "top_level", "=", "TopLevel", ".", "new", "(", "fn", ")", "parser", "=", "ParserFactory", ".", "parser_for", "(", "top_level", ",", "fn", ",", "content", ",", "options", ",", "@stats", ")", "file_info", "<<", "parser", ".", "scan", "@stats", ".", "num_files", "+=", "1", "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.8/rdoc/rdoc.rb#L210-L231
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/missing_functionality_helper.rb
JdbcSpec.MissingFunctionalityHelper.alter_table
def alter_table(table_name, options = {}) #:nodoc: table_name = table_name.to_s.downcase altered_table_name = "altered_#{table_name}" caller = lambda {|definition| yield definition if block_given?} transaction do # A temporary table might improve performance here, but # it doesn't seem to maintain indices across the whole move. move_table(table_name, altered_table_name, options) move_table(altered_table_name, table_name, &caller) end end
ruby
def alter_table(table_name, options = {}) #:nodoc: table_name = table_name.to_s.downcase altered_table_name = "altered_#{table_name}" caller = lambda {|definition| yield definition if block_given?} transaction do # A temporary table might improve performance here, but # it doesn't seem to maintain indices across the whole move. move_table(table_name, altered_table_name, options) move_table(altered_table_name, table_name, &caller) end end
[ "def", "alter_table", "(", "table_name", ",", "options", "=", "{", "}", ")", "table_name", "=", "table_name", ".", "to_s", ".", "downcase", "altered_table_name", "=", "\"altered_#{table_name}\"", "caller", "=", "lambda", "{", "|", "definition", "|", "yield", "definition", "if", "block_given?", "}", "transaction", "do", "move_table", "(", "table_name", ",", "altered_table_name", ",", "options", ")", "move_table", "(", "altered_table_name", ",", "table_name", ",", "&", "caller", ")", "end", "end" ]
Taken from SQLite adapter
[ "Taken", "from", "SQLite", "adapter" ]
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/missing_functionality_helper.rb#L5-L17
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/yaml/basenode.rb
YAML.BaseNode.select
def select( ypath_str ) matches = match_path( ypath_str ) # # Create a new generic view of the elements selected # if matches result = [] matches.each { |m| result.push m.last } YAML.transfer( 'seq', result ) end end
ruby
def select( ypath_str ) matches = match_path( ypath_str ) # # Create a new generic view of the elements selected # if matches result = [] matches.each { |m| result.push m.last } YAML.transfer( 'seq', result ) end end
[ "def", "select", "(", "ypath_str", ")", "matches", "=", "match_path", "(", "ypath_str", ")", "if", "matches", "result", "=", "[", "]", "matches", ".", "each", "{", "|", "m", "|", "result", ".", "push", "m", ".", "last", "}", "YAML", ".", "transfer", "(", "'seq'", ",", "result", ")", "end", "end" ]
Search for YPath entry and return qualified nodes.
[ "Search", "for", "YPath", "entry", "and", "return", "qualified", "nodes", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/yaml/basenode.rb#L17-L30
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/yaml/basenode.rb
YAML.BaseNode.select!
def select!( ypath_str ) matches = match_path( ypath_str ) # # Create a new generic view of the elements selected # if matches result = [] matches.each { |m| result.push m.last.transform } result end end
ruby
def select!( ypath_str ) matches = match_path( ypath_str ) # # Create a new generic view of the elements selected # if matches result = [] matches.each { |m| result.push m.last.transform } result end end
[ "def", "select!", "(", "ypath_str", ")", "matches", "=", "match_path", "(", "ypath_str", ")", "if", "matches", "result", "=", "[", "]", "matches", ".", "each", "{", "|", "m", "|", "result", ".", "push", "m", ".", "last", ".", "transform", "}", "result", "end", "end" ]
Search for YPath entry and return transformed nodes.
[ "Search", "for", "YPath", "entry", "and", "return", "transformed", "nodes", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/yaml/basenode.rb#L36-L49
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/yaml/basenode.rb
YAML.BaseNode.search
def search( ypath_str ) matches = match_path( ypath_str ) if matches matches.collect { |m| path = [] m.each_index { |i| path.push m[i] if ( i % 2 ).zero? } "/" + path.compact.join( "/" ) } end end
ruby
def search( ypath_str ) matches = match_path( ypath_str ) if matches matches.collect { |m| path = [] m.each_index { |i| path.push m[i] if ( i % 2 ).zero? } "/" + path.compact.join( "/" ) } end end
[ "def", "search", "(", "ypath_str", ")", "matches", "=", "match_path", "(", "ypath_str", ")", "if", "matches", "matches", ".", "collect", "{", "|", "m", "|", "path", "=", "[", "]", "m", ".", "each_index", "{", "|", "i", "|", "path", ".", "push", "m", "[", "i", "]", "if", "(", "i", "%", "2", ")", ".", "zero?", "}", "\"/\"", "+", "path", ".", "compact", ".", "join", "(", "\"/\"", ")", "}", "end", "end" ]
Search for YPath entry and return a list of qualified paths.
[ "Search", "for", "YPath", "entry", "and", "return", "a", "list", "of", "qualified", "paths", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/yaml/basenode.rb#L55-L67
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/yaml/basenode.rb
YAML.BaseNode.match_path
def match_path( ypath_str ) depth = 0 matches = [] YPath.each_path( ypath_str ) do |ypath| seg = match_segment( ypath, 0 ) matches += seg if seg end matches.uniq end
ruby
def match_path( ypath_str ) depth = 0 matches = [] YPath.each_path( ypath_str ) do |ypath| seg = match_segment( ypath, 0 ) matches += seg if seg end matches.uniq end
[ "def", "match_path", "(", "ypath_str", ")", "depth", "=", "0", "matches", "=", "[", "]", "YPath", ".", "each_path", "(", "ypath_str", ")", "do", "|", "ypath", "|", "seg", "=", "match_segment", "(", "ypath", ",", "0", ")", "matches", "+=", "seg", "if", "seg", "end", "matches", ".", "uniq", "end" ]
YPath search returning a complete depth array
[ "YPath", "search", "returning", "a", "complete", "depth", "array" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/yaml/basenode.rb#L80-L88
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/yaml/basenode.rb
YAML.BaseNode.match_segment
def match_segment( ypath, depth ) deep_nodes = [] seg = ypath.segments[ depth ] if seg == "/" unless String === @value idx = -1 @value.collect { |v| idx += 1 if Hash === @value match_init = [v[0].transform, v[1]] match_deep = v[1].match_segment( ypath, depth ) else match_init = [idx, v] match_deep = v.match_segment( ypath, depth ) end if match_deep match_deep.each { |m| deep_nodes.push( match_init + m ) } end } end depth += 1 seg = ypath.segments[ depth ] end match_nodes = case seg when "." [[nil, self]] when ".." [["..", nil]] when "*" if @value.is_a? Enumerable idx = -1 @value.collect { |h| idx += 1 if Hash === @value [h[0].transform, h[1]] else [idx, h] end } end else if seg =~ /^"(.*)"$/ seg = $1 elsif seg =~ /^'(.*)'$/ seg = $1 end if ( v = at( seg ) ) [[ seg, v ]] end end return deep_nodes unless match_nodes pred = ypath.predicates[ depth ] if pred case pred when /^\.=/ pred = $' # ' match_nodes.reject! { |n| n.last.value != pred } else match_nodes.reject! { |n| n.last.at( pred ).nil? } end end return match_nodes + deep_nodes unless ypath.segments.length > depth + 1 #puts "DEPTH: #{depth + 1}" deep_nodes = [] match_nodes.each { |n| if n[1].is_a? BaseNode match_deep = n[1].match_segment( ypath, depth + 1 ) if match_deep match_deep.each { |m| deep_nodes.push( n + m ) } end else deep_nodes = [] end } deep_nodes = nil if deep_nodes.length == 0 deep_nodes end
ruby
def match_segment( ypath, depth ) deep_nodes = [] seg = ypath.segments[ depth ] if seg == "/" unless String === @value idx = -1 @value.collect { |v| idx += 1 if Hash === @value match_init = [v[0].transform, v[1]] match_deep = v[1].match_segment( ypath, depth ) else match_init = [idx, v] match_deep = v.match_segment( ypath, depth ) end if match_deep match_deep.each { |m| deep_nodes.push( match_init + m ) } end } end depth += 1 seg = ypath.segments[ depth ] end match_nodes = case seg when "." [[nil, self]] when ".." [["..", nil]] when "*" if @value.is_a? Enumerable idx = -1 @value.collect { |h| idx += 1 if Hash === @value [h[0].transform, h[1]] else [idx, h] end } end else if seg =~ /^"(.*)"$/ seg = $1 elsif seg =~ /^'(.*)'$/ seg = $1 end if ( v = at( seg ) ) [[ seg, v ]] end end return deep_nodes unless match_nodes pred = ypath.predicates[ depth ] if pred case pred when /^\.=/ pred = $' # ' match_nodes.reject! { |n| n.last.value != pred } else match_nodes.reject! { |n| n.last.at( pred ).nil? } end end return match_nodes + deep_nodes unless ypath.segments.length > depth + 1 #puts "DEPTH: #{depth + 1}" deep_nodes = [] match_nodes.each { |n| if n[1].is_a? BaseNode match_deep = n[1].match_segment( ypath, depth + 1 ) if match_deep match_deep.each { |m| deep_nodes.push( n + m ) } end else deep_nodes = [] end } deep_nodes = nil if deep_nodes.length == 0 deep_nodes end
[ "def", "match_segment", "(", "ypath", ",", "depth", ")", "deep_nodes", "=", "[", "]", "seg", "=", "ypath", ".", "segments", "[", "depth", "]", "if", "seg", "==", "\"/\"", "unless", "String", "===", "@value", "idx", "=", "-", "1", "@value", ".", "collect", "{", "|", "v", "|", "idx", "+=", "1", "if", "Hash", "===", "@value", "match_init", "=", "[", "v", "[", "0", "]", ".", "transform", ",", "v", "[", "1", "]", "]", "match_deep", "=", "v", "[", "1", "]", ".", "match_segment", "(", "ypath", ",", "depth", ")", "else", "match_init", "=", "[", "idx", ",", "v", "]", "match_deep", "=", "v", ".", "match_segment", "(", "ypath", ",", "depth", ")", "end", "if", "match_deep", "match_deep", ".", "each", "{", "|", "m", "|", "deep_nodes", ".", "push", "(", "match_init", "+", "m", ")", "}", "end", "}", "end", "depth", "+=", "1", "seg", "=", "ypath", ".", "segments", "[", "depth", "]", "end", "match_nodes", "=", "case", "seg", "when", "\".\"", "[", "[", "nil", ",", "self", "]", "]", "when", "\"..\"", "[", "[", "\"..\"", ",", "nil", "]", "]", "when", "\"*\"", "if", "@value", ".", "is_a?", "Enumerable", "idx", "=", "-", "1", "@value", ".", "collect", "{", "|", "h", "|", "idx", "+=", "1", "if", "Hash", "===", "@value", "[", "h", "[", "0", "]", ".", "transform", ",", "h", "[", "1", "]", "]", "else", "[", "idx", ",", "h", "]", "end", "}", "end", "else", "if", "seg", "=~", "/", "/", "seg", "=", "$1", "elsif", "seg", "=~", "/", "/", "seg", "=", "$1", "end", "if", "(", "v", "=", "at", "(", "seg", ")", ")", "[", "[", "seg", ",", "v", "]", "]", "end", "end", "return", "deep_nodes", "unless", "match_nodes", "pred", "=", "ypath", ".", "predicates", "[", "depth", "]", "if", "pred", "case", "pred", "when", "/", "\\.", "/", "pred", "=", "$'", "match_nodes", ".", "reject!", "{", "|", "n", "|", "n", ".", "last", ".", "value", "!=", "pred", "}", "else", "match_nodes", ".", "reject!", "{", "|", "n", "|", "n", ".", "last", ".", "at", "(", "pred", ")", ".", "nil?", "}", "end", "end", "return", "match_nodes", "+", "deep_nodes", "unless", "ypath", ".", "segments", ".", "length", ">", "depth", "+", "1", "deep_nodes", "=", "[", "]", "match_nodes", ".", "each", "{", "|", "n", "|", "if", "n", "[", "1", "]", ".", "is_a?", "BaseNode", "match_deep", "=", "n", "[", "1", "]", ".", "match_segment", "(", "ypath", ",", "depth", "+", "1", ")", "if", "match_deep", "match_deep", ".", "each", "{", "|", "m", "|", "deep_nodes", ".", "push", "(", "n", "+", "m", ")", "}", "end", "else", "deep_nodes", "=", "[", "]", "end", "}", "deep_nodes", "=", "nil", "if", "deep_nodes", ".", "length", "==", "0", "deep_nodes", "end" ]
Search a node for a single YPath segment
[ "Search", "a", "node", "for", "a", "single", "YPath", "segment" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/yaml/basenode.rb#L93-L179
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/yaml/basenode.rb
YAML.BaseNode.[]
def []( *key ) if Hash === @value v = @value.detect { |k,| k.transform == key.first } v[1] if v elsif Array === @value @value.[]( *key ) end end
ruby
def []( *key ) if Hash === @value v = @value.detect { |k,| k.transform == key.first } v[1] if v elsif Array === @value @value.[]( *key ) end end
[ "def", "[]", "(", "*", "key", ")", "if", "Hash", "===", "@value", "v", "=", "@value", ".", "detect", "{", "|", "k", ",", "|", "k", ".", "transform", "==", "key", ".", "first", "}", "v", "[", "1", "]", "if", "v", "elsif", "Array", "===", "@value", "@value", ".", "[]", "(", "*", "key", ")", "end", "end" ]
We want the node to act like as Hash if it is.
[ "We", "want", "the", "node", "to", "act", "like", "as", "Hash", "if", "it", "is", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/yaml/basenode.rb#L185-L192
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/to_latex.rb
SM.ToLaTeX.escape
def escape(str) # $stderr.print "FE: ", str s = str. # sub(/\s+$/, ''). gsub(/([_\${}&%#])/, "#{BS}\\1"). gsub(/\\/, BACKSLASH). gsub(/\^/, HAT). gsub(/~/, TILDE). gsub(/</, LESSTHAN). gsub(/>/, GREATERTHAN). gsub(/,,/, ",{},"). gsub(/\`/, BACKQUOTE) # $stderr.print "-> ", s, "\n" s end
ruby
def escape(str) # $stderr.print "FE: ", str s = str. # sub(/\s+$/, ''). gsub(/([_\${}&%#])/, "#{BS}\\1"). gsub(/\\/, BACKSLASH). gsub(/\^/, HAT). gsub(/~/, TILDE). gsub(/</, LESSTHAN). gsub(/>/, GREATERTHAN). gsub(/,,/, ",{},"). gsub(/\`/, BACKQUOTE) # $stderr.print "-> ", s, "\n" s end
[ "def", "escape", "(", "str", ")", "s", "=", "str", ".", "gsub", "(", "/", "\\$", "/", ",", "\"#{BS}\\\\1\"", ")", ".", "gsub", "(", "/", "\\\\", "/", ",", "BACKSLASH", ")", ".", "gsub", "(", "/", "\\^", "/", ",", "HAT", ")", ".", "gsub", "(", "/", "/", ",", "TILDE", ")", ".", "gsub", "(", "/", "/", ",", "LESSTHAN", ")", ".", "gsub", "(", "/", "/", ",", "GREATERTHAN", ")", ".", "gsub", "(", "/", "/", ",", "\",{},\"", ")", ".", "gsub", "(", "/", "\\`", "/", ",", "BACKQUOTE", ")", "s", "end" ]
Escape a LaTeX string
[ "Escape", "a", "LaTeX", "string" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/to_latex.rb#L64-L78
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/library.rb
FFI.Library.attach_function
def attach_function(mname, a2, a3, a4=nil, a5 = nil) cname, arg_types, ret_type, opts = (a4 && (a2.is_a?(String) || a2.is_a?(Symbol))) ? [ a2, a3, a4, a5 ] : [ mname.to_s, a2, a3, a4 ] # Convert :foo to the native type arg_types.map! { |e| find_type(e) } options = Hash.new options[:convention] = defined?(@ffi_convention) ? @ffi_convention : :default options[:type_map] = defined?(@ffi_typedefs) ? @ffi_typedefs : nil options[:enums] = defined?(@ffi_enum_map) ? @ffi_enum_map : nil options.merge!(opts) if opts.is_a?(Hash) # Try to locate the function in any of the libraries invokers = [] load_error = nil ffi_libraries.each do |lib| begin invokers << FFI.create_invoker(lib, cname.to_s, arg_types, find_type(ret_type), options) rescue LoadError => ex load_error = ex end if invokers.empty? end invoker = invokers.compact.shift raise load_error if load_error && invoker.nil? #raise FFI::NotFoundError.new(cname.to_s, *libraries) unless invoker invoker.attach(self, mname.to_s) invoker # Return a version that can be called via #call end
ruby
def attach_function(mname, a2, a3, a4=nil, a5 = nil) cname, arg_types, ret_type, opts = (a4 && (a2.is_a?(String) || a2.is_a?(Symbol))) ? [ a2, a3, a4, a5 ] : [ mname.to_s, a2, a3, a4 ] # Convert :foo to the native type arg_types.map! { |e| find_type(e) } options = Hash.new options[:convention] = defined?(@ffi_convention) ? @ffi_convention : :default options[:type_map] = defined?(@ffi_typedefs) ? @ffi_typedefs : nil options[:enums] = defined?(@ffi_enum_map) ? @ffi_enum_map : nil options.merge!(opts) if opts.is_a?(Hash) # Try to locate the function in any of the libraries invokers = [] load_error = nil ffi_libraries.each do |lib| begin invokers << FFI.create_invoker(lib, cname.to_s, arg_types, find_type(ret_type), options) rescue LoadError => ex load_error = ex end if invokers.empty? end invoker = invokers.compact.shift raise load_error if load_error && invoker.nil? #raise FFI::NotFoundError.new(cname.to_s, *libraries) unless invoker invoker.attach(self, mname.to_s) invoker # Return a version that can be called via #call end
[ "def", "attach_function", "(", "mname", ",", "a2", ",", "a3", ",", "a4", "=", "nil", ",", "a5", "=", "nil", ")", "cname", ",", "arg_types", ",", "ret_type", ",", "opts", "=", "(", "a4", "&&", "(", "a2", ".", "is_a?", "(", "String", ")", "||", "a2", ".", "is_a?", "(", "Symbol", ")", ")", ")", "?", "[", "a2", ",", "a3", ",", "a4", ",", "a5", "]", ":", "[", "mname", ".", "to_s", ",", "a2", ",", "a3", ",", "a4", "]", "arg_types", ".", "map!", "{", "|", "e", "|", "find_type", "(", "e", ")", "}", "options", "=", "Hash", ".", "new", "options", "[", ":convention", "]", "=", "defined?", "(", "@ffi_convention", ")", "?", "@ffi_convention", ":", ":default", "options", "[", ":type_map", "]", "=", "defined?", "(", "@ffi_typedefs", ")", "?", "@ffi_typedefs", ":", "nil", "options", "[", ":enums", "]", "=", "defined?", "(", "@ffi_enum_map", ")", "?", "@ffi_enum_map", ":", "nil", "options", ".", "merge!", "(", "opts", ")", "if", "opts", ".", "is_a?", "(", "Hash", ")", "invokers", "=", "[", "]", "load_error", "=", "nil", "ffi_libraries", ".", "each", "do", "|", "lib", "|", "begin", "invokers", "<<", "FFI", ".", "create_invoker", "(", "lib", ",", "cname", ".", "to_s", ",", "arg_types", ",", "find_type", "(", "ret_type", ")", ",", "options", ")", "rescue", "LoadError", "=>", "ex", "load_error", "=", "ex", "end", "if", "invokers", ".", "empty?", "end", "invoker", "=", "invokers", ".", "compact", ".", "shift", "raise", "load_error", "if", "load_error", "&&", "invoker", ".", "nil?", "invoker", ".", "attach", "(", "self", ",", "mname", ".", "to_s", ")", "invoker", "end" ]
Attach C function +name+ to this module. If you want to provide an alternate name for the module function, supply it after the +name+, otherwise the C function name will be used. After the +name+, the C function argument types are provided as an Array. The C function return type is provided last.
[ "Attach", "C", "function", "+", "name", "+", "to", "this", "module", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/library.rb#L81-L108
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb
ActiveSupport.Dependencies.qualified_const_defined?
def qualified_const_defined?(path) raise NameError, "#{path.inspect} is not a valid constant name!" unless /^(::)?([A-Z]\w*)(::[A-Z]\w*)*$/ =~ path names = path.to_s.split('::') names.shift if names.first.empty? # We can't use defined? because it will invoke const_missing for the parent # of the name we are checking. names.inject(Object) do |mod, name| return false unless uninherited_const_defined?(mod, name) mod.const_get name end return true end
ruby
def qualified_const_defined?(path) raise NameError, "#{path.inspect} is not a valid constant name!" unless /^(::)?([A-Z]\w*)(::[A-Z]\w*)*$/ =~ path names = path.to_s.split('::') names.shift if names.first.empty? # We can't use defined? because it will invoke const_missing for the parent # of the name we are checking. names.inject(Object) do |mod, name| return false unless uninherited_const_defined?(mod, name) mod.const_get name end return true end
[ "def", "qualified_const_defined?", "(", "path", ")", "raise", "NameError", ",", "\"#{path.inspect} is not a valid constant name!\"", "unless", "/", "\\w", "\\w", "/", "=~", "path", "names", "=", "path", ".", "to_s", ".", "split", "(", "'::'", ")", "names", ".", "shift", "if", "names", ".", "first", ".", "empty?", "names", ".", "inject", "(", "Object", ")", "do", "|", "mod", ",", "name", "|", "return", "false", "unless", "uninherited_const_defined?", "(", "mod", ",", "name", ")", "mod", ".", "const_get", "name", "end", "return", "true", "end" ]
Is the provided constant path defined?
[ "Is", "the", "provided", "constant", "path", "defined?" ]
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/dependencies.rb#L278-L292
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb
ActiveSupport.Dependencies.search_for_file
def search_for_file(path_suffix) path_suffix = path_suffix + '.rb' unless path_suffix.ends_with? '.rb' load_paths.each do |root| path = File.join(root, path_suffix) return path if File.file? path end nil # Gee, I sure wish we had first_match ;-) end
ruby
def search_for_file(path_suffix) path_suffix = path_suffix + '.rb' unless path_suffix.ends_with? '.rb' load_paths.each do |root| path = File.join(root, path_suffix) return path if File.file? path end nil # Gee, I sure wish we had first_match ;-) end
[ "def", "search_for_file", "(", "path_suffix", ")", "path_suffix", "=", "path_suffix", "+", "'.rb'", "unless", "path_suffix", ".", "ends_with?", "'.rb'", "load_paths", ".", "each", "do", "|", "root", "|", "path", "=", "File", ".", "join", "(", "root", ",", "path_suffix", ")", "return", "path", "if", "File", ".", "file?", "path", "end", "nil", "end" ]
Search for a file in load_paths matching the provided suffix.
[ "Search", "for", "a", "file", "in", "load_paths", "matching", "the", "provided", "suffix", "." ]
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/dependencies.rb#L330-L337
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb
ActiveSupport.Dependencies.autoload_module!
def autoload_module!(into, const_name, qualified_name, path_suffix) return nil unless base_path = autoloadable_module?(path_suffix) mod = Module.new into.const_set const_name, mod autoloaded_constants << qualified_name unless load_once_paths.include?(base_path) return mod end
ruby
def autoload_module!(into, const_name, qualified_name, path_suffix) return nil unless base_path = autoloadable_module?(path_suffix) mod = Module.new into.const_set const_name, mod autoloaded_constants << qualified_name unless load_once_paths.include?(base_path) return mod end
[ "def", "autoload_module!", "(", "into", ",", "const_name", ",", "qualified_name", ",", "path_suffix", ")", "return", "nil", "unless", "base_path", "=", "autoloadable_module?", "(", "path_suffix", ")", "mod", "=", "Module", ".", "new", "into", ".", "const_set", "const_name", ",", "mod", "autoloaded_constants", "<<", "qualified_name", "unless", "load_once_paths", ".", "include?", "(", "base_path", ")", "return", "mod", "end" ]
Attempt to autoload the provided module name by searching for a directory matching the expect path suffix. If found, the module is created and assigned to +into+'s constants with the name +const_name+. Provided that the directory was loaded from a reloadable base path, it is added to the set of constants that are to be unloaded.
[ "Attempt", "to", "autoload", "the", "provided", "module", "name", "by", "searching", "for", "a", "directory", "matching", "the", "expect", "path", "suffix", ".", "If", "found", "the", "module", "is", "created", "and", "assigned", "to", "+", "into", "+", "s", "constants", "with", "the", "name", "+", "const_name", "+", ".", "Provided", "that", "the", "directory", "was", "loaded", "from", "a", "reloadable", "base", "path", "it", "is", "added", "to", "the", "set", "of", "constants", "that", "are", "to", "be", "unloaded", "." ]
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/dependencies.rb#L357-L363
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb
ActiveSupport.Dependencies.qualified_name_for
def qualified_name_for(mod, name) mod_name = to_constant_name mod (%w(Object Kernel).include? mod_name) ? name.to_s : "#{mod_name}::#{name}" end
ruby
def qualified_name_for(mod, name) mod_name = to_constant_name mod (%w(Object Kernel).include? mod_name) ? name.to_s : "#{mod_name}::#{name}" end
[ "def", "qualified_name_for", "(", "mod", ",", "name", ")", "mod_name", "=", "to_constant_name", "mod", "(", "%w(", "Object", "Kernel", ")", ".", "include?", "mod_name", ")", "?", "name", ".", "to_s", ":", "\"#{mod_name}::#{name}\"", "end" ]
Return the constant path for the provided parent and constant name.
[ "Return", "the", "constant", "path", "for", "the", "provided", "parent", "and", "constant", "name", "." ]
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/dependencies.rb#L390-L393
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb
ActiveSupport.Dependencies.load_missing_constant
def load_missing_constant(from_mod, const_name) log_call from_mod, const_name if from_mod == Kernel if ::Object.const_defined?(const_name) log "Returning Object::#{const_name} for Kernel::#{const_name}" return ::Object.const_get(const_name) else log "Substituting Object for Kernel" from_mod = Object end end # If we have an anonymous module, all we can do is attempt to load from Object. from_mod = Object if from_mod.name.blank? unless qualified_const_defined?(from_mod.name) && from_mod.name.constantize.object_id == from_mod.object_id raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!" end raise ArgumentError, "#{from_mod} is not missing constant #{const_name}!" if uninherited_const_defined?(from_mod, const_name) qualified_name = qualified_name_for from_mod, const_name path_suffix = qualified_name.underscore name_error = NameError.new("uninitialized constant #{qualified_name}") file_path = search_for_file(path_suffix) if file_path && ! loaded.include?(File.expand_path(file_path)) # We found a matching file to load require_or_load file_path raise LoadError, "Expected #{file_path} to define #{qualified_name}" unless uninherited_const_defined?(from_mod, const_name) return from_mod.const_get(const_name) elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix) return mod elsif (parent = from_mod.parent) && parent != from_mod && ! from_mod.parents.any? { |p| uninherited_const_defined?(p, const_name) } # If our parents do not have a constant named +const_name+ then we are free # to attempt to load upwards. If they do have such a constant, then this # const_missing must be due to from_mod::const_name, which should not # return constants from from_mod's parents. begin return parent.const_missing(const_name) rescue NameError => e raise unless e.missing_name? qualified_name_for(parent, const_name) raise name_error end else raise name_error end end
ruby
def load_missing_constant(from_mod, const_name) log_call from_mod, const_name if from_mod == Kernel if ::Object.const_defined?(const_name) log "Returning Object::#{const_name} for Kernel::#{const_name}" return ::Object.const_get(const_name) else log "Substituting Object for Kernel" from_mod = Object end end # If we have an anonymous module, all we can do is attempt to load from Object. from_mod = Object if from_mod.name.blank? unless qualified_const_defined?(from_mod.name) && from_mod.name.constantize.object_id == from_mod.object_id raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!" end raise ArgumentError, "#{from_mod} is not missing constant #{const_name}!" if uninherited_const_defined?(from_mod, const_name) qualified_name = qualified_name_for from_mod, const_name path_suffix = qualified_name.underscore name_error = NameError.new("uninitialized constant #{qualified_name}") file_path = search_for_file(path_suffix) if file_path && ! loaded.include?(File.expand_path(file_path)) # We found a matching file to load require_or_load file_path raise LoadError, "Expected #{file_path} to define #{qualified_name}" unless uninherited_const_defined?(from_mod, const_name) return from_mod.const_get(const_name) elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix) return mod elsif (parent = from_mod.parent) && parent != from_mod && ! from_mod.parents.any? { |p| uninherited_const_defined?(p, const_name) } # If our parents do not have a constant named +const_name+ then we are free # to attempt to load upwards. If they do have such a constant, then this # const_missing must be due to from_mod::const_name, which should not # return constants from from_mod's parents. begin return parent.const_missing(const_name) rescue NameError => e raise unless e.missing_name? qualified_name_for(parent, const_name) raise name_error end else raise name_error end end
[ "def", "load_missing_constant", "(", "from_mod", ",", "const_name", ")", "log_call", "from_mod", ",", "const_name", "if", "from_mod", "==", "Kernel", "if", "::", "Object", ".", "const_defined?", "(", "const_name", ")", "log", "\"Returning Object::#{const_name} for Kernel::#{const_name}\"", "return", "::", "Object", ".", "const_get", "(", "const_name", ")", "else", "log", "\"Substituting Object for Kernel\"", "from_mod", "=", "Object", "end", "end", "from_mod", "=", "Object", "if", "from_mod", ".", "name", ".", "blank?", "unless", "qualified_const_defined?", "(", "from_mod", ".", "name", ")", "&&", "from_mod", ".", "name", ".", "constantize", ".", "object_id", "==", "from_mod", ".", "object_id", "raise", "ArgumentError", ",", "\"A copy of #{from_mod} has been removed from the module tree but is still active!\"", "end", "raise", "ArgumentError", ",", "\"#{from_mod} is not missing constant #{const_name}!\"", "if", "uninherited_const_defined?", "(", "from_mod", ",", "const_name", ")", "qualified_name", "=", "qualified_name_for", "from_mod", ",", "const_name", "path_suffix", "=", "qualified_name", ".", "underscore", "name_error", "=", "NameError", ".", "new", "(", "\"uninitialized constant #{qualified_name}\"", ")", "file_path", "=", "search_for_file", "(", "path_suffix", ")", "if", "file_path", "&&", "!", "loaded", ".", "include?", "(", "File", ".", "expand_path", "(", "file_path", ")", ")", "require_or_load", "file_path", "raise", "LoadError", ",", "\"Expected #{file_path} to define #{qualified_name}\"", "unless", "uninherited_const_defined?", "(", "from_mod", ",", "const_name", ")", "return", "from_mod", ".", "const_get", "(", "const_name", ")", "elsif", "mod", "=", "autoload_module!", "(", "from_mod", ",", "const_name", ",", "qualified_name", ",", "path_suffix", ")", "return", "mod", "elsif", "(", "parent", "=", "from_mod", ".", "parent", ")", "&&", "parent", "!=", "from_mod", "&&", "!", "from_mod", ".", "parents", ".", "any?", "{", "|", "p", "|", "uninherited_const_defined?", "(", "p", ",", "const_name", ")", "}", "begin", "return", "parent", ".", "const_missing", "(", "const_name", ")", "rescue", "NameError", "=>", "e", "raise", "unless", "e", ".", "missing_name?", "qualified_name_for", "(", "parent", ",", "const_name", ")", "raise", "name_error", "end", "else", "raise", "name_error", "end", "end" ]
Load the constant named +const_name+ which is missing from +from_mod+. If it is not possible to load the constant into from_mod, try its parent module using const_missing.
[ "Load", "the", "constant", "named", "+", "const_name", "+", "which", "is", "missing", "from", "+", "from_mod", "+", ".", "If", "it", "is", "not", "possible", "to", "load", "the", "constant", "into", "from_mod", "try", "its", "parent", "module", "using", "const_missing", "." ]
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/dependencies.rb#L398-L445
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb
ActiveSupport.Dependencies.remove_unloadable_constants!
def remove_unloadable_constants! autoloaded_constants.each { |const| remove_constant const } autoloaded_constants.clear explicitly_unloadable_constants.each { |const| remove_constant const } end
ruby
def remove_unloadable_constants! autoloaded_constants.each { |const| remove_constant const } autoloaded_constants.clear explicitly_unloadable_constants.each { |const| remove_constant const } end
[ "def", "remove_unloadable_constants!", "autoloaded_constants", ".", "each", "{", "|", "const", "|", "remove_constant", "const", "}", "autoloaded_constants", ".", "clear", "explicitly_unloadable_constants", ".", "each", "{", "|", "const", "|", "remove_constant", "const", "}", "end" ]
Remove the constants that have been autoloaded, and those that have been marked for unloading.
[ "Remove", "the", "constants", "that", "have", "been", "autoloaded", "and", "those", "that", "have", "been", "marked", "for", "unloading", "." ]
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/dependencies.rb#L449-L453
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb
ActiveSupport.Dependencies.autoloaded?
def autoloaded?(desc) # No name => anonymous module. return false if desc.is_a?(Module) && desc.name.blank? name = to_constant_name desc return false unless qualified_const_defined? name return autoloaded_constants.include?(name) end
ruby
def autoloaded?(desc) # No name => anonymous module. return false if desc.is_a?(Module) && desc.name.blank? name = to_constant_name desc return false unless qualified_const_defined? name return autoloaded_constants.include?(name) end
[ "def", "autoloaded?", "(", "desc", ")", "return", "false", "if", "desc", ".", "is_a?", "(", "Module", ")", "&&", "desc", ".", "name", ".", "blank?", "name", "=", "to_constant_name", "desc", "return", "false", "unless", "qualified_const_defined?", "name", "return", "autoloaded_constants", ".", "include?", "(", "name", ")", "end" ]
Determine if the given constant has been automatically loaded.
[ "Determine", "if", "the", "given", "constant", "has", "been", "automatically", "loaded", "." ]
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/dependencies.rb#L456-L462
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb
ActiveSupport.Dependencies.mark_for_unload
def mark_for_unload(const_desc) name = to_constant_name const_desc if explicitly_unloadable_constants.include? name return false else explicitly_unloadable_constants << name return true end end
ruby
def mark_for_unload(const_desc) name = to_constant_name const_desc if explicitly_unloadable_constants.include? name return false else explicitly_unloadable_constants << name return true end end
[ "def", "mark_for_unload", "(", "const_desc", ")", "name", "=", "to_constant_name", "const_desc", "if", "explicitly_unloadable_constants", ".", "include?", "name", "return", "false", "else", "explicitly_unloadable_constants", "<<", "name", "return", "true", "end", "end" ]
Mark the provided constant name for unloading. This constant will be unloaded on each request, not just the next one.
[ "Mark", "the", "provided", "constant", "name", "for", "unloading", ".", "This", "constant", "will", "be", "unloaded", "on", "each", "request", "not", "just", "the", "next", "one", "." ]
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/dependencies.rb#L472-L480
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/yaml/baseemitter.rb
YAML.BaseEmitter.indent_text
def indent_text( text, mod, first_line = true ) return "" if text.to_s.empty? spacing = indent( mod ) text = text.gsub( /\A([^\n])/, "#{ spacing }\\1" ) if first_line return text.gsub( /\n^([^\n])/, "\n#{spacing}\\1" ) end
ruby
def indent_text( text, mod, first_line = true ) return "" if text.to_s.empty? spacing = indent( mod ) text = text.gsub( /\A([^\n])/, "#{ spacing }\\1" ) if first_line return text.gsub( /\n^([^\n])/, "\n#{spacing}\\1" ) end
[ "def", "indent_text", "(", "text", ",", "mod", ",", "first_line", "=", "true", ")", "return", "\"\"", "if", "text", ".", "to_s", ".", "empty?", "spacing", "=", "indent", "(", "mod", ")", "text", "=", "text", ".", "gsub", "(", "/", "\\A", "\\n", "/", ",", "\"#{ spacing }\\\\1\"", ")", "if", "first_line", "return", "text", ".", "gsub", "(", "/", "\\n", "\\n", "/", ",", "\"\\n#{spacing}\\\\1\"", ")", "end" ]
Write a text block with the current indent
[ "Write", "a", "text", "block", "with", "the", "current", "indent" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/yaml/baseemitter.rb#L100-L105
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/yaml/baseemitter.rb
YAML.BaseEmitter.indent
def indent( mod = nil ) #p [ self.id, level, mod, :INDENT ] if level <= 0 mod ||= 0 else mod ||= options(:Indent) mod += ( level - 1 ) * options(:Indent) end return " " * mod end
ruby
def indent( mod = nil ) #p [ self.id, level, mod, :INDENT ] if level <= 0 mod ||= 0 else mod ||= options(:Indent) mod += ( level - 1 ) * options(:Indent) end return " " * mod end
[ "def", "indent", "(", "mod", "=", "nil", ")", "if", "level", "<=", "0", "mod", "||=", "0", "else", "mod", "||=", "options", "(", ":Indent", ")", "mod", "+=", "(", "level", "-", "1", ")", "*", "options", "(", ":Indent", ")", "end", "return", "\" \"", "*", "mod", "end" ]
Write a current indent
[ "Write", "a", "current", "indent" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/yaml/baseemitter.rb#L110-L119
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/net/ftp.rb
Net.FTP.getbinaryfile
def getbinaryfile(remotefile, localfile = File.basename(remotefile), blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data if @resume rest_offset = File.size?(localfile) f = open(localfile, "a") else rest_offset = nil f = open(localfile, "w") end begin f.binmode retrbinary("RETR " + remotefile, blocksize, rest_offset) do |data| f.write(data) yield(data) if block end ensure f.close end end
ruby
def getbinaryfile(remotefile, localfile = File.basename(remotefile), blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data if @resume rest_offset = File.size?(localfile) f = open(localfile, "a") else rest_offset = nil f = open(localfile, "w") end begin f.binmode retrbinary("RETR " + remotefile, blocksize, rest_offset) do |data| f.write(data) yield(data) if block end ensure f.close end end
[ "def", "getbinaryfile", "(", "remotefile", ",", "localfile", "=", "File", ".", "basename", "(", "remotefile", ")", ",", "blocksize", "=", "DEFAULT_BLOCKSIZE", ",", "&", "block", ")", "if", "@resume", "rest_offset", "=", "File", ".", "size?", "(", "localfile", ")", "f", "=", "open", "(", "localfile", ",", "\"a\"", ")", "else", "rest_offset", "=", "nil", "f", "=", "open", "(", "localfile", ",", "\"w\"", ")", "end", "begin", "f", ".", "binmode", "retrbinary", "(", "\"RETR \"", "+", "remotefile", ",", "blocksize", ",", "rest_offset", ")", "do", "|", "data", "|", "f", ".", "write", "(", "data", ")", "yield", "(", "data", ")", "if", "block", "end", "ensure", "f", ".", "close", "end", "end" ]
Retrieves +remotefile+ in binary mode, storing the result in +localfile+. If a block is supplied, it is passed the retrieved data in +blocksize+ chunks.
[ "Retrieves", "+", "remotefile", "+", "in", "binary", "mode", "storing", "the", "result", "in", "+", "localfile", "+", ".", "If", "a", "block", "is", "supplied", "it", "is", "passed", "the", "retrieved", "data", "in", "+", "blocksize", "+", "chunks", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/net/ftp.rb#L493-L511
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/ring.rb
Rinda.RingServer.do_write
def do_write(msg) Thread.new do begin tuple, sec = Marshal.load(msg) @ts.write(tuple, sec) rescue end end end
ruby
def do_write(msg) Thread.new do begin tuple, sec = Marshal.load(msg) @ts.write(tuple, sec) rescue end end end
[ "def", "do_write", "(", "msg", ")", "Thread", ".", "new", "do", "begin", "tuple", ",", "sec", "=", "Marshal", ".", "load", "(", "msg", ")", "@ts", ".", "write", "(", "tuple", ",", "sec", ")", "rescue", "end", "end", "end" ]
Extracts the response URI from +msg+ and adds it to TupleSpace where it will be picked up by +reply_service+ for notification.
[ "Extracts", "the", "response", "URI", "from", "+", "msg", "+", "and", "adds", "it", "to", "TupleSpace", "where", "it", "will", "be", "picked", "up", "by", "+", "reply_service", "+", "for", "notification", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/ring.rb#L57-L65
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/ring.rb
Rinda.RingFinger.lookup_ring
def lookup_ring(timeout=5, &block) return lookup_ring_any(timeout) unless block_given? msg = Marshal.dump([[:lookup_ring, DRbObject.new(block)], timeout]) @broadcast_list.each do |it| soc = UDPSocket.open begin soc.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true) soc.send(msg, 0, it, @port) rescue nil ensure soc.close end end sleep(timeout) end
ruby
def lookup_ring(timeout=5, &block) return lookup_ring_any(timeout) unless block_given? msg = Marshal.dump([[:lookup_ring, DRbObject.new(block)], timeout]) @broadcast_list.each do |it| soc = UDPSocket.open begin soc.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true) soc.send(msg, 0, it, @port) rescue nil ensure soc.close end end sleep(timeout) end
[ "def", "lookup_ring", "(", "timeout", "=", "5", ",", "&", "block", ")", "return", "lookup_ring_any", "(", "timeout", ")", "unless", "block_given?", "msg", "=", "Marshal", ".", "dump", "(", "[", "[", ":lookup_ring", ",", "DRbObject", ".", "new", "(", "block", ")", "]", ",", "timeout", "]", ")", "@broadcast_list", ".", "each", "do", "|", "it", "|", "soc", "=", "UDPSocket", ".", "open", "begin", "soc", ".", "setsockopt", "(", "Socket", "::", "SOL_SOCKET", ",", "Socket", "::", "SO_BROADCAST", ",", "true", ")", "soc", ".", "send", "(", "msg", ",", "0", ",", "it", ",", "@port", ")", "rescue", "nil", "ensure", "soc", ".", "close", "end", "end", "sleep", "(", "timeout", ")", "end" ]
Looks up RingServers waiting +timeout+ seconds. RingServers will be given +block+ as a callback, which will be called with the remote TupleSpace.
[ "Looks", "up", "RingServers", "waiting", "+", "timeout", "+", "seconds", ".", "RingServers", "will", "be", "given", "+", "block", "+", "as", "a", "callback", "which", "will", "be", "called", "with", "the", "remote", "TupleSpace", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/ring.rb#L176-L192
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/chm_generator.rb
Generators.CHMGenerator.create_project_file
def create_project_file template = TemplatePage.new(RDoc::Page::HPP_FILE) values = { "title" => @options.title, "opname" => @op_name } files = [] @files.each do |f| files << { "html_file_name" => f.path } end values['all_html_files'] = files File.open(@project_name, "w") do |f| template.write_html_on(f, values) end end
ruby
def create_project_file template = TemplatePage.new(RDoc::Page::HPP_FILE) values = { "title" => @options.title, "opname" => @op_name } files = [] @files.each do |f| files << { "html_file_name" => f.path } end values['all_html_files'] = files File.open(@project_name, "w") do |f| template.write_html_on(f, values) end end
[ "def", "create_project_file", "template", "=", "TemplatePage", ".", "new", "(", "RDoc", "::", "Page", "::", "HPP_FILE", ")", "values", "=", "{", "\"title\"", "=>", "@options", ".", "title", ",", "\"opname\"", "=>", "@op_name", "}", "files", "=", "[", "]", "@files", ".", "each", "do", "|", "f", "|", "files", "<<", "{", "\"html_file_name\"", "=>", "f", ".", "path", "}", "end", "values", "[", "'all_html_files'", "]", "=", "files", "File", ".", "open", "(", "@project_name", ",", "\"w\"", ")", "do", "|", "f", "|", "template", ".", "write_html_on", "(", "f", ",", "values", ")", "end", "end" ]
The project file links together all the various files that go to make up the help.
[ "The", "project", "file", "links", "together", "all", "the", "various", "files", "that", "go", "to", "make", "up", "the", "help", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/chm_generator.rb#L54-L67
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/chm_generator.rb
Generators.CHMGenerator.create_contents_and_index
def create_contents_and_index contents = [] index = [] (@files+@classes).sort.each do |entry| content_entry = { "c_name" => entry.name, "ref" => entry.path } index << { "name" => entry.name, "aref" => entry.path } internals = [] methods = entry.build_method_summary_list(entry.path) content_entry["methods"] = methods unless methods.empty? contents << content_entry index.concat methods end values = { "contents" => contents } template = TemplatePage.new(RDoc::Page::CONTENTS) File.open("contents.hhc", "w") do |f| template.write_html_on(f, values) end values = { "index" => index } template = TemplatePage.new(RDoc::Page::CHM_INDEX) File.open("index.hhk", "w") do |f| template.write_html_on(f, values) end end
ruby
def create_contents_and_index contents = [] index = [] (@files+@classes).sort.each do |entry| content_entry = { "c_name" => entry.name, "ref" => entry.path } index << { "name" => entry.name, "aref" => entry.path } internals = [] methods = entry.build_method_summary_list(entry.path) content_entry["methods"] = methods unless methods.empty? contents << content_entry index.concat methods end values = { "contents" => contents } template = TemplatePage.new(RDoc::Page::CONTENTS) File.open("contents.hhc", "w") do |f| template.write_html_on(f, values) end values = { "index" => index } template = TemplatePage.new(RDoc::Page::CHM_INDEX) File.open("index.hhk", "w") do |f| template.write_html_on(f, values) end end
[ "def", "create_contents_and_index", "contents", "=", "[", "]", "index", "=", "[", "]", "(", "@files", "+", "@classes", ")", ".", "sort", ".", "each", "do", "|", "entry", "|", "content_entry", "=", "{", "\"c_name\"", "=>", "entry", ".", "name", ",", "\"ref\"", "=>", "entry", ".", "path", "}", "index", "<<", "{", "\"name\"", "=>", "entry", ".", "name", ",", "\"aref\"", "=>", "entry", ".", "path", "}", "internals", "=", "[", "]", "methods", "=", "entry", ".", "build_method_summary_list", "(", "entry", ".", "path", ")", "content_entry", "[", "\"methods\"", "]", "=", "methods", "unless", "methods", ".", "empty?", "contents", "<<", "content_entry", "index", ".", "concat", "methods", "end", "values", "=", "{", "\"contents\"", "=>", "contents", "}", "template", "=", "TemplatePage", ".", "new", "(", "RDoc", "::", "Page", "::", "CONTENTS", ")", "File", ".", "open", "(", "\"contents.hhc\"", ",", "\"w\"", ")", "do", "|", "f", "|", "template", ".", "write_html_on", "(", "f", ",", "values", ")", "end", "values", "=", "{", "\"index\"", "=>", "index", "}", "template", "=", "TemplatePage", ".", "new", "(", "RDoc", "::", "Page", "::", "CHM_INDEX", ")", "File", ".", "open", "(", "\"index.hhk\"", ",", "\"w\"", ")", "do", "|", "f", "|", "template", ".", "write_html_on", "(", "f", ",", "values", ")", "end", "end" ]
The contents is a list of all files and modules. For each we include as sub-entries the list of methods they contain. As we build the contents we also build an index file
[ "The", "contents", "is", "a", "list", "of", "all", "files", "and", "modules", ".", "For", "each", "we", "include", "as", "sub", "-", "entries", "the", "list", "of", "methods", "they", "contain", ".", "As", "we", "build", "the", "contents", "we", "also", "build", "an", "index", "file" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/generators/chm_generator.rb#L74-L102
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleEntry.get_renewer
def get_renewer(it) case it when Numeric, true, nil return it, nil else begin return it.renew, it rescue Exception return it, nil end end end
ruby
def get_renewer(it) case it when Numeric, true, nil return it, nil else begin return it.renew, it rescue Exception return it, nil end end end
[ "def", "get_renewer", "(", "it", ")", "case", "it", "when", "Numeric", ",", "true", ",", "nil", "return", "it", ",", "nil", "else", "begin", "return", "it", ".", "renew", ",", "it", "rescue", "Exception", "return", "it", ",", "nil", "end", "end", "end" ]
Returns a valid argument to make_expires and the renewer or nil. Given +true+, +nil+, or Numeric, returns that value and +nil+ (no actual renewer). Otherwise it returns an expiry value from calling +it.renew+ and the renewer.
[ "Returns", "a", "valid", "argument", "to", "make_expires", "and", "the", "renewer", "or", "nil", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L145-L156
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleBag.push
def push(tuple) key = bin_key(tuple) @hash[key] ||= TupleBin.new @hash[key].add(tuple) end
ruby
def push(tuple) key = bin_key(tuple) @hash[key] ||= TupleBin.new @hash[key].add(tuple) end
[ "def", "push", "(", "tuple", ")", "key", "=", "bin_key", "(", "tuple", ")", "@hash", "[", "key", "]", "||=", "TupleBin", ".", "new", "@hash", "[", "key", "]", ".", "add", "(", "tuple", ")", "end" ]
Add +tuple+ to the TupleBag.
[ "Add", "+", "tuple", "+", "to", "the", "TupleBag", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L333-L337
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleBag.delete
def delete(tuple) key = bin_key(tuple) bin = @hash[key] return nil unless bin bin.delete(tuple) @hash.delete(key) if bin.empty? tuple end
ruby
def delete(tuple) key = bin_key(tuple) bin = @hash[key] return nil unless bin bin.delete(tuple) @hash.delete(key) if bin.empty? tuple end
[ "def", "delete", "(", "tuple", ")", "key", "=", "bin_key", "(", "tuple", ")", "bin", "=", "@hash", "[", "key", "]", "return", "nil", "unless", "bin", "bin", ".", "delete", "(", "tuple", ")", "@hash", ".", "delete", "(", "key", ")", "if", "bin", ".", "empty?", "tuple", "end" ]
Removes +tuple+ from the TupleBag.
[ "Removes", "+", "tuple", "+", "from", "the", "TupleBag", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L342-L349
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleBag.find_all
def find_all(template) bin_for_find(template).find_all do |tuple| tuple.alive? && template.match(tuple) end end
ruby
def find_all(template) bin_for_find(template).find_all do |tuple| tuple.alive? && template.match(tuple) end end
[ "def", "find_all", "(", "template", ")", "bin_for_find", "(", "template", ")", ".", "find_all", "do", "|", "tuple", "|", "tuple", ".", "alive?", "&&", "template", ".", "match", "(", "tuple", ")", "end", "end" ]
Finds all live tuples that match +template+.
[ "Finds", "all", "live", "tuples", "that", "match", "+", "template", "+", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L353-L357
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleBag.find
def find(template) bin_for_find(template).find do |tuple| tuple.alive? && template.match(tuple) end end
ruby
def find(template) bin_for_find(template).find do |tuple| tuple.alive? && template.match(tuple) end end
[ "def", "find", "(", "template", ")", "bin_for_find", "(", "template", ")", ".", "find", "do", "|", "tuple", "|", "tuple", ".", "alive?", "&&", "template", ".", "match", "(", "tuple", ")", "end", "end" ]
Finds a live tuple that matches +template+.
[ "Finds", "a", "live", "tuple", "that", "matches", "+", "template", "+", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L362-L366
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleBag.delete_unless_alive
def delete_unless_alive deleted = [] @hash.each do |key, bin| bin.delete_if do |tuple| if tuple.alive? false else deleted.push(tuple) true end end end deleted end
ruby
def delete_unless_alive deleted = [] @hash.each do |key, bin| bin.delete_if do |tuple| if tuple.alive? false else deleted.push(tuple) true end end end deleted end
[ "def", "delete_unless_alive", "deleted", "=", "[", "]", "@hash", ".", "each", "do", "|", "key", ",", "bin", "|", "bin", ".", "delete_if", "do", "|", "tuple", "|", "if", "tuple", ".", "alive?", "false", "else", "deleted", ".", "push", "(", "tuple", ")", "true", "end", "end", "end", "deleted", "end" ]
Delete tuples which dead tuples from the TupleBag, returning the deleted tuples.
[ "Delete", "tuples", "which", "dead", "tuples", "from", "the", "TupleBag", "returning", "the", "deleted", "tuples", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L382-L395
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleSpace.write
def write(tuple, sec=nil) entry = create_entry(tuple, sec) synchronize do if entry.expired? @read_waiter.find_all_template(entry).each do |template| template.read(tuple) end notify_event('write', entry.value) notify_event('delete', entry.value) else @bag.push(entry) start_keeper if entry.expires @read_waiter.find_all_template(entry).each do |template| template.read(tuple) end @take_waiter.find_all_template(entry).each do |template| template.signal end notify_event('write', entry.value) end end entry end
ruby
def write(tuple, sec=nil) entry = create_entry(tuple, sec) synchronize do if entry.expired? @read_waiter.find_all_template(entry).each do |template| template.read(tuple) end notify_event('write', entry.value) notify_event('delete', entry.value) else @bag.push(entry) start_keeper if entry.expires @read_waiter.find_all_template(entry).each do |template| template.read(tuple) end @take_waiter.find_all_template(entry).each do |template| template.signal end notify_event('write', entry.value) end end entry end
[ "def", "write", "(", "tuple", ",", "sec", "=", "nil", ")", "entry", "=", "create_entry", "(", "tuple", ",", "sec", ")", "synchronize", "do", "if", "entry", ".", "expired?", "@read_waiter", ".", "find_all_template", "(", "entry", ")", ".", "each", "do", "|", "template", "|", "template", ".", "read", "(", "tuple", ")", "end", "notify_event", "(", "'write'", ",", "entry", ".", "value", ")", "notify_event", "(", "'delete'", ",", "entry", ".", "value", ")", "else", "@bag", ".", "push", "(", "entry", ")", "start_keeper", "if", "entry", ".", "expires", "@read_waiter", ".", "find_all_template", "(", "entry", ")", ".", "each", "do", "|", "template", "|", "template", ".", "read", "(", "tuple", ")", "end", "@take_waiter", ".", "find_all_template", "(", "entry", ")", ".", "each", "do", "|", "template", "|", "template", ".", "signal", "end", "notify_event", "(", "'write'", ",", "entry", ".", "value", ")", "end", "end", "entry", "end" ]
Creates a new TupleSpace. +period+ is used to control how often to look for dead tuples after modifications to the TupleSpace. If no dead tuples are found +period+ seconds after the last modification, the TupleSpace will stop looking for dead tuples. Adds +tuple+
[ "Creates", "a", "new", "TupleSpace", ".", "+", "period", "+", "is", "used", "to", "control", "how", "often", "to", "look", "for", "dead", "tuples", "after", "modifications", "to", "the", "TupleSpace", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L451-L473
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleSpace.move
def move(port, tuple, sec=nil) template = WaitTemplateEntry.new(self, tuple, sec) yield(template) if block_given? synchronize do entry = @bag.find(template) if entry port.push(entry.value) if port @bag.delete(entry) notify_event('take', entry.value) return entry.value end raise RequestExpiredError if template.expired? begin @take_waiter.push(template) start_keeper if template.expires while true raise RequestCanceledError if template.canceled? raise RequestExpiredError if template.expired? entry = @bag.find(template) if entry port.push(entry.value) if port @bag.delete(entry) notify_event('take', entry.value) return entry.value end template.wait end ensure @take_waiter.delete(template) end end end
ruby
def move(port, tuple, sec=nil) template = WaitTemplateEntry.new(self, tuple, sec) yield(template) if block_given? synchronize do entry = @bag.find(template) if entry port.push(entry.value) if port @bag.delete(entry) notify_event('take', entry.value) return entry.value end raise RequestExpiredError if template.expired? begin @take_waiter.push(template) start_keeper if template.expires while true raise RequestCanceledError if template.canceled? raise RequestExpiredError if template.expired? entry = @bag.find(template) if entry port.push(entry.value) if port @bag.delete(entry) notify_event('take', entry.value) return entry.value end template.wait end ensure @take_waiter.delete(template) end end end
[ "def", "move", "(", "port", ",", "tuple", ",", "sec", "=", "nil", ")", "template", "=", "WaitTemplateEntry", ".", "new", "(", "self", ",", "tuple", ",", "sec", ")", "yield", "(", "template", ")", "if", "block_given?", "synchronize", "do", "entry", "=", "@bag", ".", "find", "(", "template", ")", "if", "entry", "port", ".", "push", "(", "entry", ".", "value", ")", "if", "port", "@bag", ".", "delete", "(", "entry", ")", "notify_event", "(", "'take'", ",", "entry", ".", "value", ")", "return", "entry", ".", "value", "end", "raise", "RequestExpiredError", "if", "template", ".", "expired?", "begin", "@take_waiter", ".", "push", "(", "template", ")", "start_keeper", "if", "template", ".", "expires", "while", "true", "raise", "RequestCanceledError", "if", "template", ".", "canceled?", "raise", "RequestExpiredError", "if", "template", ".", "expired?", "entry", "=", "@bag", ".", "find", "(", "template", ")", "if", "entry", "port", ".", "push", "(", "entry", ".", "value", ")", "if", "port", "@bag", ".", "delete", "(", "entry", ")", "notify_event", "(", "'take'", ",", "entry", ".", "value", ")", "return", "entry", ".", "value", "end", "template", ".", "wait", "end", "ensure", "@take_waiter", ".", "delete", "(", "template", ")", "end", "end", "end" ]
Moves +tuple+ to +port+.
[ "Moves", "+", "tuple", "+", "to", "+", "port", "+", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L485-L517
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleSpace.read
def read(tuple, sec=nil) template = WaitTemplateEntry.new(self, tuple, sec) yield(template) if block_given? synchronize do entry = @bag.find(template) return entry.value if entry raise RequestExpiredError if template.expired? begin @read_waiter.push(template) start_keeper if template.expires template.wait raise RequestCanceledError if template.canceled? raise RequestExpiredError if template.expired? return template.found ensure @read_waiter.delete(template) end end end
ruby
def read(tuple, sec=nil) template = WaitTemplateEntry.new(self, tuple, sec) yield(template) if block_given? synchronize do entry = @bag.find(template) return entry.value if entry raise RequestExpiredError if template.expired? begin @read_waiter.push(template) start_keeper if template.expires template.wait raise RequestCanceledError if template.canceled? raise RequestExpiredError if template.expired? return template.found ensure @read_waiter.delete(template) end end end
[ "def", "read", "(", "tuple", ",", "sec", "=", "nil", ")", "template", "=", "WaitTemplateEntry", ".", "new", "(", "self", ",", "tuple", ",", "sec", ")", "yield", "(", "template", ")", "if", "block_given?", "synchronize", "do", "entry", "=", "@bag", ".", "find", "(", "template", ")", "return", "entry", ".", "value", "if", "entry", "raise", "RequestExpiredError", "if", "template", ".", "expired?", "begin", "@read_waiter", ".", "push", "(", "template", ")", "start_keeper", "if", "template", ".", "expires", "template", ".", "wait", "raise", "RequestCanceledError", "if", "template", ".", "canceled?", "raise", "RequestExpiredError", "if", "template", ".", "expired?", "return", "template", ".", "found", "ensure", "@read_waiter", ".", "delete", "(", "template", ")", "end", "end", "end" ]
Reads +tuple+, but does not remove it.
[ "Reads", "+", "tuple", "+", "but", "does", "not", "remove", "it", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L522-L541
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleSpace.read_all
def read_all(tuple) template = WaitTemplateEntry.new(self, tuple, nil) synchronize do entry = @bag.find_all(template) entry.collect do |e| e.value end end end
ruby
def read_all(tuple) template = WaitTemplateEntry.new(self, tuple, nil) synchronize do entry = @bag.find_all(template) entry.collect do |e| e.value end end end
[ "def", "read_all", "(", "tuple", ")", "template", "=", "WaitTemplateEntry", ".", "new", "(", "self", ",", "tuple", ",", "nil", ")", "synchronize", "do", "entry", "=", "@bag", ".", "find_all", "(", "template", ")", "entry", ".", "collect", "do", "|", "e", "|", "e", ".", "value", "end", "end", "end" ]
Returns all tuples matching +tuple+. Does not remove the found tuples.
[ "Returns", "all", "tuples", "matching", "+", "tuple", "+", ".", "Does", "not", "remove", "the", "found", "tuples", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L546-L554
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleSpace.notify
def notify(event, tuple, sec=nil) template = NotifyTemplateEntry.new(self, event, tuple, sec) synchronize do @notify_waiter.push(template) end template end
ruby
def notify(event, tuple, sec=nil) template = NotifyTemplateEntry.new(self, event, tuple, sec) synchronize do @notify_waiter.push(template) end template end
[ "def", "notify", "(", "event", ",", "tuple", ",", "sec", "=", "nil", ")", "template", "=", "NotifyTemplateEntry", ".", "new", "(", "self", ",", "event", ",", "tuple", ",", "sec", ")", "synchronize", "do", "@notify_waiter", ".", "push", "(", "template", ")", "end", "template", "end" ]
Registers for notifications of +event+. Returns a NotifyTemplateEntry. See NotifyTemplateEntry for examples of how to listen for notifications. +event+ can be: 'write':: A tuple was added 'take':: A tuple was taken or moved 'delete':: A tuple was lost after being overwritten or expiring The TupleSpace will also notify you of the 'close' event when the NotifyTemplateEntry has expired.
[ "Registers", "for", "notifications", "of", "+", "event", "+", ".", "Returns", "a", "NotifyTemplateEntry", ".", "See", "NotifyTemplateEntry", "for", "examples", "of", "how", "to", "listen", "for", "notifications", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L568-L574
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleSpace.keep_clean
def keep_clean synchronize do @read_waiter.delete_unless_alive.each do |e| e.signal end @take_waiter.delete_unless_alive.each do |e| e.signal end @notify_waiter.delete_unless_alive.each do |e| e.notify(['close']) end @bag.delete_unless_alive.each do |e| notify_event('delete', e.value) end end end
ruby
def keep_clean synchronize do @read_waiter.delete_unless_alive.each do |e| e.signal end @take_waiter.delete_unless_alive.each do |e| e.signal end @notify_waiter.delete_unless_alive.each do |e| e.notify(['close']) end @bag.delete_unless_alive.each do |e| notify_event('delete', e.value) end end end
[ "def", "keep_clean", "synchronize", "do", "@read_waiter", ".", "delete_unless_alive", ".", "each", "do", "|", "e", "|", "e", ".", "signal", "end", "@take_waiter", ".", "delete_unless_alive", ".", "each", "do", "|", "e", "|", "e", ".", "signal", "end", "@notify_waiter", ".", "delete_unless_alive", ".", "each", "do", "|", "e", "|", "e", ".", "notify", "(", "[", "'close'", "]", ")", "end", "@bag", ".", "delete_unless_alive", ".", "each", "do", "|", "e", "|", "notify_event", "(", "'delete'", ",", "e", ".", "value", ")", "end", "end", "end" ]
Removes dead tuples.
[ "Removes", "dead", "tuples", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L585-L600
train
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb
Rinda.TupleSpace.notify_event
def notify_event(event, tuple) ev = [event, tuple] @notify_waiter.find_all_template(ev).each do |template| template.notify(ev) end end
ruby
def notify_event(event, tuple) ev = [event, tuple] @notify_waiter.find_all_template(ev).each do |template| template.notify(ev) end end
[ "def", "notify_event", "(", "event", ",", "tuple", ")", "ev", "=", "[", "event", ",", "tuple", "]", "@notify_waiter", ".", "find_all_template", "(", "ev", ")", ".", "each", "do", "|", "template", "|", "template", ".", "notify", "(", "ev", ")", "end", "end" ]
Notifies all registered listeners for +event+ of a status change of +tuple+.
[ "Notifies", "all", "registered", "listeners", "for", "+", "event", "+", "of", "a", "status", "change", "of", "+", "tuple", "+", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/tuplespace.rb#L606-L611
train
bjoernalbers/aruba-doubles
lib/aruba-doubles/history.rb
ArubaDoubles.History.to_pretty
def to_pretty to_a.each_with_index.map { |e,i| "%5d %s" % [i+1, e.shelljoin] }.join("\n") end
ruby
def to_pretty to_a.each_with_index.map { |e,i| "%5d %s" % [i+1, e.shelljoin] }.join("\n") end
[ "def", "to_pretty", "to_a", ".", "each_with_index", ".", "map", "{", "|", "e", ",", "i", "|", "\"%5d %s\"", "%", "[", "i", "+", "1", ",", "e", ".", "shelljoin", "]", "}", ".", "join", "(", "\"\\n\"", ")", "end" ]
Return entries just like running `history` in your shell. @return [String] pretty representation of the entries
[ "Return", "entries", "just", "like", "running", "history", "in", "your", "shell", "." ]
5e835bf60fef4bdf903c225a7c29968d17899516
https://github.com/bjoernalbers/aruba-doubles/blob/5e835bf60fef4bdf903c225a7c29968d17899516/lib/aruba-doubles/history.rb#L34-L36
train
benton/fog_tracker
lib/fog_tracker/collection_tracker.rb
FogTracker.CollectionTracker.update
def update new_collection = Array.new fog_collection = @account_tracker.connection.send(@type) || Array.new @log.info "Fetching #{fog_collection.count} #{@type} on #{@account_name}." # Here's where most of the network overhead is actually incurred fog_collection.each do |resource| @log.debug "Fetching resource: #{resource.class} #{resource.identity}" resource._fog_collection_tracker = self new_collection << resource #@log.debug "Got resource: #{resource.inspect}" end @log.info "Fetched #{new_collection.count} #{@type} on #{@account_name}." @collection = new_collection end
ruby
def update new_collection = Array.new fog_collection = @account_tracker.connection.send(@type) || Array.new @log.info "Fetching #{fog_collection.count} #{@type} on #{@account_name}." # Here's where most of the network overhead is actually incurred fog_collection.each do |resource| @log.debug "Fetching resource: #{resource.class} #{resource.identity}" resource._fog_collection_tracker = self new_collection << resource #@log.debug "Got resource: #{resource.inspect}" end @log.info "Fetched #{new_collection.count} #{@type} on #{@account_name}." @collection = new_collection end
[ "def", "update", "new_collection", "=", "Array", ".", "new", "fog_collection", "=", "@account_tracker", ".", "connection", ".", "send", "(", "@type", ")", "||", "Array", ".", "new", "@log", ".", "info", "\"Fetching #{fog_collection.count} #{@type} on #{@account_name}.\"", "fog_collection", ".", "each", "do", "|", "resource", "|", "@log", ".", "debug", "\"Fetching resource: #{resource.class} #{resource.identity}\"", "resource", ".", "_fog_collection_tracker", "=", "self", "new_collection", "<<", "resource", "end", "@log", ".", "info", "\"Fetched #{new_collection.count} #{@type} on #{@account_name}.\"", "@collection", "=", "new_collection", "end" ]
Creates an object for tracking a single Fog collection in a single account @param [String] resource_type the Fog collection name for this resource type @param [AccountTracker] account_tracker the AccountTracker for this tracker's account. Usually the AccountTracker that created this object Polls the {AccountTracker}'s connection for updated info on all existing instances of this tracker's resource_type
[ "Creates", "an", "object", "for", "tracking", "a", "single", "Fog", "collection", "in", "a", "single", "account" ]
73fdf35dd76ff1b1fc448698f2761ebfbea52e0e
https://github.com/benton/fog_tracker/blob/73fdf35dd76ff1b1fc448698f2761ebfbea52e0e/lib/fog_tracker/collection_tracker.rb#L26-L39
train
benton/fog_tracker
lib/fog_tracker/account_tracker.rb
FogTracker.AccountTracker.start
def start if not running? @log.debug "Starting tracking for account #{@name}..." @timer = Thread.new do begin while true update ; sleep @delay end rescue Exception => e sleep @delay ; retry end end else @log.info "Already tracking account #{@name}" end end
ruby
def start if not running? @log.debug "Starting tracking for account #{@name}..." @timer = Thread.new do begin while true update ; sleep @delay end rescue Exception => e sleep @delay ; retry end end else @log.info "Already tracking account #{@name}" end end
[ "def", "start", "if", "not", "running?", "@log", ".", "debug", "\"Starting tracking for account #{@name}...\"", "@timer", "=", "Thread", ".", "new", "do", "begin", "while", "true", "update", ";", "sleep", "@delay", "end", "rescue", "Exception", "=>", "e", "sleep", "@delay", ";", "retry", "end", "end", "else", "@log", ".", "info", "\"Already tracking account #{@name}\"", "end", "end" ]
Creates an object for tracking all collections in a single Fog account @param [String] account_name a human-readable name for the account @param [Hash] account a Hash of account configuration data @param [Hash] options optional additional parameters: - :delay (Integer) - Default time between polling of accounts - :callback (Proc) - A Method or Proc to call each time an account is polled. (should take an Array of resources as its only required parameter) - :error_callback (Proc) - A Method or Proc to call if polling errors occur. (should take a single Exception as its only required parameter) - :logger - a Ruby Logger-compatible object Starts a background thread, which periodically polls for all the resource collections for this tracker's account
[ "Creates", "an", "object", "for", "tracking", "all", "collections", "in", "a", "single", "Fog", "account" ]
73fdf35dd76ff1b1fc448698f2761ebfbea52e0e
https://github.com/benton/fog_tracker/blob/73fdf35dd76ff1b1fc448698f2761ebfbea52e0e/lib/fog_tracker/account_tracker.rb#L43-L58
train
benton/fog_tracker
lib/fog_tracker/account_tracker.rb
FogTracker.AccountTracker.update
def update begin @log.info "Polling account #{@name}..." @collection_trackers.each {|tracker| tracker.update} @preceeding_update_time = @most_recent_update @most_recent_update = Time.now @log.info "Polled account #{@name}" @callback.call(all_resources) if @callback rescue Exception => e @log.error "Exception polling account #{name}: #{e.message}" e.backtrace.each {|line| @log.debug line} @error_proc.call(e) if @error_proc raise e end end
ruby
def update begin @log.info "Polling account #{@name}..." @collection_trackers.each {|tracker| tracker.update} @preceeding_update_time = @most_recent_update @most_recent_update = Time.now @log.info "Polled account #{@name}" @callback.call(all_resources) if @callback rescue Exception => e @log.error "Exception polling account #{name}: #{e.message}" e.backtrace.each {|line| @log.debug line} @error_proc.call(e) if @error_proc raise e end end
[ "def", "update", "begin", "@log", ".", "info", "\"Polling account #{@name}...\"", "@collection_trackers", ".", "each", "{", "|", "tracker", "|", "tracker", ".", "update", "}", "@preceeding_update_time", "=", "@most_recent_update", "@most_recent_update", "=", "Time", ".", "now", "@log", ".", "info", "\"Polled account #{@name}\"", "@callback", ".", "call", "(", "all_resources", ")", "if", "@callback", "rescue", "Exception", "=>", "e", "@log", ".", "error", "\"Exception polling account #{name}: #{e.message}\"", "e", ".", "backtrace", ".", "each", "{", "|", "line", "|", "@log", ".", "debug", "line", "}", "@error_proc", ".", "call", "(", "e", ")", "if", "@error_proc", "raise", "e", "end", "end" ]
Polls once for all the resource collections for this tracker's account
[ "Polls", "once", "for", "all", "the", "resource", "collections", "for", "this", "tracker", "s", "account" ]
73fdf35dd76ff1b1fc448698f2761ebfbea52e0e
https://github.com/benton/fog_tracker/blob/73fdf35dd76ff1b1fc448698f2761ebfbea52e0e/lib/fog_tracker/account_tracker.rb#L72-L86
train
CORE4/fulmar-shell
lib/fulmar/shell.rb
Fulmar.Shell.execute_quiet
def execute_quiet(command, error_message) # Ladies and gentleman: More debug, please! puts command if @debug return_value = -1 Open3.popen3(environment, command) do |_stdin, stdout, stderr, wait_thread| Thread.new do stdout.each do |line| @last_output << line.strip puts line unless @quiet end end Thread.new do stderr.each do |line| @last_error << line puts line unless @quiet end end _stdin.close return_value = wait_thread.value if @strict and return_value.exitstatus != 0 dump_error_message(command) fail error_message end end puts "Program exited with status #{return_value.exitstatus}." if @debug return_value.exitstatus == 0 end
ruby
def execute_quiet(command, error_message) # Ladies and gentleman: More debug, please! puts command if @debug return_value = -1 Open3.popen3(environment, command) do |_stdin, stdout, stderr, wait_thread| Thread.new do stdout.each do |line| @last_output << line.strip puts line unless @quiet end end Thread.new do stderr.each do |line| @last_error << line puts line unless @quiet end end _stdin.close return_value = wait_thread.value if @strict and return_value.exitstatus != 0 dump_error_message(command) fail error_message end end puts "Program exited with status #{return_value.exitstatus}." if @debug return_value.exitstatus == 0 end
[ "def", "execute_quiet", "(", "command", ",", "error_message", ")", "puts", "command", "if", "@debug", "return_value", "=", "-", "1", "Open3", ".", "popen3", "(", "environment", ",", "command", ")", "do", "|", "_stdin", ",", "stdout", ",", "stderr", ",", "wait_thread", "|", "Thread", ".", "new", "do", "stdout", ".", "each", "do", "|", "line", "|", "@last_output", "<<", "line", ".", "strip", "puts", "line", "unless", "@quiet", "end", "end", "Thread", ".", "new", "do", "stderr", ".", "each", "do", "|", "line", "|", "@last_error", "<<", "line", "puts", "line", "unless", "@quiet", "end", "end", "_stdin", ".", "close", "return_value", "=", "wait_thread", ".", "value", "if", "@strict", "and", "return_value", ".", "exitstatus", "!=", "0", "dump_error_message", "(", "command", ")", "fail", "error_message", "end", "end", "puts", "\"Program exited with status #{return_value.exitstatus}.\"", "if", "@debug", "return_value", ".", "exitstatus", "==", "0", "end" ]
Run the command and capture the output
[ "Run", "the", "command", "and", "capture", "the", "output" ]
0c26bf98f86e99eeaa022410d4ab3a75b2283078
https://github.com/CORE4/fulmar-shell/blob/0c26bf98f86e99eeaa022410d4ab3a75b2283078/lib/fulmar/shell.rb#L124-L157
train
jphager2/mangdown
lib/mangdown/client.rb
Mangdown.Client.cbz
def cbz(dir) Mangdown::CBZ.all(dir) rescue StandardError => error raise Mangdown::Error, "Failed to package #{dir}: #{error.message}" end
ruby
def cbz(dir) Mangdown::CBZ.all(dir) rescue StandardError => error raise Mangdown::Error, "Failed to package #{dir}: #{error.message}" end
[ "def", "cbz", "(", "dir", ")", "Mangdown", "::", "CBZ", ".", "all", "(", "dir", ")", "rescue", "StandardError", "=>", "error", "raise", "Mangdown", "::", "Error", ",", "\"Failed to package #{dir}: #{error.message}\"", "end" ]
cbz all subdirectories in a directory
[ "cbz", "all", "subdirectories", "in", "a", "directory" ]
d57050f486b92873ca96a15cd20cbc1f468f2a61
https://github.com/jphager2/mangdown/blob/d57050f486b92873ca96a15cd20cbc1f468f2a61/lib/mangdown/client.rb#L26-L30
train
akhoury6/rbcli
lib/rbcli/util/trollop.rb
Trollop.Parser.each_arg
def each_arg(args) remains = [] i = 0 until i >= args.length return remains += args[i..-1] if @stop_words.member? args[i] case args[i] when /^--$/ # arg terminator return remains += args[(i + 1)..-1] when /^--(\S+?)=(.*)$/ # long argument with equals num_params_taken = yield "--#{$1}", [$2] if num_params_taken.nil? remains << args[i] if @stop_on_unknown return remains += args[i + 1..-1] end end i += 1 when /^--(\S+)$/ # long argument params = collect_argument_parameters(args, i + 1) num_params_taken = yield args[i], params if num_params_taken.nil? remains << args[i] if @stop_on_unknown return remains += args[i + 1..-1] end else i += num_params_taken end i += 1 when /^-(\S+)$/ # one or more short arguments short_remaining = "" shortargs = $1.split(//) shortargs.each_with_index do |a, j| if j == (shortargs.length - 1) params = collect_argument_parameters(args, i + 1) num_params_taken = yield "-#{a}", params unless num_params_taken short_remaining << a if @stop_on_unknown remains << "-#{short_remaining}" return remains += args[i + 1..-1] end else i += num_params_taken end else unless yield "-#{a}", [] short_remaining << a if @stop_on_unknown short_remaining += shortargs[j + 1..-1].join remains << "-#{short_remaining}" return remains += args[i + 1..-1] end end end end unless short_remaining.empty? remains << "-#{short_remaining}" end i += 1 else if @stop_on_unknown return remains += args[i..-1] else remains << args[i] i += 1 end end end remains end
ruby
def each_arg(args) remains = [] i = 0 until i >= args.length return remains += args[i..-1] if @stop_words.member? args[i] case args[i] when /^--$/ # arg terminator return remains += args[(i + 1)..-1] when /^--(\S+?)=(.*)$/ # long argument with equals num_params_taken = yield "--#{$1}", [$2] if num_params_taken.nil? remains << args[i] if @stop_on_unknown return remains += args[i + 1..-1] end end i += 1 when /^--(\S+)$/ # long argument params = collect_argument_parameters(args, i + 1) num_params_taken = yield args[i], params if num_params_taken.nil? remains << args[i] if @stop_on_unknown return remains += args[i + 1..-1] end else i += num_params_taken end i += 1 when /^-(\S+)$/ # one or more short arguments short_remaining = "" shortargs = $1.split(//) shortargs.each_with_index do |a, j| if j == (shortargs.length - 1) params = collect_argument_parameters(args, i + 1) num_params_taken = yield "-#{a}", params unless num_params_taken short_remaining << a if @stop_on_unknown remains << "-#{short_remaining}" return remains += args[i + 1..-1] end else i += num_params_taken end else unless yield "-#{a}", [] short_remaining << a if @stop_on_unknown short_remaining += shortargs[j + 1..-1].join remains << "-#{short_remaining}" return remains += args[i + 1..-1] end end end end unless short_remaining.empty? remains << "-#{short_remaining}" end i += 1 else if @stop_on_unknown return remains += args[i..-1] else remains << args[i] i += 1 end end end remains end
[ "def", "each_arg", "(", "args", ")", "remains", "=", "[", "]", "i", "=", "0", "until", "i", ">=", "args", ".", "length", "return", "remains", "+=", "args", "[", "i", "..", "-", "1", "]", "if", "@stop_words", ".", "member?", "args", "[", "i", "]", "case", "args", "[", "i", "]", "when", "/", "/", "return", "remains", "+=", "args", "[", "(", "i", "+", "1", ")", "..", "-", "1", "]", "when", "/", "\\S", "/", "num_params_taken", "=", "yield", "\"--#{$1}\"", ",", "[", "$2", "]", "if", "num_params_taken", ".", "nil?", "remains", "<<", "args", "[", "i", "]", "if", "@stop_on_unknown", "return", "remains", "+=", "args", "[", "i", "+", "1", "..", "-", "1", "]", "end", "end", "i", "+=", "1", "when", "/", "\\S", "/", "params", "=", "collect_argument_parameters", "(", "args", ",", "i", "+", "1", ")", "num_params_taken", "=", "yield", "args", "[", "i", "]", ",", "params", "if", "num_params_taken", ".", "nil?", "remains", "<<", "args", "[", "i", "]", "if", "@stop_on_unknown", "return", "remains", "+=", "args", "[", "i", "+", "1", "..", "-", "1", "]", "end", "else", "i", "+=", "num_params_taken", "end", "i", "+=", "1", "when", "/", "\\S", "/", "short_remaining", "=", "\"\"", "shortargs", "=", "$1", ".", "split", "(", "/", "/", ")", "shortargs", ".", "each_with_index", "do", "|", "a", ",", "j", "|", "if", "j", "==", "(", "shortargs", ".", "length", "-", "1", ")", "params", "=", "collect_argument_parameters", "(", "args", ",", "i", "+", "1", ")", "num_params_taken", "=", "yield", "\"-#{a}\"", ",", "params", "unless", "num_params_taken", "short_remaining", "<<", "a", "if", "@stop_on_unknown", "remains", "<<", "\"-#{short_remaining}\"", "return", "remains", "+=", "args", "[", "i", "+", "1", "..", "-", "1", "]", "end", "else", "i", "+=", "num_params_taken", "end", "else", "unless", "yield", "\"-#{a}\"", ",", "[", "]", "short_remaining", "<<", "a", "if", "@stop_on_unknown", "short_remaining", "+=", "shortargs", "[", "j", "+", "1", "..", "-", "1", "]", ".", "join", "remains", "<<", "\"-#{short_remaining}\"", "return", "remains", "+=", "args", "[", "i", "+", "1", "..", "-", "1", "]", "end", "end", "end", "end", "unless", "short_remaining", ".", "empty?", "remains", "<<", "\"-#{short_remaining}\"", "end", "i", "+=", "1", "else", "if", "@stop_on_unknown", "return", "remains", "+=", "args", "[", "i", "..", "-", "1", "]", "else", "remains", "<<", "args", "[", "i", "]", "i", "+=", "1", "end", "end", "end", "remains", "end" ]
yield successive arg, parameter pairs
[ "yield", "successive", "arg", "parameter", "pairs" ]
eb8c71af7003059bb1686f89b9204139a537c10d
https://github.com/akhoury6/rbcli/blob/eb8c71af7003059bb1686f89b9204139a537c10d/lib/rbcli/util/trollop.rb#L454-L529
train
awexome/doesfacebook
lib/doesfacebook/controller_extensions.rb
DoesFacebook.ControllerExtensions.parse_signed_request
def parse_signed_request Rails.logger.info " Facebook application \"#{fb_app.namespace}\" configuration in use for this request." if request_parameter = request.params["signed_request"] encoded_signature, encoded_data = request_parameter.split(".") decoded_signature = base64_url_decode(encoded_signature) decoded_data = base64_url_decode(encoded_data) @fbparams = HashWithIndifferentAccess.new(JSON.parse(decoded_data)) Rails.logger.info " Facebook Parameters: #{fbparams.inspect}" end end
ruby
def parse_signed_request Rails.logger.info " Facebook application \"#{fb_app.namespace}\" configuration in use for this request." if request_parameter = request.params["signed_request"] encoded_signature, encoded_data = request_parameter.split(".") decoded_signature = base64_url_decode(encoded_signature) decoded_data = base64_url_decode(encoded_data) @fbparams = HashWithIndifferentAccess.new(JSON.parse(decoded_data)) Rails.logger.info " Facebook Parameters: #{fbparams.inspect}" end end
[ "def", "parse_signed_request", "Rails", ".", "logger", ".", "info", "\" Facebook application \\\"#{fb_app.namespace}\\\" configuration in use for this request.\"", "if", "request_parameter", "=", "request", ".", "params", "[", "\"signed_request\"", "]", "encoded_signature", ",", "encoded_data", "=", "request_parameter", ".", "split", "(", "\".\"", ")", "decoded_signature", "=", "base64_url_decode", "(", "encoded_signature", ")", "decoded_data", "=", "base64_url_decode", "(", "encoded_data", ")", "@fbparams", "=", "HashWithIndifferentAccess", ".", "new", "(", "JSON", ".", "parse", "(", "decoded_data", ")", ")", "Rails", ".", "logger", ".", "info", "\" Facebook Parameters: #{fbparams.inspect}\"", "end", "end" ]
If present, parses data from the signed request and inserts it into the fbparams object for use during requests
[ "If", "present", "parses", "data", "from", "the", "signed", "request", "and", "inserts", "it", "into", "the", "fbparams", "object", "for", "use", "during", "requests" ]
fcd4c5daaf7362920c103c825c24ca64c4adf13a
https://github.com/awexome/doesfacebook/blob/fcd4c5daaf7362920c103c825c24ca64c4adf13a/lib/doesfacebook/controller_extensions.rb#L79-L88
train
elektronaut/dis
lib/dis/layer.rb
Dis.Layer.store
def store(type, hash, file) raise Dis::Errors::ReadOnlyError if readonly? store!(type, hash, file) end
ruby
def store(type, hash, file) raise Dis::Errors::ReadOnlyError if readonly? store!(type, hash, file) end
[ "def", "store", "(", "type", ",", "hash", ",", "file", ")", "raise", "Dis", "::", "Errors", "::", "ReadOnlyError", "if", "readonly?", "store!", "(", "type", ",", "hash", ",", "file", ")", "end" ]
Stores a file. hash = Digest::SHA1.file(file.path).hexdigest layer.store("documents", hash, path) Hash must be a hex digest of the file content. If an object with the supplied hash already exists, no action will be performed. In other words, no data will be overwritten if a hash collision occurs. Returns an instance of Fog::Model, or raises an error if the layer is readonly.
[ "Stores", "a", "file", "." ]
f5f57f6ac9a5ccba87fd02331210de736cd4ec1c
https://github.com/elektronaut/dis/blob/f5f57f6ac9a5ccba87fd02331210de736cd4ec1c/lib/dis/layer.rb#L95-L98
train
elektronaut/dis
lib/dis/layer.rb
Dis.Layer.exists?
def exists?(type, hash) if directory(type, hash) && directory(type, hash).files.head(key_component(type, hash)) true else false end end
ruby
def exists?(type, hash) if directory(type, hash) && directory(type, hash).files.head(key_component(type, hash)) true else false end end
[ "def", "exists?", "(", "type", ",", "hash", ")", "if", "directory", "(", "type", ",", "hash", ")", "&&", "directory", "(", "type", ",", "hash", ")", ".", "files", ".", "head", "(", "key_component", "(", "type", ",", "hash", ")", ")", "true", "else", "false", "end", "end" ]
Returns true if a object with the given hash exists. layer.exists?("documents", hash)
[ "Returns", "true", "if", "a", "object", "with", "the", "given", "hash", "exists", "." ]
f5f57f6ac9a5ccba87fd02331210de736cd4ec1c
https://github.com/elektronaut/dis/blob/f5f57f6ac9a5ccba87fd02331210de736cd4ec1c/lib/dis/layer.rb#L103-L110
train
elektronaut/dis
lib/dis/layer.rb
Dis.Layer.get
def get(type, hash) dir = directory(type, hash) return unless dir dir.files.get(key_component(type, hash)) end
ruby
def get(type, hash) dir = directory(type, hash) return unless dir dir.files.get(key_component(type, hash)) end
[ "def", "get", "(", "type", ",", "hash", ")", "dir", "=", "directory", "(", "type", ",", "hash", ")", "return", "unless", "dir", "dir", ".", "files", ".", "get", "(", "key_component", "(", "type", ",", "hash", ")", ")", "end" ]
Retrieves a file from the store. layer.get("documents", hash)
[ "Retrieves", "a", "file", "from", "the", "store", "." ]
f5f57f6ac9a5ccba87fd02331210de736cd4ec1c
https://github.com/elektronaut/dis/blob/f5f57f6ac9a5ccba87fd02331210de736cd4ec1c/lib/dis/layer.rb#L115-L119
train
elektronaut/dis
lib/dis/layer.rb
Dis.Layer.delete
def delete(type, hash) raise Dis::Errors::ReadOnlyError if readonly? delete!(type, hash) end
ruby
def delete(type, hash) raise Dis::Errors::ReadOnlyError if readonly? delete!(type, hash) end
[ "def", "delete", "(", "type", ",", "hash", ")", "raise", "Dis", "::", "Errors", "::", "ReadOnlyError", "if", "readonly?", "delete!", "(", "type", ",", "hash", ")", "end" ]
Deletes a file from the store. layer.delete("documents", hash) Returns true if the file was deleted, or false if it could not be found. Raises an error if the layer is readonly.
[ "Deletes", "a", "file", "from", "the", "store", "." ]
f5f57f6ac9a5ccba87fd02331210de736cd4ec1c
https://github.com/elektronaut/dis/blob/f5f57f6ac9a5ccba87fd02331210de736cd4ec1c/lib/dis/layer.rb#L127-L130
train
rapid7/daemon_runner
lib/daemon_runner/session.rb
DaemonRunner.Session.renew!
def renew! return if renew? @renew = Thread.new do ## Wakeup every TTL/2 seconds and renew the session loop do sleep ttl / 2 begin logger.debug(" - Renewing Consul session #{id}") Diplomat::Session.renew(id) rescue Faraday::ResourceNotFound logger.warn("Consul session #{id} has expired!") init rescue StandardError => e ## Keep the thread from exiting logger.error(e) end end end self end
ruby
def renew! return if renew? @renew = Thread.new do ## Wakeup every TTL/2 seconds and renew the session loop do sleep ttl / 2 begin logger.debug(" - Renewing Consul session #{id}") Diplomat::Session.renew(id) rescue Faraday::ResourceNotFound logger.warn("Consul session #{id} has expired!") init rescue StandardError => e ## Keep the thread from exiting logger.error(e) end end end self end
[ "def", "renew!", "return", "if", "renew?", "@renew", "=", "Thread", ".", "new", "do", "loop", "do", "sleep", "ttl", "/", "2", "begin", "logger", ".", "debug", "(", "\" - Renewing Consul session #{id}\"", ")", "Diplomat", "::", "Session", ".", "renew", "(", "id", ")", "rescue", "Faraday", "::", "ResourceNotFound", "logger", ".", "warn", "(", "\"Consul session #{id} has expired!\"", ")", "init", "rescue", "StandardError", "=>", "e", "logger", ".", "error", "(", "e", ")", "end", "end", "end", "self", "end" ]
Create a thread to periodically renew the lock session
[ "Create", "a", "thread", "to", "periodically", "renew", "the", "lock", "session" ]
dc840aeade0c802739e615718c58d7b243a9f13a
https://github.com/rapid7/daemon_runner/blob/dc840aeade0c802739e615718c58d7b243a9f13a/lib/daemon_runner/session.rb#L82-L106
train
rapid7/daemon_runner
lib/daemon_runner/session.rb
DaemonRunner.Session.verify_session
def verify_session(wait_time = 2) logger.info(" - Wait until Consul session #{id} exists") wait_time.times do exists = session_exist? raise CreateSessionError, 'Error creating session' unless exists sleep 1 end logger.info(" - Found Consul session #{id}") rescue CreateSessionError init end
ruby
def verify_session(wait_time = 2) logger.info(" - Wait until Consul session #{id} exists") wait_time.times do exists = session_exist? raise CreateSessionError, 'Error creating session' unless exists sleep 1 end logger.info(" - Found Consul session #{id}") rescue CreateSessionError init end
[ "def", "verify_session", "(", "wait_time", "=", "2", ")", "logger", ".", "info", "(", "\" - Wait until Consul session #{id} exists\"", ")", "wait_time", ".", "times", "do", "exists", "=", "session_exist?", "raise", "CreateSessionError", ",", "'Error creating session'", "unless", "exists", "sleep", "1", "end", "logger", ".", "info", "(", "\" - Found Consul session #{id}\"", ")", "rescue", "CreateSessionError", "init", "end" ]
Verify wheather the session exists after a period of time
[ "Verify", "wheather", "the", "session", "exists", "after", "a", "period", "of", "time" ]
dc840aeade0c802739e615718c58d7b243a9f13a
https://github.com/rapid7/daemon_runner/blob/dc840aeade0c802739e615718c58d7b243a9f13a/lib/daemon_runner/session.rb#L116-L126
train
rapid7/daemon_runner
lib/daemon_runner/session.rb
DaemonRunner.Session.session_exist?
def session_exist? sessions = Diplomat::Session.list sessions.any? { |s| s['ID'] == id } end
ruby
def session_exist? sessions = Diplomat::Session.list sessions.any? { |s| s['ID'] == id } end
[ "def", "session_exist?", "sessions", "=", "Diplomat", "::", "Session", ".", "list", "sessions", ".", "any?", "{", "|", "s", "|", "s", "[", "'ID'", "]", "==", "id", "}", "end" ]
Does the session exist
[ "Does", "the", "session", "exist" ]
dc840aeade0c802739e615718c58d7b243a9f13a
https://github.com/rapid7/daemon_runner/blob/dc840aeade0c802739e615718c58d7b243a9f13a/lib/daemon_runner/session.rb#L143-L146
train
ruby-x/rx-file
lib/rx-file/array_node.rb
RxFile.ArrayNode.long_out
def long_out io , level indent = " " * level @children.each_with_index do |child , i| io.write "\n#{indent}" unless i == 0 io.write "- " child.out(io , level + 1) end end
ruby
def long_out io , level indent = " " * level @children.each_with_index do |child , i| io.write "\n#{indent}" unless i == 0 io.write "- " child.out(io , level + 1) end end
[ "def", "long_out", "io", ",", "level", "indent", "=", "\" \"", "*", "level", "@children", ".", "each_with_index", "do", "|", "child", ",", "i", "|", "io", ".", "write", "\"\\n#{indent}\"", "unless", "i", "==", "0", "io", ".", "write", "\"- \"", "child", ".", "out", "(", "io", ",", "level", "+", "1", ")", "end", "end" ]
Arrays start with the minus on each line "-" and each line has the value
[ "Arrays", "start", "with", "the", "minus", "on", "each", "line", "-", "and", "each", "line", "has", "the", "value" ]
7c4a5546136d1bad065803da91778b209c18cb4d
https://github.com/ruby-x/rx-file/blob/7c4a5546136d1bad065803da91778b209c18cb4d/lib/rx-file/array_node.rb#L42-L49
train
KentaaNL/buckaruby
lib/buckaruby/gateway.rb
Buckaruby.Gateway.issuers
def issuers(payment_method) if payment_method != PaymentMethod::IDEAL && payment_method != PaymentMethod::IDEAL_PROCESSING raise ArgumentError, "Invalid payment method, only iDEAL is supported." end Ideal::ISSUERS end
ruby
def issuers(payment_method) if payment_method != PaymentMethod::IDEAL && payment_method != PaymentMethod::IDEAL_PROCESSING raise ArgumentError, "Invalid payment method, only iDEAL is supported." end Ideal::ISSUERS end
[ "def", "issuers", "(", "payment_method", ")", "if", "payment_method", "!=", "PaymentMethod", "::", "IDEAL", "&&", "payment_method", "!=", "PaymentMethod", "::", "IDEAL_PROCESSING", "raise", "ArgumentError", ",", "\"Invalid payment method, only iDEAL is supported.\"", "end", "Ideal", "::", "ISSUERS", "end" ]
Get a list with payment issuers.
[ "Get", "a", "list", "with", "payment", "issuers", "." ]
0aeff3712430745e7c25f4352ab8241df5f4658f
https://github.com/KentaaNL/buckaruby/blob/0aeff3712430745e7c25f4352ab8241df5f4658f/lib/buckaruby/gateway.rb#L21-L27
train
KentaaNL/buckaruby
lib/buckaruby/gateway.rb
Buckaruby.Gateway.setup_transaction
def setup_transaction(options = {}) @logger.debug("[setup_transaction] options=#{options.inspect}") validate_setup_transaction_params!(options) normalize_account_iban!(options) if options[:payment_method] == PaymentMethod::SEPA_DIRECT_DEBIT execute_request(:setup_transaction, options) end
ruby
def setup_transaction(options = {}) @logger.debug("[setup_transaction] options=#{options.inspect}") validate_setup_transaction_params!(options) normalize_account_iban!(options) if options[:payment_method] == PaymentMethod::SEPA_DIRECT_DEBIT execute_request(:setup_transaction, options) end
[ "def", "setup_transaction", "(", "options", "=", "{", "}", ")", "@logger", ".", "debug", "(", "\"[setup_transaction] options=#{options.inspect}\"", ")", "validate_setup_transaction_params!", "(", "options", ")", "normalize_account_iban!", "(", "options", ")", "if", "options", "[", ":payment_method", "]", "==", "PaymentMethod", "::", "SEPA_DIRECT_DEBIT", "execute_request", "(", ":setup_transaction", ",", "options", ")", "end" ]
Setup a new transaction.
[ "Setup", "a", "new", "transaction", "." ]
0aeff3712430745e7c25f4352ab8241df5f4658f
https://github.com/KentaaNL/buckaruby/blob/0aeff3712430745e7c25f4352ab8241df5f4658f/lib/buckaruby/gateway.rb#L30-L38
train
KentaaNL/buckaruby
lib/buckaruby/gateway.rb
Buckaruby.Gateway.refundable?
def refundable?(options = {}) @logger.debug("[refundable?] options=#{options.inspect}") validate_required_params!(options, :transaction_id) response = execute_request(:refund_info, options) response.refundable? end
ruby
def refundable?(options = {}) @logger.debug("[refundable?] options=#{options.inspect}") validate_required_params!(options, :transaction_id) response = execute_request(:refund_info, options) response.refundable? end
[ "def", "refundable?", "(", "options", "=", "{", "}", ")", "@logger", ".", "debug", "(", "\"[refundable?] options=#{options.inspect}\"", ")", "validate_required_params!", "(", "options", ",", ":transaction_id", ")", "response", "=", "execute_request", "(", ":refund_info", ",", "options", ")", "response", ".", "refundable?", "end" ]
Checks if a transaction is refundable.
[ "Checks", "if", "a", "transaction", "is", "refundable", "." ]
0aeff3712430745e7c25f4352ab8241df5f4658f
https://github.com/KentaaNL/buckaruby/blob/0aeff3712430745e7c25f4352ab8241df5f4658f/lib/buckaruby/gateway.rb#L50-L57
train
KentaaNL/buckaruby
lib/buckaruby/gateway.rb
Buckaruby.Gateway.refund_transaction
def refund_transaction(options = {}) @logger.debug("[refund_transaction] options=#{options.inspect}") validate_refund_transaction_params!(options) response = execute_request(:refund_info, options) unless response.refundable? raise NonRefundableTransactionException, options[:transaction_id] end # Pick maximum refundable amount if amount is not supplied. options[:amount] = response.maximum_amount unless options[:amount] # Fill required parameters with data from refund info request. options.merge!( payment_method: response.payment_method, invoicenumber: response.invoicenumber, currency: response.currency ) execute_request(:refund_transaction, options) end
ruby
def refund_transaction(options = {}) @logger.debug("[refund_transaction] options=#{options.inspect}") validate_refund_transaction_params!(options) response = execute_request(:refund_info, options) unless response.refundable? raise NonRefundableTransactionException, options[:transaction_id] end # Pick maximum refundable amount if amount is not supplied. options[:amount] = response.maximum_amount unless options[:amount] # Fill required parameters with data from refund info request. options.merge!( payment_method: response.payment_method, invoicenumber: response.invoicenumber, currency: response.currency ) execute_request(:refund_transaction, options) end
[ "def", "refund_transaction", "(", "options", "=", "{", "}", ")", "@logger", ".", "debug", "(", "\"[refund_transaction] options=#{options.inspect}\"", ")", "validate_refund_transaction_params!", "(", "options", ")", "response", "=", "execute_request", "(", ":refund_info", ",", "options", ")", "unless", "response", ".", "refundable?", "raise", "NonRefundableTransactionException", ",", "options", "[", ":transaction_id", "]", "end", "options", "[", ":amount", "]", "=", "response", ".", "maximum_amount", "unless", "options", "[", ":amount", "]", "options", ".", "merge!", "(", "payment_method", ":", "response", ".", "payment_method", ",", "invoicenumber", ":", "response", ".", "invoicenumber", ",", "currency", ":", "response", ".", "currency", ")", "execute_request", "(", ":refund_transaction", ",", "options", ")", "end" ]
Refund a transaction.
[ "Refund", "a", "transaction", "." ]
0aeff3712430745e7c25f4352ab8241df5f4658f
https://github.com/KentaaNL/buckaruby/blob/0aeff3712430745e7c25f4352ab8241df5f4658f/lib/buckaruby/gateway.rb#L60-L81
train
KentaaNL/buckaruby
lib/buckaruby/gateway.rb
Buckaruby.Gateway.cancellable?
def cancellable?(options = {}) @logger.debug("[cancellable?] options=#{options.inspect}") validate_required_params!(options, :transaction_id) response = execute_request(:status, options) response.cancellable? end
ruby
def cancellable?(options = {}) @logger.debug("[cancellable?] options=#{options.inspect}") validate_required_params!(options, :transaction_id) response = execute_request(:status, options) response.cancellable? end
[ "def", "cancellable?", "(", "options", "=", "{", "}", ")", "@logger", ".", "debug", "(", "\"[cancellable?] options=#{options.inspect}\"", ")", "validate_required_params!", "(", "options", ",", ":transaction_id", ")", "response", "=", "execute_request", "(", ":status", ",", "options", ")", "response", ".", "cancellable?", "end" ]
Checks if a transaction is cancellable.
[ "Checks", "if", "a", "transaction", "is", "cancellable", "." ]
0aeff3712430745e7c25f4352ab8241df5f4658f
https://github.com/KentaaNL/buckaruby/blob/0aeff3712430745e7c25f4352ab8241df5f4658f/lib/buckaruby/gateway.rb#L93-L100
train
KentaaNL/buckaruby
lib/buckaruby/gateway.rb
Buckaruby.Gateway.cancel_transaction
def cancel_transaction(options = {}) @logger.debug("[cancel_transaction] options=#{options.inspect}") validate_required_params!(options, :transaction_id) response = execute_request(:status, options) unless response.cancellable? raise NonCancellableTransactionException, options[:transaction_id] end execute_request(:cancel, options) end
ruby
def cancel_transaction(options = {}) @logger.debug("[cancel_transaction] options=#{options.inspect}") validate_required_params!(options, :transaction_id) response = execute_request(:status, options) unless response.cancellable? raise NonCancellableTransactionException, options[:transaction_id] end execute_request(:cancel, options) end
[ "def", "cancel_transaction", "(", "options", "=", "{", "}", ")", "@logger", ".", "debug", "(", "\"[cancel_transaction] options=#{options.inspect}\"", ")", "validate_required_params!", "(", "options", ",", ":transaction_id", ")", "response", "=", "execute_request", "(", ":status", ",", "options", ")", "unless", "response", ".", "cancellable?", "raise", "NonCancellableTransactionException", ",", "options", "[", ":transaction_id", "]", "end", "execute_request", "(", ":cancel", ",", "options", ")", "end" ]
Cancel a transaction.
[ "Cancel", "a", "transaction", "." ]
0aeff3712430745e7c25f4352ab8241df5f4658f
https://github.com/KentaaNL/buckaruby/blob/0aeff3712430745e7c25f4352ab8241df5f4658f/lib/buckaruby/gateway.rb#L103-L114
train
KentaaNL/buckaruby
lib/buckaruby/gateway.rb
Buckaruby.Gateway.validate_required_params!
def validate_required_params!(params, *required) required.flatten.each do |param| if !params.key?(param) || params[param].to_s.empty? raise ArgumentError, "Missing required parameter: #{param}." end end end
ruby
def validate_required_params!(params, *required) required.flatten.each do |param| if !params.key?(param) || params[param].to_s.empty? raise ArgumentError, "Missing required parameter: #{param}." end end end
[ "def", "validate_required_params!", "(", "params", ",", "*", "required", ")", "required", ".", "flatten", ".", "each", "do", "|", "param", "|", "if", "!", "params", ".", "key?", "(", "param", ")", "||", "params", "[", "param", "]", ".", "to_s", ".", "empty?", "raise", "ArgumentError", ",", "\"Missing required parameter: #{param}.\"", "end", "end", "end" ]
Validate required parameters.
[ "Validate", "required", "parameters", "." ]
0aeff3712430745e7c25f4352ab8241df5f4658f
https://github.com/KentaaNL/buckaruby/blob/0aeff3712430745e7c25f4352ab8241df5f4658f/lib/buckaruby/gateway.rb#L128-L134
train
KentaaNL/buckaruby
lib/buckaruby/gateway.rb
Buckaruby.Gateway.validate_setup_transaction_params!
def validate_setup_transaction_params!(options) required_params = [:amount, :payment_method, :invoicenumber] required_params << :return_url if options[:payment_method] != PaymentMethod::SEPA_DIRECT_DEBIT case options[:payment_method] when PaymentMethod::IDEAL, PaymentMethod::IDEAL_PROCESSING required_params << :payment_issuer when PaymentMethod::SEPA_DIRECT_DEBIT required_params << [:account_iban, :account_name] end validate_required_params!(options, required_params) validate_amount!(options) valid_payment_methods = [ PaymentMethod::IDEAL, PaymentMethod::IDEAL_PROCESSING, PaymentMethod::VISA, PaymentMethod::MASTER_CARD, PaymentMethod::MAESTRO, PaymentMethod::SEPA_DIRECT_DEBIT, PaymentMethod::PAYPAL, PaymentMethod::BANCONTACT_MISTER_CASH ] validate_payment_method!(options, valid_payment_methods) validate_payment_issuer!(options) end
ruby
def validate_setup_transaction_params!(options) required_params = [:amount, :payment_method, :invoicenumber] required_params << :return_url if options[:payment_method] != PaymentMethod::SEPA_DIRECT_DEBIT case options[:payment_method] when PaymentMethod::IDEAL, PaymentMethod::IDEAL_PROCESSING required_params << :payment_issuer when PaymentMethod::SEPA_DIRECT_DEBIT required_params << [:account_iban, :account_name] end validate_required_params!(options, required_params) validate_amount!(options) valid_payment_methods = [ PaymentMethod::IDEAL, PaymentMethod::IDEAL_PROCESSING, PaymentMethod::VISA, PaymentMethod::MASTER_CARD, PaymentMethod::MAESTRO, PaymentMethod::SEPA_DIRECT_DEBIT, PaymentMethod::PAYPAL, PaymentMethod::BANCONTACT_MISTER_CASH ] validate_payment_method!(options, valid_payment_methods) validate_payment_issuer!(options) end
[ "def", "validate_setup_transaction_params!", "(", "options", ")", "required_params", "=", "[", ":amount", ",", ":payment_method", ",", ":invoicenumber", "]", "required_params", "<<", ":return_url", "if", "options", "[", ":payment_method", "]", "!=", "PaymentMethod", "::", "SEPA_DIRECT_DEBIT", "case", "options", "[", ":payment_method", "]", "when", "PaymentMethod", "::", "IDEAL", ",", "PaymentMethod", "::", "IDEAL_PROCESSING", "required_params", "<<", ":payment_issuer", "when", "PaymentMethod", "::", "SEPA_DIRECT_DEBIT", "required_params", "<<", "[", ":account_iban", ",", ":account_name", "]", "end", "validate_required_params!", "(", "options", ",", "required_params", ")", "validate_amount!", "(", "options", ")", "valid_payment_methods", "=", "[", "PaymentMethod", "::", "IDEAL", ",", "PaymentMethod", "::", "IDEAL_PROCESSING", ",", "PaymentMethod", "::", "VISA", ",", "PaymentMethod", "::", "MASTER_CARD", ",", "PaymentMethod", "::", "MAESTRO", ",", "PaymentMethod", "::", "SEPA_DIRECT_DEBIT", ",", "PaymentMethod", "::", "PAYPAL", ",", "PaymentMethod", "::", "BANCONTACT_MISTER_CASH", "]", "validate_payment_method!", "(", "options", ",", "valid_payment_methods", ")", "validate_payment_issuer!", "(", "options", ")", "end" ]
Validate params for setup transaction.
[ "Validate", "params", "for", "setup", "transaction", "." ]
0aeff3712430745e7c25f4352ab8241df5f4658f
https://github.com/KentaaNL/buckaruby/blob/0aeff3712430745e7c25f4352ab8241df5f4658f/lib/buckaruby/gateway.rb#L137-L159
train
KentaaNL/buckaruby
lib/buckaruby/gateway.rb
Buckaruby.Gateway.validate_payment_issuer!
def validate_payment_issuer!(options) if options[:payment_method] == PaymentMethod::IDEAL || options[:payment_method] == PaymentMethod::IDEAL_PROCESSING unless Ideal::ISSUERS.include?(options[:payment_issuer]) raise ArgumentError, "Invalid payment issuer: #{options[:payment_issuer]}" end end end
ruby
def validate_payment_issuer!(options) if options[:payment_method] == PaymentMethod::IDEAL || options[:payment_method] == PaymentMethod::IDEAL_PROCESSING unless Ideal::ISSUERS.include?(options[:payment_issuer]) raise ArgumentError, "Invalid payment issuer: #{options[:payment_issuer]}" end end end
[ "def", "validate_payment_issuer!", "(", "options", ")", "if", "options", "[", ":payment_method", "]", "==", "PaymentMethod", "::", "IDEAL", "||", "options", "[", ":payment_method", "]", "==", "PaymentMethod", "::", "IDEAL_PROCESSING", "unless", "Ideal", "::", "ISSUERS", ".", "include?", "(", "options", "[", ":payment_issuer", "]", ")", "raise", "ArgumentError", ",", "\"Invalid payment issuer: #{options[:payment_issuer]}\"", "end", "end", "end" ]
Validate the payment issuer when iDEAL is selected as payment method.
[ "Validate", "the", "payment", "issuer", "when", "iDEAL", "is", "selected", "as", "payment", "method", "." ]
0aeff3712430745e7c25f4352ab8241df5f4658f
https://github.com/KentaaNL/buckaruby/blob/0aeff3712430745e7c25f4352ab8241df5f4658f/lib/buckaruby/gateway.rb#L177-L183
train
KentaaNL/buckaruby
lib/buckaruby/gateway.rb
Buckaruby.Gateway.validate_recurrent_transaction_params!
def validate_recurrent_transaction_params!(options) required_params = [:amount, :payment_method, :invoicenumber, :transaction_id] validate_required_params!(options, required_params) validate_amount!(options) valid_payment_methods = [ PaymentMethod::VISA, PaymentMethod::MASTER_CARD, PaymentMethod::MAESTRO, PaymentMethod::SEPA_DIRECT_DEBIT, PaymentMethod::PAYPAL ] validate_payment_method!(options, valid_payment_methods) end
ruby
def validate_recurrent_transaction_params!(options) required_params = [:amount, :payment_method, :invoicenumber, :transaction_id] validate_required_params!(options, required_params) validate_amount!(options) valid_payment_methods = [ PaymentMethod::VISA, PaymentMethod::MASTER_CARD, PaymentMethod::MAESTRO, PaymentMethod::SEPA_DIRECT_DEBIT, PaymentMethod::PAYPAL ] validate_payment_method!(options, valid_payment_methods) end
[ "def", "validate_recurrent_transaction_params!", "(", "options", ")", "required_params", "=", "[", ":amount", ",", ":payment_method", ",", ":invoicenumber", ",", ":transaction_id", "]", "validate_required_params!", "(", "options", ",", "required_params", ")", "validate_amount!", "(", "options", ")", "valid_payment_methods", "=", "[", "PaymentMethod", "::", "VISA", ",", "PaymentMethod", "::", "MASTER_CARD", ",", "PaymentMethod", "::", "MAESTRO", ",", "PaymentMethod", "::", "SEPA_DIRECT_DEBIT", ",", "PaymentMethod", "::", "PAYPAL", "]", "validate_payment_method!", "(", "options", ",", "valid_payment_methods", ")", "end" ]
Validate params for recurrent transaction.
[ "Validate", "params", "for", "recurrent", "transaction", "." ]
0aeff3712430745e7c25f4352ab8241df5f4658f
https://github.com/KentaaNL/buckaruby/blob/0aeff3712430745e7c25f4352ab8241df5f4658f/lib/buckaruby/gateway.rb#L186-L198
train
KentaaNL/buckaruby
lib/buckaruby/gateway.rb
Buckaruby.Gateway.execute_request
def execute_request(request_type, options) request = build_request(request_type) response = request.execute(options) case request_type when :setup_transaction SetupTransactionResponse.new(response, config) when :recurrent_transaction RecurrentTransactionResponse.new(response, config) when :refund_transaction RefundTransactionResponse.new(response, config) when :refund_info RefundInfoResponse.new(response, config) when :status StatusResponse.new(response, config) when :cancel CancelResponse.new(response, config) end end
ruby
def execute_request(request_type, options) request = build_request(request_type) response = request.execute(options) case request_type when :setup_transaction SetupTransactionResponse.new(response, config) when :recurrent_transaction RecurrentTransactionResponse.new(response, config) when :refund_transaction RefundTransactionResponse.new(response, config) when :refund_info RefundInfoResponse.new(response, config) when :status StatusResponse.new(response, config) when :cancel CancelResponse.new(response, config) end end
[ "def", "execute_request", "(", "request_type", ",", "options", ")", "request", "=", "build_request", "(", "request_type", ")", "response", "=", "request", ".", "execute", "(", "options", ")", "case", "request_type", "when", ":setup_transaction", "SetupTransactionResponse", ".", "new", "(", "response", ",", "config", ")", "when", ":recurrent_transaction", "RecurrentTransactionResponse", ".", "new", "(", "response", ",", "config", ")", "when", ":refund_transaction", "RefundTransactionResponse", ".", "new", "(", "response", ",", "config", ")", "when", ":refund_info", "RefundInfoResponse", ".", "new", "(", "response", ",", "config", ")", "when", ":status", "StatusResponse", ".", "new", "(", "response", ",", "config", ")", "when", ":cancel", "CancelResponse", ".", "new", "(", "response", ",", "config", ")", "end", "end" ]
Build and execute a request.
[ "Build", "and", "execute", "a", "request", "." ]
0aeff3712430745e7c25f4352ab8241df5f4658f
https://github.com/KentaaNL/buckaruby/blob/0aeff3712430745e7c25f4352ab8241df5f4658f/lib/buckaruby/gateway.rb#L226-L244
train
KentaaNL/buckaruby
lib/buckaruby/gateway.rb
Buckaruby.Gateway.build_request
def build_request(request_type) case request_type when :setup_transaction SetupTransactionRequest.new(config) when :recurrent_transaction RecurrentTransactionRequest.new(config) when :refund_transaction RefundTransactionRequest.new(config) when :refund_info RefundInfoRequest.new(config) when :status StatusRequest.new(config) when :cancel CancelRequest.new(config) end end
ruby
def build_request(request_type) case request_type when :setup_transaction SetupTransactionRequest.new(config) when :recurrent_transaction RecurrentTransactionRequest.new(config) when :refund_transaction RefundTransactionRequest.new(config) when :refund_info RefundInfoRequest.new(config) when :status StatusRequest.new(config) when :cancel CancelRequest.new(config) end end
[ "def", "build_request", "(", "request_type", ")", "case", "request_type", "when", ":setup_transaction", "SetupTransactionRequest", ".", "new", "(", "config", ")", "when", ":recurrent_transaction", "RecurrentTransactionRequest", ".", "new", "(", "config", ")", "when", ":refund_transaction", "RefundTransactionRequest", ".", "new", "(", "config", ")", "when", ":refund_info", "RefundInfoRequest", ".", "new", "(", "config", ")", "when", ":status", "StatusRequest", ".", "new", "(", "config", ")", "when", ":cancel", "CancelRequest", ".", "new", "(", "config", ")", "end", "end" ]
Factory method for constructing a request.
[ "Factory", "method", "for", "constructing", "a", "request", "." ]
0aeff3712430745e7c25f4352ab8241df5f4658f
https://github.com/KentaaNL/buckaruby/blob/0aeff3712430745e7c25f4352ab8241df5f4658f/lib/buckaruby/gateway.rb#L247-L262
train
ruby-x/rx-file
lib/rx-file/node.rb
RxFile.Node.as_string
def as_string(level) io = StringIO.new out(io,level) io.string end
ruby
def as_string(level) io = StringIO.new out(io,level) io.string end
[ "def", "as_string", "(", "level", ")", "io", "=", "StringIO", ".", "new", "out", "(", "io", ",", "level", ")", "io", ".", "string", "end" ]
helper function to return the output as a string ie creates stringio, calls out and returns the string
[ "helper", "function", "to", "return", "the", "output", "as", "a", "string", "ie", "creates", "stringio", "calls", "out", "and", "returns", "the", "string" ]
7c4a5546136d1bad065803da91778b209c18cb4d
https://github.com/ruby-x/rx-file/blob/7c4a5546136d1bad065803da91778b209c18cb4d/lib/rx-file/node.rb#L50-L54
train
ruby-x/rx-file
lib/rx-file/object_node.rb
RxFile.ObjectNode.add
def add k , v raise "Key should be symbol not #{k}" unless k.is_a? Symbol if( v.is_simple?) @simple[k] = v else @complex[k] = v end end
ruby
def add k , v raise "Key should be symbol not #{k}" unless k.is_a? Symbol if( v.is_simple?) @simple[k] = v else @complex[k] = v end end
[ "def", "add", "k", ",", "v", "raise", "\"Key should be symbol not #{k}\"", "unless", "k", ".", "is_a?", "Symbol", "if", "(", "v", ".", "is_simple?", ")", "@simple", "[", "k", "]", "=", "v", "else", "@complex", "[", "k", "]", "=", "v", "end", "end" ]
attributes hold key value pairs
[ "attributes", "hold", "key", "value", "pairs" ]
7c4a5546136d1bad065803da91778b209c18cb4d
https://github.com/ruby-x/rx-file/blob/7c4a5546136d1bad065803da91778b209c18cb4d/lib/rx-file/object_node.rb#L24-L31
train
mkroman/blur
library/blur/script_cache.rb
Blur.ScriptCache.save
def save directory = File.dirname @path unless File.directory? directory Dir.mkdir directory end File.open @path, ?w do |file| YAML.dump @hash, file end end
ruby
def save directory = File.dirname @path unless File.directory? directory Dir.mkdir directory end File.open @path, ?w do |file| YAML.dump @hash, file end end
[ "def", "save", "directory", "=", "File", ".", "dirname", "@path", "unless", "File", ".", "directory?", "directory", "Dir", ".", "mkdir", "directory", "end", "File", ".", "open", "@path", ",", "?w", "do", "|", "file", "|", "YAML", ".", "dump", "@hash", ",", "file", "end", "end" ]
Saves the cache as a YAML file.
[ "Saves", "the", "cache", "as", "a", "YAML", "file", "." ]
05408fbbaecb33a506c7e7c72da01d2e68848ea9
https://github.com/mkroman/blur/blob/05408fbbaecb33a506c7e7c72da01d2e68848ea9/library/blur/script_cache.rb#L18-L28
train
roqua/authmac
lib/authmac/hmac_checker.rb
Authmac.HmacChecker.params_sorted_by_key
def params_sorted_by_key(params) case params when Hash params.map { |k, v| [k.to_s, params_sorted_by_key(v)] } .sort_by { |k, v| k } .to_h when Array params.map { |val| params_sorted_by_key(val) } else params.to_s end end
ruby
def params_sorted_by_key(params) case params when Hash params.map { |k, v| [k.to_s, params_sorted_by_key(v)] } .sort_by { |k, v| k } .to_h when Array params.map { |val| params_sorted_by_key(val) } else params.to_s end end
[ "def", "params_sorted_by_key", "(", "params", ")", "case", "params", "when", "Hash", "params", ".", "map", "{", "|", "k", ",", "v", "|", "[", "k", ".", "to_s", ",", "params_sorted_by_key", "(", "v", ")", "]", "}", ".", "sort_by", "{", "|", "k", ",", "v", "|", "k", "}", ".", "to_h", "when", "Array", "params", ".", "map", "{", "|", "val", "|", "params_sorted_by_key", "(", "val", ")", "}", "else", "params", ".", "to_s", "end", "end" ]
stringifies and sorts hashes by key at all levels.
[ "stringifies", "and", "sorts", "hashes", "by", "key", "at", "all", "levels", "." ]
c0e064b80f90c10f93c4f5d8e5e3e590829feba4
https://github.com/roqua/authmac/blob/c0e064b80f90c10f93c4f5d8e5e3e590829feba4/lib/authmac/hmac_checker.rb#L55-L66
train
richo/juici
lib/juici/controllers/trigger.rb
Juici::Controllers.Trigger.rebuild!
def rebuild! unless project = ::Juici::Project.where(name: params[:project]).first not_found end unless build = ::Juici::Build.where(parent: project.name, _id: params[:id]).first not_found end ::Juici::Build.new_from(build).tap do |new_build| new_build.save! $build_queue << new_build $build_queue.bump! end end
ruby
def rebuild! unless project = ::Juici::Project.where(name: params[:project]).first not_found end unless build = ::Juici::Build.where(parent: project.name, _id: params[:id]).first not_found end ::Juici::Build.new_from(build).tap do |new_build| new_build.save! $build_queue << new_build $build_queue.bump! end end
[ "def", "rebuild!", "unless", "project", "=", "::", "Juici", "::", "Project", ".", "where", "(", "name", ":", "params", "[", ":project", "]", ")", ".", "first", "not_found", "end", "unless", "build", "=", "::", "Juici", "::", "Build", ".", "where", "(", "parent", ":", "project", ".", "name", ",", "_id", ":", "params", "[", ":id", "]", ")", ".", "first", "not_found", "end", "::", "Juici", "::", "Build", ".", "new_from", "(", "build", ")", ".", "tap", "do", "|", "new_build", "|", "new_build", ".", "save!", "$build_queue", "<<", "new_build", "$build_queue", ".", "bump!", "end", "end" ]
Find an existing build, duplicate the sane parts of it.
[ "Find", "an", "existing", "build", "duplicate", "the", "sane", "parts", "of", "it", "." ]
5649b251a9c8f8c29623fba2fd9fd0b1fc2dbffa
https://github.com/richo/juici/blob/5649b251a9c8f8c29623fba2fd9fd0b1fc2dbffa/lib/juici/controllers/trigger.rb#L11-L24
train
bjoernalbers/aruba-doubles
lib/aruba-doubles/double.rb
ArubaDoubles.Double.run
def run(argv = ARGV) history << [filename] + argv output = @outputs[argv] || @default_output puts output[:puts] if output[:puts] warn output[:warn] if output[:warn] exit output[:exit] if output[:exit] end
ruby
def run(argv = ARGV) history << [filename] + argv output = @outputs[argv] || @default_output puts output[:puts] if output[:puts] warn output[:warn] if output[:warn] exit output[:exit] if output[:exit] end
[ "def", "run", "(", "argv", "=", "ARGV", ")", "history", "<<", "[", "filename", "]", "+", "argv", "output", "=", "@outputs", "[", "argv", "]", "||", "@default_output", "puts", "output", "[", ":puts", "]", "if", "output", "[", ":puts", "]", "warn", "output", "[", ":warn", "]", "if", "output", "[", ":warn", "]", "exit", "output", "[", ":exit", "]", "if", "output", "[", ":exit", "]", "end" ]
Run the double. This will append the call to the doubles history, display any outputs if defined and exit.
[ "Run", "the", "double", "." ]
5e835bf60fef4bdf903c225a7c29968d17899516
https://github.com/bjoernalbers/aruba-doubles/blob/5e835bf60fef4bdf903c225a7c29968d17899516/lib/aruba-doubles/double.rb#L113-L119
train
bjoernalbers/aruba-doubles
lib/aruba-doubles/double.rb
ArubaDoubles.Double.create
def create(&block) register self.instance_eval(&block) if block_given? content = self.to_ruby fullpath = File.join(self.class.bindir, filename) #puts "creating double: #{fullpath} with content:\n#{content}" # debug f = File.open(fullpath, 'w') f.puts content f.close FileUtils.chmod(0755, File.join(self.class.bindir, filename)) self end
ruby
def create(&block) register self.instance_eval(&block) if block_given? content = self.to_ruby fullpath = File.join(self.class.bindir, filename) #puts "creating double: #{fullpath} with content:\n#{content}" # debug f = File.open(fullpath, 'w') f.puts content f.close FileUtils.chmod(0755, File.join(self.class.bindir, filename)) self end
[ "def", "create", "(", "&", "block", ")", "register", "self", ".", "instance_eval", "(", "&", "block", ")", "if", "block_given?", "content", "=", "self", ".", "to_ruby", "fullpath", "=", "File", ".", "join", "(", "self", ".", "class", ".", "bindir", ",", "filename", ")", "f", "=", "File", ".", "open", "(", "fullpath", ",", "'w'", ")", "f", ".", "puts", "content", "f", ".", "close", "FileUtils", ".", "chmod", "(", "0755", ",", "File", ".", "join", "(", "self", ".", "class", ".", "bindir", ",", "filename", ")", ")", "self", "end" ]
Create the executable double. @return [String] full path to the double.
[ "Create", "the", "executable", "double", "." ]
5e835bf60fef4bdf903c225a7c29968d17899516
https://github.com/bjoernalbers/aruba-doubles/blob/5e835bf60fef4bdf903c225a7c29968d17899516/lib/aruba-doubles/double.rb#L124-L135
train
bjoernalbers/aruba-doubles
lib/aruba-doubles/double.rb
ArubaDoubles.Double.to_ruby
def to_ruby ruby = ['#!/usr/bin/env ruby'] ruby << "$: << '#{File.expand_path('..', File.dirname(__FILE__))}'" ruby << 'require "aruba-doubles"' ruby << 'ArubaDoubles::Double.run do' @outputs.each_pair { |argv,output| ruby << " on #{argv.inspect}, #{output.inspect}" } ruby << 'end' ruby.join("\n") end
ruby
def to_ruby ruby = ['#!/usr/bin/env ruby'] ruby << "$: << '#{File.expand_path('..', File.dirname(__FILE__))}'" ruby << 'require "aruba-doubles"' ruby << 'ArubaDoubles::Double.run do' @outputs.each_pair { |argv,output| ruby << " on #{argv.inspect}, #{output.inspect}" } ruby << 'end' ruby.join("\n") end
[ "def", "to_ruby", "ruby", "=", "[", "'#!/usr/bin/env ruby'", "]", "ruby", "<<", "\"$: << '#{File.expand_path('..', File.dirname(__FILE__))}'\"", "ruby", "<<", "'require \"aruba-doubles\"'", "ruby", "<<", "'ArubaDoubles::Double.run do'", "@outputs", ".", "each_pair", "{", "|", "argv", ",", "output", "|", "ruby", "<<", "\" on #{argv.inspect}, #{output.inspect}\"", "}", "ruby", "<<", "'end'", "ruby", ".", "join", "(", "\"\\n\"", ")", "end" ]
Export the double to executable Ruby code. @return [String] serialized double
[ "Export", "the", "double", "to", "executable", "Ruby", "code", "." ]
5e835bf60fef4bdf903c225a7c29968d17899516
https://github.com/bjoernalbers/aruba-doubles/blob/5e835bf60fef4bdf903c225a7c29968d17899516/lib/aruba-doubles/double.rb#L140-L148
train