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 list | docstring stringlengths 8 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 94 266 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
mongodb/mongoid | lib/rails/mongoid.rb | Rails.Mongoid.load_models | def load_models(app)
app.config.paths["app/models"].expanded.each do |path|
preload = ::Mongoid.preload_models
if preload.resizable?
files = preload.map { |model| "#{path}/#{model.underscore}.rb" }
else
files = Dir.glob("#{path}/**/*.rb")
end
files.sort... | ruby | def load_models(app)
app.config.paths["app/models"].expanded.each do |path|
preload = ::Mongoid.preload_models
if preload.resizable?
files = preload.map { |model| "#{path}/#{model.underscore}.rb" }
else
files = Dir.glob("#{path}/**/*.rb")
end
files.sort... | [
"def",
"load_models",
"(",
"app",
")",
"app",
".",
"config",
".",
"paths",
"[",
"\"app/models\"",
"]",
".",
"expanded",
".",
"each",
"do",
"|",
"path",
"|",
"preload",
"=",
"::",
"Mongoid",
".",
"preload_models",
"if",
"preload",
".",
"resizable?",
"file... | Use the application configuration to get every model and require it, so
that indexing and inheritance work in both development and production
with the same results.
@example Load all the application models.
Rails::Mongoid.load_models(app)
@param [ Application ] app The rails application. | [
"Use",
"the",
"application",
"configuration",
"to",
"get",
"every",
"model",
"and",
"require",
"it",
"so",
"that",
"indexing",
"and",
"inheritance",
"work",
"in",
"both",
"development",
"and",
"production",
"with",
"the",
"same",
"results",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/rails/mongoid.rb#L15-L28 | train |
mongodb/mongoid | lib/rails/mongoid.rb | Rails.Mongoid.load_model | def load_model(file)
begin
require_dependency(file)
rescue Exception => e
Logger.new($stdout).warn(e.message)
end
end | ruby | def load_model(file)
begin
require_dependency(file)
rescue Exception => e
Logger.new($stdout).warn(e.message)
end
end | [
"def",
"load_model",
"(",
"file",
")",
"begin",
"require_dependency",
"(",
"file",
")",
"rescue",
"Exception",
"=>",
"e",
"Logger",
".",
"new",
"(",
"$stdout",
")",
".",
"warn",
"(",
"e",
".",
"message",
")",
"end",
"end"
] | I don't want to mock out kernel for unit testing purposes, so added this
method as a convenience.
@example Load the model.
Mongoid.load_model("/mongoid/behavior")
@param [ String ] file The base filename.
@since 2.0.0.rc.3 | [
"I",
"don",
"t",
"want",
"to",
"mock",
"out",
"kernel",
"for",
"unit",
"testing",
"purposes",
"so",
"added",
"this",
"method",
"as",
"a",
"convenience",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/rails/mongoid.rb#L49-L55 | train |
mongodb/mongoid | lib/mongoid/fields.rb | Mongoid.Fields.apply_default | def apply_default(name)
unless attributes.key?(name)
if field = fields[name]
default = field.eval_default(self)
unless default.nil? || field.lazy?
attribute_will_change!(name)
attributes[name] = default
end
end
end
end | ruby | def apply_default(name)
unless attributes.key?(name)
if field = fields[name]
default = field.eval_default(self)
unless default.nil? || field.lazy?
attribute_will_change!(name)
attributes[name] = default
end
end
end
end | [
"def",
"apply_default",
"(",
"name",
")",
"unless",
"attributes",
".",
"key?",
"(",
"name",
")",
"if",
"field",
"=",
"fields",
"[",
"name",
"]",
"default",
"=",
"field",
".",
"eval_default",
"(",
"self",
")",
"unless",
"default",
".",
"nil?",
"||",
"fi... | Applies a single default value for the given name.
@example Apply a single default.
model.apply_default("name")
@param [ String ] name The name of the field.
@since 2.4.0 | [
"Applies",
"a",
"single",
"default",
"value",
"for",
"the",
"given",
"name",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/fields.rb#L101-L111 | train |
mongodb/mongoid | lib/mongoid/persistable.rb | Mongoid.Persistable.post_process_persist | def post_process_persist(result, options = {})
post_persist unless result == false
errors.clear unless performing_validations?(options)
true
end | ruby | def post_process_persist(result, options = {})
post_persist unless result == false
errors.clear unless performing_validations?(options)
true
end | [
"def",
"post_process_persist",
"(",
"result",
",",
"options",
"=",
"{",
"}",
")",
"post_persist",
"unless",
"result",
"==",
"false",
"errors",
".",
"clear",
"unless",
"performing_validations?",
"(",
"options",
")",
"true",
"end"
] | Post process the persistence operation.
@api private
@example Post process the persistence operation.
document.post_process_persist(true)
@param [ Object ] result The result of the operation.
@param [ Hash ] options The options.
@return [ true ] true.
@since 4.0.0 | [
"Post",
"process",
"the",
"persistence",
"operation",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/persistable.rb#L179-L183 | train |
mongodb/mongoid | lib/mongoid/persistable.rb | Mongoid.Persistable.process_atomic_operations | def process_atomic_operations(operations)
operations.each do |field, value|
access = database_field_name(field)
yield(access, value)
remove_change(access) unless executing_atomically?
end
end | ruby | def process_atomic_operations(operations)
operations.each do |field, value|
access = database_field_name(field)
yield(access, value)
remove_change(access) unless executing_atomically?
end
end | [
"def",
"process_atomic_operations",
"(",
"operations",
")",
"operations",
".",
"each",
"do",
"|",
"field",
",",
"value",
"|",
"access",
"=",
"database_field_name",
"(",
"field",
")",
"yield",
"(",
"access",
",",
"value",
")",
"remove_change",
"(",
"access",
... | Process the atomic operations - this handles the common behavior of
iterating through each op, getting the aliased field name, and removing
appropriate dirty changes.
@api private
@example Process the atomic operations.
document.process_atomic_operations(pulls) do |field, value|
...
end
@param [ Hash... | [
"Process",
"the",
"atomic",
"operations",
"-",
"this",
"handles",
"the",
"common",
"behavior",
"of",
"iterating",
"through",
"each",
"op",
"getting",
"the",
"aliased",
"field",
"name",
"and",
"removing",
"appropriate",
"dirty",
"changes",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/persistable.rb#L220-L226 | train |
mongodb/mongoid | lib/mongoid/persistable.rb | Mongoid.Persistable.persist_or_delay_atomic_operation | def persist_or_delay_atomic_operation(operation)
if executing_atomically?
operation.each do |(name, hash)|
@atomic_context[name] ||= {}
@atomic_context[name].merge!(hash)
end
else
persist_atomic_operations(operation)
end
end | ruby | def persist_or_delay_atomic_operation(operation)
if executing_atomically?
operation.each do |(name, hash)|
@atomic_context[name] ||= {}
@atomic_context[name].merge!(hash)
end
else
persist_atomic_operations(operation)
end
end | [
"def",
"persist_or_delay_atomic_operation",
"(",
"operation",
")",
"if",
"executing_atomically?",
"operation",
".",
"each",
"do",
"|",
"(",
"name",
",",
"hash",
")",
"|",
"@atomic_context",
"[",
"name",
"]",
"||=",
"{",
"}",
"@atomic_context",
"[",
"name",
"]"... | If we are in an atomically block, add the operations to the delayed group,
otherwise persist immediately.
@api private
@example Persist immediately or delay the operations.
document.persist_or_delay_atomic_operation(ops)
@param [ Hash ] operation The operation.
@since 4.0.0 | [
"If",
"we",
"are",
"in",
"an",
"atomically",
"block",
"add",
"the",
"operations",
"to",
"the",
"delayed",
"group",
"otherwise",
"persist",
"immediately",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/persistable.rb#L299-L308 | train |
mongodb/mongoid | lib/mongoid/persistable.rb | Mongoid.Persistable.persist_atomic_operations | def persist_atomic_operations(operations)
if persisted? && operations && !operations.empty?
selector = atomic_selector
_root.collection.find(selector).update_one(positionally(selector, operations), session: _session)
end
end | ruby | def persist_atomic_operations(operations)
if persisted? && operations && !operations.empty?
selector = atomic_selector
_root.collection.find(selector).update_one(positionally(selector, operations), session: _session)
end
end | [
"def",
"persist_atomic_operations",
"(",
"operations",
")",
"if",
"persisted?",
"&&",
"operations",
"&&",
"!",
"operations",
".",
"empty?",
"selector",
"=",
"atomic_selector",
"_root",
".",
"collection",
".",
"find",
"(",
"selector",
")",
".",
"update_one",
"(",... | Persist the atomic operations.
@api private
@example Persist the atomic operations.
persist_atomic_operations(ops)
@param [ Hash ] operations The atomic operations.
@since 4.0.0 | [
"Persist",
"the",
"atomic",
"operations",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/persistable.rb#L320-L325 | train |
mongodb/mongoid | lib/mongoid/serializable.rb | Mongoid.Serializable.serializable_hash | def serializable_hash(options = nil)
options ||= {}
attrs = {}
names = field_names(options)
method_names = Array.wrap(options[:methods]).map do |name|
name.to_s if respond_to?(name)
end.compact
(names + method_names).each do |name|
without_autobuild do
se... | ruby | def serializable_hash(options = nil)
options ||= {}
attrs = {}
names = field_names(options)
method_names = Array.wrap(options[:methods]).map do |name|
name.to_s if respond_to?(name)
end.compact
(names + method_names).each do |name|
without_autobuild do
se... | [
"def",
"serializable_hash",
"(",
"options",
"=",
"nil",
")",
"options",
"||=",
"{",
"}",
"attrs",
"=",
"{",
"}",
"names",
"=",
"field_names",
"(",
"options",
")",
"method_names",
"=",
"Array",
".",
"wrap",
"(",
"options",
"[",
":methods",
"]",
")",
"."... | Gets the document as a serializable hash, used by ActiveModel's JSON
serializer.
@example Get the serializable hash.
document.serializable_hash
@example Get the serializable hash with options.
document.serializable_hash(:include => :addresses)
@param [ Hash ] options The options to pass.
@option options ... | [
"Gets",
"the",
"document",
"as",
"a",
"serializable",
"hash",
"used",
"by",
"ActiveModel",
"s",
"JSON",
"serializer",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/serializable.rb#L38-L55 | train |
mongodb/mongoid | lib/mongoid/serializable.rb | Mongoid.Serializable.field_names | def field_names(options)
names = (as_attributes.keys + attribute_names).uniq.sort
only = Array.wrap(options[:only]).map(&:to_s)
except = Array.wrap(options[:except]).map(&:to_s)
except |= ['_type'] unless Mongoid.include_type_for_serialization
if !only.empty?
names &= only
... | ruby | def field_names(options)
names = (as_attributes.keys + attribute_names).uniq.sort
only = Array.wrap(options[:only]).map(&:to_s)
except = Array.wrap(options[:except]).map(&:to_s)
except |= ['_type'] unless Mongoid.include_type_for_serialization
if !only.empty?
names &= only
... | [
"def",
"field_names",
"(",
"options",
")",
"names",
"=",
"(",
"as_attributes",
".",
"keys",
"+",
"attribute_names",
")",
".",
"uniq",
".",
"sort",
"only",
"=",
"Array",
".",
"wrap",
"(",
"options",
"[",
":only",
"]",
")",
".",
"map",
"(",
":to_s",
")... | Get the names of all fields that will be serialized.
@api private
@example Get all the field names.
document.send(:field_names)
@return [ Array<String> ] The names of the fields.
@since 3.0.0 | [
"Get",
"the",
"names",
"of",
"all",
"fields",
"that",
"will",
"be",
"serialized",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/serializable.rb#L69-L82 | train |
mongodb/mongoid | lib/mongoid/serializable.rb | Mongoid.Serializable.serialize_attribute | def serialize_attribute(attrs, name, names, options)
if relations.key?(name)
value = send(name)
attrs[name] = value ? value.serializable_hash(options) : nil
elsif names.include?(name) && !fields.key?(name)
attrs[name] = read_raw_attribute(name)
elsif !attribute_missing?(name)
... | ruby | def serialize_attribute(attrs, name, names, options)
if relations.key?(name)
value = send(name)
attrs[name] = value ? value.serializable_hash(options) : nil
elsif names.include?(name) && !fields.key?(name)
attrs[name] = read_raw_attribute(name)
elsif !attribute_missing?(name)
... | [
"def",
"serialize_attribute",
"(",
"attrs",
",",
"name",
",",
"names",
",",
"options",
")",
"if",
"relations",
".",
"key?",
"(",
"name",
")",
"value",
"=",
"send",
"(",
"name",
")",
"attrs",
"[",
"name",
"]",
"=",
"value",
"?",
"value",
".",
"seriali... | Serialize a single attribute. Handles associations, fields, and dynamic
attributes.
@api private
@example Serialize the attribute.
document.serialize_attribute({}, "id" , [ "id" ])
@param [ Hash ] attrs The attributes.
@param [ String ] name The attribute name.
@param [ Array<String> ] names The names of al... | [
"Serialize",
"a",
"single",
"attribute",
".",
"Handles",
"associations",
"fields",
"and",
"dynamic",
"attributes",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/serializable.rb#L100-L109 | train |
mongodb/mongoid | lib/mongoid/serializable.rb | Mongoid.Serializable.serialize_relations | def serialize_relations(attributes = {}, options = {})
inclusions = options[:include]
relation_names(inclusions).each do |name|
association = relations[name.to_s]
if association && relation = send(association.name)
attributes[association.name.to_s] =
relation.serializab... | ruby | def serialize_relations(attributes = {}, options = {})
inclusions = options[:include]
relation_names(inclusions).each do |name|
association = relations[name.to_s]
if association && relation = send(association.name)
attributes[association.name.to_s] =
relation.serializab... | [
"def",
"serialize_relations",
"(",
"attributes",
"=",
"{",
"}",
",",
"options",
"=",
"{",
"}",
")",
"inclusions",
"=",
"options",
"[",
":include",
"]",
"relation_names",
"(",
"inclusions",
")",
".",
"each",
"do",
"|",
"name",
"|",
"association",
"=",
"re... | For each of the provided include options, get the association needed and
provide it in the hash.
@example Serialize the included associations.
document.serialize_relations({}, :include => :addresses)
@param [ Hash ] attributes The attributes to serialize.
@param [ Hash ] options The serialization options.
@o... | [
"For",
"each",
"of",
"the",
"provided",
"include",
"options",
"get",
"the",
"association",
"needed",
"and",
"provide",
"it",
"in",
"the",
"hash",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/serializable.rb#L125-L134 | train |
mongodb/mongoid | lib/mongoid/serializable.rb | Mongoid.Serializable.relation_names | def relation_names(inclusions)
inclusions.is_a?(Hash) ? inclusions.keys : Array.wrap(inclusions)
end | ruby | def relation_names(inclusions)
inclusions.is_a?(Hash) ? inclusions.keys : Array.wrap(inclusions)
end | [
"def",
"relation_names",
"(",
"inclusions",
")",
"inclusions",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"inclusions",
".",
"keys",
":",
"Array",
".",
"wrap",
"(",
"inclusions",
")",
"end"
] | Since the inclusions can be a hash, symbol, or array of symbols, this is
provided as a convenience to parse out the names.
@example Get the association names.
document.relation_names(:include => [ :addresses ])
@param [ Hash, Symbol, Array<Symbol> ] inclusions The inclusions.
@return [ Array<Symbol> ] The nam... | [
"Since",
"the",
"inclusions",
"can",
"be",
"a",
"hash",
"symbol",
"or",
"array",
"of",
"symbols",
"this",
"is",
"provided",
"as",
"a",
"convenience",
"to",
"parse",
"out",
"the",
"names",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/serializable.rb#L147-L149 | train |
mongodb/mongoid | lib/mongoid/serializable.rb | Mongoid.Serializable.relation_options | def relation_options(inclusions, options, name)
if inclusions.is_a?(Hash)
inclusions[name]
else
{ except: options[:except], only: options[:only] }
end
end | ruby | def relation_options(inclusions, options, name)
if inclusions.is_a?(Hash)
inclusions[name]
else
{ except: options[:except], only: options[:only] }
end
end | [
"def",
"relation_options",
"(",
"inclusions",
",",
"options",
",",
"name",
")",
"if",
"inclusions",
".",
"is_a?",
"(",
"Hash",
")",
"inclusions",
"[",
"name",
"]",
"else",
"{",
"except",
":",
"options",
"[",
":except",
"]",
",",
"only",
":",
"options",
... | Since the inclusions can be a hash, symbol, or array of symbols, this is
provided as a convenience to parse out the options.
@example Get the association options.
document.relation_names(:include => [ :addresses ])
@param [ Hash, Symbol, Array<Symbol> ] inclusions The inclusions.
@param [ Hash ] options The op... | [
"Since",
"the",
"inclusions",
"can",
"be",
"a",
"hash",
"symbol",
"or",
"array",
"of",
"symbols",
"this",
"is",
"provided",
"as",
"a",
"convenience",
"to",
"parse",
"out",
"the",
"options",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/serializable.rb#L164-L170 | train |
mongodb/mongoid | lib/mongoid/threaded.rb | Mongoid.Threaded.current_scope | def current_scope(klass = nil)
if klass && Thread.current[CURRENT_SCOPE_KEY].respond_to?(:keys)
Thread.current[CURRENT_SCOPE_KEY][
Thread.current[CURRENT_SCOPE_KEY].keys.find { |k| k <= klass }
]
else
Thread.current[CURRENT_SCOPE_KEY]
end
end | ruby | def current_scope(klass = nil)
if klass && Thread.current[CURRENT_SCOPE_KEY].respond_to?(:keys)
Thread.current[CURRENT_SCOPE_KEY][
Thread.current[CURRENT_SCOPE_KEY].keys.find { |k| k <= klass }
]
else
Thread.current[CURRENT_SCOPE_KEY]
end
end | [
"def",
"current_scope",
"(",
"klass",
"=",
"nil",
")",
"if",
"klass",
"&&",
"Thread",
".",
"current",
"[",
"CURRENT_SCOPE_KEY",
"]",
".",
"respond_to?",
"(",
":keys",
")",
"Thread",
".",
"current",
"[",
"CURRENT_SCOPE_KEY",
"]",
"[",
"Thread",
".",
"curren... | Get the current Mongoid scope.
@example Get the scope.
Threaded.current_scope(klass)
Threaded.current_scope
@param [ Klass ] klass The class type of the scope.
@return [ Criteria ] The scope.
@since 5.0.0 | [
"Get",
"the",
"current",
"Mongoid",
"scope",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/threaded.rb#L228-L236 | train |
mongodb/mongoid | lib/mongoid/threaded.rb | Mongoid.Threaded.set_current_scope | def set_current_scope(scope, klass)
if scope.nil?
if Thread.current[CURRENT_SCOPE_KEY]
Thread.current[CURRENT_SCOPE_KEY].delete(klass)
Thread.current[CURRENT_SCOPE_KEY] = nil if Thread.current[CURRENT_SCOPE_KEY].empty?
end
else
Thread.current[CURRENT_SCOPE_KEY] ||... | ruby | def set_current_scope(scope, klass)
if scope.nil?
if Thread.current[CURRENT_SCOPE_KEY]
Thread.current[CURRENT_SCOPE_KEY].delete(klass)
Thread.current[CURRENT_SCOPE_KEY] = nil if Thread.current[CURRENT_SCOPE_KEY].empty?
end
else
Thread.current[CURRENT_SCOPE_KEY] ||... | [
"def",
"set_current_scope",
"(",
"scope",
",",
"klass",
")",
"if",
"scope",
".",
"nil?",
"if",
"Thread",
".",
"current",
"[",
"CURRENT_SCOPE_KEY",
"]",
"Thread",
".",
"current",
"[",
"CURRENT_SCOPE_KEY",
"]",
".",
"delete",
"(",
"klass",
")",
"Thread",
"."... | Set the current Mongoid scope. Safe for multi-model scope chaining.
@example Set the scope.
Threaded.current_scope(scope, klass)
@param [ Criteria ] scope The current scope.
@param [ Class ] klass The current model class.
@return [ Criteria ] The scope.
@since 5.0.1 | [
"Set",
"the",
"current",
"Mongoid",
"scope",
".",
"Safe",
"for",
"multi",
"-",
"model",
"scope",
"chaining",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/threaded.rb#L263-L273 | train |
mongodb/mongoid | lib/mongoid/scopable.rb | Mongoid.Scopable.apply_default_scoping | def apply_default_scoping
if default_scoping
default_scoping.call.selector.each do |field, value|
attributes[field] = value unless value.respond_to?(:each)
end
end
end | ruby | def apply_default_scoping
if default_scoping
default_scoping.call.selector.each do |field, value|
attributes[field] = value unless value.respond_to?(:each)
end
end
end | [
"def",
"apply_default_scoping",
"if",
"default_scoping",
"default_scoping",
".",
"call",
".",
"selector",
".",
"each",
"do",
"|",
"field",
",",
"value",
"|",
"attributes",
"[",
"field",
"]",
"=",
"value",
"unless",
"value",
".",
"respond_to?",
"(",
":each",
... | Apply the default scoping to the attributes of the document, as long as
they are not complex queries.
@api private
@example Apply the default scoping.
document.apply_default_scoping
@return [ true, false ] If default scoping was applied.
@since 4.0.0 | [
"Apply",
"the",
"default",
"scoping",
"to",
"the",
"attributes",
"of",
"the",
"document",
"as",
"long",
"as",
"they",
"are",
"not",
"complex",
"queries",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/scopable.rb#L32-L38 | train |
mongodb/mongoid | lib/mongoid/validatable.rb | Mongoid.Validatable.read_attribute_for_validation | def read_attribute_for_validation(attr)
attribute = database_field_name(attr)
if relations.key?(attribute)
begin_validate
relation = without_autobuild { send(attr) }
exit_validate
relation.do_or_do_not(:in_memory) || relation
elsif fields[attribute].try(:localized?)
... | ruby | def read_attribute_for_validation(attr)
attribute = database_field_name(attr)
if relations.key?(attribute)
begin_validate
relation = without_autobuild { send(attr) }
exit_validate
relation.do_or_do_not(:in_memory) || relation
elsif fields[attribute].try(:localized?)
... | [
"def",
"read_attribute_for_validation",
"(",
"attr",
")",
"attribute",
"=",
"database_field_name",
"(",
"attr",
")",
"if",
"relations",
".",
"key?",
"(",
"attribute",
")",
"begin_validate",
"relation",
"=",
"without_autobuild",
"{",
"send",
"(",
"attr",
")",
"}"... | Overrides the default ActiveModel behavior since we need to handle
validations of associations slightly different than just calling the
getter.
@example Read the value.
person.read_attribute_for_validation(:addresses)
@param [ Symbol ] attr The name of the field or association.
@return [ Object ] The value o... | [
"Overrides",
"the",
"default",
"ActiveModel",
"behavior",
"since",
"we",
"need",
"to",
"handle",
"validations",
"of",
"associations",
"slightly",
"different",
"than",
"just",
"calling",
"the",
"getter",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/validatable.rb#L70-L82 | train |
mongodb/mongoid | lib/mongoid/traversable.rb | Mongoid.Traversable.collect_children | def collect_children
children = []
embedded_relations.each_pair do |name, association|
without_autobuild do
child = send(name)
Array.wrap(child).each do |doc|
children.push(doc)
children.concat(doc._children)
end if child
end
end
... | ruby | def collect_children
children = []
embedded_relations.each_pair do |name, association|
without_autobuild do
child = send(name)
Array.wrap(child).each do |doc|
children.push(doc)
children.concat(doc._children)
end if child
end
end
... | [
"def",
"collect_children",
"children",
"=",
"[",
"]",
"embedded_relations",
".",
"each_pair",
"do",
"|",
"name",
",",
"association",
"|",
"without_autobuild",
"do",
"child",
"=",
"send",
"(",
"name",
")",
"Array",
".",
"wrap",
"(",
"child",
")",
".",
"each... | Collect all the children of this document.
@example Collect all the children.
document.collect_children
@return [ Array<Document> ] The children.
@since 2.4.0 | [
"Collect",
"all",
"the",
"children",
"of",
"this",
"document",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/traversable.rb#L42-L54 | train |
mongodb/mongoid | lib/mongoid/traversable.rb | Mongoid.Traversable.remove_child | def remove_child(child)
name = child.association_name
if child.embedded_one?
remove_ivar(name)
else
relation = send(name)
relation.send(:delete_one, child)
end
end | ruby | def remove_child(child)
name = child.association_name
if child.embedded_one?
remove_ivar(name)
else
relation = send(name)
relation.send(:delete_one, child)
end
end | [
"def",
"remove_child",
"(",
"child",
")",
"name",
"=",
"child",
".",
"association_name",
"if",
"child",
".",
"embedded_one?",
"remove_ivar",
"(",
"name",
")",
"else",
"relation",
"=",
"send",
"(",
"name",
")",
"relation",
".",
"send",
"(",
":delete_one",
"... | Remove a child document from this parent. If an embeds one then set to
nil, otherwise remove from the embeds many.
This is called from the +RemoveEmbedded+ persistence command.
@example Remove the child.
document.remove_child(child)
@param [ Document ] child The child (embedded) document to remove.
@since 2... | [
"Remove",
"a",
"child",
"document",
"from",
"this",
"parent",
".",
"If",
"an",
"embeds",
"one",
"then",
"set",
"to",
"nil",
"otherwise",
"remove",
"from",
"the",
"embeds",
"many",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/traversable.rb#L104-L112 | train |
mongodb/mongoid | lib/mongoid/traversable.rb | Mongoid.Traversable.reset_persisted_children | def reset_persisted_children
_children.each do |child|
child.move_changes
child.new_record = false
end
_reset_memoized_children!
end | ruby | def reset_persisted_children
_children.each do |child|
child.move_changes
child.new_record = false
end
_reset_memoized_children!
end | [
"def",
"reset_persisted_children",
"_children",
".",
"each",
"do",
"|",
"child",
"|",
"child",
".",
"move_changes",
"child",
".",
"new_record",
"=",
"false",
"end",
"_reset_memoized_children!",
"end"
] | After children are persisted we can call this to move all their changes
and flag them as persisted in one call.
@example Reset the children.
document.reset_persisted_children
@return [ Array<Document> ] The children.
@since 2.1.0 | [
"After",
"children",
"are",
"persisted",
"we",
"can",
"call",
"this",
"to",
"move",
"all",
"their",
"changes",
"and",
"flag",
"them",
"as",
"persisted",
"in",
"one",
"call",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/traversable.rb#L123-L129 | train |
mongodb/mongoid | lib/mongoid/document.rb | Mongoid.Document.becomes | def becomes(klass)
unless klass.include?(Mongoid::Document)
raise ArgumentError, "A class which includes Mongoid::Document is expected"
end
became = klass.new(clone_document)
became._id = _id
became.instance_variable_set(:@changed_attributes, changed_attributes)
became.insta... | ruby | def becomes(klass)
unless klass.include?(Mongoid::Document)
raise ArgumentError, "A class which includes Mongoid::Document is expected"
end
became = klass.new(clone_document)
became._id = _id
became.instance_variable_set(:@changed_attributes, changed_attributes)
became.insta... | [
"def",
"becomes",
"(",
"klass",
")",
"unless",
"klass",
".",
"include?",
"(",
"Mongoid",
"::",
"Document",
")",
"raise",
"ArgumentError",
",",
"\"A class which includes Mongoid::Document is expected\"",
"end",
"became",
"=",
"klass",
".",
"new",
"(",
"clone_document... | Returns an instance of the specified class with the attributes,
errors, and embedded documents of the current document.
@example Return a subclass document as a superclass instance.
manager.becomes(Person)
@raise [ ArgumentError ] If the class doesn't include Mongoid::Document
@param [ Class ] klass The class... | [
"Returns",
"an",
"instance",
"of",
"the",
"specified",
"class",
"with",
"the",
"attributes",
"errors",
"and",
"embedded",
"documents",
"of",
"the",
"current",
"document",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/document.rb#L223-L249 | train |
mongodb/mongoid | lib/mongoid/association.rb | Mongoid.Association.reload_relations | def reload_relations
relations.each_pair do |name, meta|
if instance_variable_defined?("@_#{name}")
if _parent.nil? || instance_variable_get("@_#{name}") != _parent
remove_instance_variable("@_#{name}")
end
end
end
end | ruby | def reload_relations
relations.each_pair do |name, meta|
if instance_variable_defined?("@_#{name}")
if _parent.nil? || instance_variable_get("@_#{name}") != _parent
remove_instance_variable("@_#{name}")
end
end
end
end | [
"def",
"reload_relations",
"relations",
".",
"each_pair",
"do",
"|",
"name",
",",
"meta",
"|",
"if",
"instance_variable_defined?",
"(",
"\"@_#{name}\"",
")",
"if",
"_parent",
".",
"nil?",
"||",
"instance_variable_get",
"(",
"\"@_#{name}\"",
")",
"!=",
"_parent",
... | Convenience method for iterating through the loaded associations and
reloading them.
@example Reload the associations.
document.reload_relations
@return [ Hash ] The association metadata.
@since 2.1.6 | [
"Convenience",
"method",
"for",
"iterating",
"through",
"the",
"loaded",
"associations",
"and",
"reloading",
"them",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/association.rb#L141-L149 | train |
mongodb/mongoid | lib/mongoid/inspectable.rb | Mongoid.Inspectable.inspect_fields | def inspect_fields
fields.map do |name, field|
unless name == "_id"
as = field.options[:as]
"#{name}#{as ? "(#{as})" : nil}: #{@attributes[name].inspect}"
end
end.compact
end | ruby | def inspect_fields
fields.map do |name, field|
unless name == "_id"
as = field.options[:as]
"#{name}#{as ? "(#{as})" : nil}: #{@attributes[name].inspect}"
end
end.compact
end | [
"def",
"inspect_fields",
"fields",
".",
"map",
"do",
"|",
"name",
",",
"field",
"|",
"unless",
"name",
"==",
"\"_id\"",
"as",
"=",
"field",
".",
"options",
"[",
":as",
"]",
"\"#{name}#{as ? \"(#{as})\" : nil}: #{@attributes[name].inspect}\"",
"end",
"end",
".",
... | Get an array of inspected fields for the document.
@api private
@example Inspect the defined fields.
document.inspect_fields
@return [ String ] An array of pretty printed field values.
@since 1.0.0 | [
"Get",
"an",
"array",
"of",
"inspected",
"fields",
"for",
"the",
"document",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/inspectable.rb#L37-L44 | train |
mongodb/mongoid | lib/mongoid/interceptable.rb | Mongoid.Interceptable.run_callbacks | def run_callbacks(kind, *args, &block)
cascadable_children(kind).each do |child|
if child.run_callbacks(child_callback_type(kind, child), *args) == false
return false
end
end
callback_executable?(kind) ? super(kind, *args, &block) : true
end | ruby | def run_callbacks(kind, *args, &block)
cascadable_children(kind).each do |child|
if child.run_callbacks(child_callback_type(kind, child), *args) == false
return false
end
end
callback_executable?(kind) ? super(kind, *args, &block) : true
end | [
"def",
"run_callbacks",
"(",
"kind",
",",
"*",
"args",
",",
"&",
"block",
")",
"cascadable_children",
"(",
"kind",
")",
".",
"each",
"do",
"|",
"child",
"|",
"if",
"child",
".",
"run_callbacks",
"(",
"child_callback_type",
"(",
"kind",
",",
"child",
")",... | Run the callbacks for the document. This overrides active support's
functionality to cascade callbacks to embedded documents that have been
flagged as such.
@example Run the callbacks.
run_callbacks :save do
save!
end
@param [ Symbol ] kind The type of callback to execute.
@param [ Array ] args Any op... | [
"Run",
"the",
"callbacks",
"for",
"the",
"document",
".",
"This",
"overrides",
"active",
"support",
"s",
"functionality",
"to",
"cascade",
"callbacks",
"to",
"embedded",
"documents",
"that",
"have",
"been",
"flagged",
"as",
"such",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/interceptable.rb#L127-L134 | train |
mongodb/mongoid | lib/mongoid/interceptable.rb | Mongoid.Interceptable.cascadable_children | def cascadable_children(kind, children = Set.new)
embedded_relations.each_pair do |name, association|
next unless association.cascading_callbacks?
without_autobuild do
delayed_pulls = delayed_atomic_pulls[name]
delayed_unsets = delayed_atomic_unsets[name]
children.mer... | ruby | def cascadable_children(kind, children = Set.new)
embedded_relations.each_pair do |name, association|
next unless association.cascading_callbacks?
without_autobuild do
delayed_pulls = delayed_atomic_pulls[name]
delayed_unsets = delayed_atomic_unsets[name]
children.mer... | [
"def",
"cascadable_children",
"(",
"kind",
",",
"children",
"=",
"Set",
".",
"new",
")",
"embedded_relations",
".",
"each_pair",
"do",
"|",
"name",
",",
"association",
"|",
"next",
"unless",
"association",
".",
"cascading_callbacks?",
"without_autobuild",
"do",
... | Get all the child embedded documents that are flagged as cascadable.
@example Get all the cascading children.
document.cascadable_children(:update)
@param [ Symbol ] kind The type of callback.
@return [ Array<Document> ] The children.
@since 2.3.0 | [
"Get",
"all",
"the",
"child",
"embedded",
"documents",
"that",
"are",
"flagged",
"as",
"cascadable",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/interceptable.rb#L163-L180 | train |
mongodb/mongoid | lib/mongoid/interceptable.rb | Mongoid.Interceptable.cascadable_child? | def cascadable_child?(kind, child, association)
return false if kind == :initialize || kind == :find || kind == :touch
return false if kind == :validate && association.validate?
child.callback_executable?(kind) ? child.in_callback_state?(kind) : false
end | ruby | def cascadable_child?(kind, child, association)
return false if kind == :initialize || kind == :find || kind == :touch
return false if kind == :validate && association.validate?
child.callback_executable?(kind) ? child.in_callback_state?(kind) : false
end | [
"def",
"cascadable_child?",
"(",
"kind",
",",
"child",
",",
"association",
")",
"return",
"false",
"if",
"kind",
"==",
":initialize",
"||",
"kind",
"==",
":find",
"||",
"kind",
"==",
":touch",
"return",
"false",
"if",
"kind",
"==",
":validate",
"&&",
"asso... | Determine if the child should fire the callback.
@example Should the child fire the callback?
document.cascadable_child?(:update, doc)
@param [ Symbol ] kind The type of callback.
@param [ Document ] child The child document.
@return [ true, false ] If the child should fire the callback.
@since 2.3.0 | [
"Determine",
"if",
"the",
"child",
"should",
"fire",
"the",
"callback",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/interceptable.rb#L193-L197 | train |
mongodb/mongoid | lib/mongoid/config.rb | Mongoid.Config.connect_to | def connect_to(name, options = { read: { mode: :primary }})
self.clients = {
default: {
database: name,
hosts: [ "localhost:27017" ],
options: options
}
}
end | ruby | def connect_to(name, options = { read: { mode: :primary }})
self.clients = {
default: {
database: name,
hosts: [ "localhost:27017" ],
options: options
}
}
end | [
"def",
"connect_to",
"(",
"name",
",",
"options",
"=",
"{",
"read",
":",
"{",
"mode",
":",
":primary",
"}",
"}",
")",
"self",
".",
"clients",
"=",
"{",
"default",
":",
"{",
"database",
":",
"name",
",",
"hosts",
":",
"[",
"\"localhost:27017\"",
"]",
... | Connect to the provided database name on the default client.
@note Use only in development or test environments for convenience.
@example Set the database to connect to.
config.connect_to("mongoid_test")
@param [ String ] name The database name.
@since 3.0.0 | [
"Connect",
"to",
"the",
"provided",
"database",
"name",
"on",
"the",
"default",
"client",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/config.rb#L67-L75 | train |
mongodb/mongoid | lib/mongoid/config.rb | Mongoid.Config.load! | def load!(path, environment = nil)
settings = Environment.load_yaml(path, environment)
if settings.present?
Clients.disconnect
Clients.clear
load_configuration(settings)
end
settings
end | ruby | def load!(path, environment = nil)
settings = Environment.load_yaml(path, environment)
if settings.present?
Clients.disconnect
Clients.clear
load_configuration(settings)
end
settings
end | [
"def",
"load!",
"(",
"path",
",",
"environment",
"=",
"nil",
")",
"settings",
"=",
"Environment",
".",
"load_yaml",
"(",
"path",
",",
"environment",
")",
"if",
"settings",
".",
"present?",
"Clients",
".",
"disconnect",
"Clients",
".",
"clear",
"load_configur... | Load the settings from a compliant mongoid.yml file. This can be used for
easy setup with frameworks other than Rails.
@example Configure Mongoid.
Mongoid.load!("/path/to/mongoid.yml")
@param [ String ] path The path to the file.
@param [ String, Symbol ] environment The environment to load.
@since 2.0.1 | [
"Load",
"the",
"settings",
"from",
"a",
"compliant",
"mongoid",
".",
"yml",
"file",
".",
"This",
"can",
"be",
"used",
"for",
"easy",
"setup",
"with",
"frameworks",
"other",
"than",
"Rails",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/config.rb#L98-L106 | train |
mongodb/mongoid | lib/mongoid/config.rb | Mongoid.Config.register_model | def register_model(klass)
LOCK.synchronize do
models.push(klass) unless models.include?(klass)
end
end | ruby | def register_model(klass)
LOCK.synchronize do
models.push(klass) unless models.include?(klass)
end
end | [
"def",
"register_model",
"(",
"klass",
")",
"LOCK",
".",
"synchronize",
"do",
"models",
".",
"push",
"(",
"klass",
")",
"unless",
"models",
".",
"include?",
"(",
"klass",
")",
"end",
"end"
] | Register a model in the application with Mongoid.
@example Register a model.
config.register_model(Band)
@param [ Class ] klass The model to register.
@since 3.1.0 | [
"Register",
"a",
"model",
"in",
"the",
"application",
"with",
"Mongoid",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/config.rb#L129-L133 | train |
mongodb/mongoid | lib/mongoid/config.rb | Mongoid.Config.load_configuration | def load_configuration(settings)
configuration = settings.with_indifferent_access
self.options = configuration[:options]
self.clients = configuration[:clients]
set_log_levels
end | ruby | def load_configuration(settings)
configuration = settings.with_indifferent_access
self.options = configuration[:options]
self.clients = configuration[:clients]
set_log_levels
end | [
"def",
"load_configuration",
"(",
"settings",
")",
"configuration",
"=",
"settings",
".",
"with_indifferent_access",
"self",
".",
"options",
"=",
"configuration",
"[",
":options",
"]",
"self",
".",
"clients",
"=",
"configuration",
"[",
":clients",
"]",
"set_log_le... | From a hash of settings, load all the configuration.
@example Load the configuration.
config.load_configuration(settings)
@param [ Hash ] settings The configuration settings.
@since 3.1.0 | [
"From",
"a",
"hash",
"of",
"settings",
"load",
"all",
"the",
"configuration",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/config.rb#L143-L148 | train |
mongodb/mongoid | lib/mongoid/config.rb | Mongoid.Config.truncate! | def truncate!
Clients.default.database.collections.each do |collection|
collection.find.delete_many
end and true
end | ruby | def truncate!
Clients.default.database.collections.each do |collection|
collection.find.delete_many
end and true
end | [
"def",
"truncate!",
"Clients",
".",
"default",
".",
"database",
".",
"collections",
".",
"each",
"do",
"|",
"collection",
"|",
"collection",
".",
"find",
".",
"delete_many",
"end",
"and",
"true",
"end"
] | Truncate all data in all collections, but not the indexes.
@example Truncate all collection data.
Mongoid::Config.truncate!
@note This will be slower than purge!
@return [ true ] true.
@since 2.0.2 | [
"Truncate",
"all",
"data",
"in",
"all",
"collections",
"but",
"not",
"the",
"indexes",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/config.rb#L202-L206 | train |
mongodb/mongoid | lib/mongoid/config.rb | Mongoid.Config.options= | def options=(options)
if options
options.each_pair do |option, value|
Validators::Option.validate(option)
send("#{option}=", value)
end
end
end | ruby | def options=(options)
if options
options.each_pair do |option, value|
Validators::Option.validate(option)
send("#{option}=", value)
end
end
end | [
"def",
"options",
"=",
"(",
"options",
")",
"if",
"options",
"options",
".",
"each_pair",
"do",
"|",
"option",
",",
"value",
"|",
"Validators",
"::",
"Option",
".",
"validate",
"(",
"option",
")",
"send",
"(",
"\"#{option}=\"",
",",
"value",
")",
"end",
... | Set the configuration options. Will validate each one individually.
@example Set the options.
config.options = { raise_not_found_error: true }
@param [ Hash ] options The configuration options.
@since 3.0.0 | [
"Set",
"the",
"configuration",
"options",
".",
"Will",
"validate",
"each",
"one",
"individually",
"."
] | 56976e32610f4c2450882b0bfe14da099f0703f4 | https://github.com/mongodb/mongoid/blob/56976e32610f4c2450882b0bfe14da099f0703f4/lib/mongoid/config.rb#L216-L223 | train |
thoughtbot/clearance | lib/clearance/authorization.rb | Clearance.Authorization.deny_access | def deny_access(flash_message = nil)
respond_to do |format|
format.any(:js, :json, :xml) { head :unauthorized }
format.any { redirect_request(flash_message) }
end
end | ruby | def deny_access(flash_message = nil)
respond_to do |format|
format.any(:js, :json, :xml) { head :unauthorized }
format.any { redirect_request(flash_message) }
end
end | [
"def",
"deny_access",
"(",
"flash_message",
"=",
"nil",
")",
"respond_to",
"do",
"|",
"format",
"|",
"format",
".",
"any",
"(",
":js",
",",
":json",
",",
":xml",
")",
"{",
"head",
":unauthorized",
"}",
"format",
".",
"any",
"{",
"redirect_request",
"(",
... | Responds to unauthorized requests in a manner fitting the request format.
`js`, `json`, and `xml` requests will receive a 401 with no body. All
other formats will be redirected appropriately and can optionally have the
flash message set.
When redirecting, the originally requested url will be stored in the
session... | [
"Responds",
"to",
"unauthorized",
"requests",
"in",
"a",
"manner",
"fitting",
"the",
"request",
"format",
".",
"js",
"json",
"and",
"xml",
"requests",
"will",
"receive",
"a",
"401",
"with",
"no",
"body",
".",
"All",
"other",
"formats",
"will",
"be",
"redir... | 1623cdeb648f33a55f0eb7be17e8f19a4291e1f2 | https://github.com/thoughtbot/clearance/blob/1623cdeb648f33a55f0eb7be17e8f19a4291e1f2/lib/clearance/authorization.rb#L43-L48 | train |
thoughtbot/clearance | lib/clearance/rack_session.rb | Clearance.RackSession.call | def call(env)
session = Clearance::Session.new(env)
env[:clearance] = session
response = @app.call(env)
session.add_cookie_to_headers response[1]
response
end | ruby | def call(env)
session = Clearance::Session.new(env)
env[:clearance] = session
response = @app.call(env)
session.add_cookie_to_headers response[1]
response
end | [
"def",
"call",
"(",
"env",
")",
"session",
"=",
"Clearance",
"::",
"Session",
".",
"new",
"(",
"env",
")",
"env",
"[",
":clearance",
"]",
"=",
"session",
"response",
"=",
"@app",
".",
"call",
"(",
"env",
")",
"session",
".",
"add_cookie_to_headers",
"r... | Reads previously existing sessions from a cookie and maintains the cookie
on each response. | [
"Reads",
"previously",
"existing",
"sessions",
"from",
"a",
"cookie",
"and",
"maintains",
"the",
"cookie",
"on",
"each",
"response",
"."
] | 1623cdeb648f33a55f0eb7be17e8f19a4291e1f2 | https://github.com/thoughtbot/clearance/blob/1623cdeb648f33a55f0eb7be17e8f19a4291e1f2/lib/clearance/rack_session.rb#L20-L26 | train |
meew0/discordrb | lib/discordrb/data/user.rb | Discordrb.User.send_file | def send_file(file, caption = nil, filename: nil, spoiler: nil)
pm.send_file(file, caption: caption, filename: filename, spoiler: spoiler)
end | ruby | def send_file(file, caption = nil, filename: nil, spoiler: nil)
pm.send_file(file, caption: caption, filename: filename, spoiler: spoiler)
end | [
"def",
"send_file",
"(",
"file",
",",
"caption",
"=",
"nil",
",",
"filename",
":",
"nil",
",",
"spoiler",
":",
"nil",
")",
"pm",
".",
"send_file",
"(",
"file",
",",
"caption",
":",
"caption",
",",
"filename",
":",
"filename",
",",
"spoiler",
":",
"sp... | Send the user a file.
@param file [File] The file to send to the user
@param caption [String] The caption of the file being sent
@param filename [String] Overrides the filename of the uploaded file
@param spoiler [true, false] Whether or not this file should appear as a spoiler.
@return [Message] the message sent ... | [
"Send",
"the",
"user",
"a",
"file",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/user.rb#L108-L110 | train |
meew0/discordrb | lib/discordrb/data/user.rb | Discordrb.User.update_presence | def update_presence(data)
@status = data['status'].to_sym
if data['game']
game = data['game']
@game = game['name']
@stream_url = game['url']
@stream_type = game['type']
else
@game = @stream_url = @stream_type = nil
end
end | ruby | def update_presence(data)
@status = data['status'].to_sym
if data['game']
game = data['game']
@game = game['name']
@stream_url = game['url']
@stream_type = game['type']
else
@game = @stream_url = @stream_type = nil
end
end | [
"def",
"update_presence",
"(",
"data",
")",
"@status",
"=",
"data",
"[",
"'status'",
"]",
".",
"to_sym",
"if",
"data",
"[",
"'game'",
"]",
"game",
"=",
"data",
"[",
"'game'",
"]",
"@game",
"=",
"game",
"[",
"'name'",
"]",
"@stream_url",
"=",
"game",
... | Set the user's presence data
@note for internal use only
@!visibility private | [
"Set",
"the",
"user",
"s",
"presence",
"data"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/user.rb#L122-L134 | train |
meew0/discordrb | lib/discordrb/permissions.rb | Discordrb.PermissionCalculator.permission? | def permission?(action, channel = nil)
# If the member is the server owner, it irrevocably has all permissions.
return true if owner?
# First, check whether the user has Manage Roles defined.
# (Coincidentally, Manage Permissions is the same permission as Manage Roles, and a
# Manage Perm... | ruby | def permission?(action, channel = nil)
# If the member is the server owner, it irrevocably has all permissions.
return true if owner?
# First, check whether the user has Manage Roles defined.
# (Coincidentally, Manage Permissions is the same permission as Manage Roles, and a
# Manage Perm... | [
"def",
"permission?",
"(",
"action",
",",
"channel",
"=",
"nil",
")",
"# If the member is the server owner, it irrevocably has all permissions.",
"return",
"true",
"if",
"owner?",
"# First, check whether the user has Manage Roles defined.",
"# (Coincidentally, Manage Permissions is the... | Checks whether this user can do the particular action, regardless of whether it has the permission defined,
through for example being the server owner or having the Manage Roles permission
@param action [Symbol] The permission that should be checked. See also {Permissions::FLAGS} for a list.
@param channel [Channel,... | [
"Checks",
"whether",
"this",
"user",
"can",
"do",
"the",
"particular",
"action",
"regardless",
"of",
"whether",
"it",
"has",
"the",
"permission",
"defined",
"through",
"for",
"example",
"being",
"the",
"server",
"owner",
"or",
"having",
"the",
"Manage",
"Roles... | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/permissions.rb#L135-L147 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.category= | def category=(channel)
channel = @bot.channel(channel)
raise ArgumentError, 'Cannot set parent category to a channel that isn\'t a category' unless channel.category?
update_channel_data(parent_id: channel.id)
end | ruby | def category=(channel)
channel = @bot.channel(channel)
raise ArgumentError, 'Cannot set parent category to a channel that isn\'t a category' unless channel.category?
update_channel_data(parent_id: channel.id)
end | [
"def",
"category",
"=",
"(",
"channel",
")",
"channel",
"=",
"@bot",
".",
"channel",
"(",
"channel",
")",
"raise",
"ArgumentError",
",",
"'Cannot set parent category to a channel that isn\\'t a category'",
"unless",
"channel",
".",
"category?",
"update_channel_data",
"(... | Sets this channels parent category
@param channel [Channel, #resolve_id] the target category channel
@raise [ArgumentError] if the target channel isn't a category | [
"Sets",
"this",
"channels",
"parent",
"category"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L155-L160 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.sort_after | def sort_after(other = nil, lock_permissions = false)
raise TypeError, 'other must be one of Channel, NilClass, or #resolve_id' unless other.is_a?(Channel) || other.nil? || other.respond_to?(:resolve_id)
other = @bot.channel(other.resolve_id) if other
# Container for the API request payload
mo... | ruby | def sort_after(other = nil, lock_permissions = false)
raise TypeError, 'other must be one of Channel, NilClass, or #resolve_id' unless other.is_a?(Channel) || other.nil? || other.respond_to?(:resolve_id)
other = @bot.channel(other.resolve_id) if other
# Container for the API request payload
mo... | [
"def",
"sort_after",
"(",
"other",
"=",
"nil",
",",
"lock_permissions",
"=",
"false",
")",
"raise",
"TypeError",
",",
"'other must be one of Channel, NilClass, or #resolve_id'",
"unless",
"other",
".",
"is_a?",
"(",
"Channel",
")",
"||",
"other",
".",
"nil?",
"||"... | Sorts this channel's position to follow another channel.
@param other [Channel, #resolve_id, nil] The channel below which this channel should be sorted. If the given
channel is a category, this channel will be sorted at the top of that category. If it is `nil`, the channel will
be sorted at the top of the channe... | [
"Sorts",
"this",
"channel",
"s",
"position",
"to",
"follow",
"another",
"channel",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L169-L228 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.nsfw= | def nsfw=(nsfw)
raise ArgumentError, 'nsfw value must be true or false' unless nsfw.is_a?(TrueClass) || nsfw.is_a?(FalseClass)
update_channel_data(nsfw: nsfw)
end | ruby | def nsfw=(nsfw)
raise ArgumentError, 'nsfw value must be true or false' unless nsfw.is_a?(TrueClass) || nsfw.is_a?(FalseClass)
update_channel_data(nsfw: nsfw)
end | [
"def",
"nsfw",
"=",
"(",
"nsfw",
")",
"raise",
"ArgumentError",
",",
"'nsfw value must be true or false'",
"unless",
"nsfw",
".",
"is_a?",
"(",
"TrueClass",
")",
"||",
"nsfw",
".",
"is_a?",
"(",
"FalseClass",
")",
"update_channel_data",
"(",
"nsfw",
":",
"nsfw... | Sets whether this channel is NSFW
@param nsfw [true, false]
@raise [ArguementError] if value isn't one of true, false | [
"Sets",
"whether",
"this",
"channel",
"is",
"NSFW"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L233-L237 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.send_temporary_message | def send_temporary_message(content, timeout, tts = false, embed = nil)
@bot.send_temporary_message(@id, content, timeout, tts, embed)
end | ruby | def send_temporary_message(content, timeout, tts = false, embed = nil)
@bot.send_temporary_message(@id, content, timeout, tts, embed)
end | [
"def",
"send_temporary_message",
"(",
"content",
",",
"timeout",
",",
"tts",
"=",
"false",
",",
"embed",
"=",
"nil",
")",
"@bot",
".",
"send_temporary_message",
"(",
"@id",
",",
"content",
",",
"timeout",
",",
"tts",
",",
"embed",
")",
"end"
] | Sends a temporary message to this channel.
@param content [String] The content to send. Should not be longer than 2000 characters or it will result in an error.
@param timeout [Float] The amount of time in seconds after which the message sent will be deleted.
@param tts [true, false] Whether or not this message shou... | [
"Sends",
"a",
"temporary",
"message",
"to",
"this",
"channel",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L352-L354 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.send_embed | def send_embed(message = '', embed = nil)
embed ||= Discordrb::Webhooks::Embed.new
yield(embed) if block_given?
send_message(message, false, embed)
end | ruby | def send_embed(message = '', embed = nil)
embed ||= Discordrb::Webhooks::Embed.new
yield(embed) if block_given?
send_message(message, false, embed)
end | [
"def",
"send_embed",
"(",
"message",
"=",
"''",
",",
"embed",
"=",
"nil",
")",
"embed",
"||=",
"Discordrb",
"::",
"Webhooks",
"::",
"Embed",
".",
"new",
"yield",
"(",
"embed",
")",
"if",
"block_given?",
"send_message",
"(",
"message",
",",
"false",
",",
... | Convenience method to send a message with an embed.
@example Send a message with an embed
channel.send_embed do |embed|
embed.title = 'The Ruby logo'
embed.image = Discordrb::Webhooks::EmbedImage.new(url: 'https://www.ruby-lang.org/images/header-ruby-logo.png')
end
@param message [String] The message ... | [
"Convenience",
"method",
"to",
"send",
"a",
"message",
"with",
"an",
"embed",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L367-L371 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.send_file | def send_file(file, caption: nil, tts: false, filename: nil, spoiler: nil)
@bot.send_file(@id, file, caption: caption, tts: tts, filename: filename, spoiler: spoiler)
end | ruby | def send_file(file, caption: nil, tts: false, filename: nil, spoiler: nil)
@bot.send_file(@id, file, caption: caption, tts: tts, filename: filename, spoiler: spoiler)
end | [
"def",
"send_file",
"(",
"file",
",",
"caption",
":",
"nil",
",",
"tts",
":",
"false",
",",
"filename",
":",
"nil",
",",
"spoiler",
":",
"nil",
")",
"@bot",
".",
"send_file",
"(",
"@id",
",",
"file",
",",
"caption",
":",
"caption",
",",
"tts",
":",... | Sends a file to this channel. If it is an image, it will be embedded.
@param file [File] The file to send. There's no clear size limit for this, you'll have to attempt it for yourself (most non-image files are fine, large images may fail to embed)
@param caption [string] The caption for the file.
@param tts [true, f... | [
"Sends",
"a",
"file",
"to",
"this",
"channel",
".",
"If",
"it",
"is",
"an",
"image",
"it",
"will",
"be",
"embedded",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L393-L395 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.delete_overwrite | def delete_overwrite(target, reason = nil)
raise 'Tried deleting a overwrite for an invalid target' unless target.is_a?(Member) || target.is_a?(User) || target.is_a?(Role) || target.is_a?(Profile) || target.is_a?(Recipient) || target.respond_to?(:resolve_id)
API::Channel.delete_permission(@bot.token, @id, ... | ruby | def delete_overwrite(target, reason = nil)
raise 'Tried deleting a overwrite for an invalid target' unless target.is_a?(Member) || target.is_a?(User) || target.is_a?(Role) || target.is_a?(Profile) || target.is_a?(Recipient) || target.respond_to?(:resolve_id)
API::Channel.delete_permission(@bot.token, @id, ... | [
"def",
"delete_overwrite",
"(",
"target",
",",
"reason",
"=",
"nil",
")",
"raise",
"'Tried deleting a overwrite for an invalid target'",
"unless",
"target",
".",
"is_a?",
"(",
"Member",
")",
"||",
"target",
".",
"is_a?",
"(",
"User",
")",
"||",
"target",
".",
... | Deletes a permission overwrite for this channel
@param target [Member, User, Role, Profile, Recipient, #resolve_id] What permission overwrite to delete
@param reason [String] The reason the for the overwrite deletion. | [
"Deletes",
"a",
"permission",
"overwrite",
"for",
"this",
"channel"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L482-L486 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.update_from | def update_from(other)
@topic = other.topic
@name = other.name
@position = other.position
@topic = other.topic
@recipients = other.recipients
@bitrate = other.bitrate
@user_limit = other.user_limit
@permission_overwrites = other.permission_overwrites
@nsfw = other.n... | ruby | def update_from(other)
@topic = other.topic
@name = other.name
@position = other.position
@topic = other.topic
@recipients = other.recipients
@bitrate = other.bitrate
@user_limit = other.user_limit
@permission_overwrites = other.permission_overwrites
@nsfw = other.n... | [
"def",
"update_from",
"(",
"other",
")",
"@topic",
"=",
"other",
".",
"topic",
"@name",
"=",
"other",
".",
"name",
"@position",
"=",
"other",
".",
"position",
"@topic",
"=",
"other",
".",
"topic",
"@recipients",
"=",
"other",
".",
"recipients",
"@bitrate",... | Updates the cached data from another channel.
@note For internal use only
@!visibility private | [
"Updates",
"the",
"cached",
"data",
"from",
"another",
"channel",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L491-L503 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.users | def users
if text?
@server.online_members(include_idle: true).select { |u| u.can_read_messages? self }
elsif voice?
@server.voice_states.map { |id, voice_state| @server.member(id) if !voice_state.voice_channel.nil? && voice_state.voice_channel.id == @id }.compact
end
end | ruby | def users
if text?
@server.online_members(include_idle: true).select { |u| u.can_read_messages? self }
elsif voice?
@server.voice_states.map { |id, voice_state| @server.member(id) if !voice_state.voice_channel.nil? && voice_state.voice_channel.id == @id }.compact
end
end | [
"def",
"users",
"if",
"text?",
"@server",
".",
"online_members",
"(",
"include_idle",
":",
"true",
")",
".",
"select",
"{",
"|",
"u",
"|",
"u",
".",
"can_read_messages?",
"self",
"}",
"elsif",
"voice?",
"@server",
".",
"voice_states",
".",
"map",
"{",
"|... | The list of users currently in this channel. For a voice channel, it will return all the members currently
in that channel. For a text channel, it will return all online members that have permission to read it.
@return [Array<Member>] the users in this channel | [
"The",
"list",
"of",
"users",
"currently",
"in",
"this",
"channel",
".",
"For",
"a",
"voice",
"channel",
"it",
"will",
"return",
"all",
"the",
"members",
"currently",
"in",
"that",
"channel",
".",
"For",
"a",
"text",
"channel",
"it",
"will",
"return",
"a... | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L508-L514 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.history | def history(amount, before_id = nil, after_id = nil, around_id = nil)
logs = API::Channel.messages(@bot.token, @id, amount, before_id, after_id, around_id)
JSON.parse(logs).map { |message| Message.new(message, @bot) }
end | ruby | def history(amount, before_id = nil, after_id = nil, around_id = nil)
logs = API::Channel.messages(@bot.token, @id, amount, before_id, after_id, around_id)
JSON.parse(logs).map { |message| Message.new(message, @bot) }
end | [
"def",
"history",
"(",
"amount",
",",
"before_id",
"=",
"nil",
",",
"after_id",
"=",
"nil",
",",
"around_id",
"=",
"nil",
")",
"logs",
"=",
"API",
"::",
"Channel",
".",
"messages",
"(",
"@bot",
".",
"token",
",",
"@id",
",",
"amount",
",",
"before_id... | Retrieves some of this channel's message history.
@param amount [Integer] How many messages to retrieve. This must be less than or equal to 100, if it is higher
than 100 it will be treated as 100 on Discord's side.
@param before_id [Integer] The ID of the most recent message the retrieval should start at, or nil i... | [
"Retrieves",
"some",
"of",
"this",
"channel",
"s",
"message",
"history",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L529-L532 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.history_ids | def history_ids(amount, before_id = nil, after_id = nil, around_id = nil)
logs = API::Channel.messages(@bot.token, @id, amount, before_id, after_id, around_id)
JSON.parse(logs).map { |message| message['id'].to_i }
end | ruby | def history_ids(amount, before_id = nil, after_id = nil, around_id = nil)
logs = API::Channel.messages(@bot.token, @id, amount, before_id, after_id, around_id)
JSON.parse(logs).map { |message| message['id'].to_i }
end | [
"def",
"history_ids",
"(",
"amount",
",",
"before_id",
"=",
"nil",
",",
"after_id",
"=",
"nil",
",",
"around_id",
"=",
"nil",
")",
"logs",
"=",
"API",
"::",
"Channel",
".",
"messages",
"(",
"@bot",
".",
"token",
",",
"@id",
",",
"amount",
",",
"befor... | Retrieves message history, but only message IDs for use with prune.
@note For internal use only
@!visibility private | [
"Retrieves",
"message",
"history",
"but",
"only",
"message",
"IDs",
"for",
"use",
"with",
"prune",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L537-L540 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.load_message | def load_message(message_id)
response = API::Channel.message(@bot.token, @id, message_id)
Message.new(JSON.parse(response), @bot)
rescue RestClient::ResourceNotFound
nil
end | ruby | def load_message(message_id)
response = API::Channel.message(@bot.token, @id, message_id)
Message.new(JSON.parse(response), @bot)
rescue RestClient::ResourceNotFound
nil
end | [
"def",
"load_message",
"(",
"message_id",
")",
"response",
"=",
"API",
"::",
"Channel",
".",
"message",
"(",
"@bot",
".",
"token",
",",
"@id",
",",
"message_id",
")",
"Message",
".",
"new",
"(",
"JSON",
".",
"parse",
"(",
"response",
")",
",",
"@bot",
... | Returns a single message from this channel's history by ID.
@param message_id [Integer] The ID of the message to retrieve.
@return [Message, nil] the retrieved message, or `nil` if it couldn't be found. | [
"Returns",
"a",
"single",
"message",
"from",
"this",
"channel",
"s",
"history",
"by",
"ID",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L545-L550 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.pins | def pins
msgs = API::Channel.pinned_messages(@bot.token, @id)
JSON.parse(msgs).map { |msg| Message.new(msg, @bot) }
end | ruby | def pins
msgs = API::Channel.pinned_messages(@bot.token, @id)
JSON.parse(msgs).map { |msg| Message.new(msg, @bot) }
end | [
"def",
"pins",
"msgs",
"=",
"API",
"::",
"Channel",
".",
"pinned_messages",
"(",
"@bot",
".",
"token",
",",
"@id",
")",
"JSON",
".",
"parse",
"(",
"msgs",
")",
".",
"map",
"{",
"|",
"msg",
"|",
"Message",
".",
"new",
"(",
"msg",
",",
"@bot",
")",... | Requests all pinned messages in a channel.
@return [Array<Message>] the received messages. | [
"Requests",
"all",
"pinned",
"messages",
"in",
"a",
"channel",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L556-L559 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.prune | def prune(amount, strict = false, &block)
raise ArgumentError, 'Can only delete between 1 and 100 messages!' unless amount.between?(1, 100)
messages =
if block_given?
history(amount).select(&block).map(&:id)
else
history_ids(amount)
end
case messages.size
... | ruby | def prune(amount, strict = false, &block)
raise ArgumentError, 'Can only delete between 1 and 100 messages!' unless amount.between?(1, 100)
messages =
if block_given?
history(amount).select(&block).map(&:id)
else
history_ids(amount)
end
case messages.size
... | [
"def",
"prune",
"(",
"amount",
",",
"strict",
"=",
"false",
",",
"&",
"block",
")",
"raise",
"ArgumentError",
",",
"'Can only delete between 1 and 100 messages!'",
"unless",
"amount",
".",
"between?",
"(",
"1",
",",
"100",
")",
"messages",
"=",
"if",
"block_gi... | Delete the last N messages on this channel.
@param amount [Integer] The amount of message history to consider for pruning. Must be a value between 2 and 100 (Discord limitation)
@param strict [true, false] Whether an error should be raised when a message is reached that is too old to be bulk
deleted. If this is fa... | [
"Delete",
"the",
"last",
"N",
"messages",
"on",
"this",
"channel",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L570-L589 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.delete_messages | def delete_messages(messages, strict = false)
raise ArgumentError, 'Can only delete between 2 and 100 messages!' unless messages.count.between?(2, 100)
messages.map!(&:resolve_id)
bulk_delete(messages, strict)
end | ruby | def delete_messages(messages, strict = false)
raise ArgumentError, 'Can only delete between 2 and 100 messages!' unless messages.count.between?(2, 100)
messages.map!(&:resolve_id)
bulk_delete(messages, strict)
end | [
"def",
"delete_messages",
"(",
"messages",
",",
"strict",
"=",
"false",
")",
"raise",
"ArgumentError",
",",
"'Can only delete between 2 and 100 messages!'",
"unless",
"messages",
".",
"count",
".",
"between?",
"(",
"2",
",",
"100",
")",
"messages",
".",
"map!",
... | Deletes a collection of messages
@param messages [Array<Message, Integer, #resolve_id>] the messages (or message IDs) to delete. Total must be an amount between 2 and 100 (Discord limitation)
@param strict [true, false] Whether an error should be raised when a message is reached that is too old to be bulk
deleted.... | [
"Deletes",
"a",
"collection",
"of",
"messages"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L597-L602 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.make_invite | def make_invite(max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil)
response = API::Channel.create_invite(@bot.token, @id, max_age, max_uses, temporary, unique, reason)
Invite.new(JSON.parse(response), @bot)
end | ruby | def make_invite(max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil)
response = API::Channel.create_invite(@bot.token, @id, max_age, max_uses, temporary, unique, reason)
Invite.new(JSON.parse(response), @bot)
end | [
"def",
"make_invite",
"(",
"max_age",
"=",
"0",
",",
"max_uses",
"=",
"0",
",",
"temporary",
"=",
"false",
",",
"unique",
"=",
"false",
",",
"reason",
"=",
"nil",
")",
"response",
"=",
"API",
"::",
"Channel",
".",
"create_invite",
"(",
"@bot",
".",
"... | Creates a new invite to this channel.
@param max_age [Integer] How many seconds this invite should last.
@param max_uses [Integer] How many times this invite should be able to be used.
@param temporary [true, false] Whether membership should be temporary (kicked after going offline).
@param unique [true, false] If ... | [
"Creates",
"a",
"new",
"invite",
"to",
"this",
"channel",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L633-L636 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.create_group | def create_group(user_ids)
raise 'Attempted to create group channel on a non-pm channel!' unless pm?
response = API::Channel.create_group(@bot.token, @id, user_ids.shift)
channel = Channel.new(JSON.parse(response), @bot)
channel.add_group_users(user_ids)
end | ruby | def create_group(user_ids)
raise 'Attempted to create group channel on a non-pm channel!' unless pm?
response = API::Channel.create_group(@bot.token, @id, user_ids.shift)
channel = Channel.new(JSON.parse(response), @bot)
channel.add_group_users(user_ids)
end | [
"def",
"create_group",
"(",
"user_ids",
")",
"raise",
"'Attempted to create group channel on a non-pm channel!'",
"unless",
"pm?",
"response",
"=",
"API",
"::",
"Channel",
".",
"create_group",
"(",
"@bot",
".",
"token",
",",
"@id",
",",
"user_ids",
".",
"shift",
"... | Creates a Group channel
@param user_ids [Array<Integer>] Array of user IDs to add to the new group channel (Excluding
the recipient of the PM channel).
@return [Channel] the created channel. | [
"Creates",
"a",
"Group",
"channel"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L653-L659 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.add_group_users | def add_group_users(user_ids)
raise 'Attempted to add a user to a non-group channel!' unless group?
user_ids = [user_ids] unless user_ids.is_a? Array
user_ids.each do |user_id|
API::Channel.add_group_user(@bot.token, @id, user_id.resolve_id)
end
self
end | ruby | def add_group_users(user_ids)
raise 'Attempted to add a user to a non-group channel!' unless group?
user_ids = [user_ids] unless user_ids.is_a? Array
user_ids.each do |user_id|
API::Channel.add_group_user(@bot.token, @id, user_id.resolve_id)
end
self
end | [
"def",
"add_group_users",
"(",
"user_ids",
")",
"raise",
"'Attempted to add a user to a non-group channel!'",
"unless",
"group?",
"user_ids",
"=",
"[",
"user_ids",
"]",
"unless",
"user_ids",
".",
"is_a?",
"Array",
"user_ids",
".",
"each",
"do",
"|",
"user_id",
"|",
... | Adds a user to a group channel.
@param user_ids [Array<#resolve_id>, #resolve_id] User ID or array of user IDs to add to the group channel.
@return [Channel] the group channel. | [
"Adds",
"a",
"user",
"to",
"a",
"group",
"channel",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L664-L672 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.remove_group_users | def remove_group_users(user_ids)
raise 'Attempted to remove a user from a non-group channel!' unless group?
user_ids = [user_ids] unless user_ids.is_a? Array
user_ids.each do |user_id|
API::Channel.remove_group_user(@bot.token, @id, user_id.resolve_id)
end
self
end | ruby | def remove_group_users(user_ids)
raise 'Attempted to remove a user from a non-group channel!' unless group?
user_ids = [user_ids] unless user_ids.is_a? Array
user_ids.each do |user_id|
API::Channel.remove_group_user(@bot.token, @id, user_id.resolve_id)
end
self
end | [
"def",
"remove_group_users",
"(",
"user_ids",
")",
"raise",
"'Attempted to remove a user from a non-group channel!'",
"unless",
"group?",
"user_ids",
"=",
"[",
"user_ids",
"]",
"unless",
"user_ids",
".",
"is_a?",
"Array",
"user_ids",
".",
"each",
"do",
"|",
"user_id",... | Removes a user from a group channel.
@param user_ids [Array<#resolve_id>, #resolve_id] User ID or array of user IDs to remove from the group channel.
@return [Channel] the group channel. | [
"Removes",
"a",
"user",
"from",
"a",
"group",
"channel",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L679-L687 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.webhooks | def webhooks
raise 'Tried to request webhooks from a non-server channel' unless server
webhooks = JSON.parse(API::Channel.webhooks(@bot.token, @id))
webhooks.map { |webhook_data| Webhook.new(webhook_data, @bot) }
end | ruby | def webhooks
raise 'Tried to request webhooks from a non-server channel' unless server
webhooks = JSON.parse(API::Channel.webhooks(@bot.token, @id))
webhooks.map { |webhook_data| Webhook.new(webhook_data, @bot) }
end | [
"def",
"webhooks",
"raise",
"'Tried to request webhooks from a non-server channel'",
"unless",
"server",
"webhooks",
"=",
"JSON",
".",
"parse",
"(",
"API",
"::",
"Channel",
".",
"webhooks",
"(",
"@bot",
".",
"token",
",",
"@id",
")",
")",
"webhooks",
".",
"map",... | Requests a list of Webhooks on the channel.
@return [Array<Webhook>] webhooks on the channel. | [
"Requests",
"a",
"list",
"of",
"Webhooks",
"on",
"the",
"channel",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L702-L707 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.invites | def invites
raise 'Tried to request invites from a non-server channel' unless server
invites = JSON.parse(API::Channel.invites(@bot.token, @id))
invites.map { |invite_data| Invite.new(invite_data, @bot) }
end | ruby | def invites
raise 'Tried to request invites from a non-server channel' unless server
invites = JSON.parse(API::Channel.invites(@bot.token, @id))
invites.map { |invite_data| Invite.new(invite_data, @bot) }
end | [
"def",
"invites",
"raise",
"'Tried to request invites from a non-server channel'",
"unless",
"server",
"invites",
"=",
"JSON",
".",
"parse",
"(",
"API",
"::",
"Channel",
".",
"invites",
"(",
"@bot",
".",
"token",
",",
"@id",
")",
")",
"invites",
".",
"map",
"{... | Requests a list of Invites to the channel.
@return [Array<Invite>] invites to the channel. | [
"Requests",
"a",
"list",
"of",
"Invites",
"to",
"the",
"channel",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L711-L716 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.add_recipient | def add_recipient(recipient)
raise 'Tried to add recipient to a non-group channel' unless group?
raise ArgumentError, 'Tried to add a non-recipient to a group' unless recipient.is_a?(Recipient)
@recipients << recipient
end | ruby | def add_recipient(recipient)
raise 'Tried to add recipient to a non-group channel' unless group?
raise ArgumentError, 'Tried to add a non-recipient to a group' unless recipient.is_a?(Recipient)
@recipients << recipient
end | [
"def",
"add_recipient",
"(",
"recipient",
")",
"raise",
"'Tried to add recipient to a non-group channel'",
"unless",
"group?",
"raise",
"ArgumentError",
",",
"'Tried to add a non-recipient to a group'",
"unless",
"recipient",
".",
"is_a?",
"(",
"Recipient",
")",
"@recipients"... | Adds a recipient to a group channel.
@param recipient [Recipient] the recipient to add to the group
@raise [ArgumentError] if tried to add a non-recipient
@note For internal use only
@!visibility private | [
"Adds",
"a",
"recipient",
"to",
"a",
"group",
"channel",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L728-L733 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.remove_recipient | def remove_recipient(recipient)
raise 'Tried to remove recipient from a non-group channel' unless group?
raise ArgumentError, 'Tried to remove a non-recipient from a group' unless recipient.is_a?(Recipient)
@recipients.delete(recipient)
end | ruby | def remove_recipient(recipient)
raise 'Tried to remove recipient from a non-group channel' unless group?
raise ArgumentError, 'Tried to remove a non-recipient from a group' unless recipient.is_a?(Recipient)
@recipients.delete(recipient)
end | [
"def",
"remove_recipient",
"(",
"recipient",
")",
"raise",
"'Tried to remove recipient from a non-group channel'",
"unless",
"group?",
"raise",
"ArgumentError",
",",
"'Tried to remove a non-recipient from a group'",
"unless",
"recipient",
".",
"is_a?",
"(",
"Recipient",
")",
... | Removes a recipient from a group channel.
@param recipient [Recipient] the recipient to remove from the group
@raise [ArgumentError] if tried to remove a non-recipient
@note For internal use only
@!visibility private | [
"Removes",
"a",
"recipient",
"from",
"a",
"group",
"channel",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L740-L745 | train |
meew0/discordrb | lib/discordrb/data/channel.rb | Discordrb.Channel.bulk_delete | def bulk_delete(ids, strict = false)
min_snowflake = IDObject.synthesise(Time.now - TWO_WEEKS)
ids.reject! do |e|
next unless e < min_snowflake
message = "Attempted to bulk_delete message #{e} which is too old (min = #{min_snowflake})"
raise ArgumentError, message if strict
... | ruby | def bulk_delete(ids, strict = false)
min_snowflake = IDObject.synthesise(Time.now - TWO_WEEKS)
ids.reject! do |e|
next unless e < min_snowflake
message = "Attempted to bulk_delete message #{e} which is too old (min = #{min_snowflake})"
raise ArgumentError, message if strict
... | [
"def",
"bulk_delete",
"(",
"ids",
",",
"strict",
"=",
"false",
")",
"min_snowflake",
"=",
"IDObject",
".",
"synthesise",
"(",
"Time",
".",
"now",
"-",
"TWO_WEEKS",
")",
"ids",
".",
"reject!",
"do",
"|",
"e",
"|",
"next",
"unless",
"e",
"<",
"min_snowfl... | Deletes a list of messages on this channel using bulk delete. | [
"Deletes",
"a",
"list",
"of",
"messages",
"on",
"this",
"channel",
"using",
"bulk",
"delete",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/channel.rb#L770-L785 | train |
meew0/discordrb | lib/discordrb/container.rb | Discordrb.EventContainer.include_events | def include_events(container)
handlers = container.instance_variable_get '@event_handlers'
return unless handlers
@event_handlers ||= {}
@event_handlers.merge!(handlers) { |_, old, new| old + new }
end | ruby | def include_events(container)
handlers = container.instance_variable_get '@event_handlers'
return unless handlers
@event_handlers ||= {}
@event_handlers.merge!(handlers) { |_, old, new| old + new }
end | [
"def",
"include_events",
"(",
"container",
")",
"handlers",
"=",
"container",
".",
"instance_variable_get",
"'@event_handlers'",
"return",
"unless",
"handlers",
"@event_handlers",
"||=",
"{",
"}",
"@event_handlers",
".",
"merge!",
"(",
"handlers",
")",
"{",
"|",
"... | Adds all event handlers from another container into this one. Existing event handlers will be overwritten.
@param container [Module] A module that `extend`s {EventContainer} from which the handlers will be added. | [
"Adds",
"all",
"event",
"handlers",
"from",
"another",
"container",
"into",
"this",
"one",
".",
"Existing",
"event",
"handlers",
"will",
"be",
"overwritten",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/container.rb#L526-L532 | train |
meew0/discordrb | lib/discordrb/data/webhook.rb | Discordrb.Webhook.update | def update(data)
# Only pass a value for avatar if the key is defined as sending nil will delete the
data[:avatar] = avatarise(data[:avatar]) if data.key?(:avatar)
data[:channel_id] = data[:channel].resolve_id
data.delete(:channel)
update_webhook(data)
end | ruby | def update(data)
# Only pass a value for avatar if the key is defined as sending nil will delete the
data[:avatar] = avatarise(data[:avatar]) if data.key?(:avatar)
data[:channel_id] = data[:channel].resolve_id
data.delete(:channel)
update_webhook(data)
end | [
"def",
"update",
"(",
"data",
")",
"# Only pass a value for avatar if the key is defined as sending nil will delete the",
"data",
"[",
":avatar",
"]",
"=",
"avatarise",
"(",
"data",
"[",
":avatar",
"]",
")",
"if",
"data",
".",
"key?",
"(",
":avatar",
")",
"data",
... | Updates the webhook if you need to edit more than 1 attribute.
@param data [Hash] the data to update.
@option data [String, #read, nil] :avatar The new avatar, in base64-encoded JPG format, or nil to delete the avatar.
@option data [Channel, String, Integer, #resolve_id] :channel The channel the webhook should use.
... | [
"Updates",
"the",
"webhook",
"if",
"you",
"need",
"to",
"edit",
"more",
"than",
"1",
"attribute",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/webhook.rb#L77-L83 | train |
meew0/discordrb | lib/discordrb/data/webhook.rb | Discordrb.Webhook.delete | def delete(reason = nil)
if token?
API::Webhook.token_delete_webhook(@token, @id, reason)
else
API::Webhook.delete_webhook(@bot.token, @id, reason)
end
end | ruby | def delete(reason = nil)
if token?
API::Webhook.token_delete_webhook(@token, @id, reason)
else
API::Webhook.delete_webhook(@bot.token, @id, reason)
end
end | [
"def",
"delete",
"(",
"reason",
"=",
"nil",
")",
"if",
"token?",
"API",
"::",
"Webhook",
".",
"token_delete_webhook",
"(",
"@token",
",",
"@id",
",",
"reason",
")",
"else",
"API",
"::",
"Webhook",
".",
"delete_webhook",
"(",
"@bot",
".",
"token",
",",
... | Deletes the webhook.
@param reason [String] The reason the invite is being deleted. | [
"Deletes",
"the",
"webhook",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/data/webhook.rb#L87-L93 | train |
meew0/discordrb | lib/discordrb/webhooks/embeds.rb | Discordrb::Webhooks.Embed.colour= | def colour=(value)
if value.nil?
@colour = nil
elsif value.is_a? Integer
raise ArgumentError, 'Embed colour must be 24-bit!' if value >= 16_777_216
@colour = value
elsif value.is_a? String
self.colour = value.delete('#').to_i(16)
elsif value.is_a? Array
r... | ruby | def colour=(value)
if value.nil?
@colour = nil
elsif value.is_a? Integer
raise ArgumentError, 'Embed colour must be 24-bit!' if value >= 16_777_216
@colour = value
elsif value.is_a? String
self.colour = value.delete('#').to_i(16)
elsif value.is_a? Array
r... | [
"def",
"colour",
"=",
"(",
"value",
")",
"if",
"value",
".",
"nil?",
"@colour",
"=",
"nil",
"elsif",
"value",
".",
"is_a?",
"Integer",
"raise",
"ArgumentError",
",",
"'Embed colour must be 24-bit!'",
"if",
"value",
">=",
"16_777_216",
"@colour",
"=",
"value",
... | Sets the colour of the bar to the side of the embed to something new.
@param value [Integer, String, {Integer, Integer, Integer}, #to_i, nil] The colour in decimal, hexadecimal, R/G/B decimal, or nil to clear the embeds colour
form. | [
"Sets",
"the",
"colour",
"of",
"the",
"bar",
"to",
"the",
"side",
"of",
"the",
"embed",
"to",
"something",
"new",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/webhooks/embeds.rb#L42-L58 | train |
meew0/discordrb | lib/discordrb/webhooks/embeds.rb | Discordrb::Webhooks.Embed.add_field | def add_field(name: nil, value: nil, inline: nil)
self << EmbedField.new(name: name, value: value, inline: inline)
end | ruby | def add_field(name: nil, value: nil, inline: nil)
self << EmbedField.new(name: name, value: value, inline: inline)
end | [
"def",
"add_field",
"(",
"name",
":",
"nil",
",",
"value",
":",
"nil",
",",
"inline",
":",
"nil",
")",
"self",
"<<",
"EmbedField",
".",
"new",
"(",
"name",
":",
"name",
",",
"value",
":",
"value",
",",
"inline",
":",
"inline",
")",
"end"
] | Convenience method to add a field to the embed without having to create one manually.
@see EmbedField
@example Add a field to an embed, conveniently
embed.add_field(name: 'A field', value: "The field's content")
@param name [String] The field's name
@param value [String] The field's value
@param inline [true, f... | [
"Convenience",
"method",
"to",
"add",
"a",
"field",
"to",
"the",
"embed",
"without",
"having",
"to",
"create",
"one",
"manually",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/webhooks/embeds.rb#L98-L100 | train |
meew0/discordrb | lib/discordrb/light/light_bot.rb | Discordrb::Light.LightBot.profile | def profile
response = Discordrb::API::User.profile(@token)
LightProfile.new(JSON.parse(response), self)
end | ruby | def profile
response = Discordrb::API::User.profile(@token)
LightProfile.new(JSON.parse(response), self)
end | [
"def",
"profile",
"response",
"=",
"Discordrb",
"::",
"API",
"::",
"User",
".",
"profile",
"(",
"@token",
")",
"LightProfile",
".",
"new",
"(",
"JSON",
".",
"parse",
"(",
"response",
")",
",",
"self",
")",
"end"
] | Create a new LightBot. This does no networking yet, all networking is done by the methods on this class.
@param token [String] The token that should be used to authenticate to Discord. Can be an OAuth token or a regular
user account token.
@return [LightProfile] the details of the user this bot is connected to. | [
"Create",
"a",
"new",
"LightBot",
".",
"This",
"does",
"no",
"networking",
"yet",
"all",
"networking",
"is",
"done",
"by",
"the",
"methods",
"on",
"this",
"class",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/light/light_bot.rb#L33-L36 | train |
meew0/discordrb | lib/discordrb/light/light_bot.rb | Discordrb::Light.LightBot.connections | def connections
response = Discordrb::API::User.connections(@token)
JSON.parse(response).map { |e| Connection.new(e, self) }
end | ruby | def connections
response = Discordrb::API::User.connections(@token)
JSON.parse(response).map { |e| Connection.new(e, self) }
end | [
"def",
"connections",
"response",
"=",
"Discordrb",
"::",
"API",
"::",
"User",
".",
"connections",
"(",
"@token",
")",
"JSON",
".",
"parse",
"(",
"response",
")",
".",
"map",
"{",
"|",
"e",
"|",
"Connection",
".",
"new",
"(",
"e",
",",
"self",
")",
... | Gets the connections associated with this account.
@return [Array<Connection>] this account's connections. | [
"Gets",
"the",
"connections",
"associated",
"with",
"this",
"account",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/light/light_bot.rb#L53-L56 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.find_emoji | def find_emoji(name)
LOGGER.out("Resolving emoji #{name}")
emoji.find { |element| element.name == name }
end | ruby | def find_emoji(name)
LOGGER.out("Resolving emoji #{name}")
emoji.find { |element| element.name == name }
end | [
"def",
"find_emoji",
"(",
"name",
")",
"LOGGER",
".",
"out",
"(",
"\"Resolving emoji #{name}\"",
")",
"emoji",
".",
"find",
"{",
"|",
"element",
"|",
"element",
".",
"name",
"==",
"name",
"}",
"end"
] | Finds an emoji by its name.
@param name [String] The emoji name that should be resolved.
@return [GlobalEmoji, nil] the emoji identified by the name, or `nil` if it couldn't be found. | [
"Finds",
"an",
"emoji",
"by",
"its",
"name",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L189-L192 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.bot_application | def bot_application
return unless @type == :bot
response = API.oauth_application(token)
Application.new(JSON.parse(response), self)
end | ruby | def bot_application
return unless @type == :bot
response = API.oauth_application(token)
Application.new(JSON.parse(response), self)
end | [
"def",
"bot_application",
"return",
"unless",
"@type",
"==",
":bot",
"response",
"=",
"API",
".",
"oauth_application",
"(",
"token",
")",
"Application",
".",
"new",
"(",
"JSON",
".",
"parse",
"(",
"response",
")",
",",
"self",
")",
"end"
] | The bot's OAuth application.
@return [Application, nil] The bot's application info. Returns `nil` if bot is not a bot account. | [
"The",
"bot",
"s",
"OAuth",
"application",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L206-L211 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.accept_invite | def accept_invite(invite)
resolved = invite(invite).code
API::Invite.accept(token, resolved)
end | ruby | def accept_invite(invite)
resolved = invite(invite).code
API::Invite.accept(token, resolved)
end | [
"def",
"accept_invite",
"(",
"invite",
")",
"resolved",
"=",
"invite",
"(",
"invite",
")",
".",
"code",
"API",
"::",
"Invite",
".",
"accept",
"(",
"token",
",",
"resolved",
")",
"end"
] | Makes the bot join an invite to a server.
@param invite [String, Invite] The invite to join. For possible formats see {#resolve_invite_code}. | [
"Makes",
"the",
"bot",
"join",
"an",
"invite",
"to",
"a",
"server",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L272-L275 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.send_message | def send_message(channel, content, tts = false, embed = nil)
channel = channel.resolve_id
debug("Sending message to #{channel} with content '#{content}'")
response = API::Channel.create_message(token, channel, content, tts, embed ? embed.to_hash : nil)
Message.new(JSON.parse(response), self)
... | ruby | def send_message(channel, content, tts = false, embed = nil)
channel = channel.resolve_id
debug("Sending message to #{channel} with content '#{content}'")
response = API::Channel.create_message(token, channel, content, tts, embed ? embed.to_hash : nil)
Message.new(JSON.parse(response), self)
... | [
"def",
"send_message",
"(",
"channel",
",",
"content",
",",
"tts",
"=",
"false",
",",
"embed",
"=",
"nil",
")",
"channel",
"=",
"channel",
".",
"resolve_id",
"debug",
"(",
"\"Sending message to #{channel} with content '#{content}'\"",
")",
"response",
"=",
"API",
... | Sends a text message to a channel given its ID and the message's content.
@param channel [Channel, Integer, #resolve_id] The channel to send something to.
@param content [String] The text that should be sent as a message. It is limited to 2000 characters (Discord imposed).
@param tts [true, false] Whether or not thi... | [
"Sends",
"a",
"text",
"message",
"to",
"a",
"channel",
"given",
"its",
"ID",
"and",
"the",
"message",
"s",
"content",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L366-L372 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.send_temporary_message | def send_temporary_message(channel, content, timeout, tts = false, embed = nil)
Thread.new do
Thread.current[:discordrb_name] = "#{@current_thread}-temp-msg"
message = send_message(channel, content, tts, embed)
sleep(timeout)
message.delete
end
nil
end | ruby | def send_temporary_message(channel, content, timeout, tts = false, embed = nil)
Thread.new do
Thread.current[:discordrb_name] = "#{@current_thread}-temp-msg"
message = send_message(channel, content, tts, embed)
sleep(timeout)
message.delete
end
nil
end | [
"def",
"send_temporary_message",
"(",
"channel",
",",
"content",
",",
"timeout",
",",
"tts",
"=",
"false",
",",
"embed",
"=",
"nil",
")",
"Thread",
".",
"new",
"do",
"Thread",
".",
"current",
"[",
":discordrb_name",
"]",
"=",
"\"#{@current_thread}-temp-msg\"",... | Sends a text message to a channel given its ID and the message's content,
then deletes it after the specified timeout in seconds.
@param channel [Channel, Integer, #resolve_id] The channel to send something to.
@param content [String] The text that should be sent as a message. It is limited to 2000 characters (Disco... | [
"Sends",
"a",
"text",
"message",
"to",
"a",
"channel",
"given",
"its",
"ID",
"and",
"the",
"message",
"s",
"content",
"then",
"deletes",
"it",
"after",
"the",
"specified",
"timeout",
"in",
"seconds",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L381-L391 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.send_file | def send_file(channel, file, caption: nil, tts: false, filename: nil, spoiler: nil)
if file.respond_to?(:read)
if spoiler
filename ||= File.basename(file.path)
filename = 'SPOILER_' + filename unless filename.start_with? 'SPOILER_'
end
# https://github.com/rest-client/r... | ruby | def send_file(channel, file, caption: nil, tts: false, filename: nil, spoiler: nil)
if file.respond_to?(:read)
if spoiler
filename ||= File.basename(file.path)
filename = 'SPOILER_' + filename unless filename.start_with? 'SPOILER_'
end
# https://github.com/rest-client/r... | [
"def",
"send_file",
"(",
"channel",
",",
"file",
",",
"caption",
":",
"nil",
",",
"tts",
":",
"false",
",",
"filename",
":",
"nil",
",",
"spoiler",
":",
"nil",
")",
"if",
"file",
".",
"respond_to?",
"(",
":read",
")",
"if",
"spoiler",
"filename",
"||... | Sends a file to a channel. If it is an image, it will automatically be embedded.
@note This executes in a blocking way, so if you're sending long files, be wary of delays.
@param channel [Channel, Integer, #resolve_id] The channel to send something to.
@param file [File] The file that should be sent.
@param caption... | [
"Sends",
"a",
"file",
"to",
"a",
"channel",
".",
"If",
"it",
"is",
"an",
"image",
"it",
"will",
"automatically",
"be",
"embedded",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L403-L416 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.create_server | def create_server(name, region = :'eu-central')
response = API::Server.create(token, name, region)
id = JSON.parse(response)['id'].to_i
sleep 0.1 until @servers[id]
server = @servers[id]
debug "Successfully created server #{server.id} with name #{server.name}"
server
end | ruby | def create_server(name, region = :'eu-central')
response = API::Server.create(token, name, region)
id = JSON.parse(response)['id'].to_i
sleep 0.1 until @servers[id]
server = @servers[id]
debug "Successfully created server #{server.id} with name #{server.name}"
server
end | [
"def",
"create_server",
"(",
"name",
",",
"region",
"=",
":'",
"'",
")",
"response",
"=",
"API",
"::",
"Server",
".",
"create",
"(",
"token",
",",
"name",
",",
"region",
")",
"id",
"=",
"JSON",
".",
"parse",
"(",
"response",
")",
"[",
"'id'",
"]",
... | Creates a server on Discord with a specified name and a region.
@note Discord's API doesn't directly return the server when creating it, so this method
waits until the data has been received via the websocket. This may make the execution take a while.
@param name [String] The name the new server should have. Doesn... | [
"Creates",
"a",
"server",
"on",
"Discord",
"with",
"a",
"specified",
"name",
"and",
"a",
"region",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L424-L431 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.update_oauth_application | def update_oauth_application(name, redirect_uris, description = '', icon = nil)
API.update_oauth_application(@token, name, redirect_uris, description, icon)
end | ruby | def update_oauth_application(name, redirect_uris, description = '', icon = nil)
API.update_oauth_application(@token, name, redirect_uris, description, icon)
end | [
"def",
"update_oauth_application",
"(",
"name",
",",
"redirect_uris",
",",
"description",
"=",
"''",
",",
"icon",
"=",
"nil",
")",
"API",
".",
"update_oauth_application",
"(",
"@token",
",",
"name",
",",
"redirect_uris",
",",
"description",
",",
"icon",
")",
... | Changes information about your OAuth application
@param name [String] What your application should be called.
@param redirect_uris [Array<String>] URIs that Discord should redirect your users to after authorizing.
@param description [String] A string that describes what your application does.
@param icon [String, n... | [
"Changes",
"information",
"about",
"your",
"OAuth",
"application"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L449-L451 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.parse_mentions | def parse_mentions(mentions, server = nil)
array_to_return = []
# While possible mentions may be in message
while mentions.include?('<') && mentions.include?('>')
# Removing all content before the next possible mention
mentions = mentions.split('<', 2)[1]
# Locate the first val... | ruby | def parse_mentions(mentions, server = nil)
array_to_return = []
# While possible mentions may be in message
while mentions.include?('<') && mentions.include?('>')
# Removing all content before the next possible mention
mentions = mentions.split('<', 2)[1]
# Locate the first val... | [
"def",
"parse_mentions",
"(",
"mentions",
",",
"server",
"=",
"nil",
")",
"array_to_return",
"=",
"[",
"]",
"# While possible mentions may be in message",
"while",
"mentions",
".",
"include?",
"(",
"'<'",
")",
"&&",
"mentions",
".",
"include?",
"(",
"'>'",
")",
... | Gets the users, channels, roles and emoji from a string.
@param mentions [String] The mentions, which should look like `<@12314873129>`, `<#123456789>`, `<@&123456789>` or `<:name:126328:>`.
@param server [Server, nil] The server of the associated mentions. (recommended for role parsing, to speed things up)
@return ... | [
"Gets",
"the",
"users",
"channels",
"roles",
"and",
"emoji",
"from",
"a",
"string",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L457-L485 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.update_status | def update_status(status, activity, url, since = 0, afk = false, activity_type = 0)
gateway_check
@activity = activity
@status = status
@streamurl = url
type = url ? 1 : activity_type
activity_obj = activity || url ? { 'name' => activity, 'url' => url, 'type' => type } : nil
... | ruby | def update_status(status, activity, url, since = 0, afk = false, activity_type = 0)
gateway_check
@activity = activity
@status = status
@streamurl = url
type = url ? 1 : activity_type
activity_obj = activity || url ? { 'name' => activity, 'url' => url, 'type' => type } : nil
... | [
"def",
"update_status",
"(",
"status",
",",
"activity",
",",
"url",
",",
"since",
"=",
"0",
",",
"afk",
"=",
"false",
",",
"activity_type",
"=",
"0",
")",
"gateway_check",
"@activity",
"=",
"activity",
"@status",
"=",
"status",
"@streamurl",
"=",
"url",
... | Updates presence status.
@param status [String] The status the bot should show up as. Can be `online`, `dnd`, `idle`, or `invisible`
@param activity [String, nil] The name of the activity to be played/watched/listened to/stream name on the stream.
@param url [String, nil] The Twitch URL to display as a stream. nil f... | [
"Updates",
"presence",
"status",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L503-L516 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.add_await! | def add_await!(type, attributes = {})
raise "You can't await an AwaitEvent!" if type == Discordrb::Events::AwaitEvent
timeout = attributes[:timeout]
raise ArgumentError, 'Timeout must be a number > 0' if timeout&.is_a?(Numeric) && !timeout&.positive?
mutex = Mutex.new
cv = ConditionVaria... | ruby | def add_await!(type, attributes = {})
raise "You can't await an AwaitEvent!" if type == Discordrb::Events::AwaitEvent
timeout = attributes[:timeout]
raise ArgumentError, 'Timeout must be a number > 0' if timeout&.is_a?(Numeric) && !timeout&.positive?
mutex = Mutex.new
cv = ConditionVaria... | [
"def",
"add_await!",
"(",
"type",
",",
"attributes",
"=",
"{",
"}",
")",
"raise",
"\"You can't await an AwaitEvent!\"",
"if",
"type",
"==",
"Discordrb",
"::",
"Events",
"::",
"AwaitEvent",
"timeout",
"=",
"attributes",
"[",
":timeout",
"]",
"raise",
"ArgumentErr... | Awaits an event, blocking the current thread until a response is received.
@param type [Class] The event class that should be listened for.
@option attributes [Numeric] :timeout the amount of time to wait for a response before returning `nil`. Waits forever if omitted.
@return [Event, nil] The event object that was ... | [
"Awaits",
"an",
"event",
"blocking",
"the",
"current",
"thread",
"until",
"a",
"response",
"is",
"received",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L619-L650 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.prune_empty_groups | def prune_empty_groups
@channels.each_value do |channel|
channel.leave_group if channel.group? && channel.recipients.empty?
end
end | ruby | def prune_empty_groups
@channels.each_value do |channel|
channel.leave_group if channel.group? && channel.recipients.empty?
end
end | [
"def",
"prune_empty_groups",
"@channels",
".",
"each_value",
"do",
"|",
"channel",
"|",
"channel",
".",
"leave_group",
"if",
"channel",
".",
"group?",
"&&",
"channel",
".",
"recipients",
".",
"empty?",
"end",
"end"
] | Makes the bot leave any groups with no recipients remaining | [
"Makes",
"the",
"bot",
"leave",
"any",
"groups",
"with",
"no",
"recipients",
"remaining"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L694-L698 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.update_voice_state | def update_voice_state(data)
@session_id = data['session_id']
server_id = data['guild_id'].to_i
server = server(server_id)
return unless server
user_id = data['user_id'].to_i
old_voice_state = server.voice_states[user_id]
old_channel_id = old_voice_state.voice_channel.id if o... | ruby | def update_voice_state(data)
@session_id = data['session_id']
server_id = data['guild_id'].to_i
server = server(server_id)
return unless server
user_id = data['user_id'].to_i
old_voice_state = server.voice_states[user_id]
old_channel_id = old_voice_state.voice_channel.id if o... | [
"def",
"update_voice_state",
"(",
"data",
")",
"@session_id",
"=",
"data",
"[",
"'session_id'",
"]",
"server_id",
"=",
"data",
"[",
"'guild_id'",
"]",
".",
"to_i",
"server",
"=",
"server",
"(",
"server_id",
")",
"return",
"unless",
"server",
"user_id",
"=",
... | Internal handler for VOICE_STATE_UPDATE | [
"Internal",
"handler",
"for",
"VOICE_STATE_UPDATE"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L763-L777 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.update_voice_server | def update_voice_server(data)
server_id = data['guild_id'].to_i
channel = @should_connect_to_voice[server_id]
debug("Voice server update received! chan: #{channel.inspect}")
return unless channel
@should_connect_to_voice.delete(server_id)
debug('Updating voice server!')
toke... | ruby | def update_voice_server(data)
server_id = data['guild_id'].to_i
channel = @should_connect_to_voice[server_id]
debug("Voice server update received! chan: #{channel.inspect}")
return unless channel
@should_connect_to_voice.delete(server_id)
debug('Updating voice server!')
toke... | [
"def",
"update_voice_server",
"(",
"data",
")",
"server_id",
"=",
"data",
"[",
"'guild_id'",
"]",
".",
"to_i",
"channel",
"=",
"@should_connect_to_voice",
"[",
"server_id",
"]",
"debug",
"(",
"\"Voice server update received! chan: #{channel.inspect}\"",
")",
"return",
... | Internal handler for VOICE_SERVER_UPDATE | [
"Internal",
"handler",
"for",
"VOICE_SERVER_UPDATE"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L780-L800 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.create_channel | def create_channel(data)
channel = Channel.new(data, self)
server = channel.server
# Handle normal and private channels separately
if server
server.add_channel(channel)
@channels[channel.id] = channel
elsif channel.pm?
@pm_channels[channel.recipient.id] = channel
... | ruby | def create_channel(data)
channel = Channel.new(data, self)
server = channel.server
# Handle normal and private channels separately
if server
server.add_channel(channel)
@channels[channel.id] = channel
elsif channel.pm?
@pm_channels[channel.recipient.id] = channel
... | [
"def",
"create_channel",
"(",
"data",
")",
"channel",
"=",
"Channel",
".",
"new",
"(",
"data",
",",
"self",
")",
"server",
"=",
"channel",
".",
"server",
"# Handle normal and private channels separately",
"if",
"server",
"server",
".",
"add_channel",
"(",
"chann... | Internal handler for CHANNEL_CREATE | [
"Internal",
"handler",
"for",
"CHANNEL_CREATE"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L803-L816 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.update_channel | def update_channel(data)
channel = Channel.new(data, self)
old_channel = @channels[channel.id]
return unless old_channel
old_channel.update_from(channel)
end | ruby | def update_channel(data)
channel = Channel.new(data, self)
old_channel = @channels[channel.id]
return unless old_channel
old_channel.update_from(channel)
end | [
"def",
"update_channel",
"(",
"data",
")",
"channel",
"=",
"Channel",
".",
"new",
"(",
"data",
",",
"self",
")",
"old_channel",
"=",
"@channels",
"[",
"channel",
".",
"id",
"]",
"return",
"unless",
"old_channel",
"old_channel",
".",
"update_from",
"(",
"ch... | Internal handler for CHANNEL_UPDATE | [
"Internal",
"handler",
"for",
"CHANNEL_UPDATE"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L819-L825 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.delete_channel | def delete_channel(data)
channel = Channel.new(data, self)
server = channel.server
# Handle normal and private channels separately
if server
@channels.delete(channel.id)
server.delete_channel(channel.id)
elsif channel.pm?
@pm_channels.delete(channel.recipient.id)
... | ruby | def delete_channel(data)
channel = Channel.new(data, self)
server = channel.server
# Handle normal and private channels separately
if server
@channels.delete(channel.id)
server.delete_channel(channel.id)
elsif channel.pm?
@pm_channels.delete(channel.recipient.id)
... | [
"def",
"delete_channel",
"(",
"data",
")",
"channel",
"=",
"Channel",
".",
"new",
"(",
"data",
",",
"self",
")",
"server",
"=",
"channel",
".",
"server",
"# Handle normal and private channels separately",
"if",
"server",
"@channels",
".",
"delete",
"(",
"channel... | Internal handler for CHANNEL_DELETE | [
"Internal",
"handler",
"for",
"CHANNEL_DELETE"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L828-L841 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.add_recipient | def add_recipient(data)
channel_id = data['channel_id'].to_i
channel = self.channel(channel_id)
recipient_user = ensure_user(data['user'])
recipient = Recipient.new(recipient_user, channel, self)
channel.add_recipient(recipient)
end | ruby | def add_recipient(data)
channel_id = data['channel_id'].to_i
channel = self.channel(channel_id)
recipient_user = ensure_user(data['user'])
recipient = Recipient.new(recipient_user, channel, self)
channel.add_recipient(recipient)
end | [
"def",
"add_recipient",
"(",
"data",
")",
"channel_id",
"=",
"data",
"[",
"'channel_id'",
"]",
".",
"to_i",
"channel",
"=",
"self",
".",
"channel",
"(",
"channel_id",
")",
"recipient_user",
"=",
"ensure_user",
"(",
"data",
"[",
"'user'",
"]",
")",
"recipie... | Internal handler for CHANNEL_RECIPIENT_ADD | [
"Internal",
"handler",
"for",
"CHANNEL_RECIPIENT_ADD"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L844-L851 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.add_guild_member | def add_guild_member(data)
server_id = data['guild_id'].to_i
server = self.server(server_id)
member = Member.new(data, server, self)
server.add_member(member)
end | ruby | def add_guild_member(data)
server_id = data['guild_id'].to_i
server = self.server(server_id)
member = Member.new(data, server, self)
server.add_member(member)
end | [
"def",
"add_guild_member",
"(",
"data",
")",
"server_id",
"=",
"data",
"[",
"'guild_id'",
"]",
".",
"to_i",
"server",
"=",
"self",
".",
"server",
"(",
"server_id",
")",
"member",
"=",
"Member",
".",
"new",
"(",
"data",
",",
"server",
",",
"self",
")",
... | Internal handler for GUILD_MEMBER_ADD | [
"Internal",
"handler",
"for",
"GUILD_MEMBER_ADD"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L864-L870 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.update_guild_member | def update_guild_member(data)
server_id = data['guild_id'].to_i
server = self.server(server_id)
member = server.member(data['user']['id'].to_i)
member.update_roles(data['roles'])
member.update_nick(data['nick'])
end | ruby | def update_guild_member(data)
server_id = data['guild_id'].to_i
server = self.server(server_id)
member = server.member(data['user']['id'].to_i)
member.update_roles(data['roles'])
member.update_nick(data['nick'])
end | [
"def",
"update_guild_member",
"(",
"data",
")",
"server_id",
"=",
"data",
"[",
"'guild_id'",
"]",
".",
"to_i",
"server",
"=",
"self",
".",
"server",
"(",
"server_id",
")",
"member",
"=",
"server",
".",
"member",
"(",
"data",
"[",
"'user'",
"]",
"[",
"'... | Internal handler for GUILD_MEMBER_UPDATE | [
"Internal",
"handler",
"for",
"GUILD_MEMBER_UPDATE"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L873-L880 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.delete_guild_member | def delete_guild_member(data)
server_id = data['guild_id'].to_i
server = self.server(server_id)
user_id = data['user']['id'].to_i
server.delete_member(user_id)
rescue Discordrb::Errors::NoPermission
Discordrb::LOGGER.warn("delete_guild_member attempted to access a server for which the... | ruby | def delete_guild_member(data)
server_id = data['guild_id'].to_i
server = self.server(server_id)
user_id = data['user']['id'].to_i
server.delete_member(user_id)
rescue Discordrb::Errors::NoPermission
Discordrb::LOGGER.warn("delete_guild_member attempted to access a server for which the... | [
"def",
"delete_guild_member",
"(",
"data",
")",
"server_id",
"=",
"data",
"[",
"'guild_id'",
"]",
".",
"to_i",
"server",
"=",
"self",
".",
"server",
"(",
"server_id",
")",
"user_id",
"=",
"data",
"[",
"'user'",
"]",
"[",
"'id'",
"]",
".",
"to_i",
"serv... | Internal handler for GUILD_MEMBER_DELETE | [
"Internal",
"handler",
"for",
"GUILD_MEMBER_DELETE"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L883-L891 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.update_guild_role | def update_guild_role(data)
role_data = data['role']
server_id = data['guild_id'].to_i
server = @servers[server_id]
new_role = Role.new(role_data, self, server)
role_id = role_data['id'].to_i
old_role = server.roles.find { |r| r.id == role_id }
old_role.update_from(new_role)
... | ruby | def update_guild_role(data)
role_data = data['role']
server_id = data['guild_id'].to_i
server = @servers[server_id]
new_role = Role.new(role_data, self, server)
role_id = role_data['id'].to_i
old_role = server.roles.find { |r| r.id == role_id }
old_role.update_from(new_role)
... | [
"def",
"update_guild_role",
"(",
"data",
")",
"role_data",
"=",
"data",
"[",
"'role'",
"]",
"server_id",
"=",
"data",
"[",
"'guild_id'",
"]",
".",
"to_i",
"server",
"=",
"@servers",
"[",
"server_id",
"]",
"new_role",
"=",
"Role",
".",
"new",
"(",
"role_d... | Internal handler for GUILD_ROLE_UPDATE | [
"Internal",
"handler",
"for",
"GUILD_ROLE_UPDATE"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L910-L918 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.create_guild_role | def create_guild_role(data)
role_data = data['role']
server_id = data['guild_id'].to_i
server = @servers[server_id]
new_role = Role.new(role_data, self, server)
existing_role = server.role(new_role.id)
if existing_role
existing_role.update_from(new_role)
else
se... | ruby | def create_guild_role(data)
role_data = data['role']
server_id = data['guild_id'].to_i
server = @servers[server_id]
new_role = Role.new(role_data, self, server)
existing_role = server.role(new_role.id)
if existing_role
existing_role.update_from(new_role)
else
se... | [
"def",
"create_guild_role",
"(",
"data",
")",
"role_data",
"=",
"data",
"[",
"'role'",
"]",
"server_id",
"=",
"data",
"[",
"'guild_id'",
"]",
".",
"to_i",
"server",
"=",
"@servers",
"[",
"server_id",
"]",
"new_role",
"=",
"Role",
".",
"new",
"(",
"role_d... | Internal handler for GUILD_ROLE_CREATE | [
"Internal",
"handler",
"for",
"GUILD_ROLE_CREATE"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L921-L932 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.delete_guild_role | def delete_guild_role(data)
role_id = data['role_id'].to_i
server_id = data['guild_id'].to_i
server = @servers[server_id]
server.delete_role(role_id)
end | ruby | def delete_guild_role(data)
role_id = data['role_id'].to_i
server_id = data['guild_id'].to_i
server = @servers[server_id]
server.delete_role(role_id)
end | [
"def",
"delete_guild_role",
"(",
"data",
")",
"role_id",
"=",
"data",
"[",
"'role_id'",
"]",
".",
"to_i",
"server_id",
"=",
"data",
"[",
"'guild_id'",
"]",
".",
"to_i",
"server",
"=",
"@servers",
"[",
"server_id",
"]",
"server",
".",
"delete_role",
"(",
... | Internal handler for GUILD_ROLE_DELETE | [
"Internal",
"handler",
"for",
"GUILD_ROLE_DELETE"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L935-L940 | train |
meew0/discordrb | lib/discordrb/bot.rb | Discordrb.Bot.update_guild_emoji | def update_guild_emoji(data)
server_id = data['guild_id'].to_i
server = @servers[server_id]
server.update_emoji_data(data)
end | ruby | def update_guild_emoji(data)
server_id = data['guild_id'].to_i
server = @servers[server_id]
server.update_emoji_data(data)
end | [
"def",
"update_guild_emoji",
"(",
"data",
")",
"server_id",
"=",
"data",
"[",
"'guild_id'",
"]",
".",
"to_i",
"server",
"=",
"@servers",
"[",
"server_id",
"]",
"server",
".",
"update_emoji_data",
"(",
"data",
")",
"end"
] | Internal handler for GUILD_EMOJIS_UPDATE | [
"Internal",
"handler",
"for",
"GUILD_EMOJIS_UPDATE"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/bot.rb#L943-L947 | train |
meew0/discordrb | lib/discordrb/cache.rb | Discordrb.Cache.voice_regions | def voice_regions
return @voice_regions unless @voice_regions.empty?
regions = JSON.parse API.voice_regions(token)
regions.each do |data|
@voice_regions[data['id']] = VoiceRegion.new(data)
end
@voice_regions
end | ruby | def voice_regions
return @voice_regions unless @voice_regions.empty?
regions = JSON.parse API.voice_regions(token)
regions.each do |data|
@voice_regions[data['id']] = VoiceRegion.new(data)
end
@voice_regions
end | [
"def",
"voice_regions",
"return",
"@voice_regions",
"unless",
"@voice_regions",
".",
"empty?",
"regions",
"=",
"JSON",
".",
"parse",
"API",
".",
"voice_regions",
"(",
"token",
")",
"regions",
".",
"each",
"do",
"|",
"data",
"|",
"@voice_regions",
"[",
"data",
... | Returns or caches the available voice regions | [
"Returns",
"or",
"caches",
"the",
"available",
"voice",
"regions"
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/cache.rb#L29-L38 | train |
meew0/discordrb | lib/discordrb/cache.rb | Discordrb.Cache.channel | def channel(id, server = nil)
id = id.resolve_id
raise Discordrb::Errors::NoPermission if @restricted_channels.include? id
debug("Obtaining data for channel with id #{id}")
return @channels[id] if @channels[id]
begin
begin
response = API::Channel.resolve(token, id)
... | ruby | def channel(id, server = nil)
id = id.resolve_id
raise Discordrb::Errors::NoPermission if @restricted_channels.include? id
debug("Obtaining data for channel with id #{id}")
return @channels[id] if @channels[id]
begin
begin
response = API::Channel.resolve(token, id)
... | [
"def",
"channel",
"(",
"id",
",",
"server",
"=",
"nil",
")",
"id",
"=",
"id",
".",
"resolve_id",
"raise",
"Discordrb",
"::",
"Errors",
"::",
"NoPermission",
"if",
"@restricted_channels",
".",
"include?",
"id",
"debug",
"(",
"\"Obtaining data for channel with id ... | Gets a channel given its ID. This queries the internal channel cache, and if the channel doesn't
exist in there, it will get the data from Discord.
@param id [Integer] The channel ID for which to search for.
@param server [Server] The server for which to search the channel for. If this isn't specified, it will be
... | [
"Gets",
"a",
"channel",
"given",
"its",
"ID",
".",
"This",
"queries",
"the",
"internal",
"channel",
"cache",
"and",
"if",
"the",
"channel",
"doesn",
"t",
"exist",
"in",
"there",
"it",
"will",
"get",
"the",
"data",
"from",
"Discord",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/cache.rb#L46-L67 | train |
meew0/discordrb | lib/discordrb/cache.rb | Discordrb.Cache.user | def user(id)
id = id.resolve_id
return @users[id] if @users[id]
LOGGER.out("Resolving user #{id}")
begin
response = API::User.resolve(token, id)
rescue RestClient::ResourceNotFound
return nil
end
user = User.new(JSON.parse(response), self)
@users[id] = us... | ruby | def user(id)
id = id.resolve_id
return @users[id] if @users[id]
LOGGER.out("Resolving user #{id}")
begin
response = API::User.resolve(token, id)
rescue RestClient::ResourceNotFound
return nil
end
user = User.new(JSON.parse(response), self)
@users[id] = us... | [
"def",
"user",
"(",
"id",
")",
"id",
"=",
"id",
".",
"resolve_id",
"return",
"@users",
"[",
"id",
"]",
"if",
"@users",
"[",
"id",
"]",
"LOGGER",
".",
"out",
"(",
"\"Resolving user #{id}\"",
")",
"begin",
"response",
"=",
"API",
"::",
"User",
".",
"re... | Gets a user by its ID.
@note This can only resolve users known by the bot (i.e. that share a server with the bot).
@param id [Integer] The user ID that should be resolved.
@return [User, nil] The user identified by the ID, or `nil` if it couldn't be found. | [
"Gets",
"a",
"user",
"by",
"its",
"ID",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/cache.rb#L75-L87 | train |
meew0/discordrb | lib/discordrb/cache.rb | Discordrb.Cache.server | def server(id)
id = id.resolve_id
return @servers[id] if @servers[id]
LOGGER.out("Resolving server #{id}")
begin
response = API::Server.resolve(token, id)
rescue Discordrb::Errors::NoPermission
return nil
end
server = Server.new(JSON.parse(response), self)
... | ruby | def server(id)
id = id.resolve_id
return @servers[id] if @servers[id]
LOGGER.out("Resolving server #{id}")
begin
response = API::Server.resolve(token, id)
rescue Discordrb::Errors::NoPermission
return nil
end
server = Server.new(JSON.parse(response), self)
... | [
"def",
"server",
"(",
"id",
")",
"id",
"=",
"id",
".",
"resolve_id",
"return",
"@servers",
"[",
"id",
"]",
"if",
"@servers",
"[",
"id",
"]",
"LOGGER",
".",
"out",
"(",
"\"Resolving server #{id}\"",
")",
"begin",
"response",
"=",
"API",
"::",
"Server",
... | Gets a server by its ID.
@note This can only resolve servers the bot is currently in.
@param id [Integer] The server ID that should be resolved.
@return [Server, nil] The server identified by the ID, or `nil` if it couldn't be found. | [
"Gets",
"a",
"server",
"by",
"its",
"ID",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/cache.rb#L93-L105 | train |
meew0/discordrb | lib/discordrb/cache.rb | Discordrb.Cache.member | def member(server_or_id, user_id)
server_id = server_or_id.resolve_id
user_id = user_id.resolve_id
server = server_or_id.is_a?(Server) ? server_or_id : self.server(server_id)
return server.member(user_id) if server.member_cached?(user_id)
LOGGER.out("Resolving member #{server_id} on ser... | ruby | def member(server_or_id, user_id)
server_id = server_or_id.resolve_id
user_id = user_id.resolve_id
server = server_or_id.is_a?(Server) ? server_or_id : self.server(server_id)
return server.member(user_id) if server.member_cached?(user_id)
LOGGER.out("Resolving member #{server_id} on ser... | [
"def",
"member",
"(",
"server_or_id",
",",
"user_id",
")",
"server_id",
"=",
"server_or_id",
".",
"resolve_id",
"user_id",
"=",
"user_id",
".",
"resolve_id",
"server",
"=",
"server_or_id",
".",
"is_a?",
"(",
"Server",
")",
"?",
"server_or_id",
":",
"self",
"... | Gets a member by both IDs, or `Server` and user ID.
@param server_or_id [Server, Integer] The `Server` or server ID for which a member should be resolved
@param user_id [Integer] The ID of the user that should be resolved
@return [Member, nil] The member identified by the IDs, or `nil` if none could be found | [
"Gets",
"a",
"member",
"by",
"both",
"IDs",
"or",
"Server",
"and",
"user",
"ID",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/cache.rb#L111-L127 | train |
meew0/discordrb | lib/discordrb/cache.rb | Discordrb.Cache.ensure_user | def ensure_user(data)
if @users.include?(data['id'].to_i)
@users[data['id'].to_i]
else
@users[data['id'].to_i] = User.new(data, self)
end
end | ruby | def ensure_user(data)
if @users.include?(data['id'].to_i)
@users[data['id'].to_i]
else
@users[data['id'].to_i] = User.new(data, self)
end
end | [
"def",
"ensure_user",
"(",
"data",
")",
"if",
"@users",
".",
"include?",
"(",
"data",
"[",
"'id'",
"]",
".",
"to_i",
")",
"@users",
"[",
"data",
"[",
"'id'",
"]",
".",
"to_i",
"]",
"else",
"@users",
"[",
"data",
"[",
"'id'",
"]",
".",
"to_i",
"]"... | Ensures a given user object is cached and if not, cache it from the given data hash.
@param data [Hash] A data hash representing a user.
@return [User] the user represented by the data hash. | [
"Ensures",
"a",
"given",
"user",
"object",
"is",
"cached",
"and",
"if",
"not",
"cache",
"it",
"from",
"the",
"given",
"data",
"hash",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/cache.rb#L149-L155 | train |
meew0/discordrb | lib/discordrb/cache.rb | Discordrb.Cache.ensure_server | def ensure_server(data)
if @servers.include?(data['id'].to_i)
@servers[data['id'].to_i]
else
@servers[data['id'].to_i] = Server.new(data, self)
end
end | ruby | def ensure_server(data)
if @servers.include?(data['id'].to_i)
@servers[data['id'].to_i]
else
@servers[data['id'].to_i] = Server.new(data, self)
end
end | [
"def",
"ensure_server",
"(",
"data",
")",
"if",
"@servers",
".",
"include?",
"(",
"data",
"[",
"'id'",
"]",
".",
"to_i",
")",
"@servers",
"[",
"data",
"[",
"'id'",
"]",
".",
"to_i",
"]",
"else",
"@servers",
"[",
"data",
"[",
"'id'",
"]",
".",
"to_i... | Ensures a given server object is cached and if not, cache it from the given data hash.
@param data [Hash] A data hash representing a server.
@return [Server] the server represented by the data hash. | [
"Ensures",
"a",
"given",
"server",
"object",
"is",
"cached",
"and",
"if",
"not",
"cache",
"it",
"from",
"the",
"given",
"data",
"hash",
"."
] | 764298a1ff0be69a1853b510d736f21c2b91a2fe | https://github.com/meew0/discordrb/blob/764298a1ff0be69a1853b510d736f21c2b91a2fe/lib/discordrb/cache.rb#L160-L166 | train |
Subsets and Splits
SQL Console for semeru/code-text-ruby
Retrieves 20,000 non-null code samples labeled as Ruby, providing a basic overview of the dataset but without deeper analysis.