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
m247/epp-client
lib/epp-client/xml_helper.rb
EPP.XMLHelpers.epp_namespace
def epp_namespace(node, name = nil, namespaces = {}) return namespaces['epp'] if namespaces.has_key?('epp') xml_namespace(node, name, 'urn:ietf:params:xml:ns:epp-1.0') end
ruby
def epp_namespace(node, name = nil, namespaces = {}) return namespaces['epp'] if namespaces.has_key?('epp') xml_namespace(node, name, 'urn:ietf:params:xml:ns:epp-1.0') end
[ "def", "epp_namespace", "(", "node", ",", "name", "=", "nil", ",", "namespaces", "=", "{", "}", ")", "return", "namespaces", "[", "'epp'", "]", "if", "namespaces", ".", "has_key?", "(", "'epp'", ")", "xml_namespace", "(", "node", ",", "name", ",", "'urn:ietf:params:xml:ns:epp-1.0'", ")", "end" ]
Creates and returns an instance of the EPP 1.0 namespace @param [XML::Node] node to create the namespace on @param [String, nil] Name to give the namespace @return [XML::Namespace] EPP 1.0 namespace
[ "Creates", "and", "returns", "an", "instance", "of", "the", "EPP", "1", ".", "0", "namespace" ]
72227e57d248f215d842e3dd37e72432d2a79270
https://github.com/m247/epp-client/blob/72227e57d248f215d842e3dd37e72432d2a79270/lib/epp-client/xml_helper.rb#L8-L11
train
m247/epp-client
lib/epp-client/xml_helper.rb
EPP.XMLHelpers.epp_node
def epp_node(name, value = nil, namespaces = {}) value, namespaces = nil, value if value.kind_of?(Hash) node = xml_node(name, value) node.namespaces.namespace = epp_namespace(node, nil, namespaces) node end
ruby
def epp_node(name, value = nil, namespaces = {}) value, namespaces = nil, value if value.kind_of?(Hash) node = xml_node(name, value) node.namespaces.namespace = epp_namespace(node, nil, namespaces) node end
[ "def", "epp_node", "(", "name", ",", "value", "=", "nil", ",", "namespaces", "=", "{", "}", ")", "value", ",", "namespaces", "=", "nil", ",", "value", "if", "value", ".", "kind_of?", "(", "Hash", ")", "node", "=", "xml_node", "(", "name", ",", "value", ")", "node", ".", "namespaces", ".", "namespace", "=", "epp_namespace", "(", "node", ",", "nil", ",", "namespaces", ")", "node", "end" ]
Creates and returns a new node in the EPP 1.0 namespace @param [String] name of the node to create @param [String,XML::Node,nil] value of the node @return [XML::Node]
[ "Creates", "and", "returns", "a", "new", "node", "in", "the", "EPP", "1", ".", "0", "namespace" ]
72227e57d248f215d842e3dd37e72432d2a79270
https://github.com/m247/epp-client/blob/72227e57d248f215d842e3dd37e72432d2a79270/lib/epp-client/xml_helper.rb#L18-L24
train
m247/epp-client
lib/epp-client/xml_helper.rb
EPP.XMLHelpers.xml_namespace
def xml_namespace(node, name, uri, namespaces = {}) XML::Namespace.new(node, name, uri) end
ruby
def xml_namespace(node, name, uri, namespaces = {}) XML::Namespace.new(node, name, uri) end
[ "def", "xml_namespace", "(", "node", ",", "name", ",", "uri", ",", "namespaces", "=", "{", "}", ")", "XML", "::", "Namespace", ".", "new", "(", "node", ",", "name", ",", "uri", ")", "end" ]
Creates and returns a new XML namespace @param [XML::Node] node XML node to add the namespace to @param [String] name Name of the namespace to create @param [String] uri URI of the namespace to create @return [XML::Namespace]
[ "Creates", "and", "returns", "a", "new", "XML", "namespace" ]
72227e57d248f215d842e3dd37e72432d2a79270
https://github.com/m247/epp-client/blob/72227e57d248f215d842e3dd37e72432d2a79270/lib/epp-client/xml_helper.rb#L41-L43
train
m247/epp-client
lib/epp-client/xml_helper.rb
EPP.XMLHelpers.xml_document
def xml_document(obj) case obj when XML::Document XML::Document.document(obj) else XML::Document.new('1.0') end end
ruby
def xml_document(obj) case obj when XML::Document XML::Document.document(obj) else XML::Document.new('1.0') end end
[ "def", "xml_document", "(", "obj", ")", "case", "obj", "when", "XML", "::", "Document", "XML", "::", "Document", ".", "document", "(", "obj", ")", "else", "XML", "::", "Document", ".", "new", "(", "'1.0'", ")", "end", "end" ]
Creates and returns a new XML document @param [XML::Document,String] obj Object to create the document with @return [XML::Document]
[ "Creates", "and", "returns", "a", "new", "XML", "document" ]
72227e57d248f215d842e3dd37e72432d2a79270
https://github.com/m247/epp-client/blob/72227e57d248f215d842e3dd37e72432d2a79270/lib/epp-client/xml_helper.rb#L49-L56
train
mbj/vanguard
lib/vanguard/dsl.rb
Vanguard.DSL.method_missing
def method_missing(method_name, *arguments) klass = REGISTRY.fetch(method_name) { super } Evaluator.new(klass, arguments).rules.each do |rule| add(rule) end self end
ruby
def method_missing(method_name, *arguments) klass = REGISTRY.fetch(method_name) { super } Evaluator.new(klass, arguments).rules.each do |rule| add(rule) end self end
[ "def", "method_missing", "(", "method_name", ",", "*", "arguments", ")", "klass", "=", "REGISTRY", ".", "fetch", "(", "method_name", ")", "{", "super", "}", "Evaluator", ".", "new", "(", "klass", ",", "arguments", ")", ".", "rules", ".", "each", "do", "|", "rule", "|", "add", "(", "rule", ")", "end", "self", "end" ]
Hook called when method is missing @param [Symbol] method_name @return [self] @api private
[ "Hook", "called", "when", "method", "is", "missing" ]
1babf0b4b08712f22da0c44f0f72f9651c714aae
https://github.com/mbj/vanguard/blob/1babf0b4b08712f22da0c44f0f72f9651c714aae/lib/vanguard/dsl.rb#L32-L40
train
anshulverma/cliqr
lib/cliqr/interface.rb
Cliqr.Interface.execute
def execute(args = [], **options) execute_internal(args, options) Executor::ExitCode.code(:success) rescue Cliqr::Error::CliqrError => e puts e.message Executor::ExitCode.code(e) end
ruby
def execute(args = [], **options) execute_internal(args, options) Executor::ExitCode.code(:success) rescue Cliqr::Error::CliqrError => e puts e.message Executor::ExitCode.code(e) end
[ "def", "execute", "(", "args", "=", "[", "]", ",", "**", "options", ")", "execute_internal", "(", "args", ",", "options", ")", "Executor", "::", "ExitCode", ".", "code", "(", ":success", ")", "rescue", "Cliqr", "::", "Error", "::", "CliqrError", "=>", "e", "puts", "e", ".", "message", "Executor", "::", "ExitCode", ".", "code", "(", "e", ")", "end" ]
Execute a command @param [Array<String>] args Arguments that will be used to execute the command @param [Hash] options Options for command execution @return [Integer] Exit code of the command execution
[ "Execute", "a", "command" ]
8e3e7d7d7ce129b29744ca65f9331c814f74756b
https://github.com/anshulverma/cliqr/blob/8e3e7d7d7ce129b29744ca65f9331c814f74756b/lib/cliqr/interface.rb#L38-L44
train
anshulverma/cliqr
lib/cliqr/interface.rb
Cliqr.Interface.execute_internal
def execute_internal(args = [], **options) options = { output: :default, environment: :cli }.merge(options) @runner.execute(args, options) end
ruby
def execute_internal(args = [], **options) options = { output: :default, environment: :cli }.merge(options) @runner.execute(args, options) end
[ "def", "execute_internal", "(", "args", "=", "[", "]", ",", "**", "options", ")", "options", "=", "{", "output", ":", ":default", ",", "environment", ":", ":cli", "}", ".", "merge", "(", "options", ")", "@runner", ".", "execute", "(", "args", ",", "options", ")", "end" ]
Executes a command without handling error conditions @return [Integer] Exit code
[ "Executes", "a", "command", "without", "handling", "error", "conditions" ]
8e3e7d7d7ce129b29744ca65f9331c814f74756b
https://github.com/anshulverma/cliqr/blob/8e3e7d7d7ce129b29744ca65f9331c814f74756b/lib/cliqr/interface.rb#L49-L55
train
anshulverma/cliqr
lib/cliqr/interface.rb
Cliqr.InterfaceBuilder.build
def build raise Cliqr::Error::ConfigNotFound, 'a valid config should be defined' if @config.nil? unless @config.valid? raise Cliqr::Error::ValidationError, \ "invalid Cliqr interface configuration - [#{@config.errors}]" end Interface.new(@config) end
ruby
def build raise Cliqr::Error::ConfigNotFound, 'a valid config should be defined' if @config.nil? unless @config.valid? raise Cliqr::Error::ValidationError, \ "invalid Cliqr interface configuration - [#{@config.errors}]" end Interface.new(@config) end
[ "def", "build", "raise", "Cliqr", "::", "Error", "::", "ConfigNotFound", ",", "'a valid config should be defined'", "if", "@config", ".", "nil?", "unless", "@config", ".", "valid?", "raise", "Cliqr", "::", "Error", "::", "ValidationError", ",", "\"invalid Cliqr interface configuration - [#{@config.errors}]\"", "end", "Interface", ".", "new", "(", "@config", ")", "end" ]
Start building a command line interface @param [Cliqr::CLI::Config] config the configuration options for the interface (validated using CLI::Validator) @return [Cliqr::CLI::ConfigBuilder] Validate and build a cli interface based on the configuration options @return [Cliqr::CLI::Interface] @throws [Cliqr::Error::ConfigNotFound] if a config is <tt>nil</tt> @throws [Cliqr::Error::ValidationError] if the validation for config fails
[ "Start", "building", "a", "command", "line", "interface" ]
8e3e7d7d7ce129b29744ca65f9331c814f74756b
https://github.com/anshulverma/cliqr/blob/8e3e7d7d7ce129b29744ca65f9331c814f74756b/lib/cliqr/interface.rb#L87-L95
train
DannyBen/runfile
lib/runfile/runner.rb
Runfile.Runner.execute
def execute(argv, filename='Runfile') @ignore_settings = !filename argv = expand_shortcuts argv filename and File.file?(filename) or handle_no_runfile argv begin load settings.helper if settings.helper load filename rescue => ex abort "Runfile error:\n#{ex.message}\n#{ex.backtrace[0]}" end run(*argv) end
ruby
def execute(argv, filename='Runfile') @ignore_settings = !filename argv = expand_shortcuts argv filename and File.file?(filename) or handle_no_runfile argv begin load settings.helper if settings.helper load filename rescue => ex abort "Runfile error:\n#{ex.message}\n#{ex.backtrace[0]}" end run(*argv) end
[ "def", "execute", "(", "argv", ",", "filename", "=", "'Runfile'", ")", "@ignore_settings", "=", "!", "filename", "argv", "=", "expand_shortcuts", "argv", "filename", "and", "File", ".", "file?", "(", "filename", ")", "or", "handle_no_runfile", "argv", "begin", "load", "settings", ".", "helper", "if", "settings", ".", "helper", "load", "filename", "rescue", "=>", "ex", "abort", "\"Runfile error:\\n#{ex.message}\\n#{ex.backtrace[0]}\"", "end", "run", "(", "*", "argv", ")", "end" ]
Initialize all variables to sensible defaults. Load and execute a Runfile call.
[ "Initialize", "all", "variables", "to", "sensible", "defaults", ".", "Load", "and", "execute", "a", "Runfile", "call", "." ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/runner.rb#L35-L47
train
DannyBen/runfile
lib/runfile/runner.rb
Runfile.Runner.add_action
def add_action(name, altname=nil, &block) if @last_usage.nil? @last_usage = altname ? "(#{name}|#{altname})" : name end [@namespace, @superspace].each do |prefix| prefix or next name = "#{prefix}_#{name}" @last_usage = "#{prefix} #{last_usage}" unless @last_usage == false end name = name.to_sym @actions[name] = Action.new(block, @last_usage, @last_help) @last_usage = nil @last_help = nil if altname @last_usage = false add_action(altname, nil, &block) end end
ruby
def add_action(name, altname=nil, &block) if @last_usage.nil? @last_usage = altname ? "(#{name}|#{altname})" : name end [@namespace, @superspace].each do |prefix| prefix or next name = "#{prefix}_#{name}" @last_usage = "#{prefix} #{last_usage}" unless @last_usage == false end name = name.to_sym @actions[name] = Action.new(block, @last_usage, @last_help) @last_usage = nil @last_help = nil if altname @last_usage = false add_action(altname, nil, &block) end end
[ "def", "add_action", "(", "name", ",", "altname", "=", "nil", ",", "&", "block", ")", "if", "@last_usage", ".", "nil?", "@last_usage", "=", "altname", "?", "\"(#{name}|#{altname})\"", ":", "name", "end", "[", "@namespace", ",", "@superspace", "]", ".", "each", "do", "|", "prefix", "|", "prefix", "or", "next", "name", "=", "\"#{prefix}_#{name}\"", "@last_usage", "=", "\"#{prefix} #{last_usage}\"", "unless", "@last_usage", "==", "false", "end", "name", "=", "name", ".", "to_sym", "@actions", "[", "name", "]", "=", "Action", ".", "new", "(", "block", ",", "@last_usage", ",", "@last_help", ")", "@last_usage", "=", "nil", "@last_help", "=", "nil", "if", "altname", "@last_usage", "=", "false", "add_action", "(", "altname", ",", "nil", ",", "&", "block", ")", "end", "end" ]
Add an action to the @actions array, and use the last known usage and help messages sent by the DSL.
[ "Add", "an", "action", "to", "the" ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/runner.rb#L51-L68
train
DannyBen/runfile
lib/runfile/runner.rb
Runfile.Runner.add_option
def add_option(flag, text, scope=nil) scope or scope = 'Options' @options[scope] ||= {} @options[scope][flag] = text end
ruby
def add_option(flag, text, scope=nil) scope or scope = 'Options' @options[scope] ||= {} @options[scope][flag] = text end
[ "def", "add_option", "(", "flag", ",", "text", ",", "scope", "=", "nil", ")", "scope", "or", "scope", "=", "'Options'", "@options", "[", "scope", "]", "||=", "{", "}", "@options", "[", "scope", "]", "[", "flag", "]", "=", "text", "end" ]
Add an option flag and its help text.
[ "Add", "an", "option", "flag", "and", "its", "help", "text", "." ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/runner.rb#L71-L75
train
DannyBen/runfile
lib/runfile/runner.rb
Runfile.Runner.add_param
def add_param(name, text, scope=nil) scope or scope = 'Parameters' @params[scope] ||= {} @params[scope][name] = text end
ruby
def add_param(name, text, scope=nil) scope or scope = 'Parameters' @params[scope] ||= {} @params[scope][name] = text end
[ "def", "add_param", "(", "name", ",", "text", ",", "scope", "=", "nil", ")", "scope", "or", "scope", "=", "'Parameters'", "@params", "[", "scope", "]", "||=", "{", "}", "@params", "[", "scope", "]", "[", "name", "]", "=", "text", "end" ]
Add a patameter and its help text.
[ "Add", "a", "patameter", "and", "its", "help", "text", "." ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/runner.rb#L78-L82
train
DannyBen/runfile
lib/runfile/runner.rb
Runfile.Runner.run
def run(*argv) begin docopt_exec argv rescue Docopt::Exit => ex puts ex.message exit 2 end end
ruby
def run(*argv) begin docopt_exec argv rescue Docopt::Exit => ex puts ex.message exit 2 end end
[ "def", "run", "(", "*", "argv", ")", "begin", "docopt_exec", "argv", "rescue", "Docopt", "::", "Exit", "=>", "ex", "puts", "ex", ".", "message", "exit", "2", "end", "end" ]
Run the command. This is a wrapper around docopt. It will generate the docopt document on the fly, using all the information collected so far.
[ "Run", "the", "command", ".", "This", "is", "a", "wrapper", "around", "docopt", ".", "It", "will", "generate", "the", "docopt", "document", "on", "the", "fly", "using", "all", "the", "information", "collected", "so", "far", "." ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/runner.rb#L92-L99
train
EvidentSecurity/esp_sdk
lib/esp/extensions/active_resource/validations.rb
ActiveResource.Validations.load_remote_errors
def load_remote_errors(remote_errors, save_cache = false) if self.class.format == ActiveResource::Formats::JsonAPIFormat errors.from_json_api(remote_errors.response.body, save_cache) elsif self.class.format == ActiveResource::Formats[:json] super end end
ruby
def load_remote_errors(remote_errors, save_cache = false) if self.class.format == ActiveResource::Formats::JsonAPIFormat errors.from_json_api(remote_errors.response.body, save_cache) elsif self.class.format == ActiveResource::Formats[:json] super end end
[ "def", "load_remote_errors", "(", "remote_errors", ",", "save_cache", "=", "false", ")", "if", "self", ".", "class", ".", "format", "==", "ActiveResource", "::", "Formats", "::", "JsonAPIFormat", "errors", ".", "from_json_api", "(", "remote_errors", ".", "response", ".", "body", ",", "save_cache", ")", "elsif", "self", ".", "class", ".", "format", "==", "ActiveResource", "::", "Formats", "[", ":json", "]", "super", "end", "end" ]
Loads the set of remote errors into the object's Errors based on the content-type of the error-block received.
[ "Loads", "the", "set", "of", "remote", "errors", "into", "the", "object", "s", "Errors", "based", "on", "the", "content", "-", "type", "of", "the", "error", "-", "block", "received", "." ]
feb1740a8e8849bdeb967a22358f9bcfaa99d215
https://github.com/EvidentSecurity/esp_sdk/blob/feb1740a8e8849bdeb967a22358f9bcfaa99d215/lib/esp/extensions/active_resource/validations.rb#L6-L12
train
RISCfuture/slugalicious
lib/slugalicious.rb
Slugalicious.ClassMethods.find_from_slug_path
def find_from_slug_path(path) slug = path.split('/').last scope = path[0..(-(slug.size + 1))] find_from_slug slug, scope end
ruby
def find_from_slug_path(path) slug = path.split('/').last scope = path[0..(-(slug.size + 1))] find_from_slug slug, scope end
[ "def", "find_from_slug_path", "(", "path", ")", "slug", "=", "path", ".", "split", "(", "'/'", ")", ".", "last", "scope", "=", "path", "[", "0", "..", "(", "-", "(", "slug", ".", "size", "+", "1", ")", ")", "]", "find_from_slug", "slug", ",", "scope", "end" ]
Locates a record from a given path, that consists of a slug and its scope, as would appear in a URL path component. @param [String] path The scope and slug concatenated together. @return [ActiveRecord::Base] The object with that slug. @raise [ActiveRecord::RecordNotFound] If no object with that slug is found.
[ "Locates", "a", "record", "from", "a", "given", "path", "that", "consists", "of", "a", "slug", "and", "its", "scope", "as", "would", "appear", "in", "a", "URL", "path", "component", "." ]
db95f204451c8942cb065ebd70acc610bdb6370c
https://github.com/RISCfuture/slugalicious/blob/db95f204451c8942cb065ebd70acc610bdb6370c/lib/slugalicious.rb#L61-L65
train
etehtsea/oxblood
lib/oxblood/pipeline.rb
Oxblood.Pipeline.sync
def sync serialized_commands = @commands.map { |c| Protocol.build_command(*c) } connection.socket.write(serialized_commands.join) Array.new(@commands.size) { connection.read_response } ensure @commands.clear end
ruby
def sync serialized_commands = @commands.map { |c| Protocol.build_command(*c) } connection.socket.write(serialized_commands.join) Array.new(@commands.size) { connection.read_response } ensure @commands.clear end
[ "def", "sync", "serialized_commands", "=", "@commands", ".", "map", "{", "|", "c", "|", "Protocol", ".", "build_command", "(", "*", "c", ")", "}", "connection", ".", "socket", ".", "write", "(", "serialized_commands", ".", "join", ")", "Array", ".", "new", "(", "@commands", ".", "size", ")", "{", "connection", ".", "read_response", "}", "ensure", "@commands", ".", "clear", "end" ]
Sends all commands at once and reads responses @return [Array] of responses
[ "Sends", "all", "commands", "at", "once", "and", "reads", "responses" ]
0bfc3f6114a6eb5716a9cd44ecea914b273dc268
https://github.com/etehtsea/oxblood/blob/0bfc3f6114a6eb5716a9cd44ecea914b273dc268/lib/oxblood/pipeline.rb#L28-L34
train
tongueroo/lono-cfn
lib/lono-cfn/base.rb
LonoCfn.Base.get_source_path
def get_source_path(path, type) default_convention_path = convention_path(@stack_name, type) return default_convention_path if path.nil? # convention path based on the input from the user convention_path(path, type) end
ruby
def get_source_path(path, type) default_convention_path = convention_path(@stack_name, type) return default_convention_path if path.nil? # convention path based on the input from the user convention_path(path, type) end
[ "def", "get_source_path", "(", "path", ",", "type", ")", "default_convention_path", "=", "convention_path", "(", "@stack_name", ",", "type", ")", "return", "default_convention_path", "if", "path", ".", "nil?", "convention_path", "(", "path", ",", "type", ")", "end" ]
if existing in params path then use that if it doesnt assume it is a full path and check that else fall back to convention, which also eventually gets checked in check_for_errors Type - :params or :template
[ "if", "existing", "in", "params", "path", "then", "use", "that", "if", "it", "doesnt", "assume", "it", "is", "a", "full", "path", "and", "check", "that", "else", "fall", "back", "to", "convention", "which", "also", "eventually", "gets", "checked", "in", "check_for_errors" ]
17bb48f40d5eb0441117bf14b4fbd09a057ff8f1
https://github.com/tongueroo/lono-cfn/blob/17bb48f40d5eb0441117bf14b4fbd09a057ff8f1/lib/lono-cfn/base.rb#L80-L86
train
tongueroo/lono-cfn
lib/lono-cfn/base.rb
LonoCfn.Base.detect_format
def detect_format formats = Dir.glob("#{@project_root}/output/**/*").map { |path| path }. reject { |s| s =~ %r{/params/} }. # reject output/params folder map { |path| File.extname(path) }. reject { |s| s.empty? }. # reject "" uniq if formats.size > 1 puts "ERROR: Detected multiple formats: #{formats.join(", ")}".colorize(:red) puts "All the output files must use the same format. Either all json or all yml." exit 1 else formats.first.sub(/^\./,'') end end
ruby
def detect_format formats = Dir.glob("#{@project_root}/output/**/*").map { |path| path }. reject { |s| s =~ %r{/params/} }. # reject output/params folder map { |path| File.extname(path) }. reject { |s| s.empty? }. # reject "" uniq if formats.size > 1 puts "ERROR: Detected multiple formats: #{formats.join(", ")}".colorize(:red) puts "All the output files must use the same format. Either all json or all yml." exit 1 else formats.first.sub(/^\./,'') end end
[ "def", "detect_format", "formats", "=", "Dir", ".", "glob", "(", "\"#{@project_root}/output/**/*\"", ")", ".", "map", "{", "|", "path", "|", "path", "}", ".", "reject", "{", "|", "s", "|", "s", "=~", "%r{", "}", "}", ".", "map", "{", "|", "path", "|", "File", ".", "extname", "(", "path", ")", "}", ".", "reject", "{", "|", "s", "|", "s", ".", "empty?", "}", ".", "uniq", "if", "formats", ".", "size", ">", "1", "puts", "\"ERROR: Detected multiple formats: #{formats.join(\", \")}\"", ".", "colorize", "(", ":red", ")", "puts", "\"All the output files must use the same format. Either all json or all yml.\"", "exit", "1", "else", "formats", ".", "first", ".", "sub", "(", "/", "\\.", "/", ",", "''", ")", "end", "end" ]
Returns String with value of "yml" or "json".
[ "Returns", "String", "with", "value", "of", "yml", "or", "json", "." ]
17bb48f40d5eb0441117bf14b4fbd09a057ff8f1
https://github.com/tongueroo/lono-cfn/blob/17bb48f40d5eb0441117bf14b4fbd09a057ff8f1/lib/lono-cfn/base.rb#L102-L115
train
EvidentSecurity/esp_sdk
lib/esp/extensions/active_resource/paginated_collection.rb
ActiveResource.PaginatedCollection.page
def page(page_number = nil) fail ArgumentError, "You must supply a page number." unless page_number.present? fail ArgumentError, "Page number cannot be less than 1." if page_number.to_i < 1 fail ArgumentError, "Page number cannot be greater than the last page number." if page_number.to_i > last_page_number.to_i page_number.to_i != current_page_number.to_i ? updated_collection(from: from, page: { number: page_number, size: (next_page_params || previous_page_params)['page']['size'] }) : self end
ruby
def page(page_number = nil) fail ArgumentError, "You must supply a page number." unless page_number.present? fail ArgumentError, "Page number cannot be less than 1." if page_number.to_i < 1 fail ArgumentError, "Page number cannot be greater than the last page number." if page_number.to_i > last_page_number.to_i page_number.to_i != current_page_number.to_i ? updated_collection(from: from, page: { number: page_number, size: (next_page_params || previous_page_params)['page']['size'] }) : self end
[ "def", "page", "(", "page_number", "=", "nil", ")", "fail", "ArgumentError", ",", "\"You must supply a page number.\"", "unless", "page_number", ".", "present?", "fail", "ArgumentError", ",", "\"Page number cannot be less than 1.\"", "if", "page_number", ".", "to_i", "<", "1", "fail", "ArgumentError", ",", "\"Page number cannot be greater than the last page number.\"", "if", "page_number", ".", "to_i", ">", "last_page_number", ".", "to_i", "page_number", ".", "to_i", "!=", "current_page_number", ".", "to_i", "?", "updated_collection", "(", "from", ":", "from", ",", "page", ":", "{", "number", ":", "page_number", ",", "size", ":", "(", "next_page_params", "||", "previous_page_params", ")", "[", "'page'", "]", "[", "'size'", "]", "}", ")", ":", "self", "end" ]
Returns the +page_number+ page of data. Returns +self+ when +page_number+ == +#current_page_number+ @param page_number [Integer] The page number of the data wanted. Must be between 1 and +#last_page_number+. @return [PaginatedCollection, self] @raise [ArgumentError] if no page number or an out-of-bounds page number is supplied. @example alerts.current_page_number # => 5 page = alerts.page(2) alerts.current_page_number # => 5 page.current_page_number # => 2
[ "Returns", "the", "+", "page_number", "+", "page", "of", "data", "." ]
feb1740a8e8849bdeb967a22358f9bcfaa99d215
https://github.com/EvidentSecurity/esp_sdk/blob/feb1740a8e8849bdeb967a22358f9bcfaa99d215/lib/esp/extensions/active_resource/paginated_collection.rb#L137-L142
train
DannyBen/runfile
lib/runfile/runfile_helper.rb
Runfile.RunfileHelper.make_runfile
def make_runfile(name=nil) name = 'Runfile' if name.nil? template = File.expand_path("../templates/Runfile", __FILE__) name += ".runfile" unless name == 'Runfile' dest = "#{Dir.pwd}/#{name}" begin File.write(dest, File.read(template)) puts "#{name} created." rescue => e abort "Failed creating #{name}\n#{e.message}" end end
ruby
def make_runfile(name=nil) name = 'Runfile' if name.nil? template = File.expand_path("../templates/Runfile", __FILE__) name += ".runfile" unless name == 'Runfile' dest = "#{Dir.pwd}/#{name}" begin File.write(dest, File.read(template)) puts "#{name} created." rescue => e abort "Failed creating #{name}\n#{e.message}" end end
[ "def", "make_runfile", "(", "name", "=", "nil", ")", "name", "=", "'Runfile'", "if", "name", ".", "nil?", "template", "=", "File", ".", "expand_path", "(", "\"../templates/Runfile\"", ",", "__FILE__", ")", "name", "+=", "\".runfile\"", "unless", "name", "==", "'Runfile'", "dest", "=", "\"#{Dir.pwd}/#{name}\"", "begin", "File", ".", "write", "(", "dest", ",", "File", ".", "read", "(", "template", ")", ")", "puts", "\"#{name} created.\"", "rescue", "=>", "e", "abort", "\"Failed creating #{name}\\n#{e.message}\"", "end", "end" ]
Create a new runfile in the current directory. We can either create a standard 'Runfile' or a 'named.runfile'.
[ "Create", "a", "new", "runfile", "in", "the", "current", "directory", ".", "We", "can", "either", "create", "a", "standard", "Runfile", "or", "a", "named", ".", "runfile", "." ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/runfile_helper.rb#L49-L60
train
DannyBen/runfile
lib/runfile/runfile_helper.rb
Runfile.RunfileHelper.show_make_help
def show_make_help(runfiles, compact=false) say "!txtpur!Runfile engine v#{Runfile::VERSION}" unless compact if runfiles.size < 3 and !compact say "\nTip: Type '!txtblu!run new!txtrst!' or '!txtblu!run new name!txtrst!' to create a runfile.\nFor global access, place !txtblu!named.runfiles!txtrst! in ~/runfile/ or in /etc/runfile/." end if runfiles.empty? say "\n!txtred!Runfile not found." else say "" compact ? say_runfile_usage(runfiles) : say_runfile_list(runfiles) end end
ruby
def show_make_help(runfiles, compact=false) say "!txtpur!Runfile engine v#{Runfile::VERSION}" unless compact if runfiles.size < 3 and !compact say "\nTip: Type '!txtblu!run new!txtrst!' or '!txtblu!run new name!txtrst!' to create a runfile.\nFor global access, place !txtblu!named.runfiles!txtrst! in ~/runfile/ or in /etc/runfile/." end if runfiles.empty? say "\n!txtred!Runfile not found." else say "" compact ? say_runfile_usage(runfiles) : say_runfile_list(runfiles) end end
[ "def", "show_make_help", "(", "runfiles", ",", "compact", "=", "false", ")", "say", "\"!txtpur!Runfile engine v#{Runfile::VERSION}\"", "unless", "compact", "if", "runfiles", ".", "size", "<", "3", "and", "!", "compact", "say", "\"\\nTip: Type '!txtblu!run new!txtrst!' or '!txtblu!run new name!txtrst!' to create a runfile.\\nFor global access, place !txtblu!named.runfiles!txtrst! in ~/runfile/ or in /etc/runfile/.\"", "end", "if", "runfiles", ".", "empty?", "say", "\"\\n!txtred!Runfile not found.\"", "else", "say", "\"\"", "compact", "?", "say_runfile_usage", "(", "runfiles", ")", ":", "say_runfile_list", "(", "runfiles", ")", "end", "end" ]
Show some helpful tips, and a list of available runfiles
[ "Show", "some", "helpful", "tips", "and", "a", "list", "of", "available", "runfiles" ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/runfile_helper.rb#L74-L85
train
DannyBen/runfile
lib/runfile/runfile_helper.rb
Runfile.RunfileHelper.say_runfile_list
def say_runfile_list(runfiles) runfile_paths = runfiles.map { |f| File.dirname f } max = runfile_paths.max_by(&:length).size width = detect_terminal_size[0] runfiles.each do |f| f[/([^\/]+).runfile$/] command = "run #{$1}" spacer_size = width - max - command.size - 6 spacer_size = [1, spacer_size].max spacer = '.' * spacer_size say " !txtgrn!#{command}!txtrst! #{spacer} #{File.dirname f}" end end
ruby
def say_runfile_list(runfiles) runfile_paths = runfiles.map { |f| File.dirname f } max = runfile_paths.max_by(&:length).size width = detect_terminal_size[0] runfiles.each do |f| f[/([^\/]+).runfile$/] command = "run #{$1}" spacer_size = width - max - command.size - 6 spacer_size = [1, spacer_size].max spacer = '.' * spacer_size say " !txtgrn!#{command}!txtrst! #{spacer} #{File.dirname f}" end end
[ "def", "say_runfile_list", "(", "runfiles", ")", "runfile_paths", "=", "runfiles", ".", "map", "{", "|", "f", "|", "File", ".", "dirname", "f", "}", "max", "=", "runfile_paths", ".", "max_by", "(", "&", ":length", ")", ".", "size", "width", "=", "detect_terminal_size", "[", "0", "]", "runfiles", ".", "each", "do", "|", "f", "|", "f", "[", "/", "\\/", "/", "]", "command", "=", "\"run #{$1}\"", "spacer_size", "=", "width", "-", "max", "-", "command", ".", "size", "-", "6", "spacer_size", "=", "[", "1", ",", "spacer_size", "]", ".", "max", "spacer", "=", "'.'", "*", "spacer_size", "say", "\" !txtgrn!#{command}!txtrst! #{spacer} #{File.dirname f}\"", "end", "end" ]
Output the list of available runfiles
[ "Output", "the", "list", "of", "available", "runfiles" ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/runfile_helper.rb#L110-L122
train
DannyBen/runfile
lib/runfile/runfile_helper.rb
Runfile.RunfileHelper.say_runfile_usage
def say_runfile_usage(runfiles) runfiles_as_columns = get_runfiles_as_columns runfiles say "#{settings.intro}\n" if settings.intro say "Usage: run <file>" say runfiles_as_columns show_shortcuts if settings.shortcuts end
ruby
def say_runfile_usage(runfiles) runfiles_as_columns = get_runfiles_as_columns runfiles say "#{settings.intro}\n" if settings.intro say "Usage: run <file>" say runfiles_as_columns show_shortcuts if settings.shortcuts end
[ "def", "say_runfile_usage", "(", "runfiles", ")", "runfiles_as_columns", "=", "get_runfiles_as_columns", "runfiles", "say", "\"#{settings.intro}\\n\"", "if", "settings", ".", "intro", "say", "\"Usage: run <file>\"", "say", "runfiles_as_columns", "show_shortcuts", "if", "settings", ".", "shortcuts", "end" ]
Output the list of available runfiles without filename
[ "Output", "the", "list", "of", "available", "runfiles", "without", "filename" ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/runfile_helper.rb#L125-L133
train
DannyBen/runfile
lib/runfile/runfile_helper.rb
Runfile.RunfileHelper.show_shortcuts
def show_shortcuts say "\nShortcuts:" max = settings.shortcuts.keys.max_by(&:length).length settings.shortcuts.each_pair do |shortcut, command| say " #{shortcut.rjust max} : #{command}" end end
ruby
def show_shortcuts say "\nShortcuts:" max = settings.shortcuts.keys.max_by(&:length).length settings.shortcuts.each_pair do |shortcut, command| say " #{shortcut.rjust max} : #{command}" end end
[ "def", "show_shortcuts", "say", "\"\\nShortcuts:\"", "max", "=", "settings", ".", "shortcuts", ".", "keys", ".", "max_by", "(", "&", ":length", ")", ".", "length", "settings", ".", "shortcuts", ".", "each_pair", "do", "|", "shortcut", ",", "command", "|", "say", "\" #{shortcut.rjust max} : #{command}\"", "end", "end" ]
Prints a friendly output of the shortcut list
[ "Prints", "a", "friendly", "output", "of", "the", "shortcut", "list" ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/runfile_helper.rb#L136-L142
train
DannyBen/runfile
lib/runfile/runfile_helper.rb
Runfile.RunfileHelper.get_runfiles_as_columns
def get_runfiles_as_columns(runfiles) namelist = runfile_names runfiles width = detect_terminal_size[0] max = namelist.max_by(&:length).length message = " " + namelist.map {|f| f.ljust max+1 }.join(' ') word_wrap message, width end
ruby
def get_runfiles_as_columns(runfiles) namelist = runfile_names runfiles width = detect_terminal_size[0] max = namelist.max_by(&:length).length message = " " + namelist.map {|f| f.ljust max+1 }.join(' ') word_wrap message, width end
[ "def", "get_runfiles_as_columns", "(", "runfiles", ")", "namelist", "=", "runfile_names", "runfiles", "width", "=", "detect_terminal_size", "[", "0", "]", "max", "=", "namelist", ".", "max_by", "(", "&", ":length", ")", ".", "length", "message", "=", "\" \"", "+", "namelist", ".", "map", "{", "|", "f", "|", "f", ".", "ljust", "max", "+", "1", "}", ".", "join", "(", "' '", ")", "word_wrap", "message", ",", "width", "end" ]
Returns the list of runfiles, organized as columns based on the current terminal width
[ "Returns", "the", "list", "of", "runfiles", "organized", "as", "columns", "based", "on", "the", "current", "terminal", "width" ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/runfile_helper.rb#L146-L152
train
EvidentSecurity/esp_sdk
lib/esp/resources/resource.rb
ESP.Resource.serializable_hash
def serializable_hash(*) h = attributes.extract!('included') h['data'] = { 'type' => self.class.to_s.underscore.sub('esp/', '').pluralize, 'attributes' => changed_attributes.except('id', 'type', 'created_at', 'updated_at', 'relationships') } h['data']['id'] = id if id.present? h end
ruby
def serializable_hash(*) h = attributes.extract!('included') h['data'] = { 'type' => self.class.to_s.underscore.sub('esp/', '').pluralize, 'attributes' => changed_attributes.except('id', 'type', 'created_at', 'updated_at', 'relationships') } h['data']['id'] = id if id.present? h end
[ "def", "serializable_hash", "(", "*", ")", "h", "=", "attributes", ".", "extract!", "(", "'included'", ")", "h", "[", "'data'", "]", "=", "{", "'type'", "=>", "self", ".", "class", ".", "to_s", ".", "underscore", ".", "sub", "(", "'esp/'", ",", "''", ")", ".", "pluralize", ",", "'attributes'", "=>", "changed_attributes", ".", "except", "(", "'id'", ",", "'type'", ",", "'created_at'", ",", "'updated_at'", ",", "'relationships'", ")", "}", "h", "[", "'data'", "]", "[", "'id'", "]", "=", "id", "if", "id", ".", "present?", "h", "end" ]
Pass a json api compliant hash to the api.
[ "Pass", "a", "json", "api", "compliant", "hash", "to", "the", "api", "." ]
feb1740a8e8849bdeb967a22358f9bcfaa99d215
https://github.com/EvidentSecurity/esp_sdk/blob/feb1740a8e8849bdeb967a22358f9bcfaa99d215/lib/esp/resources/resource.rb#L17-L23
train
etehtsea/oxblood
lib/oxblood/pool.rb
Oxblood.Pool.with
def with conn = @pool.checkout session = Session.new(conn) yield(session) ensure if conn session.discard if conn.in_transaction? @pool.checkin end end
ruby
def with conn = @pool.checkout session = Session.new(conn) yield(session) ensure if conn session.discard if conn.in_transaction? @pool.checkin end end
[ "def", "with", "conn", "=", "@pool", ".", "checkout", "session", "=", "Session", ".", "new", "(", "conn", ")", "yield", "(", "session", ")", "ensure", "if", "conn", "session", ".", "discard", "if", "conn", ".", "in_transaction?", "@pool", ".", "checkin", "end", "end" ]
Initialize connection pool @param [Hash] options Connection options @option options [Float] :timeout (1.0) Connection acquisition timeout. @option options [Integer] :size Pool size. @option options [Hash] :connection see {Connection#initialize} Run commands on a connection from pool. Connection is wrapped to the {Session}. @yield [session] provide {Session} to a block @yieldreturn response from the last executed operation @example pool = Oxblood::Pool.new(size: 8) pool.with do |session| session.set('hello', 'world') session.get('hello') end # => 'world'
[ "Initialize", "connection", "pool" ]
0bfc3f6114a6eb5716a9cd44ecea914b273dc268
https://github.com/etehtsea/oxblood/blob/0bfc3f6114a6eb5716a9cd44ecea914b273dc268/lib/oxblood/pool.rb#L40-L49
train
DannyBen/runfile
lib/runfile/docopt_helper.rb
Runfile.DocoptHelper.docopt_usage
def docopt_usage doc = ["\nUsage:"]; @actions.each do |_name, action| doc << " run #{action.usage}" unless action.usage == false end basic_flags = @version ? "(-h|--help|--version)" : "(-h|--help)" if @superspace doc << " run #{@superspace} #{basic_flags}\n" else doc << " run #{basic_flags}\n" end doc end
ruby
def docopt_usage doc = ["\nUsage:"]; @actions.each do |_name, action| doc << " run #{action.usage}" unless action.usage == false end basic_flags = @version ? "(-h|--help|--version)" : "(-h|--help)" if @superspace doc << " run #{@superspace} #{basic_flags}\n" else doc << " run #{basic_flags}\n" end doc end
[ "def", "docopt_usage", "doc", "=", "[", "\"\\nUsage:\"", "]", ";", "@actions", ".", "each", "do", "|", "_name", ",", "action", "|", "doc", "<<", "\" run #{action.usage}\"", "unless", "action", ".", "usage", "==", "false", "end", "basic_flags", "=", "@version", "?", "\"(-h|--help|--version)\"", ":", "\"(-h|--help)\"", "if", "@superspace", "doc", "<<", "\" run #{@superspace} #{basic_flags}\\n\"", "else", "doc", "<<", "\" run #{basic_flags}\\n\"", "end", "doc", "end" ]
Return all docopt lines for the 'Usage' section
[ "Return", "all", "docopt", "lines", "for", "the", "Usage", "section" ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/docopt_helper.rb#L45-L57
train
DannyBen/runfile
lib/runfile/docopt_helper.rb
Runfile.DocoptHelper.docopt_commands
def docopt_commands(width) doc = [] caption_printed = false @actions.each do |_name, action| action.help or next doc << "Commands:" unless caption_printed caption_printed = true helpline = " #{action.help}" wrapped = word_wrap helpline, width doc << " #{action.usage}\n#{wrapped}\n" unless action.usage == false end doc end
ruby
def docopt_commands(width) doc = [] caption_printed = false @actions.each do |_name, action| action.help or next doc << "Commands:" unless caption_printed caption_printed = true helpline = " #{action.help}" wrapped = word_wrap helpline, width doc << " #{action.usage}\n#{wrapped}\n" unless action.usage == false end doc end
[ "def", "docopt_commands", "(", "width", ")", "doc", "=", "[", "]", "caption_printed", "=", "false", "@actions", ".", "each", "do", "|", "_name", ",", "action", "|", "action", ".", "help", "or", "next", "doc", "<<", "\"Commands:\"", "unless", "caption_printed", "caption_printed", "=", "true", "helpline", "=", "\" #{action.help}\"", "wrapped", "=", "word_wrap", "helpline", ",", "width", "doc", "<<", "\" #{action.usage}\\n#{wrapped}\\n\"", "unless", "action", ".", "usage", "==", "false", "end", "doc", "end" ]
Return all docopt lines for the 'Commands' section
[ "Return", "all", "docopt", "lines", "for", "the", "Commands", "section" ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/docopt_helper.rb#L60-L72
train
DannyBen/runfile
lib/runfile/docopt_helper.rb
Runfile.DocoptHelper.docopt_examples
def docopt_examples(width) return [] if @examples.empty? doc = ["Examples:"] base_command = @superspace ? "run #{@superspace}" : "run" @examples.each do |command| helpline = " #{base_command} #{command}" wrapped = word_wrap helpline, width doc << "#{wrapped}" end doc end
ruby
def docopt_examples(width) return [] if @examples.empty? doc = ["Examples:"] base_command = @superspace ? "run #{@superspace}" : "run" @examples.each do |command| helpline = " #{base_command} #{command}" wrapped = word_wrap helpline, width doc << "#{wrapped}" end doc end
[ "def", "docopt_examples", "(", "width", ")", "return", "[", "]", "if", "@examples", ".", "empty?", "doc", "=", "[", "\"Examples:\"", "]", "base_command", "=", "@superspace", "?", "\"run #{@superspace}\"", ":", "\"run\"", "@examples", ".", "each", "do", "|", "command", "|", "helpline", "=", "\" #{base_command} #{command}\"", "wrapped", "=", "word_wrap", "helpline", ",", "width", "doc", "<<", "\"#{wrapped}\"", "end", "doc", "end" ]
Return all docopt lines for the 'Examples' section
[ "Return", "all", "docopt", "lines", "for", "the", "Examples", "section" ]
2e9da12766c88f27981f0b7b044a26ee724cfda5
https://github.com/DannyBen/runfile/blob/2e9da12766c88f27981f0b7b044a26ee724cfda5/lib/runfile/docopt_helper.rb#L88-L99
train
Threespot/tolaria
lib/tolaria/form_buildable.rb
Tolaria.FormBuildable.hint
def hint(hint_text, options = {}) css_class = "hint #{options.delete(:class)}" content_tag(:p, content_tag(:span, hint_text.chomp), class:css_class, **options) end
ruby
def hint(hint_text, options = {}) css_class = "hint #{options.delete(:class)}" content_tag(:p, content_tag(:span, hint_text.chomp), class:css_class, **options) end
[ "def", "hint", "(", "hint_text", ",", "options", "=", "{", "}", ")", "css_class", "=", "\"hint #{options.delete(:class)}\"", "content_tag", "(", ":p", ",", "content_tag", "(", ":span", ",", "hint_text", ".", "chomp", ")", ",", "class", ":", "css_class", ",", "**", "options", ")", "end" ]
Returns a `p.hint` used to explain a nearby form field containing the given `hint_text`.
[ "Returns", "a", "p", ".", "hint", "used", "to", "explain", "a", "nearby", "form", "field", "containing", "the", "given", "hint_text", "." ]
e60c5e330f7b423879433e35ec01ee2263e41c2c
https://github.com/Threespot/tolaria/blob/e60c5e330f7b423879433e35ec01ee2263e41c2c/lib/tolaria/form_buildable.rb#L6-L9
train
Threespot/tolaria
lib/tolaria/form_buildable.rb
Tolaria.FormBuildable.image_association_select
def image_association_select(method, collection, value_method, text_method, preview_url_method, options = {}) render(partial:"admin/shared/forms/image_association_select", locals: { f: self, method: method, collection: collection, value_method: value_method, text_method: text_method, preview_url_method: preview_url_method, options: options, html_options: options, }) end
ruby
def image_association_select(method, collection, value_method, text_method, preview_url_method, options = {}) render(partial:"admin/shared/forms/image_association_select", locals: { f: self, method: method, collection: collection, value_method: value_method, text_method: text_method, preview_url_method: preview_url_method, options: options, html_options: options, }) end
[ "def", "image_association_select", "(", "method", ",", "collection", ",", "value_method", ",", "text_method", ",", "preview_url_method", ",", "options", "=", "{", "}", ")", "render", "(", "partial", ":", "\"admin/shared/forms/image_association_select\"", ",", "locals", ":", "{", "f", ":", "self", ",", "method", ":", "method", ",", "collection", ":", "collection", ",", "value_method", ":", "value_method", ",", "text_method", ":", "text_method", ",", "preview_url_method", ":", "preview_url_method", ",", "options", ":", "options", ",", "html_options", ":", "options", ",", "}", ")", "end" ]
Creates a `searchable_select` that also shows a dynamic image preview of the selected record. Useful for previewing images or avatars chosen by name. `preview_url_method` should be a method name to call on the associated model instance that returns a fully-qualified URL to the image preview.
[ "Creates", "a", "searchable_select", "that", "also", "shows", "a", "dynamic", "image", "preview", "of", "the", "selected", "record", ".", "Useful", "for", "previewing", "images", "or", "avatars", "chosen", "by", "name", ".", "preview_url_method", "should", "be", "a", "method", "name", "to", "call", "on", "the", "associated", "model", "instance", "that", "returns", "a", "fully", "-", "qualified", "URL", "to", "the", "image", "preview", "." ]
e60c5e330f7b423879433e35ec01ee2263e41c2c
https://github.com/Threespot/tolaria/blob/e60c5e330f7b423879433e35ec01ee2263e41c2c/lib/tolaria/form_buildable.rb#L35-L46
train
Threespot/tolaria
lib/tolaria/form_buildable.rb
Tolaria.FormBuildable.markdown_composer
def markdown_composer(method, options = {}) render(partial:"admin/shared/forms/markdown_composer", locals: { f: self, method: method, options: options, }) end
ruby
def markdown_composer(method, options = {}) render(partial:"admin/shared/forms/markdown_composer", locals: { f: self, method: method, options: options, }) end
[ "def", "markdown_composer", "(", "method", ",", "options", "=", "{", "}", ")", "render", "(", "partial", ":", "\"admin/shared/forms/markdown_composer\"", ",", "locals", ":", "{", "f", ":", "self", ",", "method", ":", "method", ",", "options", ":", "options", ",", "}", ")", "end" ]
Renders a Markdown composer element for editing `method`, with fullscreen previewing and some text assistance tools. Requires that you set `Tolaria.config.markdown_renderer`. Options are forwarded to `text_area`.
[ "Renders", "a", "Markdown", "composer", "element", "for", "editing", "method", "with", "fullscreen", "previewing", "and", "some", "text", "assistance", "tools", ".", "Requires", "that", "you", "set", "Tolaria", ".", "config", ".", "markdown_renderer", ".", "Options", "are", "forwarded", "to", "text_area", "." ]
e60c5e330f7b423879433e35ec01ee2263e41c2c
https://github.com/Threespot/tolaria/blob/e60c5e330f7b423879433e35ec01ee2263e41c2c/lib/tolaria/form_buildable.rb#L52-L58
train
Threespot/tolaria
lib/tolaria/form_buildable.rb
Tolaria.FormBuildable.attachment_field
def attachment_field(method, options = {}) render(partial:"admin/shared/forms/attachment_field", locals: { f: self, method: method, options: options, }) end
ruby
def attachment_field(method, options = {}) render(partial:"admin/shared/forms/attachment_field", locals: { f: self, method: method, options: options, }) end
[ "def", "attachment_field", "(", "method", ",", "options", "=", "{", "}", ")", "render", "(", "partial", ":", "\"admin/shared/forms/attachment_field\"", ",", "locals", ":", "{", "f", ":", "self", ",", "method", ":", "method", ",", "options", ":", "options", ",", "}", ")", "end" ]
Returns a file upload field with a more pleasant interface than browser file inputs. Changes messaging if the `method` already exists. Options are forwarded to the hidden `file_field`.
[ "Returns", "a", "file", "upload", "field", "with", "a", "more", "pleasant", "interface", "than", "browser", "file", "inputs", ".", "Changes", "messaging", "if", "the", "method", "already", "exists", ".", "Options", "are", "forwarded", "to", "the", "hidden", "file_field", "." ]
e60c5e330f7b423879433e35ec01ee2263e41c2c
https://github.com/Threespot/tolaria/blob/e60c5e330f7b423879433e35ec01ee2263e41c2c/lib/tolaria/form_buildable.rb#L63-L69
train
Threespot/tolaria
lib/tolaria/form_buildable.rb
Tolaria.FormBuildable.image_field
def image_field(method, options = {}) render(partial:"admin/shared/forms/image_field", locals: { f: self, method: method, options: options, preview_url: options[:preview_url] }) end
ruby
def image_field(method, options = {}) render(partial:"admin/shared/forms/image_field", locals: { f: self, method: method, options: options, preview_url: options[:preview_url] }) end
[ "def", "image_field", "(", "method", ",", "options", "=", "{", "}", ")", "render", "(", "partial", ":", "\"admin/shared/forms/image_field\"", ",", "locals", ":", "{", "f", ":", "self", ",", "method", ":", "method", ",", "options", ":", "options", ",", "preview_url", ":", "options", "[", ":preview_url", "]", "}", ")", "end" ]
Returns an image upload field with a more pleasant interface than browser file inputs. Changes messaging if the `method` already exists. #### Special Options - `:preview_url` If the file already exists, provide a URL to a 42×42px version of the image, and it will be displayed to the user in a preview box to better communicate which file they are replacing. Other options are forwarded to the hidden `file_field`.
[ "Returns", "an", "image", "upload", "field", "with", "a", "more", "pleasant", "interface", "than", "browser", "file", "inputs", ".", "Changes", "messaging", "if", "the", "method", "already", "exists", "." ]
e60c5e330f7b423879433e35ec01ee2263e41c2c
https://github.com/Threespot/tolaria/blob/e60c5e330f7b423879433e35ec01ee2263e41c2c/lib/tolaria/form_buildable.rb#L81-L88
train
Threespot/tolaria
lib/tolaria/form_buildable.rb
Tolaria.FormBuildable.timestamp_field
def timestamp_field(method, options = {}) render(partial:"admin/shared/forms/timestamp_field", locals: { f: self, method: method, options: options, }) end
ruby
def timestamp_field(method, options = {}) render(partial:"admin/shared/forms/timestamp_field", locals: { f: self, method: method, options: options, }) end
[ "def", "timestamp_field", "(", "method", ",", "options", "=", "{", "}", ")", "render", "(", "partial", ":", "\"admin/shared/forms/timestamp_field\"", ",", "locals", ":", "{", "f", ":", "self", ",", "method", ":", "method", ",", "options", ":", "options", ",", "}", ")", "end" ]
Returns a text field that allows the user to input a date and time. Automatically validates itself and recovers to a template if blanked out. This field uses moment.js to parse the date and set the values on a set of hidden Rails `datetime_select` fields. Options are forwarded to the hidden `datetime_select` group.
[ "Returns", "a", "text", "field", "that", "allows", "the", "user", "to", "input", "a", "date", "and", "time", ".", "Automatically", "validates", "itself", "and", "recovers", "to", "a", "template", "if", "blanked", "out", ".", "This", "field", "uses", "moment", ".", "js", "to", "parse", "the", "date", "and", "set", "the", "values", "on", "a", "set", "of", "hidden", "Rails", "datetime_select", "fields", ".", "Options", "are", "forwarded", "to", "the", "hidden", "datetime_select", "group", "." ]
e60c5e330f7b423879433e35ec01ee2263e41c2c
https://github.com/Threespot/tolaria/blob/e60c5e330f7b423879433e35ec01ee2263e41c2c/lib/tolaria/form_buildable.rb#L95-L101
train
Threespot/tolaria
lib/tolaria/form_buildable.rb
Tolaria.FormBuildable.slug_field
def slug_field(method, options = {}) pattern = options.delete(:pattern) preview_value = self.object.send(method).try(:parameterize).presence || "*" render(partial:"admin/shared/forms/slug_field", locals: { f: self, method: method, options: options, preview_value: preview_value, pattern: (pattern || "/blog-example/*") }) end
ruby
def slug_field(method, options = {}) pattern = options.delete(:pattern) preview_value = self.object.send(method).try(:parameterize).presence || "*" render(partial:"admin/shared/forms/slug_field", locals: { f: self, method: method, options: options, preview_value: preview_value, pattern: (pattern || "/blog-example/*") }) end
[ "def", "slug_field", "(", "method", ",", "options", "=", "{", "}", ")", "pattern", "=", "options", ".", "delete", "(", ":pattern", ")", "preview_value", "=", "self", ".", "object", ".", "send", "(", "method", ")", ".", "try", "(", ":parameterize", ")", ".", "presence", "||", "\"*\"", "render", "(", "partial", ":", "\"admin/shared/forms/slug_field\"", ",", "locals", ":", "{", "f", ":", "self", ",", "method", ":", "method", ",", "options", ":", "options", ",", "preview_value", ":", "preview_value", ",", "pattern", ":", "(", "pattern", "||", "\"/blog-example/*\"", ")", "}", ")", "end" ]
Returns a text field that parameterizes its input as users type and renders it into the given preview template. Useful for demonstrating the value of a URL or other sluggified text. #### Special Options - `:pattern` - Should be a string that includes an asterisk (`*`) character. As the user types, the asterisk will be replaced with a parameterized version of the text in the text box and shown in a preview area below the field. The default is `"/blog-example/*"`. Other options are forwarded to `text_field`.
[ "Returns", "a", "text", "field", "that", "parameterizes", "its", "input", "as", "users", "type", "and", "renders", "it", "into", "the", "given", "preview", "template", ".", "Useful", "for", "demonstrating", "the", "value", "of", "a", "URL", "or", "other", "sluggified", "text", "." ]
e60c5e330f7b423879433e35ec01ee2263e41c2c
https://github.com/Threespot/tolaria/blob/e60c5e330f7b423879433e35ec01ee2263e41c2c/lib/tolaria/form_buildable.rb#L116-L126
train
Threespot/tolaria
lib/tolaria/form_buildable.rb
Tolaria.FormBuildable.swatch_field
def swatch_field(method, options = {}) render(partial:"admin/shared/forms/swatch_field", locals: { f: self, method: method, options: options, }) end
ruby
def swatch_field(method, options = {}) render(partial:"admin/shared/forms/swatch_field", locals: { f: self, method: method, options: options, }) end
[ "def", "swatch_field", "(", "method", ",", "options", "=", "{", "}", ")", "render", "(", "partial", ":", "\"admin/shared/forms/swatch_field\"", ",", "locals", ":", "{", "f", ":", "self", ",", "method", ":", "method", ",", "options", ":", "options", ",", "}", ")", "end" ]
Returns a text field that expects to be given a 3 or 6-digit hexadecimal color value. A preview block near the field demonstrates the provided color to the user. Options are forwarded to `text_field`.
[ "Returns", "a", "text", "field", "that", "expects", "to", "be", "given", "a", "3", "or", "6", "-", "digit", "hexadecimal", "color", "value", ".", "A", "preview", "block", "near", "the", "field", "demonstrates", "the", "provided", "color", "to", "the", "user", ".", "Options", "are", "forwarded", "to", "text_field", "." ]
e60c5e330f7b423879433e35ec01ee2263e41c2c
https://github.com/Threespot/tolaria/blob/e60c5e330f7b423879433e35ec01ee2263e41c2c/lib/tolaria/form_buildable.rb#L132-L138
train
etehtsea/oxblood
lib/oxblood/rsocket.rb
Oxblood.RSocket.gets
def gets(separator, timeout = @timeout) while (crlf = @buffer.index(separator)).nil? @buffer << readpartial(1024, timeout) end @buffer.slice!(0, crlf + separator.bytesize) end
ruby
def gets(separator, timeout = @timeout) while (crlf = @buffer.index(separator)).nil? @buffer << readpartial(1024, timeout) end @buffer.slice!(0, crlf + separator.bytesize) end
[ "def", "gets", "(", "separator", ",", "timeout", "=", "@timeout", ")", "while", "(", "crlf", "=", "@buffer", ".", "index", "(", "separator", ")", ")", ".", "nil?", "@buffer", "<<", "readpartial", "(", "1024", ",", "timeout", ")", "end", "@buffer", ".", "slice!", "(", "0", ",", "crlf", "+", "separator", ".", "bytesize", ")", "end" ]
Read until separator @param [String] separator separator @return [String] read result
[ "Read", "until", "separator" ]
0bfc3f6114a6eb5716a9cd44ecea914b273dc268
https://github.com/etehtsea/oxblood/blob/0bfc3f6114a6eb5716a9cd44ecea914b273dc268/lib/oxblood/rsocket.rb#L59-L65
train
etehtsea/oxblood
lib/oxblood/rsocket.rb
Oxblood.RSocket.write
def write(data, timeout = @timeout) full_size = data.bytesize while data.bytesize > 0 written = socket.write_nonblock(data, exception: false) if written == :wait_writable socket.wait_writable(timeout) or fail_with_timeout! else data = data.byteslice(written..-1) end end full_size end
ruby
def write(data, timeout = @timeout) full_size = data.bytesize while data.bytesize > 0 written = socket.write_nonblock(data, exception: false) if written == :wait_writable socket.wait_writable(timeout) or fail_with_timeout! else data = data.byteslice(written..-1) end end full_size end
[ "def", "write", "(", "data", ",", "timeout", "=", "@timeout", ")", "full_size", "=", "data", ".", "bytesize", "while", "data", ".", "bytesize", ">", "0", "written", "=", "socket", ".", "write_nonblock", "(", "data", ",", "exception", ":", "false", ")", "if", "written", "==", ":wait_writable", "socket", ".", "wait_writable", "(", "timeout", ")", "or", "fail_with_timeout!", "else", "data", "=", "data", ".", "byteslice", "(", "written", "..", "-", "1", ")", "end", "end", "full_size", "end" ]
Write data to socket @param [String] data given @return [Integer] the number of bytes written
[ "Write", "data", "to", "socket" ]
0bfc3f6114a6eb5716a9cd44ecea914b273dc268
https://github.com/etehtsea/oxblood/blob/0bfc3f6114a6eb5716a9cd44ecea914b273dc268/lib/oxblood/rsocket.rb#L70-L84
train
wilg/laundry
lib/laundry/lib/soap_model.rb
Laundry.SOAPModel.instance_action_module
def instance_action_module @instance_action_module ||= Module.new do # Returns the <tt>Savon::Client</tt> from the class instance. def client(&block) self.class.client(&block) end private def merged_default_body(body = {}) default = self.respond_to?(:default_body) ? self.default_body : nil (default || {}).merge (body || {}) end end.tap { |mod| include(mod) } end
ruby
def instance_action_module @instance_action_module ||= Module.new do # Returns the <tt>Savon::Client</tt> from the class instance. def client(&block) self.class.client(&block) end private def merged_default_body(body = {}) default = self.respond_to?(:default_body) ? self.default_body : nil (default || {}).merge (body || {}) end end.tap { |mod| include(mod) } end
[ "def", "instance_action_module", "@instance_action_module", "||=", "Module", ".", "new", "do", "def", "client", "(", "&", "block", ")", "self", ".", "class", ".", "client", "(", "&", "block", ")", "end", "private", "def", "merged_default_body", "(", "body", "=", "{", "}", ")", "default", "=", "self", ".", "respond_to?", "(", ":default_body", ")", "?", "self", ".", "default_body", ":", "nil", "(", "default", "||", "{", "}", ")", ".", "merge", "(", "body", "||", "{", "}", ")", "end", "end", ".", "tap", "{", "|", "mod", "|", "include", "(", "mod", ")", "}", "end" ]
Instance methods.
[ "Instance", "methods", "." ]
50f02dcc8e9cc7006f4a5dbaa3a1149c2f56a471
https://github.com/wilg/laundry/blob/50f02dcc8e9cc7006f4a5dbaa3a1149c2f56a471/lib/laundry/lib/soap_model.rb#L94-L110
train
mbj/vanguard
lib/vanguard/result.rb
Vanguard.Result.violations
def violations validator.rules.each_with_object(Set.new) do |rule, violations| violations.merge(rule.violations(resource)) end end
ruby
def violations validator.rules.each_with_object(Set.new) do |rule, violations| violations.merge(rule.violations(resource)) end end
[ "def", "violations", "validator", ".", "rules", ".", "each_with_object", "(", "Set", ".", "new", ")", "do", "|", "rule", ",", "violations", "|", "violations", ".", "merge", "(", "rule", ".", "violations", "(", "resource", ")", ")", "end", "end" ]
Return violations for resource @param [Resource] resource @api private
[ "Return", "violations", "for", "resource" ]
1babf0b4b08712f22da0c44f0f72f9651c714aae
https://github.com/mbj/vanguard/blob/1babf0b4b08712f22da0c44f0f72f9651c714aae/lib/vanguard/result.rb#L31-L35
train
lwoggardner/rfuse
lib/rfuse.rb
RFuse.Fuse.run
def run(signals=Signal.list.keys) if mounted? begin traps = trap_signals(*signals) self.loop() ensure traps.each { |t| Signal.trap(t,"DEFAULT") } unmount() end end end
ruby
def run(signals=Signal.list.keys) if mounted? begin traps = trap_signals(*signals) self.loop() ensure traps.each { |t| Signal.trap(t,"DEFAULT") } unmount() end end end
[ "def", "run", "(", "signals", "=", "Signal", ".", "list", ".", "keys", ")", "if", "mounted?", "begin", "traps", "=", "trap_signals", "(", "*", "signals", ")", "self", ".", "loop", "(", ")", "ensure", "traps", ".", "each", "{", "|", "t", "|", "Signal", ".", "trap", "(", "t", ",", "\"DEFAULT\"", ")", "}", "unmount", "(", ")", "end", "end", "end" ]
Convenience method to run a mounted filesystem to completion. @param [Array<String|Integer>] signals list of signals to handle. Default is all available signals. See {#trap_signals} @return [void] @since 1.1.0 @see RFuse.main
[ "Convenience", "method", "to", "run", "a", "mounted", "filesystem", "to", "completion", "." ]
16e0a36c6cd69afb9a9c2a709766cf6177129e9c
https://github.com/lwoggardner/rfuse/blob/16e0a36c6cd69afb9a9c2a709766cf6177129e9c/lib/rfuse.rb#L289-L299
train
lwoggardner/rfuse
lib/rfuse.rb
RFuse.Fuse.loop
def loop() raise RFuse::Error, "Already running!" if @running raise RFuse::Error, "FUSE not mounted" unless mounted? @running = true while @running do begin ready, ignore, errors = IO.select([@fuse_io,@pr],[],[@fuse_io]) if ready.include?(@pr) signo = @pr.read_nonblock(1).unpack("c")[0] # Signal.signame exist in Ruby 2, but returns horrible errors for non-signals in 2.1.0 if (signame = Signal.list.invert[signo]) call_sigmethod(sigmethod(signame)) end elsif errors.include?(@fuse_io) @running = false raise RFuse::Error, "FUSE error" elsif ready.include?(@fuse_io) if process() < 0 # Fuse has been unmounted externally # TODO: mounted? should now return false # fuse_exited? is not true... @running = false end end rescue Errno::EWOULDBLOCK, Errno::EAGAIN #oh well... end end end
ruby
def loop() raise RFuse::Error, "Already running!" if @running raise RFuse::Error, "FUSE not mounted" unless mounted? @running = true while @running do begin ready, ignore, errors = IO.select([@fuse_io,@pr],[],[@fuse_io]) if ready.include?(@pr) signo = @pr.read_nonblock(1).unpack("c")[0] # Signal.signame exist in Ruby 2, but returns horrible errors for non-signals in 2.1.0 if (signame = Signal.list.invert[signo]) call_sigmethod(sigmethod(signame)) end elsif errors.include?(@fuse_io) @running = false raise RFuse::Error, "FUSE error" elsif ready.include?(@fuse_io) if process() < 0 # Fuse has been unmounted externally # TODO: mounted? should now return false # fuse_exited? is not true... @running = false end end rescue Errno::EWOULDBLOCK, Errno::EAGAIN #oh well... end end end
[ "def", "loop", "(", ")", "raise", "RFuse", "::", "Error", ",", "\"Already running!\"", "if", "@running", "raise", "RFuse", "::", "Error", ",", "\"FUSE not mounted\"", "unless", "mounted?", "@running", "=", "true", "while", "@running", "do", "begin", "ready", ",", "ignore", ",", "errors", "=", "IO", ".", "select", "(", "[", "@fuse_io", ",", "@pr", "]", ",", "[", "]", ",", "[", "@fuse_io", "]", ")", "if", "ready", ".", "include?", "(", "@pr", ")", "signo", "=", "@pr", ".", "read_nonblock", "(", "1", ")", ".", "unpack", "(", "\"c\"", ")", "[", "0", "]", "if", "(", "signame", "=", "Signal", ".", "list", ".", "invert", "[", "signo", "]", ")", "call_sigmethod", "(", "sigmethod", "(", "signame", ")", ")", "end", "elsif", "errors", ".", "include?", "(", "@fuse_io", ")", "@running", "=", "false", "raise", "RFuse", "::", "Error", ",", "\"FUSE error\"", "elsif", "ready", ".", "include?", "(", "@fuse_io", ")", "if", "process", "(", ")", "<", "0", "@running", "=", "false", "end", "end", "rescue", "Errno", "::", "EWOULDBLOCK", ",", "Errno", "::", "EAGAIN", "end", "end", "end" ]
Main processing loop Use {#exit} to stop processing (or externally call fusermount -u) Other ruby threads can continue while loop is running, however no thread can operate on the filesystem itself (ie with File or Dir methods) @return [void] @raise [RFuse::Error] if already running or not mounted
[ "Main", "processing", "loop" ]
16e0a36c6cd69afb9a9c2a709766cf6177129e9c
https://github.com/lwoggardner/rfuse/blob/16e0a36c6cd69afb9a9c2a709766cf6177129e9c/lib/rfuse.rb#L310-L344
train
lwoggardner/rfuse
lib/rfuse.rb
RFuse.FuseDelegator.debug=
def debug=(value) value = value ? true : false if @debug && !value $stderr.puts "=== #{ self }.debug=false" elsif !@debug && value $stderr.puts "=== #{ self }.debug=true" end @debug = value end
ruby
def debug=(value) value = value ? true : false if @debug && !value $stderr.puts "=== #{ self }.debug=false" elsif !@debug && value $stderr.puts "=== #{ self }.debug=true" end @debug = value end
[ "def", "debug", "=", "(", "value", ")", "value", "=", "value", "?", "true", ":", "false", "if", "@debug", "&&", "!", "value", "$stderr", ".", "puts", "\"=== #{ self }.debug=false\"", "elsif", "!", "@debug", "&&", "value", "$stderr", ".", "puts", "\"=== #{ self }.debug=true\"", "end", "@debug", "=", "value", "end" ]
Set debugging on or off @param [Boolean] value enable or disable debugging @return [Boolean] the new debug value @since 1.1.0
[ "Set", "debugging", "on", "or", "off" ]
16e0a36c6cd69afb9a9c2a709766cf6177129e9c
https://github.com/lwoggardner/rfuse/blob/16e0a36c6cd69afb9a9c2a709766cf6177129e9c/lib/rfuse.rb#L503-L511
train
p0deje/watir-dom-wait
lib/watir/dom/elements/element.rb
Watir.Element.dom_changed?
def dom_changed?(delay: 1.1) element_call do begin driver.manage.timeouts.script_timeout = delay + 1 driver.execute_async_script(DOM_WAIT_JS, wd, delay) rescue Selenium::WebDriver::Error::JavascriptError => error # sometimes we start script execution before new page is loaded and # in rare cases ChromeDriver throws this error, we just swallow it and retry retry if error.message.include?('document unloaded while waiting for result') raise ensure # TODO: make sure we rollback to user-defined timeout # blocked by https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/6608 driver.manage.timeouts.script_timeout = 1 end end end
ruby
def dom_changed?(delay: 1.1) element_call do begin driver.manage.timeouts.script_timeout = delay + 1 driver.execute_async_script(DOM_WAIT_JS, wd, delay) rescue Selenium::WebDriver::Error::JavascriptError => error # sometimes we start script execution before new page is loaded and # in rare cases ChromeDriver throws this error, we just swallow it and retry retry if error.message.include?('document unloaded while waiting for result') raise ensure # TODO: make sure we rollback to user-defined timeout # blocked by https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/6608 driver.manage.timeouts.script_timeout = 1 end end end
[ "def", "dom_changed?", "(", "delay", ":", "1.1", ")", "element_call", "do", "begin", "driver", ".", "manage", ".", "timeouts", ".", "script_timeout", "=", "delay", "+", "1", "driver", ".", "execute_async_script", "(", "DOM_WAIT_JS", ",", "wd", ",", "delay", ")", "rescue", "Selenium", "::", "WebDriver", "::", "Error", "::", "JavascriptError", "=>", "error", "retry", "if", "error", ".", "message", ".", "include?", "(", "'document unloaded while waiting for result'", ")", "raise", "ensure", "driver", ".", "manage", ".", "timeouts", ".", "script_timeout", "=", "1", "end", "end", "end" ]
Returns true if DOM is changed within the element. @example Wait until DOM is changed inside element with default delay browser.div(id: 'test').wait_until(&:dom_changed?).click @example Wait until DOM is changed inside element with default delay browser.div(id: 'test').wait_until do |element| element.dom_changed?(delay: 5) end @param delay [Integer, Float] how long to wait for DOM modifications to start
[ "Returns", "true", "if", "DOM", "is", "changed", "within", "the", "element", "." ]
1337c446f106748810b3e8cc1e16d02eeba25745
https://github.com/p0deje/watir-dom-wait/blob/1337c446f106748810b3e8cc1e16d02eeba25745/lib/watir/dom/elements/element.rb#L19-L35
train
EvidentSecurity/esp_sdk
lib/esp/resources/signature.rb
ESP.Signature.run!
def run!(arguments = {}) result = run(arguments) return result if result.is_a?(ActiveResource::Collection) result.message = result.errors.full_messages.join(' ') fail(ActiveResource::ResourceInvalid.new(result)) # rubocop:disable Style/RaiseArgs end
ruby
def run!(arguments = {}) result = run(arguments) return result if result.is_a?(ActiveResource::Collection) result.message = result.errors.full_messages.join(' ') fail(ActiveResource::ResourceInvalid.new(result)) # rubocop:disable Style/RaiseArgs end
[ "def", "run!", "(", "arguments", "=", "{", "}", ")", "result", "=", "run", "(", "arguments", ")", "return", "result", "if", "result", ".", "is_a?", "(", "ActiveResource", "::", "Collection", ")", "result", ".", "message", "=", "result", ".", "errors", ".", "full_messages", ".", "join", "(", "' '", ")", "fail", "(", "ActiveResource", "::", "ResourceInvalid", ".", "new", "(", "result", ")", ")", "end" ]
Run this signature. Returns a collection of alerts. Throws an error if not successful. @param (see #run) @return [ActiveResource::PaginatedCollection<ESP::Alert>] @raise [ActiveResource::ResourceInvalid] if not successful. @example signature = ESP::Signature.find(3) alerts = signature.run!(external_account_id: 3, region: 'us_east_1')
[ "Run", "this", "signature", ".", "Returns", "a", "collection", "of", "alerts", ".", "Throws", "an", "error", "if", "not", "successful", "." ]
feb1740a8e8849bdeb967a22358f9bcfaa99d215
https://github.com/EvidentSecurity/esp_sdk/blob/feb1740a8e8849bdeb967a22358f9bcfaa99d215/lib/esp/resources/signature.rb#L32-L37
train
EvidentSecurity/esp_sdk
lib/esp/resources/signature.rb
ESP.Signature.run
def run(arguments = {}) arguments = arguments.with_indifferent_access attributes['external_account_id'] ||= arguments[:external_account_id] attributes['region'] ||= arguments[:region] response = connection.post("#{self.class.prefix}signatures/#{id}/run.json", to_json) ESP::Alert.send(:instantiate_collection, self.class.format.decode(response.body)) rescue ActiveResource::BadRequest, ActiveResource::ResourceInvalid, ActiveResource::ResourceNotFound => error load_remote_errors(error, true) self.code = error.response.code self end
ruby
def run(arguments = {}) arguments = arguments.with_indifferent_access attributes['external_account_id'] ||= arguments[:external_account_id] attributes['region'] ||= arguments[:region] response = connection.post("#{self.class.prefix}signatures/#{id}/run.json", to_json) ESP::Alert.send(:instantiate_collection, self.class.format.decode(response.body)) rescue ActiveResource::BadRequest, ActiveResource::ResourceInvalid, ActiveResource::ResourceNotFound => error load_remote_errors(error, true) self.code = error.response.code self end
[ "def", "run", "(", "arguments", "=", "{", "}", ")", "arguments", "=", "arguments", ".", "with_indifferent_access", "attributes", "[", "'external_account_id'", "]", "||=", "arguments", "[", ":external_account_id", "]", "attributes", "[", "'region'", "]", "||=", "arguments", "[", ":region", "]", "response", "=", "connection", ".", "post", "(", "\"#{self.class.prefix}signatures/#{id}/run.json\"", ",", "to_json", ")", "ESP", "::", "Alert", ".", "send", "(", ":instantiate_collection", ",", "self", ".", "class", ".", "format", ".", "decode", "(", "response", ".", "body", ")", ")", "rescue", "ActiveResource", "::", "BadRequest", ",", "ActiveResource", "::", "ResourceInvalid", ",", "ActiveResource", "::", "ResourceNotFound", "=>", "error", "load_remote_errors", "(", "error", ",", "true", ")", "self", ".", "code", "=", "error", ".", "response", ".", "code", "self", "end" ]
Run this signature. Returns a collection of alerts. If not successful, returns a Signature object with the errors object populated. @param arguments [Hash] Required hash of run arguments. ===== Valid Arguments See {API documentation}[http://api-docs.evident.io?ruby#signature-run] for valid arguments @return [ActiveResource::PaginatedCollection<ESP::Alert>, self] @example signature = ESP::Signature.find(3) alerts = signature.run(external_account_id: 3, region: 'us_east_1')
[ "Run", "this", "signature", ".", "Returns", "a", "collection", "of", "alerts", ".", "If", "not", "successful", "returns", "a", "Signature", "object", "with", "the", "errors", "object", "populated", "." ]
feb1740a8e8849bdeb967a22358f9bcfaa99d215
https://github.com/EvidentSecurity/esp_sdk/blob/feb1740a8e8849bdeb967a22358f9bcfaa99d215/lib/esp/resources/signature.rb#L51-L62
train
EvidentSecurity/esp_sdk
lib/esp/resources/signature.rb
ESP.Signature.suppress
def suppress(arguments = {}) arguments = arguments.with_indifferent_access ESP::Suppression::Signature.create(signature_ids: [id], regions: Array(arguments[:regions]), external_account_ids: Array(arguments[:external_account_ids]), reason: arguments[:reason]) end
ruby
def suppress(arguments = {}) arguments = arguments.with_indifferent_access ESP::Suppression::Signature.create(signature_ids: [id], regions: Array(arguments[:regions]), external_account_ids: Array(arguments[:external_account_ids]), reason: arguments[:reason]) end
[ "def", "suppress", "(", "arguments", "=", "{", "}", ")", "arguments", "=", "arguments", ".", "with_indifferent_access", "ESP", "::", "Suppression", "::", "Signature", ".", "create", "(", "signature_ids", ":", "[", "id", "]", ",", "regions", ":", "Array", "(", "arguments", "[", ":regions", "]", ")", ",", "external_account_ids", ":", "Array", "(", "arguments", "[", ":external_account_ids", "]", ")", ",", "reason", ":", "arguments", "[", ":reason", "]", ")", "end" ]
Create a suppression for this signature. @param arguments [Hash] Required hash of signature suppression attributes. ===== Valid Arguments See {API documentation}[http://api-docs.evident.io?ruby#suppression-create] for valid arguments @return [ESP::Suppression::Signature] @example suppress(regions: ['us_east_1'], external_account_ids: [5], reason: 'My very good reason for creating this suppression')
[ "Create", "a", "suppression", "for", "this", "signature", "." ]
feb1740a8e8849bdeb967a22358f9bcfaa99d215
https://github.com/EvidentSecurity/esp_sdk/blob/feb1740a8e8849bdeb967a22358f9bcfaa99d215/lib/esp/resources/signature.rb#L73-L76
train
propublica/table-setter
lib/table_setter/table.rb
TableSetter.Table.csv_data
def csv_data case when google_key || url then Curl::Easy.perform(uri).body_str when file then File.open(uri).read end end
ruby
def csv_data case when google_key || url then Curl::Easy.perform(uri).body_str when file then File.open(uri).read end end
[ "def", "csv_data", "case", "when", "google_key", "||", "url", "then", "Curl", "::", "Easy", ".", "perform", "(", "uri", ")", ".", "body_str", "when", "file", "then", "File", ".", "open", "(", "uri", ")", ".", "read", "end", "end" ]
The csv_data for the table fu instance is loaded either from the remote source or from a local file, depending on the keys present in the yaml file.
[ "The", "csv_data", "for", "the", "table", "fu", "instance", "is", "loaded", "either", "from", "the", "remote", "source", "or", "from", "a", "local", "file", "depending", "on", "the", "keys", "present", "in", "the", "yaml", "file", "." ]
11e14dc3359be7cb78400e8a70e0bb0a199daf72
https://github.com/propublica/table-setter/blob/11e14dc3359be7cb78400e8a70e0bb0a199daf72/lib/table_setter/table.rb#L41-L46
train
propublica/table-setter
lib/table_setter/table.rb
TableSetter.Table.updated_at
def updated_at csv_time = google_key.nil? ? modification_time(uri) : google_modification_time (csv_time > yaml_time ? csv_time : yaml_time).to_s end
ruby
def updated_at csv_time = google_key.nil? ? modification_time(uri) : google_modification_time (csv_time > yaml_time ? csv_time : yaml_time).to_s end
[ "def", "updated_at", "csv_time", "=", "google_key", ".", "nil?", "?", "modification_time", "(", "uri", ")", ":", "google_modification_time", "(", "csv_time", ">", "yaml_time", "?", "csv_time", ":", "yaml_time", ")", ".", "to_s", "end" ]
The real +updated_at+ of a Table instance is the newer modification time of the csv file or the yaml file. Updates to either resource should break the cache.
[ "The", "real", "+", "updated_at", "+", "of", "a", "Table", "instance", "is", "the", "newer", "modification", "time", "of", "the", "csv", "file", "or", "the", "yaml", "file", ".", "Updates", "to", "either", "resource", "should", "break", "the", "cache", "." ]
11e14dc3359be7cb78400e8a70e0bb0a199daf72
https://github.com/propublica/table-setter/blob/11e14dc3359be7cb78400e8a70e0bb0a199daf72/lib/table_setter/table.rb#L59-L62
train
propublica/table-setter
lib/table_setter/table.rb
TableSetter.Table.paginate!
def paginate!(curr_page) return if !hard_paginate? @page = curr_page.to_i raise ArgumentError if @page < 1 || @page > total_pages adj_page = @page - 1 > 0 ? @page - 1 : 0 @prev_page = adj_page > 0 ? adj_page : nil @next_page = page < total_pages ? (@page + 1) : nil @data.only!(adj_page * per_page..(@page * per_page - 1)) end
ruby
def paginate!(curr_page) return if !hard_paginate? @page = curr_page.to_i raise ArgumentError if @page < 1 || @page > total_pages adj_page = @page - 1 > 0 ? @page - 1 : 0 @prev_page = adj_page > 0 ? adj_page : nil @next_page = page < total_pages ? (@page + 1) : nil @data.only!(adj_page * per_page..(@page * per_page - 1)) end
[ "def", "paginate!", "(", "curr_page", ")", "return", "if", "!", "hard_paginate?", "@page", "=", "curr_page", ".", "to_i", "raise", "ArgumentError", "if", "@page", "<", "1", "||", "@page", ">", "total_pages", "adj_page", "=", "@page", "-", "1", ">", "0", "?", "@page", "-", "1", ":", "0", "@prev_page", "=", "adj_page", ">", "0", "?", "adj_page", ":", "nil", "@next_page", "=", "page", "<", "total_pages", "?", "(", "@page", "+", "1", ")", ":", "nil", "@data", ".", "only!", "(", "adj_page", "*", "per_page", "..", "(", "@page", "*", "per_page", "-", "1", ")", ")", "end" ]
paginate uses TableFu's only! method to batch the table. It also computes the page attributes which are nil and meaningless otherwise.
[ "paginate", "uses", "TableFu", "s", "only!", "method", "to", "batch", "the", "table", ".", "It", "also", "computes", "the", "page", "attributes", "which", "are", "nil", "and", "meaningless", "otherwise", "." ]
11e14dc3359be7cb78400e8a70e0bb0a199daf72
https://github.com/propublica/table-setter/blob/11e14dc3359be7cb78400e8a70e0bb0a199daf72/lib/table_setter/table.rb#L85-L93
train
propublica/table-setter
lib/table_setter/table.rb
TableSetter.Table.sort_array
def sort_array if @data.sorted_by @data.sorted_by.inject([]) do |memo, (key, value)| memo << [@data.columns.index(key), value == 'descending' ? 1 : 0] end end end
ruby
def sort_array if @data.sorted_by @data.sorted_by.inject([]) do |memo, (key, value)| memo << [@data.columns.index(key), value == 'descending' ? 1 : 0] end end end
[ "def", "sort_array", "if", "@data", ".", "sorted_by", "@data", ".", "sorted_by", ".", "inject", "(", "[", "]", ")", "do", "|", "memo", ",", "(", "key", ",", "value", ")", "|", "memo", "<<", "[", "@data", ".", "columns", ".", "index", "(", "key", ")", ",", "value", "==", "'descending'", "?", "1", ":", "0", "]", "end", "end", "end" ]
A convienence method to return the sort array for table setter.
[ "A", "convienence", "method", "to", "return", "the", "sort", "array", "for", "table", "setter", "." ]
11e14dc3359be7cb78400e8a70e0bb0a199daf72
https://github.com/propublica/table-setter/blob/11e14dc3359be7cb78400e8a70e0bb0a199daf72/lib/table_setter/table.rb#L103-L109
train
propublica/table-setter
lib/table_setter/table.rb
TableSetter.Table.web_modification_time
def web_modification_time(local_url) resp = nil Net::HTTP.start(local_url.host, 80) do |http| resp = http.head(local_url.path) end resp['Last-Modified'].nil? ? Time.at(0) : Time.parse(resp['Last-Modified']) end
ruby
def web_modification_time(local_url) resp = nil Net::HTTP.start(local_url.host, 80) do |http| resp = http.head(local_url.path) end resp['Last-Modified'].nil? ? Time.at(0) : Time.parse(resp['Last-Modified']) end
[ "def", "web_modification_time", "(", "local_url", ")", "resp", "=", "nil", "Net", "::", "HTTP", ".", "start", "(", "local_url", ".", "host", ",", "80", ")", "do", "|", "http", "|", "resp", "=", "http", ".", "head", "(", "local_url", ".", "path", ")", "end", "resp", "[", "'Last-Modified'", "]", ".", "nil?", "?", "Time", ".", "at", "(", "0", ")", ":", "Time", ".", "parse", "(", "resp", "[", "'Last-Modified'", "]", ")", "end" ]
Returns the last-modified time from the remote server. Assumes the remote server knows how to do this. Returns the epoch if the remote is dense.
[ "Returns", "the", "last", "-", "modified", "time", "from", "the", "remote", "server", ".", "Assumes", "the", "remote", "server", "knows", "how", "to", "do", "this", ".", "Returns", "the", "epoch", "if", "the", "remote", "is", "dense", "." ]
11e14dc3359be7cb78400e8a70e0bb0a199daf72
https://github.com/propublica/table-setter/blob/11e14dc3359be7cb78400e8a70e0bb0a199daf72/lib/table_setter/table.rb#L135-L141
train
propublica/table-setter
lib/table_setter/table.rb
TableSetter.Table.modification_time
def modification_time(path) is_uri = URI.parse(path) if !is_uri.host.nil? return web_modification_time is_uri end File.new(path).mtime end
ruby
def modification_time(path) is_uri = URI.parse(path) if !is_uri.host.nil? return web_modification_time is_uri end File.new(path).mtime end
[ "def", "modification_time", "(", "path", ")", "is_uri", "=", "URI", ".", "parse", "(", "path", ")", "if", "!", "is_uri", ".", "host", ".", "nil?", "return", "web_modification_time", "is_uri", "end", "File", ".", "new", "(", "path", ")", ".", "mtime", "end" ]
Dispatches to web_modification_time if we're dealing with a url, otherwise just stats the local file.
[ "Dispatches", "to", "web_modification_time", "if", "we", "re", "dealing", "with", "a", "url", "otherwise", "just", "stats", "the", "local", "file", "." ]
11e14dc3359be7cb78400e8a70e0bb0a199daf72
https://github.com/propublica/table-setter/blob/11e14dc3359be7cb78400e8a70e0bb0a199daf72/lib/table_setter/table.rb#L145-L151
train
m247/epp-client
lib/epp-client/request.rb
EPP.Request.to_xml
def to_xml doc = XML::Document.new('1.0') doc.root = XML::Node.new('epp') root = doc.root epp_ns = XML::Namespace.new(root, nil, 'urn:ietf:params:xml:ns:epp-1.0') root.namespaces.namespace = epp_ns xsi_ns = XML::Namespace.new(root, 'xsi', 'http://www.w3.org/2001/XMLSchema-instance') xsi_sL = XML::Attr.new(root, 'schemaLocation', 'urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd') xsi_sL.namespaces.namespace = xsi_ns @namespaces = {'epp' => epp_ns, 'xsi' => xsi_ns} @request.set_namespaces(@namespaces) if @request.respond_to?(:set_namespaces) root << @request.to_xml doc end
ruby
def to_xml doc = XML::Document.new('1.0') doc.root = XML::Node.new('epp') root = doc.root epp_ns = XML::Namespace.new(root, nil, 'urn:ietf:params:xml:ns:epp-1.0') root.namespaces.namespace = epp_ns xsi_ns = XML::Namespace.new(root, 'xsi', 'http://www.w3.org/2001/XMLSchema-instance') xsi_sL = XML::Attr.new(root, 'schemaLocation', 'urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd') xsi_sL.namespaces.namespace = xsi_ns @namespaces = {'epp' => epp_ns, 'xsi' => xsi_ns} @request.set_namespaces(@namespaces) if @request.respond_to?(:set_namespaces) root << @request.to_xml doc end
[ "def", "to_xml", "doc", "=", "XML", "::", "Document", ".", "new", "(", "'1.0'", ")", "doc", ".", "root", "=", "XML", "::", "Node", ".", "new", "(", "'epp'", ")", "root", "=", "doc", ".", "root", "epp_ns", "=", "XML", "::", "Namespace", ".", "new", "(", "root", ",", "nil", ",", "'urn:ietf:params:xml:ns:epp-1.0'", ")", "root", ".", "namespaces", ".", "namespace", "=", "epp_ns", "xsi_ns", "=", "XML", "::", "Namespace", ".", "new", "(", "root", ",", "'xsi'", ",", "'http://www.w3.org/2001/XMLSchema-instance'", ")", "xsi_sL", "=", "XML", "::", "Attr", ".", "new", "(", "root", ",", "'schemaLocation'", ",", "'urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd'", ")", "xsi_sL", ".", "namespaces", ".", "namespace", "=", "xsi_ns", "@namespaces", "=", "{", "'epp'", "=>", "epp_ns", ",", "'xsi'", "=>", "xsi_ns", "}", "@request", ".", "set_namespaces", "(", "@namespaces", ")", "if", "@request", ".", "respond_to?", "(", ":set_namespaces", ")", "root", "<<", "@request", ".", "to_xml", "doc", "end" ]
Receiver in XML form @return [XML::Document] XML of the receiver
[ "Receiver", "in", "XML", "form" ]
72227e57d248f215d842e3dd37e72432d2a79270
https://github.com/m247/epp-client/blob/72227e57d248f215d842e3dd37e72432d2a79270/lib/epp-client/request.rb#L19-L37
train
m247/epp-client
lib/epp-client/response.rb
EPP.Response.extension
def extension @extension ||= begin list = @xml.find('/e:epp/e:response/e:extension/node()').reject { |n| n.empty? } list.size > 1 ? list : list[0] end end
ruby
def extension @extension ||= begin list = @xml.find('/e:epp/e:response/e:extension/node()').reject { |n| n.empty? } list.size > 1 ? list : list[0] end end
[ "def", "extension", "@extension", "||=", "begin", "list", "=", "@xml", ".", "find", "(", "'/e:epp/e:response/e:extension/node()'", ")", ".", "reject", "{", "|", "n", "|", "n", ".", "empty?", "}", "list", ".", "size", ">", "1", "?", "list", ":", "list", "[", "0", "]", "end", "end" ]
Response extension block @return [XML::Node, Array<XML::Node>] extension
[ "Response", "extension", "block" ]
72227e57d248f215d842e3dd37e72432d2a79270
https://github.com/m247/epp-client/blob/72227e57d248f215d842e3dd37e72432d2a79270/lib/epp-client/response.rb#L68-L73
train
imathis/jekyll-markdown-block
lib/jekyll-markdown-block.rb
Jekyll.MarkdownBlock.render
def render(context) site = context.registers[:site] converter = site.getConverterImpl(::Jekyll::Converters::Markdown) converter.convert(render_block(context)) end
ruby
def render(context) site = context.registers[:site] converter = site.getConverterImpl(::Jekyll::Converters::Markdown) converter.convert(render_block(context)) end
[ "def", "render", "(", "context", ")", "site", "=", "context", ".", "registers", "[", ":site", "]", "converter", "=", "site", ".", "getConverterImpl", "(", "::", "Jekyll", "::", "Converters", "::", "Markdown", ")", "converter", ".", "convert", "(", "render_block", "(", "context", ")", ")", "end" ]
Uses the default Jekyll markdown parser to parse the contents of this block
[ "Uses", "the", "default", "Jekyll", "markdown", "parser", "to", "parse", "the", "contents", "of", "this", "block" ]
6f1a9fd20d684a1f0bcf87d634782f5dd8cc8670
https://github.com/imathis/jekyll-markdown-block/blob/6f1a9fd20d684a1f0bcf87d634782f5dd8cc8670/lib/jekyll-markdown-block.rb#L12-L16
train
mat813/rb-kqueue
lib/rb-kqueue/queue.rb
KQueue.Queue.watch_socket_for_read
def watch_socket_for_read(fd, low_water = nil, &callback) Watcher::SocketReadWrite.new(self, fd, :read, low_water, callback) end
ruby
def watch_socket_for_read(fd, low_water = nil, &callback) Watcher::SocketReadWrite.new(self, fd, :read, low_water, callback) end
[ "def", "watch_socket_for_read", "(", "fd", ",", "low_water", "=", "nil", ",", "&", "callback", ")", "Watcher", "::", "SocketReadWrite", ".", "new", "(", "self", ",", "fd", ",", ":read", ",", "low_water", ",", "callback", ")", "end" ]
Watches a socket and produces an event when there's data available to read. Sockets which have previously had `Socket#listen` called fire events when there is an incoming connection pending. In this case, {Event#data} contains the size of the listen backlog. Other sockets return when there is data to be read, subject to the SO_RCVLOWAT value of the socket buffer. This may be overridden via the `low_water` parameter, which sets a new low-water mark. In this case, {Event#data} contains the number of bytes of protocol data available to read. If the read direction of the socket has shut down, then {Event#eof?} is set. It's possible for {Event#eof?} to be set while there's still data pending in the socket buffer. Note that this isn't compatible with JRuby unless a native-code file descriptor is passed in. This means the file descriptor must be returned by an FFI-wrapped C function. @param fd [Socket, Fixnum] A Ruby Socket, or the file descriptor for a native Socket. @param low_water [Fixnum] The low-water mark for new data. @yield [event] A block that will be run when the specified socket has data to read. @yieldparam event [Event] The Event object containing information about the event that occurred. @return [Watcher] The Watcher for this event. @raise [SystemCallError] If something goes wrong when registering the Watcher.
[ "Watches", "a", "socket", "and", "produces", "an", "event", "when", "there", "s", "data", "available", "to", "read", "." ]
f11c1a8552812bc0b635ef9751d6dc61d4beaa67
https://github.com/mat813/rb-kqueue/blob/f11c1a8552812bc0b635ef9751d6dc61d4beaa67/lib/rb-kqueue/queue.rb#L123-L125
train
mat813/rb-kqueue
lib/rb-kqueue/queue.rb
KQueue.Queue.watch_file
def watch_file(path, *flags, &callback) Watcher::File.new(self, path, flags, callback) end
ruby
def watch_file(path, *flags, &callback) Watcher::File.new(self, path, flags, callback) end
[ "def", "watch_file", "(", "path", ",", "*", "flags", ",", "&", "callback", ")", "Watcher", "::", "File", ".", "new", "(", "self", ",", "path", ",", "flags", ",", "callback", ")", "end" ]
Watches a file or directory for changes. The `flags` parameter specifies which changes will fire events. The {Event#flags} field contains the changes that caused the event to be fired. {Event#data} and {Event#eof?} are unused. Note that this only watches a single file. If the file is a direcotry, it will only report changes to the directory itself, not to any files within the directory. ## Flags `:delete` : The file was deleted. `:write` : The file was modified. `:extend` : The size of the file increased. `:attrib` : Attributes of the file, such as timestamp or permissions, changed. `:link` : The link count of the file changed. `:rename` : The file was renamed. `:revoke` : Access to the file was revoked, either via the `revoke(2)` system call or because the underlying filesystem was unmounted. @param path [String] The path to the file or directory. @param flags [Array<Symbol>] Which events to watch for. @yield [event] A block that will be run when the file changes. @yieldparam event [Event] The Event object containing information about the event that occurred. @return [Watcher] The Watcher for this event. @raise [SystemCallError] If something goes wrong when registering the Watcher.
[ "Watches", "a", "file", "or", "directory", "for", "changes", ".", "The", "flags", "parameter", "specifies", "which", "changes", "will", "fire", "events", "." ]
f11c1a8552812bc0b635ef9751d6dc61d4beaa67
https://github.com/mat813/rb-kqueue/blob/f11c1a8552812bc0b635ef9751d6dc61d4beaa67/lib/rb-kqueue/queue.rb#L226-L228
train
mat813/rb-kqueue
lib/rb-kqueue/queue.rb
KQueue.Queue.watch_process
def watch_process(pid, *flags, &callback) Watcher::Process.new(self, pid, flags, callback) end
ruby
def watch_process(pid, *flags, &callback) Watcher::Process.new(self, pid, flags, callback) end
[ "def", "watch_process", "(", "pid", ",", "*", "flags", ",", "&", "callback", ")", "Watcher", "::", "Process", ".", "new", "(", "self", ",", "pid", ",", "flags", ",", "callback", ")", "end" ]
Watches a process for changes. The `flags` parameter specifies which changes will fire events. The {Event#flags} field contains the changes that caused the event to be fired. {Event#data} and {Event#eof?} are unused. ## Flags `:exit` : The process has exited. `:fork` : The process has created a child process via `fork(2)` or similar. `:exec` : The process has executed a new process via `exec(2)` or similar. `:signal` : The process was sent a signal. This is only supported under Darwin/OS X. `:reap` : The process was reaped by the parent via `wait(2)` or similar. This is only supported under Darwin/OS X. `:track` : Follow the process across `fork(2)` calls. {Event#flags} for the parent process will contain `:fork`, while {Event#flags} for the child process will contain `:child`. If the system was unable to attach an event to the child process, {Event#flags} will contain `:trackerr`. This is not supported under Darwin/OS X. @param pid [Fixnum] The id of the process. @param flags [Array<Symbol>] Which events to watch for. @yield [event] A block that will be run when the process changes. @yieldparam event [Event] The Event object containing information about the event that occurred. @return [Watcher] The Watcher for this event. @raise [SystemCallError] If something goes wrong when registering the Watcher.
[ "Watches", "a", "process", "for", "changes", ".", "The", "flags", "parameter", "specifies", "which", "changes", "will", "fire", "events", "." ]
f11c1a8552812bc0b635ef9751d6dc61d4beaa67
https://github.com/mat813/rb-kqueue/blob/f11c1a8552812bc0b635ef9751d6dc61d4beaa67/lib/rb-kqueue/queue.rb#L271-L273
train
dagrz/nba_stats
lib/nba_stats/stats/common_team_roster.rb
NbaStats.CommonTeamRoster.common_team_roster
def common_team_roster( team_id, season, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::CommonTeamRoster.new( get(COMMON_TEAM_ROSTER_PATH, { :Season => season, :LeagueID => league_id, :TeamID => team_id }) ) end
ruby
def common_team_roster( team_id, season, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::CommonTeamRoster.new( get(COMMON_TEAM_ROSTER_PATH, { :Season => season, :LeagueID => league_id, :TeamID => team_id }) ) end
[ "def", "common_team_roster", "(", "team_id", ",", "season", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "NbaStats", "::", "Resources", "::", "CommonTeamRoster", ".", "new", "(", "get", "(", "COMMON_TEAM_ROSTER_PATH", ",", "{", ":Season", "=>", "season", ",", ":LeagueID", "=>", "league_id", ",", ":TeamID", "=>", "team_id", "}", ")", ")", "end" ]
Calls the commonteamroster API and returns a CommonTeamRoster resource. @param team_id [Integer] @param season [String] @param league_id [String] @return [NbaStats::Resources::CommonTeamRoster]
[ "Calls", "the", "commonteamroster", "API", "and", "returns", "a", "CommonTeamRoster", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/common_team_roster.rb#L17-L29
train
dcuddeback/rspec-tag_matchers
lib/rspec/tag_matchers/has_input.rb
RSpec::TagMatchers.HasInput.build_name
def build_name(*args) args.extend(DeepFlattening) args = args.deep_flatten name = args.shift.to_s name + args.map {|piece| "[#{piece}]"}.join end
ruby
def build_name(*args) args.extend(DeepFlattening) args = args.deep_flatten name = args.shift.to_s name + args.map {|piece| "[#{piece}]"}.join end
[ "def", "build_name", "(", "*", "args", ")", "args", ".", "extend", "(", "DeepFlattening", ")", "args", "=", "args", ".", "deep_flatten", "name", "=", "args", ".", "shift", ".", "to_s", "name", "+", "args", ".", "map", "{", "|", "piece", "|", "\"[#{piece}]\"", "}", ".", "join", "end" ]
Converts an array or hash of names to a name for an input form. @example build_name(:foo => :bar) # => "foo[bar]" build_name(:foo, :bar) # => "foo[bar]" build_name(:foo => {:bar => :baz}) # => "foo[bar][baz]" build_name(:foo, :bar => :baz) # => "foo[bar][baz]" @param [Array, Hash] args A hierarchy of strings. @return [String] The expected name of the form input.
[ "Converts", "an", "array", "or", "hash", "of", "names", "to", "a", "name", "for", "an", "input", "form", "." ]
6396a833d99ea669699afb1b3dfc62c4512c8882
https://github.com/dcuddeback/rspec-tag_matchers/blob/6396a833d99ea669699afb1b3dfc62c4512c8882/lib/rspec/tag_matchers/has_input.rb#L119-L124
train
dagrz/nba_stats
lib/nba_stats/stats/box_score_advanced.rb
NbaStats.BoxScoreAdvanced.box_score_advanced
def box_score_advanced( game_id, range_type=0, start_period=0, end_period=0, start_range=0, end_range=0 ) NbaStats::Resources::BoxScoreAdvanced.new( get(BOX_SCORE_ADVANCED_PATH, { :GameID => game_id, :RangeType => range_type, :StartPeriod => start_period, :EndPeriod => end_period, :StartRange => start_range, :EndRange => end_range }) ) end
ruby
def box_score_advanced( game_id, range_type=0, start_period=0, end_period=0, start_range=0, end_range=0 ) NbaStats::Resources::BoxScoreAdvanced.new( get(BOX_SCORE_ADVANCED_PATH, { :GameID => game_id, :RangeType => range_type, :StartPeriod => start_period, :EndPeriod => end_period, :StartRange => start_range, :EndRange => end_range }) ) end
[ "def", "box_score_advanced", "(", "game_id", ",", "range_type", "=", "0", ",", "start_period", "=", "0", ",", "end_period", "=", "0", ",", "start_range", "=", "0", ",", "end_range", "=", "0", ")", "NbaStats", "::", "Resources", "::", "BoxScoreAdvanced", ".", "new", "(", "get", "(", "BOX_SCORE_ADVANCED_PATH", ",", "{", ":GameID", "=>", "game_id", ",", ":RangeType", "=>", "range_type", ",", ":StartPeriod", "=>", "start_period", ",", ":EndPeriod", "=>", "end_period", ",", ":StartRange", "=>", "start_range", ",", ":EndRange", "=>", "end_range", "}", ")", ")", "end" ]
Calls the boxscoreadvanced API and returns a BoxScoreAdvanced resource. @param game_id [String] @param range_type [Integer] @param start_period [Integer] @param end_period [Integer] @param start_range [Integer] @param end_range [xxxxxxxxxx] @return [NbaStats::Resources::BoxScoreAdvanced]
[ "Calls", "the", "boxscoreadvanced", "API", "and", "returns", "a", "BoxScoreAdvanced", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/box_score_advanced.rb#L19-L37
train
dagrz/nba_stats
lib/nba_stats/stats/common_all_players.rb
NbaStats.CommonAllPlayers.common_all_players
def common_all_players( season, is_only_current_season=0, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::CommonAllPlayers.new( get(COMMON_ALL_PLAYERS_PATH, { :LeagueID => league_id, :Season => season, :IsOnlyCurrentSeason => is_only_current_season }) ) end
ruby
def common_all_players( season, is_only_current_season=0, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::CommonAllPlayers.new( get(COMMON_ALL_PLAYERS_PATH, { :LeagueID => league_id, :Season => season, :IsOnlyCurrentSeason => is_only_current_season }) ) end
[ "def", "common_all_players", "(", "season", ",", "is_only_current_season", "=", "0", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "NbaStats", "::", "Resources", "::", "CommonAllPlayers", ".", "new", "(", "get", "(", "COMMON_ALL_PLAYERS_PATH", ",", "{", ":LeagueID", "=>", "league_id", ",", ":Season", "=>", "season", ",", ":IsOnlyCurrentSeason", "=>", "is_only_current_season", "}", ")", ")", "end" ]
Calls the commonallplayers API and returns a CommonAllPlayers resource. @param season [String] @param is_only_current_season [Integer] @param league_id [String] @return [NbaStats::Resources::CommonAllPlayers]
[ "Calls", "the", "commonallplayers", "API", "and", "returns", "a", "CommonAllPlayers", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/common_all_players.rb#L17-L29
train
dagrz/nba_stats
lib/nba_stats/stats/team_info_common.rb
NbaStats.TeamInfoCommon.team_info_common
def team_info_common( team_id, season, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::TeamInfoCommon.new( get(TEAM_INFO_COMMON_PATH, { :Season => season, :SeasonType => season_type, :LeagueID => league_id, :TeamID => team_id }) ) end
ruby
def team_info_common( team_id, season, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::TeamInfoCommon.new( get(TEAM_INFO_COMMON_PATH, { :Season => season, :SeasonType => season_type, :LeagueID => league_id, :TeamID => team_id }) ) end
[ "def", "team_info_common", "(", "team_id", ",", "season", ",", "season_type", "=", "NbaStats", "::", "Constants", "::", "SEASON_TYPE_REGULAR", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "NbaStats", "::", "Resources", "::", "TeamInfoCommon", ".", "new", "(", "get", "(", "TEAM_INFO_COMMON_PATH", ",", "{", ":Season", "=>", "season", ",", ":SeasonType", "=>", "season_type", ",", ":LeagueID", "=>", "league_id", ",", ":TeamID", "=>", "team_id", "}", ")", ")", "end" ]
Calls the teaminfocommon API and returns a TeamInfoCommon resource. @param team_id [Integer] @param season [String] @param season_type [String] @param league_id [String] @return [NbaStats::Resources::TeamInfoCommon]
[ "Calls", "the", "teaminfocommon", "API", "and", "returns", "a", "TeamInfoCommon", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/team_info_common.rb#L18-L32
train
dagrz/nba_stats
lib/nba_stats/stats/team_year_by_year_stats.rb
NbaStats.TeamYearByYearStats.team_year_by_year_stats
def team_year_by_year_stats( team_id, season, per_mode=NbaStats::Constants::PER_MODE_TOTALS, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::TeamYearByYearStats.new( get(TEAM_YEAR_BY_YEAR_STATS_PATH, { :LeagueID => league_id, :PerMode => per_mode, :SeasonType => season_type, :TeamID => team_id, :Season => season }) ) end
ruby
def team_year_by_year_stats( team_id, season, per_mode=NbaStats::Constants::PER_MODE_TOTALS, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::TeamYearByYearStats.new( get(TEAM_YEAR_BY_YEAR_STATS_PATH, { :LeagueID => league_id, :PerMode => per_mode, :SeasonType => season_type, :TeamID => team_id, :Season => season }) ) end
[ "def", "team_year_by_year_stats", "(", "team_id", ",", "season", ",", "per_mode", "=", "NbaStats", "::", "Constants", "::", "PER_MODE_TOTALS", ",", "season_type", "=", "NbaStats", "::", "Constants", "::", "SEASON_TYPE_REGULAR", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "NbaStats", "::", "Resources", "::", "TeamYearByYearStats", ".", "new", "(", "get", "(", "TEAM_YEAR_BY_YEAR_STATS_PATH", ",", "{", ":LeagueID", "=>", "league_id", ",", ":PerMode", "=>", "per_mode", ",", ":SeasonType", "=>", "season_type", ",", ":TeamID", "=>", "team_id", ",", ":Season", "=>", "season", "}", ")", ")", "end" ]
Calls the teamyearbyyearstats API and returns a TeamYearByYearStats resource. @param team_id [Integer] @param season [String] @param per_mode [String] @param season_type [String] @param league_id [String] @return [NbaStats::Resources::TeamYearByYearStats]
[ "Calls", "the", "teamyearbyyearstats", "API", "and", "returns", "a", "TeamYearByYearStats", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/team_year_by_year_stats.rb#L18-L34
train
dagrz/nba_stats
lib/nba_stats/stats/box_score_usage.rb
NbaStats.BoxScoreUsage.box_score_usage
def box_score_usage( game_id, range_type=0, start_period=0, end_period=0, start_range=0, end_range=0 ) NbaStats::Resources::BoxScoreUsage.new( get(BOX_SCORE_USAGE_PATH, { :GameID => game_id, :RangeType => range_type, :StartPeriod => start_period, :EndPeriod => end_period, :StartRange => start_range, :EndRange => end_range }) ) end
ruby
def box_score_usage( game_id, range_type=0, start_period=0, end_period=0, start_range=0, end_range=0 ) NbaStats::Resources::BoxScoreUsage.new( get(BOX_SCORE_USAGE_PATH, { :GameID => game_id, :RangeType => range_type, :StartPeriod => start_period, :EndPeriod => end_period, :StartRange => start_range, :EndRange => end_range }) ) end
[ "def", "box_score_usage", "(", "game_id", ",", "range_type", "=", "0", ",", "start_period", "=", "0", ",", "end_period", "=", "0", ",", "start_range", "=", "0", ",", "end_range", "=", "0", ")", "NbaStats", "::", "Resources", "::", "BoxScoreUsage", ".", "new", "(", "get", "(", "BOX_SCORE_USAGE_PATH", ",", "{", ":GameID", "=>", "game_id", ",", ":RangeType", "=>", "range_type", ",", ":StartPeriod", "=>", "start_period", ",", ":EndPeriod", "=>", "end_period", ",", ":StartRange", "=>", "start_range", ",", ":EndRange", "=>", "end_range", "}", ")", ")", "end" ]
Calls the boxscoreusage API and returns a BoxScoreUsage resource. @param game_id [String] @param range_type [Integer] @param start_period [Integer] @param end_period [Integer] @param start_range [Integer] @param end_range [Integer] @return [NbaStats::Resources::BoxScoreUsage]
[ "Calls", "the", "boxscoreusage", "API", "and", "returns", "a", "BoxScoreUsage", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/box_score_usage.rb#L19-L37
train
dagrz/nba_stats
lib/nba_stats/stats/draft_combine_player_anthro.rb
NbaStats.DraftCombinePlayerAnthro.draft_combine_player_anthro
def draft_combine_player_anthro( season_year, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::DraftCombinePlayerAnthro.new( get(DRAFT_COMBINE_PLAYER_ANTHRO_PATH, { :LeagueID => league_id, :SeasonYear => season_year }) ) end
ruby
def draft_combine_player_anthro( season_year, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::DraftCombinePlayerAnthro.new( get(DRAFT_COMBINE_PLAYER_ANTHRO_PATH, { :LeagueID => league_id, :SeasonYear => season_year }) ) end
[ "def", "draft_combine_player_anthro", "(", "season_year", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "NbaStats", "::", "Resources", "::", "DraftCombinePlayerAnthro", ".", "new", "(", "get", "(", "DRAFT_COMBINE_PLAYER_ANTHRO_PATH", ",", "{", ":LeagueID", "=>", "league_id", ",", ":SeasonYear", "=>", "season_year", "}", ")", ")", "end" ]
Calls the draftcombineplayeranthro API and returns a DraftCombinePlayerAnthro resource. @param season_year [String] @param league_id [String] @return [NbaStats::Resources::DraftCombinePlayerAnthro]
[ "Calls", "the", "draftcombineplayeranthro", "API", "and", "returns", "a", "DraftCombinePlayerAnthro", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/draft_combine_player_anthro.rb#L15-L25
train
codez/wagons
lib/wagons/installer.rb
Wagons.Installer.available
def available return @available if defined?(@available) # only keep most recent version in @available @available = [] load_available_specs.each do |spec| if prev = @available.find { |w| w.name == spec.name } if prev.version < spec.version @available.delete(prev) @available << spec end else @available << spec end end @available end
ruby
def available return @available if defined?(@available) # only keep most recent version in @available @available = [] load_available_specs.each do |spec| if prev = @available.find { |w| w.name == spec.name } if prev.version < spec.version @available.delete(prev) @available << spec end else @available << spec end end @available end
[ "def", "available", "return", "@available", "if", "defined?", "(", "@available", ")", "@available", "=", "[", "]", "load_available_specs", ".", "each", "do", "|", "spec", "|", "if", "prev", "=", "@available", ".", "find", "{", "|", "w", "|", "w", ".", "name", "==", "spec", ".", "name", "}", "if", "prev", ".", "version", "<", "spec", ".", "version", "@available", ".", "delete", "(", "prev", ")", "@available", "<<", "spec", "end", "else", "@available", "<<", "spec", "end", "end", "@available", "end" ]
Most recent gem specifications of all wagons available in GEM_HOME.
[ "Most", "recent", "gem", "specifications", "of", "all", "wagons", "available", "in", "GEM_HOME", "." ]
91a6b687e08ceb8c3e054dd6ec36694d4babcd50
https://github.com/codez/wagons/blob/91a6b687e08ceb8c3e054dd6ec36694d4babcd50/lib/wagons/installer.rb#L20-L36
train
codez/wagons
lib/wagons/installer.rb
Wagons.Installer.wagonfile_update
def wagonfile_update(specs) wagonfile_edit(specs) do |spec, content| declaration = "gem '#{spec.name}'" declaration += ", '#{spec.version}'" if include_version_in_wagonfile unless content.sub!(gem_declaration_regexp(spec.name), declaration) content += "\n#{declaration}" end content end end
ruby
def wagonfile_update(specs) wagonfile_edit(specs) do |spec, content| declaration = "gem '#{spec.name}'" declaration += ", '#{spec.version}'" if include_version_in_wagonfile unless content.sub!(gem_declaration_regexp(spec.name), declaration) content += "\n#{declaration}" end content end end
[ "def", "wagonfile_update", "(", "specs", ")", "wagonfile_edit", "(", "specs", ")", "do", "|", "spec", ",", "content", "|", "declaration", "=", "\"gem '#{spec.name}'\"", "declaration", "+=", "\", '#{spec.version}'\"", "if", "include_version_in_wagonfile", "unless", "content", ".", "sub!", "(", "gem_declaration_regexp", "(", "spec", ".", "name", ")", ",", "declaration", ")", "content", "+=", "\"\\n#{declaration}\"", "end", "content", "end", "end" ]
Update the Wagonfile with the given gem specifications.
[ "Update", "the", "Wagonfile", "with", "the", "given", "gem", "specifications", "." ]
91a6b687e08ceb8c3e054dd6ec36694d4babcd50
https://github.com/codez/wagons/blob/91a6b687e08ceb8c3e054dd6ec36694d4babcd50/lib/wagons/installer.rb#L95-L104
train
codez/wagons
lib/wagons/installer.rb
Wagons.Installer.wagonfile_remove
def wagonfile_remove(specs) wagonfile_edit(specs) do |spec, content| content.sub(gem_declaration_regexp(spec.name), '') end end
ruby
def wagonfile_remove(specs) wagonfile_edit(specs) do |spec, content| content.sub(gem_declaration_regexp(spec.name), '') end end
[ "def", "wagonfile_remove", "(", "specs", ")", "wagonfile_edit", "(", "specs", ")", "do", "|", "spec", ",", "content", "|", "content", ".", "sub", "(", "gem_declaration_regexp", "(", "spec", ".", "name", ")", ",", "''", ")", "end", "end" ]
Remove the given gem specifications from the Wagonfile.
[ "Remove", "the", "given", "gem", "specifications", "from", "the", "Wagonfile", "." ]
91a6b687e08ceb8c3e054dd6ec36694d4babcd50
https://github.com/codez/wagons/blob/91a6b687e08ceb8c3e054dd6ec36694d4babcd50/lib/wagons/installer.rb#L107-L111
train
codez/wagons
lib/wagons/installer.rb
Wagons.Installer.check_dependencies
def check_dependencies(specs) missing = check_app_requirement(specs) present = exclude_specs(installed, specs) future = present + specs check_all_dependencies(specs, future, missing) end
ruby
def check_dependencies(specs) missing = check_app_requirement(specs) present = exclude_specs(installed, specs) future = present + specs check_all_dependencies(specs, future, missing) end
[ "def", "check_dependencies", "(", "specs", ")", "missing", "=", "check_app_requirement", "(", "specs", ")", "present", "=", "exclude_specs", "(", "installed", ",", "specs", ")", "future", "=", "present", "+", "specs", "check_all_dependencies", "(", "specs", ",", "future", ",", "missing", ")", "end" ]
Check if all wagon dependencies of the given gem specifications are met by the installed wagons. Returns nil if everything is fine or a string with error messages.
[ "Check", "if", "all", "wagon", "dependencies", "of", "the", "given", "gem", "specifications", "are", "met", "by", "the", "installed", "wagons", ".", "Returns", "nil", "if", "everything", "is", "fine", "or", "a", "string", "with", "error", "messages", "." ]
91a6b687e08ceb8c3e054dd6ec36694d4babcd50
https://github.com/codez/wagons/blob/91a6b687e08ceb8c3e054dd6ec36694d4babcd50/lib/wagons/installer.rb#L116-L123
train
codez/wagons
lib/wagons/installer.rb
Wagons.Installer.check_app_requirement
def check_app_requirement(specs) missing = [] specs.each do |spec| if wagon = wagon_class(spec) unless wagon.app_requirement.satisfied_by?(Wagons.app_version) missing << "#{spec} requires application version #{wagon.app_requirement}" end end end missing end
ruby
def check_app_requirement(specs) missing = [] specs.each do |spec| if wagon = wagon_class(spec) unless wagon.app_requirement.satisfied_by?(Wagons.app_version) missing << "#{spec} requires application version #{wagon.app_requirement}" end end end missing end
[ "def", "check_app_requirement", "(", "specs", ")", "missing", "=", "[", "]", "specs", ".", "each", "do", "|", "spec", "|", "if", "wagon", "=", "wagon_class", "(", "spec", ")", "unless", "wagon", ".", "app_requirement", ".", "satisfied_by?", "(", "Wagons", ".", "app_version", ")", "missing", "<<", "\"#{spec} requires application version #{wagon.app_requirement}\"", "end", "end", "end", "missing", "end" ]
Check if the app requirement of the given gem specifications are met by the current app version. Returns nil if everything is fine or a array with error messages.
[ "Check", "if", "the", "app", "requirement", "of", "the", "given", "gem", "specifications", "are", "met", "by", "the", "current", "app", "version", ".", "Returns", "nil", "if", "everything", "is", "fine", "or", "a", "array", "with", "error", "messages", "." ]
91a6b687e08ceb8c3e054dd6ec36694d4babcd50
https://github.com/codez/wagons/blob/91a6b687e08ceb8c3e054dd6ec36694d4babcd50/lib/wagons/installer.rb#L128-L139
train
codez/wagons
lib/wagons/installer.rb
Wagons.Installer.check_protected
def check_protected(specs) protected = [] specs.each do |spec| msg = Wagons.find(spec.name).protect? protected << msg if msg.is_a?(String) end protected.join("\n").presence end
ruby
def check_protected(specs) protected = [] specs.each do |spec| msg = Wagons.find(spec.name).protect? protected << msg if msg.is_a?(String) end protected.join("\n").presence end
[ "def", "check_protected", "(", "specs", ")", "protected", "=", "[", "]", "specs", ".", "each", "do", "|", "spec", "|", "msg", "=", "Wagons", ".", "find", "(", "spec", ".", "name", ")", ".", "protect?", "protected", "<<", "msg", "if", "msg", ".", "is_a?", "(", "String", ")", "end", "protected", ".", "join", "(", "\"\\n\"", ")", ".", "presence", "end" ]
Checks if the wagons for given gem specifications are protected. Returns nil if everything is fine or a string with error messages.
[ "Checks", "if", "the", "wagons", "for", "given", "gem", "specifications", "are", "protected", ".", "Returns", "nil", "if", "everything", "is", "fine", "or", "a", "string", "with", "error", "messages", "." ]
91a6b687e08ceb8c3e054dd6ec36694d4babcd50
https://github.com/codez/wagons/blob/91a6b687e08ceb8c3e054dd6ec36694d4babcd50/lib/wagons/installer.rb#L151-L158
train
codez/wagons
lib/wagons/installer.rb
Wagons.Installer.specs_from_names
def specs_from_names(names) names.map do |name| spec = available_spec(name) fail "#{name} was not found" if spec.nil? spec end end
ruby
def specs_from_names(names) names.map do |name| spec = available_spec(name) fail "#{name} was not found" if spec.nil? spec end end
[ "def", "specs_from_names", "(", "names", ")", "names", ".", "map", "do", "|", "name", "|", "spec", "=", "available_spec", "(", "name", ")", "fail", "\"#{name} was not found\"", "if", "spec", ".", "nil?", "spec", "end", "end" ]
List of available gem specifications with the given names. Raises an error if a name cannot be found.
[ "List", "of", "available", "gem", "specifications", "with", "the", "given", "names", ".", "Raises", "an", "error", "if", "a", "name", "cannot", "be", "found", "." ]
91a6b687e08ceb8c3e054dd6ec36694d4babcd50
https://github.com/codez/wagons/blob/91a6b687e08ceb8c3e054dd6ec36694d4babcd50/lib/wagons/installer.rb#L162-L168
train
codez/wagons
lib/wagons/installer.rb
Wagons.Installer.exclude_specs
def exclude_specs(full, to_be_excluded) full.clone.delete_if { |s| to_be_excluded.find { |d| s.name == d.name } } end
ruby
def exclude_specs(full, to_be_excluded) full.clone.delete_if { |s| to_be_excluded.find { |d| s.name == d.name } } end
[ "def", "exclude_specs", "(", "full", ",", "to_be_excluded", ")", "full", ".", "clone", ".", "delete_if", "{", "|", "s", "|", "to_be_excluded", ".", "find", "{", "|", "d", "|", "s", ".", "name", "==", "d", ".", "name", "}", "}", "end" ]
Removes all gem specifications with the same name in to_be_excluded from full. Versions are ignored.
[ "Removes", "all", "gem", "specifications", "with", "the", "same", "name", "in", "to_be_excluded", "from", "full", ".", "Versions", "are", "ignored", "." ]
91a6b687e08ceb8c3e054dd6ec36694d4babcd50
https://github.com/codez/wagons/blob/91a6b687e08ceb8c3e054dd6ec36694d4babcd50/lib/wagons/installer.rb#L172-L174
train
codez/wagons
lib/wagons/installer.rb
Wagons.Installer.wagon_class
def wagon_class(spec) @wagon_classes ||= {} return @wagon_classes[spec] if @wagon_classes.key?(spec) clazz = nil file = File.join(spec.gem_dir, 'lib', spec.name, 'wagon.rb') if File.exist?(file) require file clazz = "#{spec.name.camelize}::Wagon".constantize else fail "#{spec.name} wagon class not found in #{file}" end @wagon_classes[spec] = clazz end
ruby
def wagon_class(spec) @wagon_classes ||= {} return @wagon_classes[spec] if @wagon_classes.key?(spec) clazz = nil file = File.join(spec.gem_dir, 'lib', spec.name, 'wagon.rb') if File.exist?(file) require file clazz = "#{spec.name.camelize}::Wagon".constantize else fail "#{spec.name} wagon class not found in #{file}" end @wagon_classes[spec] = clazz end
[ "def", "wagon_class", "(", "spec", ")", "@wagon_classes", "||=", "{", "}", "return", "@wagon_classes", "[", "spec", "]", "if", "@wagon_classes", ".", "key?", "(", "spec", ")", "clazz", "=", "nil", "file", "=", "File", ".", "join", "(", "spec", ".", "gem_dir", ",", "'lib'", ",", "spec", ".", "name", ",", "'wagon.rb'", ")", "if", "File", ".", "exist?", "(", "file", ")", "require", "file", "clazz", "=", "\"#{spec.name.camelize}::Wagon\"", ".", "constantize", "else", "fail", "\"#{spec.name} wagon class not found in #{file}\"", "end", "@wagon_classes", "[", "spec", "]", "=", "clazz", "end" ]
The wagon class of the given spec.
[ "The", "wagon", "class", "of", "the", "given", "spec", "." ]
91a6b687e08ceb8c3e054dd6ec36694d4babcd50
https://github.com/codez/wagons/blob/91a6b687e08ceb8c3e054dd6ec36694d4babcd50/lib/wagons/installer.rb#L182-L195
train
dagrz/nba_stats
lib/nba_stats/stats/common_player_info.rb
NbaStats.CommonPlayerInfo.common_player_info
def common_player_info( player_id, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::CommonPlayerInfo.new( get(COMMON_PLAYER_INFO_PATH, { :PlayerID => player_id, :SeasonType => season_type, :LeagueID => league_id }) ) end
ruby
def common_player_info( player_id, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::CommonPlayerInfo.new( get(COMMON_PLAYER_INFO_PATH, { :PlayerID => player_id, :SeasonType => season_type, :LeagueID => league_id }) ) end
[ "def", "common_player_info", "(", "player_id", ",", "season_type", "=", "NbaStats", "::", "Constants", "::", "SEASON_TYPE_REGULAR", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "NbaStats", "::", "Resources", "::", "CommonPlayerInfo", ".", "new", "(", "get", "(", "COMMON_PLAYER_INFO_PATH", ",", "{", ":PlayerID", "=>", "player_id", ",", ":SeasonType", "=>", "season_type", ",", ":LeagueID", "=>", "league_id", "}", ")", ")", "end" ]
Calls the commonplayerinfo API and returns a CommonPlayerInfo resource. @param player_id [Integer] @param season_type [String] @param league_id [String] @return [NbaStats::Resources::CommonPlayerInfo]
[ "Calls", "the", "commonplayerinfo", "API", "and", "returns", "a", "CommonPlayerInfo", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/common_player_info.rb#L17-L29
train
dagrz/nba_stats
lib/nba_stats/stats/franchise_history.rb
NbaStats.FranchiseHistory.franchise_history
def franchise_history( league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::FranchiseHistory.new( get(FRANCHISE_HISTORY_PATH, { :LeagueID => league_id }) ) end
ruby
def franchise_history( league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::FranchiseHistory.new( get(FRANCHISE_HISTORY_PATH, { :LeagueID => league_id }) ) end
[ "def", "franchise_history", "(", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "NbaStats", "::", "Resources", "::", "FranchiseHistory", ".", "new", "(", "get", "(", "FRANCHISE_HISTORY_PATH", ",", "{", ":LeagueID", "=>", "league_id", "}", ")", ")", "end" ]
Calls the franchisehistory API and returns a FranchiseHistory resource. @param league_id [String] @return [NbaStats::Resources::FranchiseHistory]
[ "Calls", "the", "franchisehistory", "API", "and", "returns", "a", "FranchiseHistory", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/franchise_history.rb#L14-L22
train
dagrz/nba_stats
lib/nba_stats/stats/league_dash_lineups.rb
NbaStats.LeagueDashLineups.league_dash_lineups
def league_dash_lineups( season, group_quantity=5, measure_type=NbaStats::Constants::MEASURE_TYPE_BASE, per_mode=NbaStats::Constants::PER_MODE_GAME, plus_minus=NbaStats::Constants::NO, pace_adjust=NbaStats::Constants::NO, rank=NbaStats::Constants::NO, outcome='', location='', month=0, season_segment='', date_from='', date_to='', opponent_team_id=0, vs_conference='', vs_division='', game_segment='', period=0, last_n_games=0, game_id='', season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) unless date_from.nil? or date_from.empty? date_from = date_from.strftime('%m-%d-%Y') end unless date_to.nil? or date_to.empty? date_to = date_to.strftime('%m-%d-%Y') end NbaStats::Resources::LeagueDashLineups.new( get(LEAGUE_DASH_LINEUPS_PATH, { :DateFrom => date_from, :DateTo => date_to, :GameID => game_id, :GameSegment => game_segment, :GroupQuantity => group_quantity, :LastNGames => last_n_games, :LeagueID => league_id, :Location => location, :MeasureType => measure_type, :Month => month, :OpponentTeamID => opponent_team_id, :Outcome => outcome, :PaceAdjust => pace_adjust, :PerMode => per_mode, :Period => period, :PlusMinus => plus_minus, :Rank => rank, :Season => season, :SeasonSegment => season_segment, :SeasonType => season_type, :VsConference => vs_conference, :VsDivision => vs_division }) ) end
ruby
def league_dash_lineups( season, group_quantity=5, measure_type=NbaStats::Constants::MEASURE_TYPE_BASE, per_mode=NbaStats::Constants::PER_MODE_GAME, plus_minus=NbaStats::Constants::NO, pace_adjust=NbaStats::Constants::NO, rank=NbaStats::Constants::NO, outcome='', location='', month=0, season_segment='', date_from='', date_to='', opponent_team_id=0, vs_conference='', vs_division='', game_segment='', period=0, last_n_games=0, game_id='', season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) unless date_from.nil? or date_from.empty? date_from = date_from.strftime('%m-%d-%Y') end unless date_to.nil? or date_to.empty? date_to = date_to.strftime('%m-%d-%Y') end NbaStats::Resources::LeagueDashLineups.new( get(LEAGUE_DASH_LINEUPS_PATH, { :DateFrom => date_from, :DateTo => date_to, :GameID => game_id, :GameSegment => game_segment, :GroupQuantity => group_quantity, :LastNGames => last_n_games, :LeagueID => league_id, :Location => location, :MeasureType => measure_type, :Month => month, :OpponentTeamID => opponent_team_id, :Outcome => outcome, :PaceAdjust => pace_adjust, :PerMode => per_mode, :Period => period, :PlusMinus => plus_minus, :Rank => rank, :Season => season, :SeasonSegment => season_segment, :SeasonType => season_type, :VsConference => vs_conference, :VsDivision => vs_division }) ) end
[ "def", "league_dash_lineups", "(", "season", ",", "group_quantity", "=", "5", ",", "measure_type", "=", "NbaStats", "::", "Constants", "::", "MEASURE_TYPE_BASE", ",", "per_mode", "=", "NbaStats", "::", "Constants", "::", "PER_MODE_GAME", ",", "plus_minus", "=", "NbaStats", "::", "Constants", "::", "NO", ",", "pace_adjust", "=", "NbaStats", "::", "Constants", "::", "NO", ",", "rank", "=", "NbaStats", "::", "Constants", "::", "NO", ",", "outcome", "=", "''", ",", "location", "=", "''", ",", "month", "=", "0", ",", "season_segment", "=", "''", ",", "date_from", "=", "''", ",", "date_to", "=", "''", ",", "opponent_team_id", "=", "0", ",", "vs_conference", "=", "''", ",", "vs_division", "=", "''", ",", "game_segment", "=", "''", ",", "period", "=", "0", ",", "last_n_games", "=", "0", ",", "game_id", "=", "''", ",", "season_type", "=", "NbaStats", "::", "Constants", "::", "SEASON_TYPE_REGULAR", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "unless", "date_from", ".", "nil?", "or", "date_from", ".", "empty?", "date_from", "=", "date_from", ".", "strftime", "(", "'%m-%d-%Y'", ")", "end", "unless", "date_to", ".", "nil?", "or", "date_to", ".", "empty?", "date_to", "=", "date_to", ".", "strftime", "(", "'%m-%d-%Y'", ")", "end", "NbaStats", "::", "Resources", "::", "LeagueDashLineups", ".", "new", "(", "get", "(", "LEAGUE_DASH_LINEUPS_PATH", ",", "{", ":DateFrom", "=>", "date_from", ",", ":DateTo", "=>", "date_to", ",", ":GameID", "=>", "game_id", ",", ":GameSegment", "=>", "game_segment", ",", ":GroupQuantity", "=>", "group_quantity", ",", ":LastNGames", "=>", "last_n_games", ",", ":LeagueID", "=>", "league_id", ",", ":Location", "=>", "location", ",", ":MeasureType", "=>", "measure_type", ",", ":Month", "=>", "month", ",", ":OpponentTeamID", "=>", "opponent_team_id", ",", ":Outcome", "=>", "outcome", ",", ":PaceAdjust", "=>", "pace_adjust", ",", ":PerMode", "=>", "per_mode", ",", ":Period", "=>", "period", ",", ":PlusMinus", "=>", "plus_minus", ",", ":Rank", "=>", "rank", ",", ":Season", "=>", "season", ",", ":SeasonSegment", "=>", "season_segment", ",", ":SeasonType", "=>", "season_type", ",", ":VsConference", "=>", "vs_conference", ",", ":VsDivision", "=>", "vs_division", "}", ")", ")", "end" ]
Calls the leaguedashlineups API and returns a LeagueDashLineups resource. @param season [String] @param group_quantity [Integer] @param measure_type [String] @param per_mode [String] @param plus_minus [String] @param pace_adjust [String] @param rank [String] @param outcome [String] @param location [String] @param month [Integer] @param season_segment [String] @param date_from [Date] @param date_to [Date] @param opponent_team_id [Integer] @param vs_conference [String] @param vs_division [String] @param game_segment [String] @param period [Integer] @param last_n_games [Integer] @param game_id [String] @param season_type [String] @param league_id [String] @return [NbaStats::Resources::LeagueDashLineups]
[ "Calls", "the", "leaguedashlineups", "API", "and", "returns", "a", "LeagueDashLineups", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/league_dash_lineups.rb#L35-L91
train
codez/wagons
lib/wagons/extensions/application.rb
Rails.Application.ordered_railties_with_wagons
def ordered_railties_with_wagons @ordered_railties ||= ordered_railties_without_wagons.tap do |ordered| flat = Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('4.1.6') Wagons.all.each do |w| if flat ordered.push(ordered.delete(w)) else ordered.unshift(array_deep_delete(ordered, w)) end end end end
ruby
def ordered_railties_with_wagons @ordered_railties ||= ordered_railties_without_wagons.tap do |ordered| flat = Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('4.1.6') Wagons.all.each do |w| if flat ordered.push(ordered.delete(w)) else ordered.unshift(array_deep_delete(ordered, w)) end end end end
[ "def", "ordered_railties_with_wagons", "@ordered_railties", "||=", "ordered_railties_without_wagons", ".", "tap", "do", "|", "ordered", "|", "flat", "=", "Gem", "::", "Version", ".", "new", "(", "Rails", "::", "VERSION", "::", "STRING", ")", "<", "Gem", "::", "Version", ".", "new", "(", "'4.1.6'", ")", "Wagons", ".", "all", ".", "each", "do", "|", "w", "|", "if", "flat", "ordered", ".", "push", "(", "ordered", ".", "delete", "(", "w", ")", ")", "else", "ordered", ".", "unshift", "(", "array_deep_delete", "(", "ordered", ",", "w", ")", ")", "end", "end", "end", "end" ]
Append wagons at the end of all railties, even after the application.
[ "Append", "wagons", "at", "the", "end", "of", "all", "railties", "even", "after", "the", "application", "." ]
91a6b687e08ceb8c3e054dd6ec36694d4babcd50
https://github.com/codez/wagons/blob/91a6b687e08ceb8c3e054dd6ec36694d4babcd50/lib/wagons/extensions/application.rb#L6-L17
train
dagrz/nba_stats
lib/nba_stats/stats/home_page_leaders.rb
NbaStats.HomePageLeaders.home_page_leaders
def home_page_leaders( season, game_scope=NbaStats::Constants::GAME_SCOPE_SEASON, stat_category=NbaStats::Constants::STAT_CATEGORY_POINTS, player_scope=NbaStats::Constants::PLAYER_SCOPE_ALL_PLAYERS, player_or_team=NbaStats::Constants::PLAYER_OR_TEAM_PLAYER, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::HomePageLeaders.new( get(HOME_PAGE_LEADERS_PATH, { :Season => season, :SeasonType => season_type, :LeagueID => league_id, :GameScope => game_scope, :StatCategory => stat_category, :PlayerScope => player_scope, :PlayerOrTeam => player_or_team }) ) end
ruby
def home_page_leaders( season, game_scope=NbaStats::Constants::GAME_SCOPE_SEASON, stat_category=NbaStats::Constants::STAT_CATEGORY_POINTS, player_scope=NbaStats::Constants::PLAYER_SCOPE_ALL_PLAYERS, player_or_team=NbaStats::Constants::PLAYER_OR_TEAM_PLAYER, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::HomePageLeaders.new( get(HOME_PAGE_LEADERS_PATH, { :Season => season, :SeasonType => season_type, :LeagueID => league_id, :GameScope => game_scope, :StatCategory => stat_category, :PlayerScope => player_scope, :PlayerOrTeam => player_or_team }) ) end
[ "def", "home_page_leaders", "(", "season", ",", "game_scope", "=", "NbaStats", "::", "Constants", "::", "GAME_SCOPE_SEASON", ",", "stat_category", "=", "NbaStats", "::", "Constants", "::", "STAT_CATEGORY_POINTS", ",", "player_scope", "=", "NbaStats", "::", "Constants", "::", "PLAYER_SCOPE_ALL_PLAYERS", ",", "player_or_team", "=", "NbaStats", "::", "Constants", "::", "PLAYER_OR_TEAM_PLAYER", ",", "season_type", "=", "NbaStats", "::", "Constants", "::", "SEASON_TYPE_REGULAR", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "NbaStats", "::", "Resources", "::", "HomePageLeaders", ".", "new", "(", "get", "(", "HOME_PAGE_LEADERS_PATH", ",", "{", ":Season", "=>", "season", ",", ":SeasonType", "=>", "season_type", ",", ":LeagueID", "=>", "league_id", ",", ":GameScope", "=>", "game_scope", ",", ":StatCategory", "=>", "stat_category", ",", ":PlayerScope", "=>", "player_scope", ",", ":PlayerOrTeam", "=>", "player_or_team", "}", ")", ")", "end" ]
Calls the homepageleaders API and returns a HomePageLeaders resource. @param season [String] @param season_type [String] @param league_id [String] @param game_scope [String] @param stat_category [String] @param player_scope [String] @param player_or_team [String] @return [NbaStats::Resources::HomePageLeaders]
[ "Calls", "the", "homepageleaders", "API", "and", "returns", "a", "HomePageLeaders", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/home_page_leaders.rb#L20-L40
train
dagrz/nba_stats
lib/nba_stats/stats/team_game_log.rb
NbaStats.TeamGameLog.team_game_log
def team_game_log( team_id, season, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::TeamGameLog.new( get(TEAM_GAME_LOG_PATH, { :Season => season, :SeasonType => season_type, :LeagueID => league_id, :TeamID => team_id }) ) end
ruby
def team_game_log( team_id, season, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::TeamGameLog.new( get(TEAM_GAME_LOG_PATH, { :Season => season, :SeasonType => season_type, :LeagueID => league_id, :TeamID => team_id }) ) end
[ "def", "team_game_log", "(", "team_id", ",", "season", ",", "season_type", "=", "NbaStats", "::", "Constants", "::", "SEASON_TYPE_REGULAR", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "NbaStats", "::", "Resources", "::", "TeamGameLog", ".", "new", "(", "get", "(", "TEAM_GAME_LOG_PATH", ",", "{", ":Season", "=>", "season", ",", ":SeasonType", "=>", "season_type", ",", ":LeagueID", "=>", "league_id", ",", ":TeamID", "=>", "team_id", "}", ")", ")", "end" ]
Calls the teamgamelog API and returns a TeamGameLog resource. @param team_id [Integer] @param season [String] @param season_type [String] @param league_id [String] @return [NbaStats::Resources::TeamGameLog]
[ "Calls", "the", "teamgamelog", "API", "and", "returns", "a", "TeamGameLog", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/team_game_log.rb#L18-L32
train
dagrz/nba_stats
lib/nba_stats/stats/box_score_scoring.rb
NbaStats.BoxScoreScoring.box_score_scoring
def box_score_scoring( game_id, range_type=0, start_period=0, end_period=0, start_range=0, end_range=0 ) NbaStats::Resources::BoxScoreScoring.new( get(BOX_SCORE_SCORING_PATH, { :GameID => game_id, :RangeType => range_type, :StartPeriod => start_period, :EndPeriod => end_period, :StartRange => start_range, :EndRange => end_range }) ) end
ruby
def box_score_scoring( game_id, range_type=0, start_period=0, end_period=0, start_range=0, end_range=0 ) NbaStats::Resources::BoxScoreScoring.new( get(BOX_SCORE_SCORING_PATH, { :GameID => game_id, :RangeType => range_type, :StartPeriod => start_period, :EndPeriod => end_period, :StartRange => start_range, :EndRange => end_range }) ) end
[ "def", "box_score_scoring", "(", "game_id", ",", "range_type", "=", "0", ",", "start_period", "=", "0", ",", "end_period", "=", "0", ",", "start_range", "=", "0", ",", "end_range", "=", "0", ")", "NbaStats", "::", "Resources", "::", "BoxScoreScoring", ".", "new", "(", "get", "(", "BOX_SCORE_SCORING_PATH", ",", "{", ":GameID", "=>", "game_id", ",", ":RangeType", "=>", "range_type", ",", ":StartPeriod", "=>", "start_period", ",", ":EndPeriod", "=>", "end_period", ",", ":StartRange", "=>", "start_range", ",", ":EndRange", "=>", "end_range", "}", ")", ")", "end" ]
Calls the boxscorescoring API and returns a BoxScoreScoring resource. @param game_id [String] @param range_type [Integer] @param start_period [Integer] @param end_period [Integer] @param start_range [Integer] @param end_range [Integer] @return [NbaStats::Resources::BoxScoreScoring]
[ "Calls", "the", "boxscorescoring", "API", "and", "returns", "a", "BoxScoreScoring", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/box_score_scoring.rb#L19-L37
train
dagrz/nba_stats
lib/nba_stats/stats/draft_combine_spot_shooting.rb
NbaStats.DraftCombineSpotShooting.draft_combine_spot_shooting
def draft_combine_spot_shooting( season_year, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::DraftCombineSpotShooting.new( get(DRAFT_COMBINE_SPOT_SHOOTING_PATH, { :LeagueID => league_id, :SeasonYear => season_year }) ) end
ruby
def draft_combine_spot_shooting( season_year, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::DraftCombineSpotShooting.new( get(DRAFT_COMBINE_SPOT_SHOOTING_PATH, { :LeagueID => league_id, :SeasonYear => season_year }) ) end
[ "def", "draft_combine_spot_shooting", "(", "season_year", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "NbaStats", "::", "Resources", "::", "DraftCombineSpotShooting", ".", "new", "(", "get", "(", "DRAFT_COMBINE_SPOT_SHOOTING_PATH", ",", "{", ":LeagueID", "=>", "league_id", ",", ":SeasonYear", "=>", "season_year", "}", ")", ")", "end" ]
Calls the draftcombinespotshooting API and returns a DraftCombineSpotShooting resource. @param season_year [String] @param league_id [String] @return [NbaStats::Resources::DraftCombineSpotShooting]
[ "Calls", "the", "draftcombinespotshooting", "API", "and", "returns", "a", "DraftCombineSpotShooting", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/draft_combine_spot_shooting.rb#L15-L25
train
dagrz/nba_stats
lib/nba_stats/stats/common_team_years.rb
NbaStats.CommonTeamYears.common_team_years
def common_team_years( league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::CommonTeamYears.new( get(COMMON_TEAM_YEARS_PATH, { :LeagueID => league_id }) ) end
ruby
def common_team_years( league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::CommonTeamYears.new( get(COMMON_TEAM_YEARS_PATH, { :LeagueID => league_id }) ) end
[ "def", "common_team_years", "(", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "NbaStats", "::", "Resources", "::", "CommonTeamYears", ".", "new", "(", "get", "(", "COMMON_TEAM_YEARS_PATH", ",", "{", ":LeagueID", "=>", "league_id", "}", ")", ")", "end" ]
Calls the commonteamyears API and returns a CommonTeamYears resource. @param league_id [String] @return [NbaStats::Resources::CommonTeamYears]
[ "Calls", "the", "commonteamyears", "API", "and", "returns", "a", "CommonTeamYears", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/common_team_years.rb#L14-L22
train
forcedotcom/salesforce-deskcom-api
lib/desk_api/client.rb
DeskApi.Client.request
def request(method, path, params = {}, &block) connection.send(method, path, params, &block) rescue Faraday::Error::ClientError => err raise DeskApi::Error::ClientError.new(err) rescue JSON::ParserError => err raise DeskApi::Error::ParserError.new(err) end
ruby
def request(method, path, params = {}, &block) connection.send(method, path, params, &block) rescue Faraday::Error::ClientError => err raise DeskApi::Error::ClientError.new(err) rescue JSON::ParserError => err raise DeskApi::Error::ParserError.new(err) end
[ "def", "request", "(", "method", ",", "path", ",", "params", "=", "{", "}", ",", "&", "block", ")", "connection", ".", "send", "(", "method", ",", "path", ",", "params", ",", "&", "block", ")", "rescue", "Faraday", "::", "Error", "::", "ClientError", "=>", "err", "raise", "DeskApi", "::", "Error", "::", "ClientError", ".", "new", "(", "err", ")", "rescue", "JSON", "::", "ParserError", "=>", "err", "raise", "DeskApi", "::", "Error", "::", "ParserError", ".", "new", "(", "err", ")", "end" ]
Hands off the request to Faraday for further processing @param method [Symbol] the http method to call @param path [String] the url path to the resource @param params [Hash] optional additional url params @yield [Faraday::Response] for further request customizations. @return [Faraday::Response] @raises [DeskApi::Error::ClientError] @raises [DeskApi::Error::ParserError]
[ "Hands", "off", "the", "request", "to", "Faraday", "for", "further", "processing" ]
af1080459215d4cb769e785656bcee1d56696f95
https://github.com/forcedotcom/salesforce-deskcom-api/blob/af1080459215d4cb769e785656bcee1d56696f95/lib/desk_api/client.rb#L104-L110
train
dagrz/nba_stats
lib/nba_stats/stats/shot_chart_detail.rb
NbaStats.ShotChartDetail.shot_chart_detail
def shot_chart_detail( season, team_id, player_id, game_id=nil, outcome=nil, location=nil, month=0, season_segment=nil, date_from=nil, date_to=nil, opponent_team_id=0, vs_conference=nil, vs_division=nil, position=nil, rookie_year=nil, game_segment=nil, period=0, last_n_games=0, context_filter=nil, context_measure=NbaStats::Constants::CONTEXT_MEASURE_FG_PCT, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) unless date_from.nil? date_from = date_from.strftime('%m-%d-%Y') end unless date_to.nil? date_to = date_to.strftime('%m-%d-%Y') end NbaStats::Resources::ShotChartDetail.new( get(SHOT_CHART_DETAIL_PATH, { :Season => season, :SeasonType => season_type, :LeagueID => league_id, :TeamID => team_id, :PlayerID => player_id, :GameID => game_id, :Outcome => outcome, :Location => location, :Month => month, :SeasonSegment => season_segment, :DateFrom => date_from, :DateTo => date_to, :OpponentTeamID => opponent_team_id, :VsConference => vs_conference, :VsDivision => vs_division, :Position => position, :RookieYear => rookie_year, :GameSegment => game_segment, :Period => period, :LastNGames => last_n_games, :ContextFilter => context_filter, :ContextMeasure => context_measure }) ) end
ruby
def shot_chart_detail( season, team_id, player_id, game_id=nil, outcome=nil, location=nil, month=0, season_segment=nil, date_from=nil, date_to=nil, opponent_team_id=0, vs_conference=nil, vs_division=nil, position=nil, rookie_year=nil, game_segment=nil, period=0, last_n_games=0, context_filter=nil, context_measure=NbaStats::Constants::CONTEXT_MEASURE_FG_PCT, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) unless date_from.nil? date_from = date_from.strftime('%m-%d-%Y') end unless date_to.nil? date_to = date_to.strftime('%m-%d-%Y') end NbaStats::Resources::ShotChartDetail.new( get(SHOT_CHART_DETAIL_PATH, { :Season => season, :SeasonType => season_type, :LeagueID => league_id, :TeamID => team_id, :PlayerID => player_id, :GameID => game_id, :Outcome => outcome, :Location => location, :Month => month, :SeasonSegment => season_segment, :DateFrom => date_from, :DateTo => date_to, :OpponentTeamID => opponent_team_id, :VsConference => vs_conference, :VsDivision => vs_division, :Position => position, :RookieYear => rookie_year, :GameSegment => game_segment, :Period => period, :LastNGames => last_n_games, :ContextFilter => context_filter, :ContextMeasure => context_measure }) ) end
[ "def", "shot_chart_detail", "(", "season", ",", "team_id", ",", "player_id", ",", "game_id", "=", "nil", ",", "outcome", "=", "nil", ",", "location", "=", "nil", ",", "month", "=", "0", ",", "season_segment", "=", "nil", ",", "date_from", "=", "nil", ",", "date_to", "=", "nil", ",", "opponent_team_id", "=", "0", ",", "vs_conference", "=", "nil", ",", "vs_division", "=", "nil", ",", "position", "=", "nil", ",", "rookie_year", "=", "nil", ",", "game_segment", "=", "nil", ",", "period", "=", "0", ",", "last_n_games", "=", "0", ",", "context_filter", "=", "nil", ",", "context_measure", "=", "NbaStats", "::", "Constants", "::", "CONTEXT_MEASURE_FG_PCT", ",", "season_type", "=", "NbaStats", "::", "Constants", "::", "SEASON_TYPE_REGULAR", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "unless", "date_from", ".", "nil?", "date_from", "=", "date_from", ".", "strftime", "(", "'%m-%d-%Y'", ")", "end", "unless", "date_to", ".", "nil?", "date_to", "=", "date_to", ".", "strftime", "(", "'%m-%d-%Y'", ")", "end", "NbaStats", "::", "Resources", "::", "ShotChartDetail", ".", "new", "(", "get", "(", "SHOT_CHART_DETAIL_PATH", ",", "{", ":Season", "=>", "season", ",", ":SeasonType", "=>", "season_type", ",", ":LeagueID", "=>", "league_id", ",", ":TeamID", "=>", "team_id", ",", ":PlayerID", "=>", "player_id", ",", ":GameID", "=>", "game_id", ",", ":Outcome", "=>", "outcome", ",", ":Location", "=>", "location", ",", ":Month", "=>", "month", ",", ":SeasonSegment", "=>", "season_segment", ",", ":DateFrom", "=>", "date_from", ",", ":DateTo", "=>", "date_to", ",", ":OpponentTeamID", "=>", "opponent_team_id", ",", ":VsConference", "=>", "vs_conference", ",", ":VsDivision", "=>", "vs_division", ",", ":Position", "=>", "position", ",", ":RookieYear", "=>", "rookie_year", ",", ":GameSegment", "=>", "game_segment", ",", ":Period", "=>", "period", ",", ":LastNGames", "=>", "last_n_games", ",", ":ContextFilter", "=>", "context_filter", ",", ":ContextMeasure", "=>", "context_measure", "}", ")", ")", "end" ]
Calls the shotchartdetail API and returns a ShotChartDetail resource. @param season [String] @param team_id [Integer] @param player_id [Integer] @param game_id [String] @param outcome [String] @param location [String] @param month [Integer] @param season_segment [String] @param date_from [Date] @param date_to [Date] @param opponent_team_id [Integer] @param vs_conference [String] @param vs_division [String] @param position [String] @param rookie_year [String] @param game_segment [String] @param period [Integer] @param last_n_games [Integer] @param context_filter [String] @param context_measure [String] @param season_type [String] @param league_id [String] @return [NbaStats::Resources::ShotChartDetail]
[ "Calls", "the", "shotchartdetail", "API", "and", "returns", "a", "ShotChartDetail", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/shot_chart_detail.rb#L35-L91
train
forcedotcom/salesforce-deskcom-api
lib/desk_api/configuration.rb
DeskApi.Configuration.middleware
def middleware @middleware ||= proc do |builder| builder.request(:desk_encode_dates) builder.request(:desk_encode_json) builder.request(*authorize_request) builder.request(:desk_retry) builder.response(:desk_parse_dates) builder.response(:desk_follow_redirects) builder.response(:desk_raise_error, DeskApi::Error::ClientError) builder.response(:desk_raise_error, DeskApi::Error::ServerError) builder.response(:desk_parse_json) builder.adapter(Faraday.default_adapter) end end
ruby
def middleware @middleware ||= proc do |builder| builder.request(:desk_encode_dates) builder.request(:desk_encode_json) builder.request(*authorize_request) builder.request(:desk_retry) builder.response(:desk_parse_dates) builder.response(:desk_follow_redirects) builder.response(:desk_raise_error, DeskApi::Error::ClientError) builder.response(:desk_raise_error, DeskApi::Error::ServerError) builder.response(:desk_parse_json) builder.adapter(Faraday.default_adapter) end end
[ "def", "middleware", "@middleware", "||=", "proc", "do", "|", "builder", "|", "builder", ".", "request", "(", ":desk_encode_dates", ")", "builder", ".", "request", "(", ":desk_encode_json", ")", "builder", ".", "request", "(", "*", "authorize_request", ")", "builder", ".", "request", "(", ":desk_retry", ")", "builder", ".", "response", "(", ":desk_parse_dates", ")", "builder", ".", "response", "(", ":desk_follow_redirects", ")", "builder", ".", "response", "(", ":desk_raise_error", ",", "DeskApi", "::", "Error", "::", "ClientError", ")", "builder", ".", "response", "(", ":desk_raise_error", ",", "DeskApi", "::", "Error", "::", "ServerError", ")", "builder", ".", "response", "(", ":desk_parse_json", ")", "builder", ".", "adapter", "(", "Faraday", ".", "default_adapter", ")", "end", "end" ]
Returns the middleware proc to be used by Faraday @return [Proc]
[ "Returns", "the", "middleware", "proc", "to", "be", "used", "by", "Faraday" ]
af1080459215d4cb769e785656bcee1d56696f95
https://github.com/forcedotcom/salesforce-deskcom-api/blob/af1080459215d4cb769e785656bcee1d56696f95/lib/desk_api/configuration.rb#L109-L124
train
forcedotcom/salesforce-deskcom-api
lib/desk_api/configuration.rb
DeskApi.Configuration.reset!
def reset! DeskApi::Configuration.keys.each do |key| send("#{key}=", DeskApi::Default.options[key]) end self end
ruby
def reset! DeskApi::Configuration.keys.each do |key| send("#{key}=", DeskApi::Default.options[key]) end self end
[ "def", "reset!", "DeskApi", "::", "Configuration", ".", "keys", ".", "each", "do", "|", "key", "|", "send", "(", "\"#{key}=\"", ",", "DeskApi", "::", "Default", ".", "options", "[", "key", "]", ")", "end", "self", "end" ]
Resets the client to the default settings. @return [DeskApi::Client]
[ "Resets", "the", "client", "to", "the", "default", "settings", "." ]
af1080459215d4cb769e785656bcee1d56696f95
https://github.com/forcedotcom/salesforce-deskcom-api/blob/af1080459215d4cb769e785656bcee1d56696f95/lib/desk_api/configuration.rb#L140-L145
train
forcedotcom/salesforce-deskcom-api
lib/desk_api/configuration.rb
DeskApi.Configuration.validate_credentials!
def validate_credentials! fail( DeskApi::Error::ConfigurationError, 'Invalid credentials: ' \ 'Either username/password or OAuth credentials must be specified.' ) unless credentials? validate_oauth! if oauth.values.all? validate_basic_auth! if basic_auth.values.all? end
ruby
def validate_credentials! fail( DeskApi::Error::ConfigurationError, 'Invalid credentials: ' \ 'Either username/password or OAuth credentials must be specified.' ) unless credentials? validate_oauth! if oauth.values.all? validate_basic_auth! if basic_auth.values.all? end
[ "def", "validate_credentials!", "fail", "(", "DeskApi", "::", "Error", "::", "ConfigurationError", ",", "'Invalid credentials: '", "'Either username/password or OAuth credentials must be specified.'", ")", "unless", "credentials?", "validate_oauth!", "if", "oauth", ".", "values", ".", "all?", "validate_basic_auth!", "if", "basic_auth", ".", "values", ".", "all?", "end" ]
Raises an error if credentials are not set or of the wrong type. @raise [DeskApi::Error::ConfigurationError]
[ "Raises", "an", "error", "if", "credentials", "are", "not", "set", "or", "of", "the", "wrong", "type", "." ]
af1080459215d4cb769e785656bcee1d56696f95
https://github.com/forcedotcom/salesforce-deskcom-api/blob/af1080459215d4cb769e785656bcee1d56696f95/lib/desk_api/configuration.rb#L207-L215
train
domitry/mikon
lib/mikon/pivot.rb
Mikon.DataFrame.pivot
def pivot(args={}) args = { column: nil, row: nil, value: nil, fill_value: Float::NAN }.merge(args) raise ArgumentError unless [:column, :row, :value].all?{|sym| args[sym].is_a?(Symbol)} column = self[args[:column]].factors index = self[args[:row]].factors source = column.reduce({}) do |memo, label| arr = [] df = self.select{|row| row[args[:column]] == label} index.each do |i| unless df.any?{|row| row[args[:row]] == i} arr.push(args[:fill_value]) else column = df.select{|row| row[args[:row]] == i}[args[:value]] arr.push(column.to_a[0]) end end memo[label] = arr memo end Mikon::DataFrame.new(source, index: index) end
ruby
def pivot(args={}) args = { column: nil, row: nil, value: nil, fill_value: Float::NAN }.merge(args) raise ArgumentError unless [:column, :row, :value].all?{|sym| args[sym].is_a?(Symbol)} column = self[args[:column]].factors index = self[args[:row]].factors source = column.reduce({}) do |memo, label| arr = [] df = self.select{|row| row[args[:column]] == label} index.each do |i| unless df.any?{|row| row[args[:row]] == i} arr.push(args[:fill_value]) else column = df.select{|row| row[args[:row]] == i}[args[:value]] arr.push(column.to_a[0]) end end memo[label] = arr memo end Mikon::DataFrame.new(source, index: index) end
[ "def", "pivot", "(", "args", "=", "{", "}", ")", "args", "=", "{", "column", ":", "nil", ",", "row", ":", "nil", ",", "value", ":", "nil", ",", "fill_value", ":", "Float", "::", "NAN", "}", ".", "merge", "(", "args", ")", "raise", "ArgumentError", "unless", "[", ":column", ",", ":row", ",", ":value", "]", ".", "all?", "{", "|", "sym", "|", "args", "[", "sym", "]", ".", "is_a?", "(", "Symbol", ")", "}", "column", "=", "self", "[", "args", "[", ":column", "]", "]", ".", "factors", "index", "=", "self", "[", "args", "[", ":row", "]", "]", ".", "factors", "source", "=", "column", ".", "reduce", "(", "{", "}", ")", "do", "|", "memo", ",", "label", "|", "arr", "=", "[", "]", "df", "=", "self", ".", "select", "{", "|", "row", "|", "row", "[", "args", "[", ":column", "]", "]", "==", "label", "}", "index", ".", "each", "do", "|", "i", "|", "unless", "df", ".", "any?", "{", "|", "row", "|", "row", "[", "args", "[", ":row", "]", "]", "==", "i", "}", "arr", ".", "push", "(", "args", "[", ":fill_value", "]", ")", "else", "column", "=", "df", ".", "select", "{", "|", "row", "|", "row", "[", "args", "[", ":row", "]", "]", "==", "i", "}", "[", "args", "[", ":value", "]", "]", "arr", ".", "push", "(", "column", ".", "to_a", "[", "0", "]", ")", "end", "end", "memo", "[", "label", "]", "=", "arr", "memo", "end", "Mikon", "::", "DataFrame", ".", "new", "(", "source", ",", "index", ":", "index", ")", "end" ]
Experimental Implementation. DO NOT USE THIS METHOD
[ "Experimental", "Implementation", ".", "DO", "NOT", "USE", "THIS", "METHOD" ]
69886f5b6767d141e0a5624f0de2f34743909537
https://github.com/domitry/mikon/blob/69886f5b6767d141e0a5624f0de2f34743909537/lib/mikon/pivot.rb#L5-L34
train
jasonl/eden
lib/eden/tokenizers/basic_tokenizer.rb
Eden.BasicTokenizer.translate_keyword_tokens
def translate_keyword_tokens( token ) keywords = ["__LINE__", "__ENCODING__", "__FILE__", "BEGIN", "END", "alias", "and", "begin", "break", "case", "class", "def", "defined?", "do", "else", "elsif", "end", "ensure", "false", "for", "if", "in", "module", "next", "nil", "not", "or", "redo", "rescue", "retry", "return", "self", "super", "then", "true", "undef", "unless", "until", "when", "while", "yield"] if keywords.include?( token.content ) token.type = token.content.downcase.to_sym # Change the state if we match a keyword @expr_state = :beg end # A couple of exceptions if token.content == "BEGIN" token.type = :begin_global @expr_state = :beg elsif token.content == "END" token.type = :end_global @expr_state = :beg end token end
ruby
def translate_keyword_tokens( token ) keywords = ["__LINE__", "__ENCODING__", "__FILE__", "BEGIN", "END", "alias", "and", "begin", "break", "case", "class", "def", "defined?", "do", "else", "elsif", "end", "ensure", "false", "for", "if", "in", "module", "next", "nil", "not", "or", "redo", "rescue", "retry", "return", "self", "super", "then", "true", "undef", "unless", "until", "when", "while", "yield"] if keywords.include?( token.content ) token.type = token.content.downcase.to_sym # Change the state if we match a keyword @expr_state = :beg end # A couple of exceptions if token.content == "BEGIN" token.type = :begin_global @expr_state = :beg elsif token.content == "END" token.type = :end_global @expr_state = :beg end token end
[ "def", "translate_keyword_tokens", "(", "token", ")", "keywords", "=", "[", "\"__LINE__\"", ",", "\"__ENCODING__\"", ",", "\"__FILE__\"", ",", "\"BEGIN\"", ",", "\"END\"", ",", "\"alias\"", ",", "\"and\"", ",", "\"begin\"", ",", "\"break\"", ",", "\"case\"", ",", "\"class\"", ",", "\"def\"", ",", "\"defined?\"", ",", "\"do\"", ",", "\"else\"", ",", "\"elsif\"", ",", "\"end\"", ",", "\"ensure\"", ",", "\"false\"", ",", "\"for\"", ",", "\"if\"", ",", "\"in\"", ",", "\"module\"", ",", "\"next\"", ",", "\"nil\"", ",", "\"not\"", ",", "\"or\"", ",", "\"redo\"", ",", "\"rescue\"", ",", "\"retry\"", ",", "\"return\"", ",", "\"self\"", ",", "\"super\"", ",", "\"then\"", ",", "\"true\"", ",", "\"undef\"", ",", "\"unless\"", ",", "\"until\"", ",", "\"when\"", ",", "\"while\"", ",", "\"yield\"", "]", "if", "keywords", ".", "include?", "(", "token", ".", "content", ")", "token", ".", "type", "=", "token", ".", "content", ".", "downcase", ".", "to_sym", "@expr_state", "=", ":beg", "end", "if", "token", ".", "content", "==", "\"BEGIN\"", "token", ".", "type", "=", ":begin_global", "@expr_state", "=", ":beg", "elsif", "token", ".", "content", "==", "\"END\"", "token", ".", "type", "=", ":end_global", "@expr_state", "=", ":beg", "end", "token", "end" ]
Takes an identifier token, and tranforms its type to match Ruby keywords where the identifier is actually a keyword. Reserved words are defined in S.8.5.1 of the Ruby spec.
[ "Takes", "an", "identifier", "token", "and", "tranforms", "its", "type", "to", "match", "Ruby", "keywords", "where", "the", "identifier", "is", "actually", "a", "keyword", ".", "Reserved", "words", "are", "defined", "in", "S", ".", "8", ".", "5", ".", "1", "of", "the", "Ruby", "spec", "." ]
8a08a4000c63a6b20c07a872cca2dcb0d263baf9
https://github.com/jasonl/eden/blob/8a08a4000c63a6b20c07a872cca2dcb0d263baf9/lib/eden/tokenizers/basic_tokenizer.rb#L140-L165
train
dagrz/nba_stats
lib/nba_stats/client.rb
NbaStats.Client.get
def get(path='/', params={}) uri = Addressable::URI.new uri.query_values = params # Build the path with + instead of %20 because nba.com is flaky full_path = "#{path}?#{uri.query.gsub(/%20/,'+')}" request(:get, full_path) end
ruby
def get(path='/', params={}) uri = Addressable::URI.new uri.query_values = params # Build the path with + instead of %20 because nba.com is flaky full_path = "#{path}?#{uri.query.gsub(/%20/,'+')}" request(:get, full_path) end
[ "def", "get", "(", "path", "=", "'/'", ",", "params", "=", "{", "}", ")", "uri", "=", "Addressable", "::", "URI", ".", "new", "uri", ".", "query_values", "=", "params", "full_path", "=", "\"#{path}?#{uri.query.gsub(/%20/,'+')}\"", "request", "(", ":get", ",", "full_path", ")", "end" ]
Perform a HTTP GET request @param path [String] @param params [Hash] @return [Hash]
[ "Perform", "a", "HTTP", "GET", "request" ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/client.rb#L103-L109
train
dagrz/nba_stats
lib/nba_stats/client.rb
NbaStats.Client.request
def request(method, path) resource[path].send(method.to_sym, request_headers) { |response, request, result, &block| case response.code when 200 response when 400 if response.include? ' is required' raise ArgumentError.new(response) else raise BadRequestError.new(response) end else response.return!(request, result, &block) end } end
ruby
def request(method, path) resource[path].send(method.to_sym, request_headers) { |response, request, result, &block| case response.code when 200 response when 400 if response.include? ' is required' raise ArgumentError.new(response) else raise BadRequestError.new(response) end else response.return!(request, result, &block) end } end
[ "def", "request", "(", "method", ",", "path", ")", "resource", "[", "path", "]", ".", "send", "(", "method", ".", "to_sym", ",", "request_headers", ")", "{", "|", "response", ",", "request", ",", "result", ",", "&", "block", "|", "case", "response", ".", "code", "when", "200", "response", "when", "400", "if", "response", ".", "include?", "' is required'", "raise", "ArgumentError", ".", "new", "(", "response", ")", "else", "raise", "BadRequestError", ".", "new", "(", "response", ")", "end", "else", "response", ".", "return!", "(", "request", ",", "result", ",", "&", "block", ")", "end", "}", "end" ]
Send the HTTP request @param method [String] @param path [String] @return [RestClient::Response]
[ "Send", "the", "HTTP", "request" ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/client.rb#L123-L138
train
dagrz/nba_stats
lib/nba_stats/stats/draft_combine_stats.rb
NbaStats.DraftCombineStats.draft_combine_stats
def draft_combine_stats( season_year, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::DraftCombineStats.new( get(DRAFT_COMBINE_STATS_PATH, { :LeagueID => league_id, :SeasonYear => season_year }) ) end
ruby
def draft_combine_stats( season_year, league_id=NbaStats::Constants::LEAGUE_ID_NBA ) NbaStats::Resources::DraftCombineStats.new( get(DRAFT_COMBINE_STATS_PATH, { :LeagueID => league_id, :SeasonYear => season_year }) ) end
[ "def", "draft_combine_stats", "(", "season_year", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ")", "NbaStats", "::", "Resources", "::", "DraftCombineStats", ".", "new", "(", "get", "(", "DRAFT_COMBINE_STATS_PATH", ",", "{", ":LeagueID", "=>", "league_id", ",", ":SeasonYear", "=>", "season_year", "}", ")", ")", "end" ]
Calls the draftcombinestats API and returns a DraftCombineStats resource. @param season_year [String] @param league_id [String] @return [NbaStats::Resources::DraftCombineStats]
[ "Calls", "the", "draftcombinestats", "API", "and", "returns", "a", "DraftCombineStats", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/draft_combine_stats.rb#L15-L25
train
dagrz/nba_stats
lib/nba_stats/stats/player_dashboard_by_general_splits.rb
NbaStats.PlayerDashboardByGeneralSplits.player_dashboard_by_general_splits
def player_dashboard_by_general_splits( season, player_id, date_from=nil, date_to=nil, game_segment=nil, last_n_games=0, league_id=NbaStats::Constants::LEAGUE_ID_NBA, location=nil, measure_type=NbaStats::Constants::MEASURE_TYPE_USAGE, month=0, opponent_team_id=0, outcome=nil, pace_adjust=NbaStats::Constants::NO, per_mode=NbaStats::Constants::PER_MODE_GAME, period=0, plus_minus=NbaStats::Constants::NO, rank=NbaStats::Constants::NO, season_segment=nil, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, vs_conference=nil, vs_division=nil ) unless date_from.nil? date_from = date_from.strftime('%m-%d-%Y') end unless date_to.nil? date_to = date_to.strftime('%m-%d-%Y') end NbaStats::Resources::PlayerDashboardByGeneralSplits.new( get(PLAYER_DASHBOARD_BY_GENERAL_SPLITS_PATH, { :DateFrom => date_from, :DateTo => date_to, :GameSegment => game_segment, :LastNGames => last_n_games, :LeagueID => league_id, :Location => location, :MeasureType => measure_type, :Month => month, :OpponentTeamID => opponent_team_id, :Outcome => outcome, :PaceAdjust => pace_adjust, :PerMode => per_mode, :Period => period, :PlayerID => player_id, :PlusMinus => plus_minus, :Rank => rank, :Season => season, :SeasonSegment => season_segment, :SeasonType => season_type, :VsConference => vs_conference, :VsDivision => vs_division }) ) end
ruby
def player_dashboard_by_general_splits( season, player_id, date_from=nil, date_to=nil, game_segment=nil, last_n_games=0, league_id=NbaStats::Constants::LEAGUE_ID_NBA, location=nil, measure_type=NbaStats::Constants::MEASURE_TYPE_USAGE, month=0, opponent_team_id=0, outcome=nil, pace_adjust=NbaStats::Constants::NO, per_mode=NbaStats::Constants::PER_MODE_GAME, period=0, plus_minus=NbaStats::Constants::NO, rank=NbaStats::Constants::NO, season_segment=nil, season_type=NbaStats::Constants::SEASON_TYPE_REGULAR, vs_conference=nil, vs_division=nil ) unless date_from.nil? date_from = date_from.strftime('%m-%d-%Y') end unless date_to.nil? date_to = date_to.strftime('%m-%d-%Y') end NbaStats::Resources::PlayerDashboardByGeneralSplits.new( get(PLAYER_DASHBOARD_BY_GENERAL_SPLITS_PATH, { :DateFrom => date_from, :DateTo => date_to, :GameSegment => game_segment, :LastNGames => last_n_games, :LeagueID => league_id, :Location => location, :MeasureType => measure_type, :Month => month, :OpponentTeamID => opponent_team_id, :Outcome => outcome, :PaceAdjust => pace_adjust, :PerMode => per_mode, :Period => period, :PlayerID => player_id, :PlusMinus => plus_minus, :Rank => rank, :Season => season, :SeasonSegment => season_segment, :SeasonType => season_type, :VsConference => vs_conference, :VsDivision => vs_division }) ) end
[ "def", "player_dashboard_by_general_splits", "(", "season", ",", "player_id", ",", "date_from", "=", "nil", ",", "date_to", "=", "nil", ",", "game_segment", "=", "nil", ",", "last_n_games", "=", "0", ",", "league_id", "=", "NbaStats", "::", "Constants", "::", "LEAGUE_ID_NBA", ",", "location", "=", "nil", ",", "measure_type", "=", "NbaStats", "::", "Constants", "::", "MEASURE_TYPE_USAGE", ",", "month", "=", "0", ",", "opponent_team_id", "=", "0", ",", "outcome", "=", "nil", ",", "pace_adjust", "=", "NbaStats", "::", "Constants", "::", "NO", ",", "per_mode", "=", "NbaStats", "::", "Constants", "::", "PER_MODE_GAME", ",", "period", "=", "0", ",", "plus_minus", "=", "NbaStats", "::", "Constants", "::", "NO", ",", "rank", "=", "NbaStats", "::", "Constants", "::", "NO", ",", "season_segment", "=", "nil", ",", "season_type", "=", "NbaStats", "::", "Constants", "::", "SEASON_TYPE_REGULAR", ",", "vs_conference", "=", "nil", ",", "vs_division", "=", "nil", ")", "unless", "date_from", ".", "nil?", "date_from", "=", "date_from", ".", "strftime", "(", "'%m-%d-%Y'", ")", "end", "unless", "date_to", ".", "nil?", "date_to", "=", "date_to", ".", "strftime", "(", "'%m-%d-%Y'", ")", "end", "NbaStats", "::", "Resources", "::", "PlayerDashboardByGeneralSplits", ".", "new", "(", "get", "(", "PLAYER_DASHBOARD_BY_GENERAL_SPLITS_PATH", ",", "{", ":DateFrom", "=>", "date_from", ",", ":DateTo", "=>", "date_to", ",", ":GameSegment", "=>", "game_segment", ",", ":LastNGames", "=>", "last_n_games", ",", ":LeagueID", "=>", "league_id", ",", ":Location", "=>", "location", ",", ":MeasureType", "=>", "measure_type", ",", ":Month", "=>", "month", ",", ":OpponentTeamID", "=>", "opponent_team_id", ",", ":Outcome", "=>", "outcome", ",", ":PaceAdjust", "=>", "pace_adjust", ",", ":PerMode", "=>", "per_mode", ",", ":Period", "=>", "period", ",", ":PlayerID", "=>", "player_id", ",", ":PlusMinus", "=>", "plus_minus", ",", ":Rank", "=>", "rank", ",", ":Season", "=>", "season", ",", ":SeasonSegment", "=>", "season_segment", ",", ":SeasonType", "=>", "season_type", ",", ":VsConference", "=>", "vs_conference", ",", ":VsDivision", "=>", "vs_division", "}", ")", ")", "end" ]
Calls the playerdashboardbygeneralsplits API and returns a PlayerDashboardByGeneralSplits resource. @param season [String] @param player_id [Integer] @param date_from [Date] @param date_to [Date] @param game_segment [String] @param last_n_games [Integer] @param league_id [String] @param location [String] @param measure_type [String] @param month [Integer] @param opponent_team_id [Integer] @param outcome [String] @param pace_adjust [String] @param per_mode [String] @param period [Integer] @param plus_minus [String] @param rank [String] @param season_segment [String] @param season_type [String] @param vs_conference [String] @param vs_division [String] @return [NbaStats::Resources::PlayerDashboardByGeneralSplits]
[ "Calls", "the", "playerdashboardbygeneralsplits", "API", "and", "returns", "a", "PlayerDashboardByGeneralSplits", "resource", "." ]
d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa
https://github.com/dagrz/nba_stats/blob/d6fe6cf81f74a2ce7a054aeec5e9db59a6ec42aa/lib/nba_stats/stats/player_dashboard_by_general_splits.rb#L34-L88
train
dcuddeback/rspec-tag_matchers
lib/rspec/tag_matchers/helpers/sentence_helper.rb
RSpec::TagMatchers::Helpers.SentenceHelper.make_sentence
def make_sentence(*strings) options = strings.last.is_a?(Hash) ? strings.pop : {} strings = strings.flatten.map(&:to_s).reject(&:empty?) conjunction = options[:conjunction] || "and" case strings.count when 0 "" when 1 strings.first else last = strings.pop puncuation = strings.count > 1 ? ", " : " " [strings, "#{conjunction} #{last}"].flatten.join(puncuation) end end
ruby
def make_sentence(*strings) options = strings.last.is_a?(Hash) ? strings.pop : {} strings = strings.flatten.map(&:to_s).reject(&:empty?) conjunction = options[:conjunction] || "and" case strings.count when 0 "" when 1 strings.first else last = strings.pop puncuation = strings.count > 1 ? ", " : " " [strings, "#{conjunction} #{last}"].flatten.join(puncuation) end end
[ "def", "make_sentence", "(", "*", "strings", ")", "options", "=", "strings", ".", "last", ".", "is_a?", "(", "Hash", ")", "?", "strings", ".", "pop", ":", "{", "}", "strings", "=", "strings", ".", "flatten", ".", "map", "(", "&", ":to_s", ")", ".", "reject", "(", "&", ":empty?", ")", "conjunction", "=", "options", "[", ":conjunction", "]", "||", "\"and\"", "case", "strings", ".", "count", "when", "0", "\"\"", "when", "1", "strings", ".", "first", "else", "last", "=", "strings", ".", "pop", "puncuation", "=", "strings", ".", "count", ">", "1", "?", "\", \"", ":", "\" \"", "[", "strings", ",", "\"#{conjunction} #{last}\"", "]", ".", "flatten", ".", "join", "(", "puncuation", ")", "end", "end" ]
Joins multiple strings into a sentence with punctuation and conjunctions. @example Forming sentences make_sentence("foo") # => "foo" make_sentence("foo", "bar") # => "foo and bar" make_sentence("foo", "bar", "baz") # => "foo, bar, and baz" @example Overriding the conjunction make_sentence("foo", "bar", "baz", :conjunction => "or") # => "foo, bar, or baz" @param [Strings] *strings A list of strings to be combined into a sentence. The last item can be an options hash. @option *strings.last [String] :conjunction ("and") The conjunction to use to join sentence fragments. @return [String]
[ "Joins", "multiple", "strings", "into", "a", "sentence", "with", "punctuation", "and", "conjunctions", "." ]
6396a833d99ea669699afb1b3dfc62c4512c8882
https://github.com/dcuddeback/rspec-tag_matchers/blob/6396a833d99ea669699afb1b3dfc62c4512c8882/lib/rspec/tag_matchers/helpers/sentence_helper.rb#L20-L36
train
MrEmelianenko/drape
lib/drape/automatic_delegation.rb
Drape.AutomaticDelegation.method_missing
def method_missing(method, *args, &block) return super unless delegatable?(method) self.class.delegate method send(method, *args, &block) end
ruby
def method_missing(method, *args, &block) return super unless delegatable?(method) self.class.delegate method send(method, *args, &block) end
[ "def", "method_missing", "(", "method", ",", "*", "args", ",", "&", "block", ")", "return", "super", "unless", "delegatable?", "(", "method", ")", "self", ".", "class", ".", "delegate", "method", "send", "(", "method", ",", "*", "args", ",", "&", "block", ")", "end" ]
Delegates missing instance methods to the source object.
[ "Delegates", "missing", "instance", "methods", "to", "the", "source", "object", "." ]
cc9e8d55341d3145317d425031f5cb46f9cba552
https://github.com/MrEmelianenko/drape/blob/cc9e8d55341d3145317d425031f5cb46f9cba552/lib/drape/automatic_delegation.rb#L6-L11
train