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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
Dynamoid/dynamoid | lib/dynamoid/persistence.rb | Dynamoid.Persistence.update_attributes | def update_attributes(attributes)
attributes.each { |attribute, value| write_attribute(attribute, value) }
save
end | ruby | def update_attributes(attributes)
attributes.each { |attribute, value| write_attribute(attribute, value) }
save
end | [
"def",
"update_attributes",
"(",
"attributes",
")",
"attributes",
".",
"each",
"{",
"|",
"attribute",
",",
"value",
"|",
"write_attribute",
"(",
"attribute",
",",
"value",
")",
"}",
"save",
"end"
] | Updates multiple attributes at once, saving the object once the updates are complete.
@param [Hash] attributes a hash of attributes to update
@since 0.2.0 | [
"Updates",
"multiple",
"attributes",
"at",
"once",
"saving",
"the",
"object",
"once",
"the",
"updates",
"are",
"complete",
"."
] | 9e3d006b039e45877b003564ded65509b10b6354 | https://github.com/Dynamoid/dynamoid/blob/9e3d006b039e45877b003564ded65509b10b6354/lib/dynamoid/persistence.rb#L158-L161 | train |
Dynamoid/dynamoid | lib/dynamoid/persistence.rb | Dynamoid.Persistence.delete | def delete
options = range_key ? { range_key: Dumping.dump_field(read_attribute(range_key), self.class.attributes[range_key]) } : {}
# Add an optimistic locking check if the lock_version column exists
if self.class.attributes[:lock_version]
conditions = { if: {} }
conditions[:if][:loc... | ruby | def delete
options = range_key ? { range_key: Dumping.dump_field(read_attribute(range_key), self.class.attributes[range_key]) } : {}
# Add an optimistic locking check if the lock_version column exists
if self.class.attributes[:lock_version]
conditions = { if: {} }
conditions[:if][:loc... | [
"def",
"delete",
"options",
"=",
"range_key",
"?",
"{",
"range_key",
":",
"Dumping",
".",
"dump_field",
"(",
"read_attribute",
"(",
"range_key",
")",
",",
"self",
".",
"class",
".",
"attributes",
"[",
"range_key",
"]",
")",
"}",
":",
"{",
"}",
"# Add an ... | Delete this object from the datastore.
@since 0.2.0 | [
"Delete",
"this",
"object",
"from",
"the",
"datastore",
"."
] | 9e3d006b039e45877b003564ded65509b10b6354 | https://github.com/Dynamoid/dynamoid/blob/9e3d006b039e45877b003564ded65509b10b6354/lib/dynamoid/persistence.rb#L265-L282 | train |
Dynamoid/dynamoid | lib/dynamoid/persistence.rb | Dynamoid.Persistence.persist | def persist(conditions = nil)
run_callbacks(:save) do
self.hash_key = SecureRandom.uuid if hash_key.blank?
# Add an exists check to prevent overwriting existing records with new ones
if new_record?
conditions ||= {}
(conditions[:unless_exists] ||= []) << self.class.has... | ruby | def persist(conditions = nil)
run_callbacks(:save) do
self.hash_key = SecureRandom.uuid if hash_key.blank?
# Add an exists check to prevent overwriting existing records with new ones
if new_record?
conditions ||= {}
(conditions[:unless_exists] ||= []) << self.class.has... | [
"def",
"persist",
"(",
"conditions",
"=",
"nil",
")",
"run_callbacks",
"(",
":save",
")",
"do",
"self",
".",
"hash_key",
"=",
"SecureRandom",
".",
"uuid",
"if",
"hash_key",
".",
"blank?",
"# Add an exists check to prevent overwriting existing records with new ones",
"... | Persist the object into the datastore. Assign it an id first if it doesn't have one.
@since 0.2.0 | [
"Persist",
"the",
"object",
"into",
"the",
"datastore",
".",
"Assign",
"it",
"an",
"id",
"first",
"if",
"it",
"doesn",
"t",
"have",
"one",
"."
] | 9e3d006b039e45877b003564ded65509b10b6354 | https://github.com/Dynamoid/dynamoid/blob/9e3d006b039e45877b003564ded65509b10b6354/lib/dynamoid/persistence.rb#L289-L321 | train |
Dynamoid/dynamoid | lib/dynamoid/adapter.rb | Dynamoid.Adapter.adapter | def adapter
unless @adapter_.value
adapter = self.class.adapter_plugin_class.new
adapter.connect! if adapter.respond_to?(:connect!)
@adapter_.compare_and_set(nil, adapter)
clear_cache!
end
@adapter_.value
end | ruby | def adapter
unless @adapter_.value
adapter = self.class.adapter_plugin_class.new
adapter.connect! if adapter.respond_to?(:connect!)
@adapter_.compare_and_set(nil, adapter)
clear_cache!
end
@adapter_.value
end | [
"def",
"adapter",
"unless",
"@adapter_",
".",
"value",
"adapter",
"=",
"self",
".",
"class",
".",
"adapter_plugin_class",
".",
"new",
"adapter",
".",
"connect!",
"if",
"adapter",
".",
"respond_to?",
"(",
":connect!",
")",
"@adapter_",
".",
"compare_and_set",
"... | The actual adapter currently in use.
@since 0.2.0 | [
"The",
"actual",
"adapter",
"currently",
"in",
"use",
"."
] | 9e3d006b039e45877b003564ded65509b10b6354 | https://github.com/Dynamoid/dynamoid/blob/9e3d006b039e45877b003564ded65509b10b6354/lib/dynamoid/adapter.rb#L29-L37 | train |
Dynamoid/dynamoid | lib/dynamoid/adapter.rb | Dynamoid.Adapter.benchmark | def benchmark(method, *args)
start = Time.now
result = yield
Dynamoid.logger.debug "(#{((Time.now - start) * 1000.0).round(2)} ms) #{method.to_s.split('_').collect(&:upcase).join(' ')}#{" - #{args.inspect}" unless args.nil? || args.empty?}"
result
end | ruby | def benchmark(method, *args)
start = Time.now
result = yield
Dynamoid.logger.debug "(#{((Time.now - start) * 1000.0).round(2)} ms) #{method.to_s.split('_').collect(&:upcase).join(' ')}#{" - #{args.inspect}" unless args.nil? || args.empty?}"
result
end | [
"def",
"benchmark",
"(",
"method",
",",
"*",
"args",
")",
"start",
"=",
"Time",
".",
"now",
"result",
"=",
"yield",
"Dynamoid",
".",
"logger",
".",
"debug",
"\"(#{((Time.now - start) * 1000.0).round(2)} ms) #{method.to_s.split('_').collect(&:upcase).join(' ')}#{\" - #{args.... | Shows how long it takes a method to run on the adapter. Useful for generating logged output.
@param [Symbol] method the name of the method to appear in the log
@param [Array] args the arguments to the method to appear in the log
@yield the actual code to benchmark
@return the result of the yield
@since 0.2.0 | [
"Shows",
"how",
"long",
"it",
"takes",
"a",
"method",
"to",
"run",
"on",
"the",
"adapter",
".",
"Useful",
"for",
"generating",
"logged",
"output",
"."
] | 9e3d006b039e45877b003564ded65509b10b6354 | https://github.com/Dynamoid/dynamoid/blob/9e3d006b039e45877b003564ded65509b10b6354/lib/dynamoid/adapter.rb#L52-L57 | train |
Dynamoid/dynamoid | lib/dynamoid/adapter.rb | Dynamoid.Adapter.read | def read(table, ids, options = {}, &blk)
if ids.respond_to?(:each)
batch_get_item({ table => ids }, options, &blk)
else
get_item(table, ids, options)
end
end | ruby | def read(table, ids, options = {}, &blk)
if ids.respond_to?(:each)
batch_get_item({ table => ids }, options, &blk)
else
get_item(table, ids, options)
end
end | [
"def",
"read",
"(",
"table",
",",
"ids",
",",
"options",
"=",
"{",
"}",
",",
"&",
"blk",
")",
"if",
"ids",
".",
"respond_to?",
"(",
":each",
")",
"batch_get_item",
"(",
"{",
"table",
"=>",
"ids",
"}",
",",
"options",
",",
"blk",
")",
"else",
"get... | Read one or many keys from the selected table.
This method intelligently calls batch_get or get on the underlying adapter
depending on whether ids is a range or a single key.
If a range key is present, it will also interpolate that into the ids so
that the batch get will acquire the correct record.
@param [String... | [
"Read",
"one",
"or",
"many",
"keys",
"from",
"the",
"selected",
"table",
".",
"This",
"method",
"intelligently",
"calls",
"batch_get",
"or",
"get",
"on",
"the",
"underlying",
"adapter",
"depending",
"on",
"whether",
"ids",
"is",
"a",
"range",
"or",
"a",
"s... | 9e3d006b039e45877b003564ded65509b10b6354 | https://github.com/Dynamoid/dynamoid/blob/9e3d006b039e45877b003564ded65509b10b6354/lib/dynamoid/adapter.rb#L84-L90 | train |
Dynamoid/dynamoid | lib/dynamoid/adapter.rb | Dynamoid.Adapter.delete | def delete(table, ids, options = {})
range_key = options[:range_key] # array of range keys that matches the ids passed in
if ids.respond_to?(:each)
ids = if range_key.respond_to?(:each)
# turn ids into array of arrays each element being hash_key, range_key
ids.each_wi... | ruby | def delete(table, ids, options = {})
range_key = options[:range_key] # array of range keys that matches the ids passed in
if ids.respond_to?(:each)
ids = if range_key.respond_to?(:each)
# turn ids into array of arrays each element being hash_key, range_key
ids.each_wi... | [
"def",
"delete",
"(",
"table",
",",
"ids",
",",
"options",
"=",
"{",
"}",
")",
"range_key",
"=",
"options",
"[",
":range_key",
"]",
"# array of range keys that matches the ids passed in",
"if",
"ids",
".",
"respond_to?",
"(",
":each",
")",
"ids",
"=",
"if",
... | Delete an item from a table.
@param [String] table the name of the table to write the object to
@param [Array] ids to delete, can also be a string of just one id
@param [Array] range_key of the record to delete, can also be a string of just one range_key | [
"Delete",
"an",
"item",
"from",
"a",
"table",
"."
] | 9e3d006b039e45877b003564ded65509b10b6354 | https://github.com/Dynamoid/dynamoid/blob/9e3d006b039e45877b003564ded65509b10b6354/lib/dynamoid/adapter.rb#L98-L112 | train |
Dynamoid/dynamoid | lib/dynamoid/adapter.rb | Dynamoid.Adapter.scan | def scan(table, query = {}, opts = {})
benchmark('Scan', table, query) { adapter.scan(table, query, opts) }
end | ruby | def scan(table, query = {}, opts = {})
benchmark('Scan', table, query) { adapter.scan(table, query, opts) }
end | [
"def",
"scan",
"(",
"table",
",",
"query",
"=",
"{",
"}",
",",
"opts",
"=",
"{",
"}",
")",
"benchmark",
"(",
"'Scan'",
",",
"table",
",",
"query",
")",
"{",
"adapter",
".",
"scan",
"(",
"table",
",",
"query",
",",
"opts",
")",
"}",
"end"
] | Scans a table. Generally quite slow; try to avoid using scan if at all possible.
@param [String] table the name of the table to write the object to
@param [Hash] scan_hash a hash of attributes: matching records will be returned by the scan
@since 0.2.0 | [
"Scans",
"a",
"table",
".",
"Generally",
"quite",
"slow",
";",
"try",
"to",
"avoid",
"using",
"scan",
"if",
"at",
"all",
"possible",
"."
] | 9e3d006b039e45877b003564ded65509b10b6354 | https://github.com/Dynamoid/dynamoid/blob/9e3d006b039e45877b003564ded65509b10b6354/lib/dynamoid/adapter.rb#L120-L122 | train |
Dynamoid/dynamoid | lib/dynamoid/adapter.rb | Dynamoid.Adapter.method_missing | def method_missing(method, *args, &block)
return benchmark(method, *args) { adapter.send(method, *args, &block) } if adapter.respond_to?(method)
super
end | ruby | def method_missing(method, *args, &block)
return benchmark(method, *args) { adapter.send(method, *args, &block) } if adapter.respond_to?(method)
super
end | [
"def",
"method_missing",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"return",
"benchmark",
"(",
"method",
",",
"args",
")",
"{",
"adapter",
".",
"send",
"(",
"method",
",",
"args",
",",
"block",
")",
"}",
"if",
"adapter",
".",
"respond_... | Delegate all methods that aren't defind here to the underlying adapter.
@since 0.2.0 | [
"Delegate",
"all",
"methods",
"that",
"aren",
"t",
"defind",
"here",
"to",
"the",
"underlying",
"adapter",
"."
] | 9e3d006b039e45877b003564ded65509b10b6354 | https://github.com/Dynamoid/dynamoid/blob/9e3d006b039e45877b003564ded65509b10b6354/lib/dynamoid/adapter.rb#L156-L160 | train |
Dynamoid/dynamoid | lib/dynamoid/config.rb | Dynamoid.Config.logger= | def logger=(logger)
case logger
when false, nil then @logger = NullLogger.new
when true then @logger = default_logger
else
@logger = logger if logger.respond_to?(:info)
end
end | ruby | def logger=(logger)
case logger
when false, nil then @logger = NullLogger.new
when true then @logger = default_logger
else
@logger = logger if logger.respond_to?(:info)
end
end | [
"def",
"logger",
"=",
"(",
"logger",
")",
"case",
"logger",
"when",
"false",
",",
"nil",
"then",
"@logger",
"=",
"NullLogger",
".",
"new",
"when",
"true",
"then",
"@logger",
"=",
"default_logger",
"else",
"@logger",
"=",
"logger",
"if",
"logger",
".",
"r... | If you want to, set the logger manually to any output you'd like. Or pass false or nil to disable logging entirely.
@since 0.2.0 | [
"If",
"you",
"want",
"to",
"set",
"the",
"logger",
"manually",
"to",
"any",
"output",
"you",
"d",
"like",
".",
"Or",
"pass",
"false",
"or",
"nil",
"to",
"disable",
"logging",
"entirely",
"."
] | 9e3d006b039e45877b003564ded65509b10b6354 | https://github.com/Dynamoid/dynamoid/blob/9e3d006b039e45877b003564ded65509b10b6354/lib/dynamoid/config.rb#L67-L74 | train |
boazsegev/combine_pdf | lib/combine_pdf/renderer.rb | CombinePDF.Renderer.object_to_pdf | def object_to_pdf(object)
if object.nil?
return 'null'
elsif object.is_a?(String)
return format_string_to_pdf object
elsif object.is_a?(Symbol)
return format_name_to_pdf object
elsif object.is_a?(Array)
return format_array_to_pdf object
elsif object.is_a?(In... | ruby | def object_to_pdf(object)
if object.nil?
return 'null'
elsif object.is_a?(String)
return format_string_to_pdf object
elsif object.is_a?(Symbol)
return format_name_to_pdf object
elsif object.is_a?(Array)
return format_array_to_pdf object
elsif object.is_a?(In... | [
"def",
"object_to_pdf",
"(",
"object",
")",
"if",
"object",
".",
"nil?",
"return",
"'null'",
"elsif",
"object",
".",
"is_a?",
"(",
"String",
")",
"return",
"format_string_to_pdf",
"object",
"elsif",
"object",
".",
"is_a?",
"(",
"Symbol",
")",
"return",
"form... | Formats an object into PDF format. This is used my the PDF object to format the PDF file and it is used in the secure injection which is still being developed. | [
"Formats",
"an",
"object",
"into",
"PDF",
"format",
".",
"This",
"is",
"used",
"my",
"the",
"PDF",
"object",
"to",
"format",
"the",
"PDF",
"file",
"and",
"it",
"is",
"used",
"in",
"the",
"secure",
"injection",
"which",
"is",
"still",
"being",
"developed"... | 09054051019c069f551f3e60be789577c0f93900 | https://github.com/boazsegev/combine_pdf/blob/09054051019c069f551f3e60be789577c0f93900/lib/combine_pdf/renderer.rb#L14-L32 | train |
boazsegev/combine_pdf | lib/combine_pdf/pdf_public.rb | CombinePDF.PDF.new_page | def new_page(mediabox = [0, 0, 612.0, 792.0], _location = -1)
p = PDFWriter.new(mediabox)
insert(-1, p)
p
end | ruby | def new_page(mediabox = [0, 0, 612.0, 792.0], _location = -1)
p = PDFWriter.new(mediabox)
insert(-1, p)
p
end | [
"def",
"new_page",
"(",
"mediabox",
"=",
"[",
"0",
",",
"0",
",",
"612.0",
",",
"792.0",
"]",
",",
"_location",
"=",
"-",
"1",
")",
"p",
"=",
"PDFWriter",
".",
"new",
"(",
"mediabox",
")",
"insert",
"(",
"-",
"1",
",",
"p",
")",
"p",
"end"
] | adds a new page to the end of the PDF object.
returns the new page object.
unless the media box is specified, it defaults to US Letter: [0, 0, 612.0, 792.0] | [
"adds",
"a",
"new",
"page",
"to",
"the",
"end",
"of",
"the",
"PDF",
"object",
"."
] | 09054051019c069f551f3e60be789577c0f93900 | https://github.com/boazsegev/combine_pdf/blob/09054051019c069f551f3e60be789577c0f93900/lib/combine_pdf/pdf_public.rb#L122-L126 | train |
boazsegev/combine_pdf | lib/combine_pdf/pdf_public.rb | CombinePDF.PDF.to_pdf | def to_pdf(options = {})
# reset version if not specified
@version = 1.5 if @version.to_f == 0.0
# set info for merged file
@info[:ModDate] = @info[:CreationDate] = Time.now.strftime "D:%Y%m%d%H%M%S%:::z'00"
@info[:Subject] = options[:subject] if options[:subject]
@info[:Producer] = ... | ruby | def to_pdf(options = {})
# reset version if not specified
@version = 1.5 if @version.to_f == 0.0
# set info for merged file
@info[:ModDate] = @info[:CreationDate] = Time.now.strftime "D:%Y%m%d%H%M%S%:::z'00"
@info[:Subject] = options[:subject] if options[:subject]
@info[:Producer] = ... | [
"def",
"to_pdf",
"(",
"options",
"=",
"{",
"}",
")",
"# reset version if not specified",
"@version",
"=",
"1.5",
"if",
"@version",
".",
"to_f",
"==",
"0.0",
"# set info for merged file",
"@info",
"[",
":ModDate",
"]",
"=",
"@info",
"[",
":CreationDate",
"]",
"... | Formats the data to PDF formats and returns a binary string that represents the PDF file content.
This method is used by the save(file_name) method to save the content to a file.
use this to export the PDF file without saving to disk (such as sending through HTTP ect'). | [
"Formats",
"the",
"data",
"to",
"PDF",
"formats",
"and",
"returns",
"a",
"binary",
"string",
"that",
"represents",
"the",
"PDF",
"file",
"content",
"."
] | 09054051019c069f551f3e60be789577c0f93900 | https://github.com/boazsegev/combine_pdf/blob/09054051019c069f551f3e60be789577c0f93900/lib/combine_pdf/pdf_public.rb#L174-L215 | train |
boazsegev/combine_pdf | lib/combine_pdf/pdf_public.rb | CombinePDF.PDF.pages | def pages(catalogs = nil)
page_list = []
catalogs ||= get_existing_catalogs
if catalogs.is_a?(Array)
catalogs.each { |c| page_list.concat pages(c) unless c.nil? }
elsif catalogs.is_a?(Hash)
if catalogs[:is_reference_only]
if catalogs[:referenced_object]
pag... | ruby | def pages(catalogs = nil)
page_list = []
catalogs ||= get_existing_catalogs
if catalogs.is_a?(Array)
catalogs.each { |c| page_list.concat pages(c) unless c.nil? }
elsif catalogs.is_a?(Hash)
if catalogs[:is_reference_only]
if catalogs[:referenced_object]
pag... | [
"def",
"pages",
"(",
"catalogs",
"=",
"nil",
")",
"page_list",
"=",
"[",
"]",
"catalogs",
"||=",
"get_existing_catalogs",
"if",
"catalogs",
".",
"is_a?",
"(",
"Array",
")",
"catalogs",
".",
"each",
"{",
"|",
"c",
"|",
"page_list",
".",
"concat",
"pages",... | this method returns all the pages cataloged in the catalog.
if no catalog is passed, it seeks the existing catalog(s) and searches
for any registered Page objects.
Page objects are Hash class objects. the page methods are added using a mixin or inheritance.
catalogs:: a catalog, or an Array of catalog objects. d... | [
"this",
"method",
"returns",
"all",
"the",
"pages",
"cataloged",
"in",
"the",
"catalog",
"."
] | 09054051019c069f551f3e60be789577c0f93900 | https://github.com/boazsegev/combine_pdf/blob/09054051019c069f551f3e60be789577c0f93900/lib/combine_pdf/pdf_public.rb#L225-L250 | train |
boazsegev/combine_pdf | lib/combine_pdf/pdf_public.rb | CombinePDF.PDF.fonts | def fonts(limit_to_type0 = false)
fonts_array = []
pages.each do |pg|
if pg[:Resources][:Font]
pg[:Resources][:Font].values.each do |f|
f = f[:referenced_object] if f[:referenced_object]
if (limit_to_type0 || f[:Subtype] == :Type0) && f[:Type] == :Font && !fonts_arr... | ruby | def fonts(limit_to_type0 = false)
fonts_array = []
pages.each do |pg|
if pg[:Resources][:Font]
pg[:Resources][:Font].values.each do |f|
f = f[:referenced_object] if f[:referenced_object]
if (limit_to_type0 || f[:Subtype] == :Type0) && f[:Type] == :Font && !fonts_arr... | [
"def",
"fonts",
"(",
"limit_to_type0",
"=",
"false",
")",
"fonts_array",
"=",
"[",
"]",
"pages",
".",
"each",
"do",
"|",
"pg",
"|",
"if",
"pg",
"[",
":Resources",
"]",
"[",
":Font",
"]",
"pg",
"[",
":Resources",
"]",
"[",
":Font",
"]",
".",
"values... | returns an array with the different fonts used in the file.
Type0 font objects ( "font[:Subtype] == :Type0" ) can be registered with the font library
for use in PDFWriter objects (font numbering / table creation etc').
@param limit_to_type0 [true,false] limits the list to type0 fonts. | [
"returns",
"an",
"array",
"with",
"the",
"different",
"fonts",
"used",
"in",
"the",
"file",
"."
] | 09054051019c069f551f3e60be789577c0f93900 | https://github.com/boazsegev/combine_pdf/blob/09054051019c069f551f3e60be789577c0f93900/lib/combine_pdf/pdf_public.rb#L257-L270 | train |
boazsegev/combine_pdf | lib/combine_pdf/pdf_public.rb | CombinePDF.PDF.remove | def remove(page_index)
catalog = rebuild_catalog
pages_array = catalog[:Pages][:referenced_object][:Kids]
removed_page = pages_array.delete_at page_index
catalog[:Pages][:referenced_object][:Count] = pages_array.length
removed_page
end | ruby | def remove(page_index)
catalog = rebuild_catalog
pages_array = catalog[:Pages][:referenced_object][:Kids]
removed_page = pages_array.delete_at page_index
catalog[:Pages][:referenced_object][:Count] = pages_array.length
removed_page
end | [
"def",
"remove",
"(",
"page_index",
")",
"catalog",
"=",
"rebuild_catalog",
"pages_array",
"=",
"catalog",
"[",
":Pages",
"]",
"[",
":referenced_object",
"]",
"[",
":Kids",
"]",
"removed_page",
"=",
"pages_array",
".",
"delete_at",
"page_index",
"catalog",
"[",
... | removes a PDF page from the file and the catalog
returns the removed page.
returns nil if failed or if out of bounds.
page_index:: the page's index in the zero (0) based page array. negative numbers represent a count backwards (-1 being the end of the page array and 0 being the begining). | [
"removes",
"a",
"PDF",
"page",
"from",
"the",
"file",
"and",
"the",
"catalog"
] | 09054051019c069f551f3e60be789577c0f93900 | https://github.com/boazsegev/combine_pdf/blob/09054051019c069f551f3e60be789577c0f93900/lib/combine_pdf/pdf_public.rb#L346-L352 | train |
boazsegev/combine_pdf | lib/combine_pdf/fonts.rb | CombinePDF.Fonts.register_font_from_pdf_object | def register_font_from_pdf_object(font_name, font_object)
# FIXME:
# - add stream deflation for the CMap file.
# - add :Encoding CMaps (such as :WinAnsiEncoding etc`)
# - the ToUnicode CMap parsing assumes 8 Bytes <0F0F> while 16 Bytes and multiple unicode chars are also possible.
# first... | ruby | def register_font_from_pdf_object(font_name, font_object)
# FIXME:
# - add stream deflation for the CMap file.
# - add :Encoding CMaps (such as :WinAnsiEncoding etc`)
# - the ToUnicode CMap parsing assumes 8 Bytes <0F0F> while 16 Bytes and multiple unicode chars are also possible.
# first... | [
"def",
"register_font_from_pdf_object",
"(",
"font_name",
",",
"font_object",
")",
"# FIXME:",
"# - add stream deflation for the CMap file.",
"# - add :Encoding CMaps (such as :WinAnsiEncoding etc`)",
"# - the ToUnicode CMap parsing assumes 8 Bytes <0F0F> while 16 Bytes and multiple unicode char... | Register a font that already exists in a pdf object into the font library.
The implementation is experimental, but this function attempts to deconstruct a font object in order to
extract it's cmap and metric data, allowing it's use in the CombinePDF library. | [
"Register",
"a",
"font",
"that",
"already",
"exists",
"in",
"a",
"pdf",
"object",
"into",
"the",
"font",
"library",
"."
] | 09054051019c069f551f3e60be789577c0f93900 | https://github.com/boazsegev/combine_pdf/blob/09054051019c069f551f3e60be789577c0f93900/lib/combine_pdf/fonts.rb#L205-L277 | train |
boazsegev/combine_pdf | lib/combine_pdf/page_methods.rb | CombinePDF.Page_Methods.init_contents | def init_contents
self[:Contents] = self[:Contents][:referenced_object][:indirect_without_dictionary] if self[:Contents].is_a?(Hash) && self[:Contents][:referenced_object] && self[:Contents][:referenced_object].is_a?(Hash) && self[:Contents][:referenced_object][:indirect_without_dictionary]
self[:Contents] ... | ruby | def init_contents
self[:Contents] = self[:Contents][:referenced_object][:indirect_without_dictionary] if self[:Contents].is_a?(Hash) && self[:Contents][:referenced_object] && self[:Contents][:referenced_object].is_a?(Hash) && self[:Contents][:referenced_object][:indirect_without_dictionary]
self[:Contents] ... | [
"def",
"init_contents",
"self",
"[",
":Contents",
"]",
"=",
"self",
"[",
":Contents",
"]",
"[",
":referenced_object",
"]",
"[",
":indirect_without_dictionary",
"]",
"if",
"self",
"[",
":Contents",
"]",
".",
"is_a?",
"(",
"Hash",
")",
"&&",
"self",
"[",
":C... | initializes the content stream in case it was not initialized before | [
"initializes",
"the",
"content",
"stream",
"in",
"case",
"it",
"was",
"not",
"initialized",
"before"
] | 09054051019c069f551f3e60be789577c0f93900 | https://github.com/boazsegev/combine_pdf/blob/09054051019c069f551f3e60be789577c0f93900/lib/combine_pdf/page_methods.rb#L669-L685 | train |
boazsegev/combine_pdf | lib/combine_pdf/page_methods.rb | CombinePDF.Page_Methods.insert_content | def insert_content(object, location = -1)
object = { is_reference_only: true, referenced_object: { indirect_reference_id: 0, raw_stream_content: object } } if object.is_a?(String)
raise TypeError, 'expected a String or Hash object.' unless object.is_a?(Hash)
prep_content_array
self[:Contents].in... | ruby | def insert_content(object, location = -1)
object = { is_reference_only: true, referenced_object: { indirect_reference_id: 0, raw_stream_content: object } } if object.is_a?(String)
raise TypeError, 'expected a String or Hash object.' unless object.is_a?(Hash)
prep_content_array
self[:Contents].in... | [
"def",
"insert_content",
"(",
"object",
",",
"location",
"=",
"-",
"1",
")",
"object",
"=",
"{",
"is_reference_only",
":",
"true",
",",
"referenced_object",
":",
"{",
"indirect_reference_id",
":",
"0",
",",
"raw_stream_content",
":",
"object",
"}",
"}",
"if"... | adds a string or an object to the content stream, at the location indicated
accepts:
object:: can be a string or a hash object
location:: can be any numeral related to the possition in the :Contents array. defaults to -1 == insert at the end. | [
"adds",
"a",
"string",
"or",
"an",
"object",
"to",
"the",
"content",
"stream",
"at",
"the",
"location",
"indicated"
] | 09054051019c069f551f3e60be789577c0f93900 | https://github.com/boazsegev/combine_pdf/blob/09054051019c069f551f3e60be789577c0f93900/lib/combine_pdf/page_methods.rb#L692-L699 | train |
boazsegev/combine_pdf | lib/combine_pdf/page_methods.rb | CombinePDF.Page_Methods.graphic_state | def graphic_state(graphic_state_dictionary = {})
# if the graphic state exists, return it's name
resources[:ExtGState] ||= {}
gs_res = resources[:ExtGState][:referenced_object] || resources[:ExtGState]
gs_res.each do |k, v|
return k if v.is_a?(Hash) && v == graphic_state_dictionary
... | ruby | def graphic_state(graphic_state_dictionary = {})
# if the graphic state exists, return it's name
resources[:ExtGState] ||= {}
gs_res = resources[:ExtGState][:referenced_object] || resources[:ExtGState]
gs_res.each do |k, v|
return k if v.is_a?(Hash) && v == graphic_state_dictionary
... | [
"def",
"graphic_state",
"(",
"graphic_state_dictionary",
"=",
"{",
"}",
")",
"# if the graphic state exists, return it's name",
"resources",
"[",
":ExtGState",
"]",
"||=",
"{",
"}",
"gs_res",
"=",
"resources",
"[",
":ExtGState",
"]",
"[",
":referenced_object",
"]",
... | register or get a registered graphic state dictionary.
the method returns the name of the graphos state, for use in a content stream. | [
"register",
"or",
"get",
"a",
"registered",
"graphic",
"state",
"dictionary",
".",
"the",
"method",
"returns",
"the",
"name",
"of",
"the",
"graphos",
"state",
"for",
"use",
"in",
"a",
"content",
"stream",
"."
] | 09054051019c069f551f3e60be789577c0f93900 | https://github.com/boazsegev/combine_pdf/blob/09054051019c069f551f3e60be789577c0f93900/lib/combine_pdf/page_methods.rb#L754-L769 | train |
shugo/textbringer | lib/textbringer/buffer.rb | Textbringer.Buffer.save_excursion | def save_excursion
old_point = new_mark
old_mark = @mark&.dup
old_column = @goal_column
begin
yield
ensure
point_to_mark(old_point)
old_point.delete
if old_mark
@mark.location = old_mark.location
old_mark.delete
end
@goal_... | ruby | def save_excursion
old_point = new_mark
old_mark = @mark&.dup
old_column = @goal_column
begin
yield
ensure
point_to_mark(old_point)
old_point.delete
if old_mark
@mark.location = old_mark.location
old_mark.delete
end
@goal_... | [
"def",
"save_excursion",
"old_point",
"=",
"new_mark",
"old_mark",
"=",
"@mark",
"&.",
"dup",
"old_column",
"=",
"@goal_column",
"begin",
"yield",
"ensure",
"point_to_mark",
"(",
"old_point",
")",
"old_point",
".",
"delete",
"if",
"old_mark",
"@mark",
".",
"loca... | Don't save Buffer.current. | [
"Don",
"t",
"save",
"Buffer",
".",
"current",
"."
] | dcea7a098b5e04335e73faee5616bd1678add7ec | https://github.com/shugo/textbringer/blob/dcea7a098b5e04335e73faee5616bd1678add7ec/lib/textbringer/buffer.rb#L813-L828 | train |
shugo/textbringer | lib/textbringer/buffer.rb | Textbringer.Buffer.push_mark | def push_mark(pos = @point)
@mark = new_mark
@mark.location = pos
@mark_ring.push(@mark)
if self != Buffer.minibuffer
global_mark_ring = Buffer.global_mark_ring
if global_mark_ring.empty? || global_mark_ring.current.buffer != self
push_global_mark(pos)
end
... | ruby | def push_mark(pos = @point)
@mark = new_mark
@mark.location = pos
@mark_ring.push(@mark)
if self != Buffer.minibuffer
global_mark_ring = Buffer.global_mark_ring
if global_mark_ring.empty? || global_mark_ring.current.buffer != self
push_global_mark(pos)
end
... | [
"def",
"push_mark",
"(",
"pos",
"=",
"@point",
")",
"@mark",
"=",
"new_mark",
"@mark",
".",
"location",
"=",
"pos",
"@mark_ring",
".",
"push",
"(",
"@mark",
")",
"if",
"self",
"!=",
"Buffer",
".",
"minibuffer",
"global_mark_ring",
"=",
"Buffer",
".",
"gl... | Set mark at pos, and push the mark on the mark ring.
Unlike Emacs, the new mark is pushed on the mark ring instead of
the old one. | [
"Set",
"mark",
"at",
"pos",
"and",
"push",
"the",
"mark",
"on",
"the",
"mark",
"ring",
".",
"Unlike",
"Emacs",
"the",
"new",
"mark",
"is",
"pushed",
"on",
"the",
"mark",
"ring",
"instead",
"of",
"the",
"old",
"one",
"."
] | dcea7a098b5e04335e73faee5616bd1678add7ec | https://github.com/shugo/textbringer/blob/dcea7a098b5e04335e73faee5616bd1678add7ec/lib/textbringer/buffer.rb#L848-L858 | train |
shugo/textbringer | lib/textbringer/modes/programming_mode.rb | Textbringer.ProgrammingMode.indent_line | def indent_line
result = false
level = calculate_indentation
return result if level.nil?
@buffer.save_excursion do
@buffer.beginning_of_line
@buffer.composite_edit do
if @buffer.looking_at?(/[ \t]+/)
s = @buffer.match_string(0)
break if /\t/ !~ s... | ruby | def indent_line
result = false
level = calculate_indentation
return result if level.nil?
@buffer.save_excursion do
@buffer.beginning_of_line
@buffer.composite_edit do
if @buffer.looking_at?(/[ \t]+/)
s = @buffer.match_string(0)
break if /\t/ !~ s... | [
"def",
"indent_line",
"result",
"=",
"false",
"level",
"=",
"calculate_indentation",
"return",
"result",
"if",
"level",
".",
"nil?",
"@buffer",
".",
"save_excursion",
"do",
"@buffer",
".",
"beginning_of_line",
"@buffer",
".",
"composite_edit",
"do",
"if",
"@buffer... | Return true if modified. | [
"Return",
"true",
"if",
"modified",
"."
] | dcea7a098b5e04335e73faee5616bd1678add7ec | https://github.com/shugo/textbringer/blob/dcea7a098b5e04335e73faee5616bd1678add7ec/lib/textbringer/modes/programming_mode.rb#L32-L58 | train |
Eric-Guo/wechat | lib/wechat/cipher.rb | Wechat.Cipher.pack | def pack(content, app_id)
random = SecureRandom.hex(8)
text = content.force_encoding('ASCII-8BIT')
msg_len = [text.length].pack('N')
encode_padding("#{random}#{msg_len}#{text}#{app_id}")
end | ruby | def pack(content, app_id)
random = SecureRandom.hex(8)
text = content.force_encoding('ASCII-8BIT')
msg_len = [text.length].pack('N')
encode_padding("#{random}#{msg_len}#{text}#{app_id}")
end | [
"def",
"pack",
"(",
"content",
",",
"app_id",
")",
"random",
"=",
"SecureRandom",
".",
"hex",
"(",
"8",
")",
"text",
"=",
"content",
".",
"force_encoding",
"(",
"'ASCII-8BIT'",
")",
"msg_len",
"=",
"[",
"text",
".",
"length",
"]",
".",
"pack",
"(",
"... | app_id or corp_id | [
"app_id",
"or",
"corp_id"
] | 2adcd4b3ad30cfe74930dec3ed8c7f4fdb1e6ec9 | https://github.com/Eric-Guo/wechat/blob/2adcd4b3ad30cfe74930dec3ed8c7f4fdb1e6ec9/lib/wechat/cipher.rb#L32-L38 | train |
seejohnrun/ice_cube | lib/ice_cube/validations/fixed_value.rb | IceCube.Validations::FixedValue.validate_interval_lock | def validate_interval_lock(time, start_time)
t0 = starting_unit(start_time)
t1 = time.send(type)
t0 >= t1 ? t0 - t1 : INTERVALS[type] - t1 + t0
end | ruby | def validate_interval_lock(time, start_time)
t0 = starting_unit(start_time)
t1 = time.send(type)
t0 >= t1 ? t0 - t1 : INTERVALS[type] - t1 + t0
end | [
"def",
"validate_interval_lock",
"(",
"time",
",",
"start_time",
")",
"t0",
"=",
"starting_unit",
"(",
"start_time",
")",
"t1",
"=",
"time",
".",
"send",
"(",
"type",
")",
"t0",
">=",
"t1",
"?",
"t0",
"-",
"t1",
":",
"INTERVALS",
"[",
"type",
"]",
"-... | Validate if the current time unit matches the same unit from the schedule
start time, returning the difference to the interval | [
"Validate",
"if",
"the",
"current",
"time",
"unit",
"matches",
"the",
"same",
"unit",
"from",
"the",
"schedule",
"start",
"time",
"returning",
"the",
"difference",
"to",
"the",
"interval"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/validations/fixed_value.rb#L28-L32 | train |
seejohnrun/ice_cube | lib/ice_cube/validations/fixed_value.rb | IceCube.Validations::FixedValue.validate_hour_lock | def validate_hour_lock(time, start_time)
h0 = starting_unit(start_time)
h1 = time.hour
if h0 >= h1
h0 - h1
else
if dst_offset = TimeUtil.dst_change(time)
h0 - h1 + dst_offset
else
24 - h1 + h0
end
end
end | ruby | def validate_hour_lock(time, start_time)
h0 = starting_unit(start_time)
h1 = time.hour
if h0 >= h1
h0 - h1
else
if dst_offset = TimeUtil.dst_change(time)
h0 - h1 + dst_offset
else
24 - h1 + h0
end
end
end | [
"def",
"validate_hour_lock",
"(",
"time",
",",
"start_time",
")",
"h0",
"=",
"starting_unit",
"(",
"start_time",
")",
"h1",
"=",
"time",
".",
"hour",
"if",
"h0",
">=",
"h1",
"h0",
"-",
"h1",
"else",
"if",
"dst_offset",
"=",
"TimeUtil",
".",
"dst_change",... | Lock the hour if explicitly set by hour_of_day, but allow for the nearest
hour during DST start to keep the correct interval. | [
"Lock",
"the",
"hour",
"if",
"explicitly",
"set",
"by",
"hour_of_day",
"but",
"allow",
"for",
"the",
"nearest",
"hour",
"during",
"DST",
"start",
"to",
"keep",
"the",
"correct",
"interval",
"."
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/validations/fixed_value.rb#L37-L49 | train |
seejohnrun/ice_cube | lib/ice_cube/validations/fixed_value.rb | IceCube.Validations::FixedValue.validate_day_lock | def validate_day_lock(time, start_time)
days_in_month = TimeUtil.days_in_month(time)
date = Date.new(time.year, time.month, time.day)
if value && value < 0
start = TimeUtil.day_of_month(value, date)
month_overflow = days_in_month - TimeUtil.days_in_next_month(time)
elsif value &... | ruby | def validate_day_lock(time, start_time)
days_in_month = TimeUtil.days_in_month(time)
date = Date.new(time.year, time.month, time.day)
if value && value < 0
start = TimeUtil.day_of_month(value, date)
month_overflow = days_in_month - TimeUtil.days_in_next_month(time)
elsif value &... | [
"def",
"validate_day_lock",
"(",
"time",
",",
"start_time",
")",
"days_in_month",
"=",
"TimeUtil",
".",
"days_in_month",
"(",
"time",
")",
"date",
"=",
"Date",
".",
"new",
"(",
"time",
".",
"year",
",",
"time",
".",
"month",
",",
"time",
".",
"day",
")... | For monthly rules that have no specified day value, the validation relies
on the schedule start time and jumps to include every month even if it
has fewer days than the schedule's start day.
Negative day values (from month end) also include all months.
Positive day values are taken literally so months with fewer ... | [
"For",
"monthly",
"rules",
"that",
"have",
"no",
"specified",
"day",
"value",
"the",
"validation",
"relies",
"on",
"the",
"schedule",
"start",
"time",
"and",
"jumps",
"to",
"include",
"every",
"month",
"even",
"if",
"it",
"has",
"fewer",
"days",
"than",
"t... | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/validations/fixed_value.rb#L60-L85 | train |
seejohnrun/ice_cube | lib/ice_cube/builders/ical_builder.rb | IceCube.IcalBuilder.to_s | def to_s
arr = []
if freq = @hash.delete('FREQ')
arr << "FREQ=#{freq.join(',')}"
end
arr.concat(@hash.map do |key, value|
if value.is_a?(Array)
"#{key}=#{value.join(',')}"
end
end.compact)
arr.join(';')
end | ruby | def to_s
arr = []
if freq = @hash.delete('FREQ')
arr << "FREQ=#{freq.join(',')}"
end
arr.concat(@hash.map do |key, value|
if value.is_a?(Array)
"#{key}=#{value.join(',')}"
end
end.compact)
arr.join(';')
end | [
"def",
"to_s",
"arr",
"=",
"[",
"]",
"if",
"freq",
"=",
"@hash",
".",
"delete",
"(",
"'FREQ'",
")",
"arr",
"<<",
"\"FREQ=#{freq.join(',')}\"",
"end",
"arr",
".",
"concat",
"(",
"@hash",
".",
"map",
"do",
"|",
"key",
",",
"value",
"|",
"if",
"value",
... | Build for a single rule entry | [
"Build",
"for",
"a",
"single",
"rule",
"entry"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/builders/ical_builder.rb#L20-L31 | train |
seejohnrun/ice_cube | lib/ice_cube/validations/hour_of_day.rb | IceCube.Validations::HourOfDay.hour_of_day | def hour_of_day(*hours)
hours.flatten.each do |hour|
unless hour.is_a?(Integer)
raise ArgumentError, "expecting Integer value for hour, got #{hour.inspect}"
end
verify_alignment(hour, :hour, :hour_of_day) { |error| raise error }
validations_for(:hour_of_day) << Validati... | ruby | def hour_of_day(*hours)
hours.flatten.each do |hour|
unless hour.is_a?(Integer)
raise ArgumentError, "expecting Integer value for hour, got #{hour.inspect}"
end
verify_alignment(hour, :hour, :hour_of_day) { |error| raise error }
validations_for(:hour_of_day) << Validati... | [
"def",
"hour_of_day",
"(",
"*",
"hours",
")",
"hours",
".",
"flatten",
".",
"each",
"do",
"|",
"hour",
"|",
"unless",
"hour",
".",
"is_a?",
"(",
"Integer",
")",
"raise",
"ArgumentError",
",",
"\"expecting Integer value for hour, got #{hour.inspect}\"",
"end",
"v... | Add hour of day validations | [
"Add",
"hour",
"of",
"day",
"validations"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/validations/hour_of_day.rb#L6-L18 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.add_recurrence_time | def add_recurrence_time(time)
return if time.nil?
rule = SingleOccurrenceRule.new(time)
add_recurrence_rule rule
time
end | ruby | def add_recurrence_time(time)
return if time.nil?
rule = SingleOccurrenceRule.new(time)
add_recurrence_rule rule
time
end | [
"def",
"add_recurrence_time",
"(",
"time",
")",
"return",
"if",
"time",
".",
"nil?",
"rule",
"=",
"SingleOccurrenceRule",
".",
"new",
"(",
"time",
")",
"add_recurrence_rule",
"rule",
"time",
"end"
] | Add a recurrence time to the schedule | [
"Add",
"a",
"recurrence",
"time",
"to",
"the",
"schedule"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L48-L53 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.add_exception_time | def add_exception_time(time)
return if time.nil?
rule = SingleOccurrenceRule.new(time)
add_exception_rule rule
time
end | ruby | def add_exception_time(time)
return if time.nil?
rule = SingleOccurrenceRule.new(time)
add_exception_rule rule
time
end | [
"def",
"add_exception_time",
"(",
"time",
")",
"return",
"if",
"time",
".",
"nil?",
"rule",
"=",
"SingleOccurrenceRule",
".",
"new",
"(",
"time",
")",
"add_exception_rule",
"rule",
"time",
"end"
] | Add an exception time to the schedule | [
"Add",
"an",
"exception",
"time",
"to",
"the",
"schedule"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L59-L64 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.remove_recurrence_time | def remove_recurrence_time(time)
found = false
@all_recurrence_rules.delete_if do |rule|
found = true if rule.is_a?(SingleOccurrenceRule) && rule.time == time
end
time if found
end | ruby | def remove_recurrence_time(time)
found = false
@all_recurrence_rules.delete_if do |rule|
found = true if rule.is_a?(SingleOccurrenceRule) && rule.time == time
end
time if found
end | [
"def",
"remove_recurrence_time",
"(",
"time",
")",
"found",
"=",
"false",
"@all_recurrence_rules",
".",
"delete_if",
"do",
"|",
"rule",
"|",
"found",
"=",
"true",
"if",
"rule",
".",
"is_a?",
"(",
"SingleOccurrenceRule",
")",
"&&",
"rule",
".",
"time",
"==",
... | Remove a recurrence time | [
"Remove",
"a",
"recurrence",
"time"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L116-L122 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.next_occurrences | def next_occurrences(num, from = nil, options = {})
from = TimeUtil.match_zone(from, start_time) || TimeUtil.now(start_time)
enumerate_occurrences(from + 1, nil, options).take(num)
end | ruby | def next_occurrences(num, from = nil, options = {})
from = TimeUtil.match_zone(from, start_time) || TimeUtil.now(start_time)
enumerate_occurrences(from + 1, nil, options).take(num)
end | [
"def",
"next_occurrences",
"(",
"num",
",",
"from",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
")",
"from",
"=",
"TimeUtil",
".",
"match_zone",
"(",
"from",
",",
"start_time",
")",
"||",
"TimeUtil",
".",
"now",
"(",
"start_time",
")",
"enumerate_occurren... | The next n occurrences after now | [
"The",
"next",
"n",
"occurrences",
"after",
"now"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L171-L174 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.previous_occurrence | def previous_occurrence(from)
from = TimeUtil.match_zone(from, start_time) or raise ArgumentError, "Time required, got #{from.inspect}"
return nil if from <= start_time
enumerate_occurrences(start_time, from - 1).to_a.last
end | ruby | def previous_occurrence(from)
from = TimeUtil.match_zone(from, start_time) or raise ArgumentError, "Time required, got #{from.inspect}"
return nil if from <= start_time
enumerate_occurrences(start_time, from - 1).to_a.last
end | [
"def",
"previous_occurrence",
"(",
"from",
")",
"from",
"=",
"TimeUtil",
".",
"match_zone",
"(",
"from",
",",
"start_time",
")",
"or",
"raise",
"ArgumentError",
",",
"\"Time required, got #{from.inspect}\"",
"return",
"nil",
"if",
"from",
"<=",
"start_time",
"enum... | The previous occurrence from a given time | [
"The",
"previous",
"occurrence",
"from",
"a",
"given",
"time"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L185-L189 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.previous_occurrences | def previous_occurrences(num, from)
from = TimeUtil.match_zone(from, start_time) or raise ArgumentError, "Time required, got #{from.inspect}"
return [] if from <= start_time
a = enumerate_occurrences(start_time, from - 1).to_a
a.size > num ? a[-1*num,a.size] : a
end | ruby | def previous_occurrences(num, from)
from = TimeUtil.match_zone(from, start_time) or raise ArgumentError, "Time required, got #{from.inspect}"
return [] if from <= start_time
a = enumerate_occurrences(start_time, from - 1).to_a
a.size > num ? a[-1*num,a.size] : a
end | [
"def",
"previous_occurrences",
"(",
"num",
",",
"from",
")",
"from",
"=",
"TimeUtil",
".",
"match_zone",
"(",
"from",
",",
"start_time",
")",
"or",
"raise",
"ArgumentError",
",",
"\"Time required, got #{from.inspect}\"",
"return",
"[",
"]",
"if",
"from",
"<=",
... | The previous n occurrences before a given time | [
"The",
"previous",
"n",
"occurrences",
"before",
"a",
"given",
"time"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L192-L197 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.occurs_between? | def occurs_between?(begin_time, closing_time, options = {})
enumerate_occurrences(begin_time, closing_time, options).next
true
rescue StopIteration
false
end | ruby | def occurs_between?(begin_time, closing_time, options = {})
enumerate_occurrences(begin_time, closing_time, options).next
true
rescue StopIteration
false
end | [
"def",
"occurs_between?",
"(",
"begin_time",
",",
"closing_time",
",",
"options",
"=",
"{",
"}",
")",
"enumerate_occurrences",
"(",
"begin_time",
",",
"closing_time",
",",
"options",
")",
".",
"next",
"true",
"rescue",
"StopIteration",
"false",
"end"
] | Return a boolean indicating if an occurrence falls between two times | [
"Return",
"a",
"boolean",
"indicating",
"if",
"an",
"occurrence",
"falls",
"between",
"two",
"times"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L218-L223 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.occurs_on? | def occurs_on?(date)
date = TimeUtil.ensure_date(date)
begin_time = TimeUtil.beginning_of_date(date, start_time)
closing_time = TimeUtil.end_of_date(date, start_time)
occurs_between?(begin_time, closing_time)
end | ruby | def occurs_on?(date)
date = TimeUtil.ensure_date(date)
begin_time = TimeUtil.beginning_of_date(date, start_time)
closing_time = TimeUtil.end_of_date(date, start_time)
occurs_between?(begin_time, closing_time)
end | [
"def",
"occurs_on?",
"(",
"date",
")",
"date",
"=",
"TimeUtil",
".",
"ensure_date",
"(",
"date",
")",
"begin_time",
"=",
"TimeUtil",
".",
"beginning_of_date",
"(",
"date",
",",
"start_time",
")",
"closing_time",
"=",
"TimeUtil",
".",
"end_of_date",
"(",
"dat... | Return a boolean indicating if an occurrence falls on a certain date | [
"Return",
"a",
"boolean",
"indicating",
"if",
"an",
"occurrence",
"falls",
"on",
"a",
"certain",
"date"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L235-L240 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.occurring_at? | def occurring_at?(time)
time = TimeUtil.match_zone(time, start_time) or raise ArgumentError, "Time required, got #{time.inspect}"
if duration > 0
return false if exception_time?(time)
occurs_between?(time - duration + 1, time)
else
occurs_at?(time)
end
end | ruby | def occurring_at?(time)
time = TimeUtil.match_zone(time, start_time) or raise ArgumentError, "Time required, got #{time.inspect}"
if duration > 0
return false if exception_time?(time)
occurs_between?(time - duration + 1, time)
else
occurs_at?(time)
end
end | [
"def",
"occurring_at?",
"(",
"time",
")",
"time",
"=",
"TimeUtil",
".",
"match_zone",
"(",
"time",
",",
"start_time",
")",
"or",
"raise",
"ArgumentError",
",",
"\"Time required, got #{time.inspect}\"",
"if",
"duration",
">",
"0",
"return",
"false",
"if",
"except... | Determine if the schedule is occurring at a given time | [
"Determine",
"if",
"the",
"schedule",
"is",
"occurring",
"at",
"a",
"given",
"time"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L243-L251 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.conflicts_with? | def conflicts_with?(other_schedule, closing_time = nil)
closing_time = TimeUtil.ensure_time(closing_time)
unless terminating? || other_schedule.terminating? || closing_time
raise ArgumentError, "One or both schedules must be terminating to use #conflicts_with?"
end
# Pick the terminating... | ruby | def conflicts_with?(other_schedule, closing_time = nil)
closing_time = TimeUtil.ensure_time(closing_time)
unless terminating? || other_schedule.terminating? || closing_time
raise ArgumentError, "One or both schedules must be terminating to use #conflicts_with?"
end
# Pick the terminating... | [
"def",
"conflicts_with?",
"(",
"other_schedule",
",",
"closing_time",
"=",
"nil",
")",
"closing_time",
"=",
"TimeUtil",
".",
"ensure_time",
"(",
"closing_time",
")",
"unless",
"terminating?",
"||",
"other_schedule",
".",
"terminating?",
"||",
"closing_time",
"raise"... | Determine if this schedule conflicts with another schedule
@param [IceCube::Schedule] other_schedule - The schedule to compare to
@param [Time] closing_time - the last time to consider
@return [Boolean] whether or not the schedules conflict at all | [
"Determine",
"if",
"this",
"schedule",
"conflicts",
"with",
"another",
"schedule"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L257-L291 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.first | def first(n = nil)
occurrences = enumerate_occurrences(start_time).take(n || 1)
n.nil? ? occurrences.first : occurrences
end | ruby | def first(n = nil)
occurrences = enumerate_occurrences(start_time).take(n || 1)
n.nil? ? occurrences.first : occurrences
end | [
"def",
"first",
"(",
"n",
"=",
"nil",
")",
"occurrences",
"=",
"enumerate_occurrences",
"(",
"start_time",
")",
".",
"take",
"(",
"n",
"||",
"1",
")",
"n",
".",
"nil?",
"?",
"occurrences",
".",
"first",
":",
"occurrences",
"end"
] | Get the first n occurrences, or the first occurrence if n is skipped | [
"Get",
"the",
"first",
"n",
"occurrences",
"or",
"the",
"first",
"occurrence",
"if",
"n",
"is",
"skipped"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L299-L302 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.last | def last(n = nil)
require_terminating_rules
occurrences = enumerate_occurrences(start_time).to_a
n.nil? ? occurrences.last : occurrences[-n..-1]
end | ruby | def last(n = nil)
require_terminating_rules
occurrences = enumerate_occurrences(start_time).to_a
n.nil? ? occurrences.last : occurrences[-n..-1]
end | [
"def",
"last",
"(",
"n",
"=",
"nil",
")",
"require_terminating_rules",
"occurrences",
"=",
"enumerate_occurrences",
"(",
"start_time",
")",
".",
"to_a",
"n",
".",
"nil?",
"?",
"occurrences",
".",
"last",
":",
"occurrences",
"[",
"-",
"n",
"..",
"-",
"1",
... | Get the final n occurrences of a terminating schedule
or the final one if no n is given | [
"Get",
"the",
"final",
"n",
"occurrences",
"of",
"a",
"terminating",
"schedule",
"or",
"the",
"final",
"one",
"if",
"no",
"n",
"is",
"given"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L306-L310 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.to_ical | def to_ical(force_utc = false)
pieces = []
pieces << "DTSTART#{IcalBuilder.ical_format(start_time, force_utc)}"
pieces.concat recurrence_rules.map { |r| "RRULE:#{r.to_ical}" }
pieces.concat exception_rules.map { |r| "EXRULE:#{r.to_ical}" }
pieces.concat recurrence_times_without_start_time... | ruby | def to_ical(force_utc = false)
pieces = []
pieces << "DTSTART#{IcalBuilder.ical_format(start_time, force_utc)}"
pieces.concat recurrence_rules.map { |r| "RRULE:#{r.to_ical}" }
pieces.concat exception_rules.map { |r| "EXRULE:#{r.to_ical}" }
pieces.concat recurrence_times_without_start_time... | [
"def",
"to_ical",
"(",
"force_utc",
"=",
"false",
")",
"pieces",
"=",
"[",
"]",
"pieces",
"<<",
"\"DTSTART#{IcalBuilder.ical_format(start_time, force_utc)}\"",
"pieces",
".",
"concat",
"recurrence_rules",
".",
"map",
"{",
"|",
"r",
"|",
"\"RRULE:#{r.to_ical}\"",
"}"... | Serialize this schedule to_ical | [
"Serialize",
"this",
"schedule",
"to_ical"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L327-L336 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.to_hash | def to_hash
data = {}
data[:start_time] = TimeUtil.serialize_time(start_time)
data[:start_date] = data[:start_time] if IceCube.compatibility <= 11
data[:end_time] = TimeUtil.serialize_time(end_time) if end_time
data[:rrules] = recurrence_rules.map(&:to_hash)
if IceCube.compatibility ... | ruby | def to_hash
data = {}
data[:start_time] = TimeUtil.serialize_time(start_time)
data[:start_date] = data[:start_time] if IceCube.compatibility <= 11
data[:end_time] = TimeUtil.serialize_time(end_time) if end_time
data[:rrules] = recurrence_rules.map(&:to_hash)
if IceCube.compatibility ... | [
"def",
"to_hash",
"data",
"=",
"{",
"}",
"data",
"[",
":start_time",
"]",
"=",
"TimeUtil",
".",
"serialize_time",
"(",
"start_time",
")",
"data",
"[",
":start_date",
"]",
"=",
"data",
"[",
":start_time",
"]",
"if",
"IceCube",
".",
"compatibility",
"<=",
... | Convert the schedule to a hash | [
"Convert",
"the",
"schedule",
"to",
"a",
"hash"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L357-L373 | train |
seejohnrun/ice_cube | lib/ice_cube/schedule.rb | IceCube.Schedule.enumerate_occurrences | def enumerate_occurrences(opening_time, closing_time = nil, options = {})
opening_time = TimeUtil.match_zone(opening_time, start_time)
closing_time = TimeUtil.match_zone(closing_time, start_time)
opening_time += TimeUtil.subsec(start_time) - TimeUtil.subsec(opening_time)
opening_time = start_tim... | ruby | def enumerate_occurrences(opening_time, closing_time = nil, options = {})
opening_time = TimeUtil.match_zone(opening_time, start_time)
closing_time = TimeUtil.match_zone(closing_time, start_time)
opening_time += TimeUtil.subsec(start_time) - TimeUtil.subsec(opening_time)
opening_time = start_tim... | [
"def",
"enumerate_occurrences",
"(",
"opening_time",
",",
"closing_time",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
")",
"opening_time",
"=",
"TimeUtil",
".",
"match_zone",
"(",
"opening_time",
",",
"start_time",
")",
"closing_time",
"=",
"TimeUtil",
".",
"ma... | Find all of the occurrences for the schedule between opening_time
and closing_time
Iteration is unrolled in pairs to skip duplicate times in end of DST | [
"Find",
"all",
"of",
"the",
"occurrences",
"for",
"the",
"schedule",
"between",
"opening_time",
"and",
"closing_time",
"Iteration",
"is",
"unrolled",
"in",
"pairs",
"to",
"skip",
"duplicate",
"times",
"in",
"end",
"of",
"DST"
] | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/schedule.rb#L424-L444 | train |
seejohnrun/ice_cube | lib/ice_cube/rules/weekly_rule.rb | IceCube.WeeklyRule.wday_offset | def wday_offset(step_time, start_time)
return 0 if step_time == start_time
wday_validations = other_interval_validations.select { |v| v.type == :wday }
return 0 if wday_validations.none?
days = step_time.to_date - start_time.to_date
interval = base_interval_validation.validate(step_time,... | ruby | def wday_offset(step_time, start_time)
return 0 if step_time == start_time
wday_validations = other_interval_validations.select { |v| v.type == :wday }
return 0 if wday_validations.none?
days = step_time.to_date - start_time.to_date
interval = base_interval_validation.validate(step_time,... | [
"def",
"wday_offset",
"(",
"step_time",
",",
"start_time",
")",
"return",
"0",
"if",
"step_time",
"==",
"start_time",
"wday_validations",
"=",
"other_interval_validations",
".",
"select",
"{",
"|",
"v",
"|",
"v",
".",
"type",
"==",
":wday",
"}",
"return",
"0... | Calculate how many days to the first wday validation in the correct
interval week. This may move backwards within the week if starting in an
interval week with earlier validations. | [
"Calculate",
"how",
"many",
"days",
"to",
"the",
"first",
"wday",
"validation",
"in",
"the",
"correct",
"interval",
"week",
".",
"This",
"may",
"move",
"backwards",
"within",
"the",
"week",
"if",
"starting",
"in",
"an",
"interval",
"week",
"with",
"earlier",... | fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd | https://github.com/seejohnrun/ice_cube/blob/fb6c657bdc4f87dfda2bf83f15c5f487b78ccabd/lib/ice_cube/rules/weekly_rule.rb#L47-L59 | train |
jeremytregunna/ruby-trello | lib/trello/client.rb | Trello.Client.find | def find(path, id, params = {})
response = get("/#{path.to_s.pluralize}/#{id}", params)
trello_class = class_from_path(path)
trello_class.parse response do |data|
data.client = self
end
end | ruby | def find(path, id, params = {})
response = get("/#{path.to_s.pluralize}/#{id}", params)
trello_class = class_from_path(path)
trello_class.parse response do |data|
data.client = self
end
end | [
"def",
"find",
"(",
"path",
",",
"id",
",",
"params",
"=",
"{",
"}",
")",
"response",
"=",
"get",
"(",
"\"/#{path.to_s.pluralize}/#{id}\"",
",",
"params",
")",
"trello_class",
"=",
"class_from_path",
"(",
"path",
")",
"trello_class",
".",
"parse",
"response"... | Finds given resource by id
Examples:
client.find(:board, "board1234")
client.find(:member, "user1234") | [
"Finds",
"given",
"resource",
"by",
"id"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/client.rb#L43-L49 | train |
jeremytregunna/ruby-trello | lib/trello/client.rb | Trello.Client.find_many | def find_many(trello_class, path, params = {})
response = get(path, params)
trello_class.parse_many response do |data|
data.client = self
end
end | ruby | def find_many(trello_class, path, params = {})
response = get(path, params)
trello_class.parse_many response do |data|
data.client = self
end
end | [
"def",
"find_many",
"(",
"trello_class",
",",
"path",
",",
"params",
"=",
"{",
"}",
")",
"response",
"=",
"get",
"(",
"path",
",",
"params",
")",
"trello_class",
".",
"parse_many",
"response",
"do",
"|",
"data",
"|",
"data",
".",
"client",
"=",
"self",... | Finds given resource by path with params | [
"Finds",
"given",
"resource",
"by",
"path",
"with",
"params"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/client.rb#L52-L57 | train |
jeremytregunna/ruby-trello | lib/trello/label_name.rb | Trello.LabelName.update_fields | def update_fields(fields)
attributes[:yellow] = fields['yellow'] || attributes[:yellow]
attributes[:red] = fields['red'] || attributes[:red]
attributes[:orange] = fields['orange'] || attributes[:orange]
attributes[:green] = fields['green'] || attributes[:green]
attributes[:purple] = field... | ruby | def update_fields(fields)
attributes[:yellow] = fields['yellow'] || attributes[:yellow]
attributes[:red] = fields['red'] || attributes[:red]
attributes[:orange] = fields['orange'] || attributes[:orange]
attributes[:green] = fields['green'] || attributes[:green]
attributes[:purple] = field... | [
"def",
"update_fields",
"(",
"fields",
")",
"attributes",
"[",
":yellow",
"]",
"=",
"fields",
"[",
"'yellow'",
"]",
"||",
"attributes",
"[",
":yellow",
"]",
"attributes",
"[",
":red",
"]",
"=",
"fields",
"[",
"'red'",
"]",
"||",
"attributes",
"[",
":red"... | Update the fields of a label.
Supply a hash of stringkeyed data retrieved from the Trello API representing
a label. | [
"Update",
"the",
"fields",
"of",
"a",
"label",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/label_name.rb#L11-L24 | train |
jeremytregunna/ruby-trello | lib/trello/webhook.rb | Trello.Webhook.save | def save
# If we have an id, just update our fields.
return update! if id
from_response client.post("/webhooks", {
description: description,
idModel: id_model,
callbackURL: callback_url
})
end | ruby | def save
# If we have an id, just update our fields.
return update! if id
from_response client.post("/webhooks", {
description: description,
idModel: id_model,
callbackURL: callback_url
})
end | [
"def",
"save",
"# If we have an id, just update our fields.",
"return",
"update!",
"if",
"id",
"from_response",
"client",
".",
"post",
"(",
"\"/webhooks\"",
",",
"{",
"description",
":",
"description",
",",
"idModel",
":",
"id_model",
",",
"callbackURL",
":",
"callb... | Save the webhook.
@raise [Trello::Error] if the Webhook could not be saved.
@return [String] the JSON representation of the saved webhook. | [
"Save",
"the",
"webhook",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/webhook.rb#L64-L73 | train |
jeremytregunna/ruby-trello | lib/trello/webhook.rb | Trello.Webhook.update! | def update!
client.put("/webhooks/#{id}", {
description: description,
idModel: id_model,
callbackURL: callback_url,
active: active
})
end | ruby | def update!
client.put("/webhooks/#{id}", {
description: description,
idModel: id_model,
callbackURL: callback_url,
active: active
})
end | [
"def",
"update!",
"client",
".",
"put",
"(",
"\"/webhooks/#{id}\"",
",",
"{",
"description",
":",
"description",
",",
"idModel",
":",
"id_model",
",",
"callbackURL",
":",
"callback_url",
",",
"active",
":",
"active",
"}",
")",
"end"
] | Update the webhook.
@raise [Trello::Error] if the Webhook could not be saved.
@return [String] the JSON representation of the updated webhook. | [
"Update",
"the",
"webhook",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/webhook.rb#L80-L87 | train |
jeremytregunna/ruby-trello | lib/trello/plugin_datum.rb | Trello.PluginDatum.update_fields | def update_fields(fields)
attributes[:id] = fields['id'] || attributes[:id]
attributes[:idPlugin] = fields['idPlugin'] || attributes[:idPlugin]
attributes[:scope] = fields['scope'] || attributes[:scope]
attributes[:value] = JSON.parse(fields['value']).presence if fields.has_key?(... | ruby | def update_fields(fields)
attributes[:id] = fields['id'] || attributes[:id]
attributes[:idPlugin] = fields['idPlugin'] || attributes[:idPlugin]
attributes[:scope] = fields['scope'] || attributes[:scope]
attributes[:value] = JSON.parse(fields['value']).presence if fields.has_key?(... | [
"def",
"update_fields",
"(",
"fields",
")",
"attributes",
"[",
":id",
"]",
"=",
"fields",
"[",
"'id'",
"]",
"||",
"attributes",
"[",
":id",
"]",
"attributes",
"[",
":idPlugin",
"]",
"=",
"fields",
"[",
"'idPlugin'",
"]",
"||",
"attributes",
"[",
":idPlug... | Supply a hash of stringkeyed data retrieved from the Trello API representing
an attachment. | [
"Supply",
"a",
"hash",
"of",
"stringkeyed",
"data",
"retrieved",
"from",
"the",
"Trello",
"API",
"representing",
"an",
"attachment",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/plugin_datum.rb#L23-L31 | train |
jeremytregunna/ruby-trello | lib/trello/card.rb | Trello.Card.update_fields | def update_fields(fields)
attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || attributes[:id]
attributes[:short_id] = fields[SYMBOL_TO_STRING[:short_id]] || attributes[:short_id]
attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || ... | ruby | def update_fields(fields)
attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || attributes[:id]
attributes[:short_id] = fields[SYMBOL_TO_STRING[:short_id]] || attributes[:short_id]
attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || ... | [
"def",
"update_fields",
"(",
"fields",
")",
"attributes",
"[",
":id",
"]",
"=",
"fields",
"[",
"SYMBOL_TO_STRING",
"[",
":id",
"]",
"]",
"||",
"attributes",
"[",
":id",
"]",
"attributes",
"[",
":short_id",
"]",
"=",
"fields",
"[",
"SYMBOL_TO_STRING",
"[",
... | Update the fields of a card.
Supply a hash of string keyed data retrieved from the Trello API representing
a card.
Note that this this method does not save anything new to the Trello API,
it just assigns the input attributes to your local object. If you use
this method to assign attributes, call `save` or `updat... | [
"Update",
"the",
"fields",
"of",
"a",
"card",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/card.rb#L171-L196 | train |
jeremytregunna/ruby-trello | lib/trello/card.rb | Trello.Card.update! | def update!
@previously_changed = changes
# extract only new values to build payload
payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }]
@changed_attributes.clear
client.put("/cards/#{id}", payload)
end | ruby | def update!
@previously_changed = changes
# extract only new values to build payload
payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }]
@changed_attributes.clear
client.put("/cards/#{id}", payload)
end | [
"def",
"update!",
"@previously_changed",
"=",
"changes",
"# extract only new values to build payload",
"payload",
"=",
"Hash",
"[",
"changes",
".",
"map",
"{",
"|",
"key",
",",
"values",
"|",
"[",
"SYMBOL_TO_STRING",
"[",
"key",
".",
"to_sym",
"]",
".",
"to_sym"... | Update an existing record.
Warning: this updates all fields using values already in memory. If
an external resource has updated these fields, you should refresh!
this object before making your changes, and before updating the record.
@raise [Trello::Error] if the card could not be updated.
@return [String] The ... | [
"Update",
"an",
"existing",
"record",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/card.rb#L276-L283 | train |
jeremytregunna/ruby-trello | lib/trello/card.rb | Trello.Card.move_to_list | def move_to_list(list)
list_number = list.is_a?(String) ? list : list.id
unless list_id == list_number
client.put("/cards/#{id}/idList", {
value: list_number
})
end
end | ruby | def move_to_list(list)
list_number = list.is_a?(String) ? list : list.id
unless list_id == list_number
client.put("/cards/#{id}/idList", {
value: list_number
})
end
end | [
"def",
"move_to_list",
"(",
"list",
")",
"list_number",
"=",
"list",
".",
"is_a?",
"(",
"String",
")",
"?",
"list",
":",
"list",
".",
"id",
"unless",
"list_id",
"==",
"list_number",
"client",
".",
"put",
"(",
"\"/cards/#{id}/idList\"",
",",
"{",
"value",
... | Move this card to the given list | [
"Move",
"this",
"card",
"to",
"the",
"given",
"list"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/card.rb#L338-L345 | train |
jeremytregunna/ruby-trello | lib/trello/card.rb | Trello.Card.move_to_list_on_any_board | def move_to_list_on_any_board(list_id)
list = List.find(list_id)
if board.id == list.board_id
move_to_list(list_id)
else
move_to_board(Board.find(list.board_id), list)
end
end | ruby | def move_to_list_on_any_board(list_id)
list = List.find(list_id)
if board.id == list.board_id
move_to_list(list_id)
else
move_to_board(Board.find(list.board_id), list)
end
end | [
"def",
"move_to_list_on_any_board",
"(",
"list_id",
")",
"list",
"=",
"List",
".",
"find",
"(",
"list_id",
")",
"if",
"board",
".",
"id",
"==",
"list",
".",
"board_id",
"move_to_list",
"(",
"list_id",
")",
"else",
"move_to_board",
"(",
"Board",
".",
"find"... | Moves this card to the given list no matter which board it is on | [
"Moves",
"this",
"card",
"to",
"the",
"given",
"list",
"no",
"matter",
"which",
"board",
"it",
"is",
"on"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/card.rb#L348-L355 | train |
jeremytregunna/ruby-trello | lib/trello/card.rb | Trello.Card.upvote | def upvote
begin
client.post("/cards/#{id}/membersVoted", {
value: me.id
})
rescue Trello::Error => e
fail e unless e.message =~ /has already voted/i
end
self
end | ruby | def upvote
begin
client.post("/cards/#{id}/membersVoted", {
value: me.id
})
rescue Trello::Error => e
fail e unless e.message =~ /has already voted/i
end
self
end | [
"def",
"upvote",
"begin",
"client",
".",
"post",
"(",
"\"/cards/#{id}/membersVoted\"",
",",
"{",
"value",
":",
"me",
".",
"id",
"}",
")",
"rescue",
"Trello",
"::",
"Error",
"=>",
"e",
"fail",
"e",
"unless",
"e",
".",
"message",
"=~",
"/",
"/i",
"end",
... | Current authenticated user upvotes a card | [
"Current",
"authenticated",
"user",
"upvotes",
"a",
"card"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/card.rb#L379-L389 | train |
jeremytregunna/ruby-trello | lib/trello/card.rb | Trello.Card.remove_upvote | def remove_upvote
begin
client.delete("/cards/#{id}/membersVoted/#{me.id}")
rescue Trello::Error => e
fail e unless e.message =~ /has not voted/i
end
self
end | ruby | def remove_upvote
begin
client.delete("/cards/#{id}/membersVoted/#{me.id}")
rescue Trello::Error => e
fail e unless e.message =~ /has not voted/i
end
self
end | [
"def",
"remove_upvote",
"begin",
"client",
".",
"delete",
"(",
"\"/cards/#{id}/membersVoted/#{me.id}\"",
")",
"rescue",
"Trello",
"::",
"Error",
"=>",
"e",
"fail",
"e",
"unless",
"e",
".",
"message",
"=~",
"/",
"/i",
"end",
"self",
"end"
] | Recind upvote. Noop if authenticated user hasn't previously voted | [
"Recind",
"upvote",
".",
"Noop",
"if",
"authenticated",
"user",
"hasn",
"t",
"previously",
"voted"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/card.rb#L392-L400 | train |
jeremytregunna/ruby-trello | lib/trello/card.rb | Trello.Card.add_label | def add_label(label)
unless label.valid?
errors.add(:label, "is not valid.")
return Trello.logger.warn "Label is not valid." unless label.valid?
end
client.post("/cards/#{id}/idLabels", {value: label.id})
end | ruby | def add_label(label)
unless label.valid?
errors.add(:label, "is not valid.")
return Trello.logger.warn "Label is not valid." unless label.valid?
end
client.post("/cards/#{id}/idLabels", {value: label.id})
end | [
"def",
"add_label",
"(",
"label",
")",
"unless",
"label",
".",
"valid?",
"errors",
".",
"add",
"(",
":label",
",",
"\"is not valid.\"",
")",
"return",
"Trello",
".",
"logger",
".",
"warn",
"\"Label is not valid.\"",
"unless",
"label",
".",
"valid?",
"end",
"... | Add a label | [
"Add",
"a",
"label"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/card.rb#L403-L409 | train |
jeremytregunna/ruby-trello | lib/trello/card.rb | Trello.Card.remove_label | def remove_label(label)
unless label.valid?
errors.add(:label, "is not valid.")
return Trello.logger.warn "Label is not valid." unless label.valid?
end
client.delete("/cards/#{id}/idLabels/#{label.id}")
end | ruby | def remove_label(label)
unless label.valid?
errors.add(:label, "is not valid.")
return Trello.logger.warn "Label is not valid." unless label.valid?
end
client.delete("/cards/#{id}/idLabels/#{label.id}")
end | [
"def",
"remove_label",
"(",
"label",
")",
"unless",
"label",
".",
"valid?",
"errors",
".",
"add",
"(",
":label",
",",
"\"is not valid.\"",
")",
"return",
"Trello",
".",
"logger",
".",
"warn",
"\"Label is not valid.\"",
"unless",
"label",
".",
"valid?",
"end",
... | Remove a label | [
"Remove",
"a",
"label"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/card.rb#L412-L418 | train |
jeremytregunna/ruby-trello | lib/trello/card.rb | Trello.Card.add_attachment | def add_attachment(attachment, name = '')
# Is it a file object or a string (url)?
if attachment.respond_to?(:path) && attachment.respond_to?(:read)
client.post("/cards/#{id}/attachments", {
file: attachment,
name: name
})
else
client.post("/cards/#{id... | ruby | def add_attachment(attachment, name = '')
# Is it a file object or a string (url)?
if attachment.respond_to?(:path) && attachment.respond_to?(:read)
client.post("/cards/#{id}/attachments", {
file: attachment,
name: name
})
else
client.post("/cards/#{id... | [
"def",
"add_attachment",
"(",
"attachment",
",",
"name",
"=",
"''",
")",
"# Is it a file object or a string (url)?",
"if",
"attachment",
".",
"respond_to?",
"(",
":path",
")",
"&&",
"attachment",
".",
"respond_to?",
"(",
":read",
")",
"client",
".",
"post",
"(",... | Add an attachment to this card | [
"Add",
"an",
"attachment",
"to",
"this",
"card"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/card.rb#L421-L434 | train |
jeremytregunna/ruby-trello | lib/trello/card.rb | Trello.Card.attachments | def attachments
attachments = Attachment.from_response client.get("/cards/#{id}/attachments")
MultiAssociation.new(self, attachments).proxy
end | ruby | def attachments
attachments = Attachment.from_response client.get("/cards/#{id}/attachments")
MultiAssociation.new(self, attachments).proxy
end | [
"def",
"attachments",
"attachments",
"=",
"Attachment",
".",
"from_response",
"client",
".",
"get",
"(",
"\"/cards/#{id}/attachments\"",
")",
"MultiAssociation",
".",
"new",
"(",
"self",
",",
"attachments",
")",
".",
"proxy",
"end"
] | Retrieve a list of attachments | [
"Retrieve",
"a",
"list",
"of",
"attachments"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/card.rb#L437-L440 | train |
jeremytregunna/ruby-trello | lib/trello/organization.rb | Trello.Organization.boards | def boards
boards = Board.from_response client.get("/organizations/#{id}/boards/all")
MultiAssociation.new(self, boards).proxy
end | ruby | def boards
boards = Board.from_response client.get("/organizations/#{id}/boards/all")
MultiAssociation.new(self, boards).proxy
end | [
"def",
"boards",
"boards",
"=",
"Board",
".",
"from_response",
"client",
".",
"get",
"(",
"\"/organizations/#{id}/boards/all\"",
")",
"MultiAssociation",
".",
"new",
"(",
"self",
",",
"boards",
")",
".",
"proxy",
"end"
] | Returns a list of boards under this organization. | [
"Returns",
"a",
"list",
"of",
"boards",
"under",
"this",
"organization",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/organization.rb#L52-L55 | train |
jeremytregunna/ruby-trello | lib/trello/organization.rb | Trello.Organization.members | def members(params = {})
members = Member.from_response client.get("/organizations/#{id}/members/all", params)
MultiAssociation.new(self, members).proxy
end | ruby | def members(params = {})
members = Member.from_response client.get("/organizations/#{id}/members/all", params)
MultiAssociation.new(self, members).proxy
end | [
"def",
"members",
"(",
"params",
"=",
"{",
"}",
")",
"members",
"=",
"Member",
".",
"from_response",
"client",
".",
"get",
"(",
"\"/organizations/#{id}/members/all\"",
",",
"params",
")",
"MultiAssociation",
".",
"new",
"(",
"self",
",",
"members",
")",
".",... | Returns an array of members associated with the organization. | [
"Returns",
"an",
"array",
"of",
"members",
"associated",
"with",
"the",
"organization",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/organization.rb#L58-L61 | train |
jeremytregunna/ruby-trello | lib/trello/comment.rb | Trello.Comment.update_fields | def update_fields(fields)
attributes[:action_id] = fields['id'] || attributes[:action_id]
attributes[:text] = fields['data']['text'] || attributes[:text]
attributes[:date] = Time.iso8601(fields['date']) if fields.has_key?('date')
attributes[:member_creator_id... | ruby | def update_fields(fields)
attributes[:action_id] = fields['id'] || attributes[:action_id]
attributes[:text] = fields['data']['text'] || attributes[:text]
attributes[:date] = Time.iso8601(fields['date']) if fields.has_key?('date')
attributes[:member_creator_id... | [
"def",
"update_fields",
"(",
"fields",
")",
"attributes",
"[",
":action_id",
"]",
"=",
"fields",
"[",
"'id'",
"]",
"||",
"attributes",
"[",
":action_id",
"]",
"attributes",
"[",
":text",
"]",
"=",
"fields",
"[",
"'data'",
"]",
"[",
"'text'",
"]",
"||",
... | Update the attributes of a Comment
Supply a hash of string keyed data retrieved from the Trello API representing
a Comment. | [
"Update",
"the",
"attributes",
"of",
"a",
"Comment"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/comment.rb#L29-L35 | train |
jeremytregunna/ruby-trello | lib/trello/attachment.rb | Trello.Attachment.update_fields | def update_fields(fields)
attributes[:name] = fields['name'] || attributes[:name]
attributes[:id] = fields['id'] || attributes[:id]
attributes[:pos] = fields['pos'] || attributes[:pos]
attributes[:url] = fields['url'] || attributes[:url]
attributes[:bytes] = fie... | ruby | def update_fields(fields)
attributes[:name] = fields['name'] || attributes[:name]
attributes[:id] = fields['id'] || attributes[:id]
attributes[:pos] = fields['pos'] || attributes[:pos]
attributes[:url] = fields['url'] || attributes[:url]
attributes[:bytes] = fie... | [
"def",
"update_fields",
"(",
"fields",
")",
"attributes",
"[",
":name",
"]",
"=",
"fields",
"[",
"'name'",
"]",
"||",
"attributes",
"[",
":name",
"]",
"attributes",
"[",
":id",
"]",
"=",
"fields",
"[",
"'id'",
"]",
"||",
"attributes",
"[",
":id",
"]",
... | Update the fields of an attachment.
Supply a hash of stringkeyed data retrieved from the Trello API representing
an attachment. | [
"Update",
"the",
"fields",
"of",
"an",
"attachment",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/attachment.rb#L26-L38 | train |
jeremytregunna/ruby-trello | lib/trello/custom_field_item.rb | Trello.CustomFieldItem.option_value | def option_value
if option_id
option_endpoint = "/customFields/#{custom_field_id}/options/#{option_id}"
option = CustomFieldOption.from_response client.get(option_endpoint)
option.value
end
end | ruby | def option_value
if option_id
option_endpoint = "/customFields/#{custom_field_id}/options/#{option_id}"
option = CustomFieldOption.from_response client.get(option_endpoint)
option.value
end
end | [
"def",
"option_value",
"if",
"option_id",
"option_endpoint",
"=",
"\"/customFields/#{custom_field_id}/options/#{option_id}\"",
"option",
"=",
"CustomFieldOption",
".",
"from_response",
"client",
".",
"get",
"(",
"option_endpoint",
")",
"option",
".",
"value",
"end",
"end"... | Need to make another call to get the actual value if the custom field type == 'list' | [
"Need",
"to",
"make",
"another",
"call",
"to",
"get",
"the",
"actual",
"value",
"if",
"the",
"custom",
"field",
"type",
"==",
"list"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/custom_field_item.rb#L69-L75 | train |
jeremytregunna/ruby-trello | lib/trello/checklist.rb | Trello.Checklist.update_fields | def update_fields(fields)
attributes[:id] = fields['id'] || attributes[:id]
attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
attributes[:description] = fields['desc'] || attributes[:description]
attributes[:closed] = fields['closed'] if fields.has_key?('closed')
att... | ruby | def update_fields(fields)
attributes[:id] = fields['id'] || attributes[:id]
attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
attributes[:description] = fields['desc'] || attributes[:description]
attributes[:closed] = fields['closed'] if fields.has_key?('closed')
att... | [
"def",
"update_fields",
"(",
"fields",
")",
"attributes",
"[",
":id",
"]",
"=",
"fields",
"[",
"'id'",
"]",
"||",
"attributes",
"[",
":id",
"]",
"attributes",
"[",
":name",
"]",
"=",
"fields",
"[",
"'name'",
"]",
"||",
"fields",
"[",
":name",
"]",
"|... | Update the fields of a checklist.
Supply a hash of string keyed data retrieved from the Trello API representing
a checklist. | [
"Update",
"the",
"fields",
"of",
"a",
"checklist",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/checklist.rb#L47-L60 | train |
jeremytregunna/ruby-trello | lib/trello/checklist.rb | Trello.Checklist.save | def save
return update! if id
from_response(client.post("/checklists", {
name: name,
idCard: card_id
}))
end | ruby | def save
return update! if id
from_response(client.post("/checklists", {
name: name,
idCard: card_id
}))
end | [
"def",
"save",
"return",
"update!",
"if",
"id",
"from_response",
"(",
"client",
".",
"post",
"(",
"\"/checklists\"",
",",
"{",
"name",
":",
"name",
",",
"idCard",
":",
"card_id",
"}",
")",
")",
"end"
] | Save a record. | [
"Save",
"a",
"record",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/checklist.rb#L68-L75 | train |
jeremytregunna/ruby-trello | lib/trello/checklist.rb | Trello.Checklist.members | def members
members = member_ids.map do |member_id|
Member.find(member_id)
end
MultiAssociation.new(self, members).proxy
end | ruby | def members
members = member_ids.map do |member_id|
Member.find(member_id)
end
MultiAssociation.new(self, members).proxy
end | [
"def",
"members",
"members",
"=",
"member_ids",
".",
"map",
"do",
"|",
"member_id",
"|",
"Member",
".",
"find",
"(",
"member_id",
")",
"end",
"MultiAssociation",
".",
"new",
"(",
"self",
",",
"members",
")",
".",
"proxy",
"end"
] | Return a list of members active in this checklist. | [
"Return",
"a",
"list",
"of",
"members",
"active",
"in",
"this",
"checklist",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/checklist.rb#L98-L103 | train |
jeremytregunna/ruby-trello | lib/trello/checklist.rb | Trello.Checklist.add_item | def add_item(name, checked = false, position = 'bottom')
client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
end | ruby | def add_item(name, checked = false, position = 'bottom')
client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
end | [
"def",
"add_item",
"(",
"name",
",",
"checked",
"=",
"false",
",",
"position",
"=",
"'bottom'",
")",
"client",
".",
"post",
"(",
"\"/checklists/#{id}/checkItems\"",
",",
"{",
"name",
":",
"name",
",",
"checked",
":",
"checked",
",",
"pos",
":",
"position",... | Add an item to the checklist | [
"Add",
"an",
"item",
"to",
"the",
"checklist"
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/checklist.rb#L106-L108 | train |
jeremytregunna/ruby-trello | lib/trello/has_actions.rb | Trello.HasActions.actions | def actions(options = {})
actions = Action.from_response client.get("#{request_prefix}/actions", { filter: :all }.merge(options))
MultiAssociation.new(self, actions).proxy
end | ruby | def actions(options = {})
actions = Action.from_response client.get("#{request_prefix}/actions", { filter: :all }.merge(options))
MultiAssociation.new(self, actions).proxy
end | [
"def",
"actions",
"(",
"options",
"=",
"{",
"}",
")",
"actions",
"=",
"Action",
".",
"from_response",
"client",
".",
"get",
"(",
"\"#{request_prefix}/actions\"",
",",
"{",
"filter",
":",
":all",
"}",
".",
"merge",
"(",
"options",
")",
")",
"MultiAssociatio... | Returns a list of the actions associated with this object. | [
"Returns",
"a",
"list",
"of",
"the",
"actions",
"associated",
"with",
"this",
"object",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/has_actions.rb#L4-L7 | train |
jeremytregunna/ruby-trello | lib/trello/item_state.rb | Trello.CheckItemState.update_fields | def update_fields(fields)
attributes[:id] = fields['id'] || attributes[:id]
attributes[:state] = fields['state'] || attributes[:state]
attributes[:item_id] = fields['idCheckItem'] || attributes[:item_id]
self
end | ruby | def update_fields(fields)
attributes[:id] = fields['id'] || attributes[:id]
attributes[:state] = fields['state'] || attributes[:state]
attributes[:item_id] = fields['idCheckItem'] || attributes[:item_id]
self
end | [
"def",
"update_fields",
"(",
"fields",
")",
"attributes",
"[",
":id",
"]",
"=",
"fields",
"[",
"'id'",
"]",
"||",
"attributes",
"[",
":id",
"]",
"attributes",
"[",
":state",
"]",
"=",
"fields",
"[",
"'state'",
"]",
"||",
"attributes",
"[",
":state",
"]... | Update the fields of an item state.
Supply a hash of string keyed data retrieved from the Trello API representing
an item state. | [
"Update",
"the",
"fields",
"of",
"an",
"item",
"state",
"."
] | ad79c9d8152ad5395b3b61c43170908f1912bfb2 | https://github.com/jeremytregunna/ruby-trello/blob/ad79c9d8152ad5395b3b61c43170908f1912bfb2/lib/trello/item_state.rb#L18-L23 | train |
diasks2/pragmatic_segmenter | lib/pragmatic_segmenter/cleaner.rb | PragmaticSegmenter.Cleaner.clean | def clean
return unless text
remove_all_newlines
replace_double_newlines
replace_newlines
replace_escaped_newlines
@text.apply(HTML::All)
replace_punctuation_in_brackets
@text.apply(InlineFormattingRule)
clean_quotations
clean_table_of_contents
check_f... | ruby | def clean
return unless text
remove_all_newlines
replace_double_newlines
replace_newlines
replace_escaped_newlines
@text.apply(HTML::All)
replace_punctuation_in_brackets
@text.apply(InlineFormattingRule)
clean_quotations
clean_table_of_contents
check_f... | [
"def",
"clean",
"return",
"unless",
"text",
"remove_all_newlines",
"replace_double_newlines",
"replace_newlines",
"replace_escaped_newlines",
"@text",
".",
"apply",
"(",
"HTML",
"::",
"All",
")",
"replace_punctuation_in_brackets",
"@text",
".",
"apply",
"(",
"InlineFormat... | Clean text of unwanted formatting
Example:
>> text = "This is a sentence\ncut off in the middle because pdf."
>> PragmaticSegmenter::Cleaner(text: text).clean
=> "This is a sentence cut off in the middle because pdf."
Arguments:
text: (String) *required
language: (String) *optional
... | [
"Clean",
"text",
"of",
"unwanted",
"formatting"
] | bb59de8e46e18d2e0bfee074b7d4cacda9612df2 | https://github.com/diasks2/pragmatic_segmenter/blob/bb59de8e46e18d2e0bfee074b7d4cacda9612df2/lib/pragmatic_segmenter/cleaner.rb#L33-L48 | train |
SamSaffron/message_bus | lib/message_bus/http_client.rb | MessageBus.HTTPClient.subscribe | def subscribe(channel, last_message_id: nil, &callback)
raise InvalidChannel unless channel.to_s.start_with?("/")
raise MissingBlock unless block_given?
last_message_id = -1 if last_message_id && !last_message_id.is_a?(Integer)
@channels[channel] ||= Channel.new
channel = @channels[chann... | ruby | def subscribe(channel, last_message_id: nil, &callback)
raise InvalidChannel unless channel.to_s.start_with?("/")
raise MissingBlock unless block_given?
last_message_id = -1 if last_message_id && !last_message_id.is_a?(Integer)
@channels[channel] ||= Channel.new
channel = @channels[chann... | [
"def",
"subscribe",
"(",
"channel",
",",
"last_message_id",
":",
"nil",
",",
"&",
"callback",
")",
"raise",
"InvalidChannel",
"unless",
"channel",
".",
"to_s",
".",
"start_with?",
"(",
"\"/\"",
")",
"raise",
"MissingBlock",
"unless",
"block_given?",
"last_messag... | Subscribes to a channel which executes the given callback when a message
is published to the channel
@example Subscribing to a channel for message
client = MessageBus::HTTPClient.new('http://some.test.com')
client.subscribe("/test") do |payload, _message_id, _global_id|
puts payload
end
A last_messa... | [
"Subscribes",
"to",
"a",
"channel",
"which",
"executes",
"the",
"given",
"callback",
"when",
"a",
"message",
"is",
"published",
"to",
"the",
"channel"
] | 90fba639eb5d332ca8e87fd35f1d603a5743076d | https://github.com/SamSaffron/message_bus/blob/90fba639eb5d332ca8e87fd35f1d603a5743076d/lib/message_bus/http_client.rb#L168-L179 | train |
SamSaffron/message_bus | lib/message_bus/http_client.rb | MessageBus.HTTPClient.unsubscribe | def unsubscribe(channel, &callback)
if callback
@channels[channel].callbacks.delete(callback)
remove_channel(channel) if @channels[channel].callbacks.empty?
else
remove_channel(channel)
end
stop if @channels.empty?
@status
end | ruby | def unsubscribe(channel, &callback)
if callback
@channels[channel].callbacks.delete(callback)
remove_channel(channel) if @channels[channel].callbacks.empty?
else
remove_channel(channel)
end
stop if @channels.empty?
@status
end | [
"def",
"unsubscribe",
"(",
"channel",
",",
"&",
"callback",
")",
"if",
"callback",
"@channels",
"[",
"channel",
"]",
".",
"callbacks",
".",
"delete",
"(",
"callback",
")",
"remove_channel",
"(",
"channel",
")",
"if",
"@channels",
"[",
"channel",
"]",
".",
... | unsubscribes from a channel
@example Unsubscribing from a channel
client = MessageBus::HTTPClient.new('http://some.test.com')
callback = -> { |payload| puts payload }
client.subscribe("/test", &callback)
client.unsubscribe("/test")
If a callback is given, only the specific callback will be unsubscribed.... | [
"unsubscribes",
"from",
"a",
"channel"
] | 90fba639eb5d332ca8e87fd35f1d603a5743076d | https://github.com/SamSaffron/message_bus/blob/90fba639eb5d332ca8e87fd35f1d603a5743076d/lib/message_bus/http_client.rb#L201-L211 | train |
anycable/anycable | lib/anycable/rpc_handler.rb | AnyCable.RPCHandler.connect | def connect(request, _unused_call)
logger.debug("RPC Connect: #{request.inspect}")
socket = build_socket(env: rack_env(request))
connection = factory.call(socket)
connection.handle_open
if socket.closed?
AnyCable::ConnectionResponse.new(status: AnyCable::Status::FAILURE)
... | ruby | def connect(request, _unused_call)
logger.debug("RPC Connect: #{request.inspect}")
socket = build_socket(env: rack_env(request))
connection = factory.call(socket)
connection.handle_open
if socket.closed?
AnyCable::ConnectionResponse.new(status: AnyCable::Status::FAILURE)
... | [
"def",
"connect",
"(",
"request",
",",
"_unused_call",
")",
"logger",
".",
"debug",
"(",
"\"RPC Connect: #{request.inspect}\"",
")",
"socket",
"=",
"build_socket",
"(",
"env",
":",
"rack_env",
"(",
"request",
")",
")",
"connection",
"=",
"factory",
".",
"call"... | Handle connection request from WebSocket server | [
"Handle",
"connection",
"request",
"from",
"WebSocket",
"server"
] | d7515e8e034d42e86ebeb09786a92aad2a11b25f | https://github.com/anycable/anycable/blob/d7515e8e034d42e86ebeb09786a92aad2a11b25f/lib/anycable/rpc_handler.rb#L14-L39 | train |
anycable/anycable | lib/anycable/rpc_handler.rb | AnyCable.RPCHandler.rack_env | def rack_env(request)
uri = URI.parse(request.path)
# Minimum required variables according to Rack Spec
env = {
"REQUEST_METHOD" => "GET",
"SCRIPT_NAME" => "",
"PATH_INFO" => uri.path,
"QUERY_STRING" => uri.query,
"SERVER_NAME" => uri.host,
"SERVER_PORT... | ruby | def rack_env(request)
uri = URI.parse(request.path)
# Minimum required variables according to Rack Spec
env = {
"REQUEST_METHOD" => "GET",
"SCRIPT_NAME" => "",
"PATH_INFO" => uri.path,
"QUERY_STRING" => uri.query,
"SERVER_NAME" => uri.host,
"SERVER_PORT... | [
"def",
"rack_env",
"(",
"request",
")",
"uri",
"=",
"URI",
".",
"parse",
"(",
"request",
".",
"path",
")",
"# Minimum required variables according to Rack Spec",
"env",
"=",
"{",
"\"REQUEST_METHOD\"",
"=>",
"\"GET\"",
",",
"\"SCRIPT_NAME\"",
"=>",
"\"\"",
",",
"... | Build Rack env from request | [
"Build",
"Rack",
"env",
"from",
"request"
] | d7515e8e034d42e86ebeb09786a92aad2a11b25f | https://github.com/anycable/anycable/blob/d7515e8e034d42e86ebeb09786a92aad2a11b25f/lib/anycable/rpc_handler.rb#L101-L119 | train |
anycable/anycable | lib/anycable/config.rb | AnyCable.Config.to_grpc_params | def to_grpc_params
{
pool_size: rpc_pool_size,
max_waiting_requests: rpc_max_waiting_requests,
poll_period: rpc_poll_period,
pool_keep_alive: rpc_pool_keep_alive,
server_args: rpc_server_args
}
end | ruby | def to_grpc_params
{
pool_size: rpc_pool_size,
max_waiting_requests: rpc_max_waiting_requests,
poll_period: rpc_poll_period,
pool_keep_alive: rpc_pool_keep_alive,
server_args: rpc_server_args
}
end | [
"def",
"to_grpc_params",
"{",
"pool_size",
":",
"rpc_pool_size",
",",
"max_waiting_requests",
":",
"rpc_max_waiting_requests",
",",
"poll_period",
":",
"rpc_poll_period",
",",
"pool_keep_alive",
":",
"rpc_pool_keep_alive",
",",
"server_args",
":",
"rpc_server_args",
"}",
... | Build gRPC server parameters | [
"Build",
"gRPC",
"server",
"parameters"
] | d7515e8e034d42e86ebeb09786a92aad2a11b25f | https://github.com/anycable/anycable/blob/d7515e8e034d42e86ebeb09786a92aad2a11b25f/lib/anycable/config.rb#L62-L70 | train |
anycable/anycable | lib/anycable/config.rb | AnyCable.Config.to_redis_params | def to_redis_params
{ url: redis_url }.tap do |params|
next if redis_sentinels.nil?
raise ArgumentError, "redis_sentinels must be an array; got #{redis_sentinels}" unless
redis_sentinels.is_a?(Array)
next if redis_sentinels.empty?
params[:sentinels] = redis_sentinels.m... | ruby | def to_redis_params
{ url: redis_url }.tap do |params|
next if redis_sentinels.nil?
raise ArgumentError, "redis_sentinels must be an array; got #{redis_sentinels}" unless
redis_sentinels.is_a?(Array)
next if redis_sentinels.empty?
params[:sentinels] = redis_sentinels.m... | [
"def",
"to_redis_params",
"{",
"url",
":",
"redis_url",
"}",
".",
"tap",
"do",
"|",
"params",
"|",
"next",
"if",
"redis_sentinels",
".",
"nil?",
"raise",
"ArgumentError",
",",
"\"redis_sentinels must be an array; got #{redis_sentinels}\"",
"unless",
"redis_sentinels",
... | Build Redis parameters | [
"Build",
"Redis",
"parameters"
] | d7515e8e034d42e86ebeb09786a92aad2a11b25f | https://github.com/anycable/anycable/blob/d7515e8e034d42e86ebeb09786a92aad2a11b25f/lib/anycable/config.rb#L73-L84 | train |
anycable/anycable | lib/anycable/server.rb | AnyCable.Server.start | def start
return if running?
raise "Cannot re-start stopped server" if stopped?
check_default_host
logger.info "RPC server is starting..."
@start_thread = Thread.new { grpc_server.run }
grpc_server.wait_till_running
logger.info "RPC server is listening on #{host}"
end | ruby | def start
return if running?
raise "Cannot re-start stopped server" if stopped?
check_default_host
logger.info "RPC server is starting..."
@start_thread = Thread.new { grpc_server.run }
grpc_server.wait_till_running
logger.info "RPC server is listening on #{host}"
end | [
"def",
"start",
"return",
"if",
"running?",
"raise",
"\"Cannot re-start stopped server\"",
"if",
"stopped?",
"check_default_host",
"logger",
".",
"info",
"\"RPC server is starting...\"",
"@start_thread",
"=",
"Thread",
".",
"new",
"{",
"grpc_server",
".",
"run",
"}",
... | Start gRPC server in background and
wait untill it ready to accept connections | [
"Start",
"gRPC",
"server",
"in",
"background",
"and",
"wait",
"untill",
"it",
"ready",
"to",
"accept",
"connections"
] | d7515e8e034d42e86ebeb09786a92aad2a11b25f | https://github.com/anycable/anycable/blob/d7515e8e034d42e86ebeb09786a92aad2a11b25f/lib/anycable/server.rb#L76-L90 | train |
toshimaru/jekyll-toc | lib/jekyll-toc.rb | Jekyll.TableOfContentsFilter.toc_only | def toc_only(html)
Jekyll.logger.warn 'Deprecation: toc_only filter is deprecated and will be remove in jekyll-toc v1.0.',
'Use `{% toc %}` instead of `{{ content | toc_only }}`.'
return '' unless toc_enabled?
TableOfContents::Parser.new(html, toc_config).build_toc
end | ruby | def toc_only(html)
Jekyll.logger.warn 'Deprecation: toc_only filter is deprecated and will be remove in jekyll-toc v1.0.',
'Use `{% toc %}` instead of `{{ content | toc_only }}`.'
return '' unless toc_enabled?
TableOfContents::Parser.new(html, toc_config).build_toc
end | [
"def",
"toc_only",
"(",
"html",
")",
"Jekyll",
".",
"logger",
".",
"warn",
"'Deprecation: toc_only filter is deprecated and will be remove in jekyll-toc v1.0.'",
",",
"'Use `{% toc %}` instead of `{{ content | toc_only }}`.'",
"return",
"''",
"unless",
"toc_enabled?",
"TableOfConte... | Deprecated method. Removed in v1.0. | [
"Deprecated",
"method",
".",
"Removed",
"in",
"v1",
".",
"0",
"."
] | c36830f0b3d7ddf73793e34f8d498303064c1cef | https://github.com/toshimaru/jekyll-toc/blob/c36830f0b3d7ddf73793e34f8d498303064c1cef/lib/jekyll-toc.rb#L22-L28 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/utils.rb | PhusionPassenger.Utils.generate_random_id | def generate_random_id(method)
data = File.open("/dev/urandom", "rb") do |f|
f.read(64)
end
case method
when :base64
data = base64(data)
data.gsub!("+", '')
data.gsub!("/", '')
data.gsub!(/==$/, '')
return data
when :hex
return data.u... | ruby | def generate_random_id(method)
data = File.open("/dev/urandom", "rb") do |f|
f.read(64)
end
case method
when :base64
data = base64(data)
data.gsub!("+", '')
data.gsub!("/", '')
data.gsub!(/==$/, '')
return data
when :hex
return data.u... | [
"def",
"generate_random_id",
"(",
"method",
")",
"data",
"=",
"File",
".",
"open",
"(",
"\"/dev/urandom\"",
",",
"\"rb\"",
")",
"do",
"|",
"f",
"|",
"f",
".",
"read",
"(",
"64",
")",
"end",
"case",
"method",
"when",
":base64",
"data",
"=",
"base64",
... | Generate a long, cryptographically secure random ID string, which
is also a valid filename. | [
"Generate",
"a",
"long",
"cryptographically",
"secure",
"random",
"ID",
"string",
"which",
"is",
"also",
"a",
"valid",
"filename",
"."
] | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/utils.rb#L44-L60 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/utils.rb | PhusionPassenger.Utils.print_exception | def print_exception(current_location, exception, destination = nil)
if !exception.is_a?(SystemExit)
data = exception.backtrace_string(current_location)
if defined?(DebugLogging) && self.is_a?(DebugLogging)
error(data)
else
destination ||= STDERR
destination.pu... | ruby | def print_exception(current_location, exception, destination = nil)
if !exception.is_a?(SystemExit)
data = exception.backtrace_string(current_location)
if defined?(DebugLogging) && self.is_a?(DebugLogging)
error(data)
else
destination ||= STDERR
destination.pu... | [
"def",
"print_exception",
"(",
"current_location",
",",
"exception",
",",
"destination",
"=",
"nil",
")",
"if",
"!",
"exception",
".",
"is_a?",
"(",
"SystemExit",
")",
"data",
"=",
"exception",
".",
"backtrace_string",
"(",
"current_location",
")",
"if",
"defi... | Print the given exception, including the stack trace, to STDERR.
+current_location+ is a string which describes where the code is
currently at. Usually the current class name will be enough.
It may be nil.
This method requires 'ruby_core_enhancements'. If 'debug_logging'
is loaded and included in the current mod... | [
"Print",
"the",
"given",
"exception",
"including",
"the",
"stack",
"trace",
"to",
"STDERR",
"."
] | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/utils.rb#L83-L94 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/utils.rb | PhusionPassenger.Utils.create_thread_and_abort_on_exception | def create_thread_and_abort_on_exception(*args)
Thread.new do
Thread.current.abort_on_exception = true
begin
yield(*args)
rescue SystemExit
raise
rescue Exception => e
print_exception(nil, e)
exit(1)
end
end
end | ruby | def create_thread_and_abort_on_exception(*args)
Thread.new do
Thread.current.abort_on_exception = true
begin
yield(*args)
rescue SystemExit
raise
rescue Exception => e
print_exception(nil, e)
exit(1)
end
end
end | [
"def",
"create_thread_and_abort_on_exception",
"(",
"*",
"args",
")",
"Thread",
".",
"new",
"do",
"Thread",
".",
"current",
".",
"abort_on_exception",
"=",
"true",
"begin",
"yield",
"(",
"args",
")",
"rescue",
"SystemExit",
"raise",
"rescue",
"Exception",
"=>",
... | A wrapper around Thread.new that installs a default exception handler.
If an uncaught exception is encountered, it will immediately log the
exception and abort the entire program.
Thread#abort_on_exception is also supposed to do that, but the problem
is that it is implemented by forwarding the uncaught exception
... | [
"A",
"wrapper",
"around",
"Thread",
".",
"new",
"that",
"installs",
"a",
"default",
"exception",
"handler",
".",
"If",
"an",
"uncaught",
"exception",
"is",
"encountered",
"it",
"will",
"immediately",
"log",
"the",
"exception",
"and",
"abort",
"the",
"entire",
... | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/utils.rb#L109-L121 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/utils.rb | PhusionPassenger.Utils.process_is_alive? | def process_is_alive?(pid)
begin
Process.kill(0, pid)
return true
rescue Errno::ESRCH
return false
rescue SystemCallError => e
return true
end
end | ruby | def process_is_alive?(pid)
begin
Process.kill(0, pid)
return true
rescue Errno::ESRCH
return false
rescue SystemCallError => e
return true
end
end | [
"def",
"process_is_alive?",
"(",
"pid",
")",
"begin",
"Process",
".",
"kill",
"(",
"0",
",",
"pid",
")",
"return",
"true",
"rescue",
"Errno",
"::",
"ESRCH",
"return",
"false",
"rescue",
"SystemCallError",
"=>",
"e",
"return",
"true",
"end",
"end"
] | Checks whether the given process exists. | [
"Checks",
"whether",
"the",
"given",
"process",
"exists",
"."
] | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/utils.rb#L159-L168 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/utils.rb | PhusionPassenger.Utils.global_backtrace_report | def global_backtrace_report
if Kernel.respond_to?(:caller_for_all_threads)
all_thread_stacks = caller_for_all_threads
elsif Thread.respond_to?(:list) && Thread.public_method_defined?(:backtrace)
all_thread_stacks = {}
Thread.list.each do |thread|
all_thread_stacks[thread] =... | ruby | def global_backtrace_report
if Kernel.respond_to?(:caller_for_all_threads)
all_thread_stacks = caller_for_all_threads
elsif Thread.respond_to?(:list) && Thread.public_method_defined?(:backtrace)
all_thread_stacks = {}
Thread.list.each do |thread|
all_thread_stacks[thread] =... | [
"def",
"global_backtrace_report",
"if",
"Kernel",
".",
"respond_to?",
"(",
":caller_for_all_threads",
")",
"all_thread_stacks",
"=",
"caller_for_all_threads",
"elsif",
"Thread",
".",
"respond_to?",
"(",
":list",
")",
"&&",
"Thread",
".",
"public_method_defined?",
"(",
... | Returns a string which reports the backtraces for all threads,
or if that's not supported the backtrace for the current thread. | [
"Returns",
"a",
"string",
"which",
"reports",
"the",
"backtraces",
"for",
"all",
"threads",
"or",
"if",
"that",
"s",
"not",
"supported",
"the",
"backtrace",
"for",
"the",
"current",
"thread",
"."
] | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/utils.rb#L201-L238 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/native_support.rb | PhusionPassenger.NativeSupportLoader.current_user_name_or_id | def current_user_name_or_id
require 'etc' if !defined?(Etc)
begin
user = Etc.getpwuid(Process.uid)
rescue ArgumentError
user = nil
end
if user
return user.name
else
return "##{Process.uid}"
end
end | ruby | def current_user_name_or_id
require 'etc' if !defined?(Etc)
begin
user = Etc.getpwuid(Process.uid)
rescue ArgumentError
user = nil
end
if user
return user.name
else
return "##{Process.uid}"
end
end | [
"def",
"current_user_name_or_id",
"require",
"'etc'",
"if",
"!",
"defined?",
"(",
"Etc",
")",
"begin",
"user",
"=",
"Etc",
".",
"getpwuid",
"(",
"Process",
".",
"uid",
")",
"rescue",
"ArgumentError",
"user",
"=",
"nil",
"end",
"if",
"user",
"return",
"user... | Name of the user under which we are executing, or the id as fallback
N.B. loader_shared_helpers.rb has the same method | [
"Name",
"of",
"the",
"user",
"under",
"which",
"we",
"are",
"executing",
"or",
"the",
"id",
"as",
"fallback",
"N",
".",
"B",
".",
"loader_shared_helpers",
".",
"rb",
"has",
"the",
"same",
"method"
] | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/native_support.rb#L229-L241 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb | PhusionPassenger.LoaderSharedHelpers.maybe_make_path_relative_to_app_root | def maybe_make_path_relative_to_app_root(app_root, abs_path)
if Dir.logical_pwd == app_root && File.dirname(abs_path) == app_root
File.basename(abs_path)
else
abs_path
end
end | ruby | def maybe_make_path_relative_to_app_root(app_root, abs_path)
if Dir.logical_pwd == app_root && File.dirname(abs_path) == app_root
File.basename(abs_path)
else
abs_path
end
end | [
"def",
"maybe_make_path_relative_to_app_root",
"(",
"app_root",
",",
"abs_path",
")",
"if",
"Dir",
".",
"logical_pwd",
"==",
"app_root",
"&&",
"File",
".",
"dirname",
"(",
"abs_path",
")",
"==",
"app_root",
"File",
".",
"basename",
"(",
"abs_path",
")",
"else"... | If the current working directory equals `app_root`, and `abs_path` is a
file inside `app_root`, then returns its basename. Otherwise, returns
`abs_path`.
The main use case for this method is to ensure that we load config.ru
with a relative path (only its base name) in most circumstances,
instead of with an absolu... | [
"If",
"the",
"current",
"working",
"directory",
"equals",
"app_root",
"and",
"abs_path",
"is",
"a",
"file",
"inside",
"app_root",
"then",
"returns",
"its",
"basename",
".",
"Otherwise",
"returns",
"abs_path",
"."
] | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb#L251-L257 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb | PhusionPassenger.LoaderSharedHelpers.before_handling_requests | def before_handling_requests(forked, options)
if forked
# Reseed pseudo-random number generator for security reasons.
srand
end
if options["process_title"] && !options["process_title"].empty?
$0 = options["process_title"] + ": " + options["app_group_name"]
end
# I... | ruby | def before_handling_requests(forked, options)
if forked
# Reseed pseudo-random number generator for security reasons.
srand
end
if options["process_title"] && !options["process_title"].empty?
$0 = options["process_title"] + ": " + options["app_group_name"]
end
# I... | [
"def",
"before_handling_requests",
"(",
"forked",
",",
"options",
")",
"if",
"forked",
"# Reseed pseudo-random number generator for security reasons.",
"srand",
"end",
"if",
"options",
"[",
"\"process_title\"",
"]",
"&&",
"!",
"options",
"[",
"\"process_title\"",
"]",
"... | To be called before the request handler main loop is entered, but after the app
startup file has been loaded. This function will fire off necessary events
and perform necessary preparation tasks.
+forked+ indicates whether the current worker process is forked off from
an ApplicationSpawner that has preloaded the a... | [
"To",
"be",
"called",
"before",
"the",
"request",
"handler",
"main",
"loop",
"is",
"entered",
"but",
"after",
"the",
"app",
"startup",
"file",
"has",
"been",
"loaded",
".",
"This",
"function",
"will",
"fire",
"off",
"necessary",
"events",
"and",
"perform",
... | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb#L300-L334 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/message_channel.rb | PhusionPassenger.MessageChannel.read_hash | def read_hash
buffer = new_buffer
if !@io.read(HEADER_SIZE, buffer)
return nil
end
while buffer.size < HEADER_SIZE
tmp = @io.read(HEADER_SIZE - buffer.size)
if tmp.empty?
return nil
else
buffer << tmp
end
end
chunk_size = b... | ruby | def read_hash
buffer = new_buffer
if !@io.read(HEADER_SIZE, buffer)
return nil
end
while buffer.size < HEADER_SIZE
tmp = @io.read(HEADER_SIZE - buffer.size)
if tmp.empty?
return nil
else
buffer << tmp
end
end
chunk_size = b... | [
"def",
"read_hash",
"buffer",
"=",
"new_buffer",
"if",
"!",
"@io",
".",
"read",
"(",
"HEADER_SIZE",
",",
"buffer",
")",
"return",
"nil",
"end",
"while",
"buffer",
".",
"size",
"<",
"HEADER_SIZE",
"tmp",
"=",
"@io",
".",
"read",
"(",
"HEADER_SIZE",
"-",
... | Read an array message from the underlying file descriptor and return the
result as a hash instead of an array. This assumes that the array message
has an even number of elements.
Returns nil when end-of-stream has been reached.
Might raise SystemCallError, IOError or SocketError when something
goes wrong. | [
"Read",
"an",
"array",
"message",
"from",
"the",
"underlying",
"file",
"descriptor",
"and",
"return",
"the",
"result",
"as",
"a",
"hash",
"instead",
"of",
"an",
"array",
".",
"This",
"assumes",
"that",
"the",
"array",
"message",
"has",
"an",
"even",
"numbe... | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/message_channel.rb#L108-L162 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/message_channel.rb | PhusionPassenger.MessageChannel.read_scalar | def read_scalar(buffer = new_buffer, max_size = nil)
if !@io.read(4, buffer)
return nil
end
while buffer.size < 4
tmp = @io.read(4 - buffer.size)
if tmp.empty?
return nil
else
buffer << tmp
end
end
size = buffer.unpack(UINT32_PAC... | ruby | def read_scalar(buffer = new_buffer, max_size = nil)
if !@io.read(4, buffer)
return nil
end
while buffer.size < 4
tmp = @io.read(4 - buffer.size)
if tmp.empty?
return nil
else
buffer << tmp
end
end
size = buffer.unpack(UINT32_PAC... | [
"def",
"read_scalar",
"(",
"buffer",
"=",
"new_buffer",
",",
"max_size",
"=",
"nil",
")",
"if",
"!",
"@io",
".",
"read",
"(",
"4",
",",
"buffer",
")",
"return",
"nil",
"end",
"while",
"buffer",
".",
"size",
"<",
"4",
"tmp",
"=",
"@io",
".",
"read",... | Read a scalar message from the underlying IO object. Returns the
read message, or nil on end-of-stream.
Might raise SystemCallError, IOError or SocketError when something
goes wrong.
The +buffer+ argument specifies a buffer in which #read_scalar
stores the read data. It is good practice to reuse existing buffers... | [
"Read",
"a",
"scalar",
"message",
"from",
"the",
"underlying",
"IO",
"object",
".",
"Returns",
"the",
"read",
"message",
"or",
"nil",
"on",
"end",
"-",
"of",
"-",
"stream",
"."
] | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/message_channel.rb#L177-L216 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/request_handler.rb | PhusionPassenger.RequestHandler.cleanup | def cleanup
if @main_loop_thread
@main_loop_thread_lock.synchronize do
@graceful_termination_pipe[1].close rescue nil
end
@main_loop_thread.join
end
@server_sockets.each_value do |info|
socket = info[:socket]
type = get_socket_address_type(info[:addres... | ruby | def cleanup
if @main_loop_thread
@main_loop_thread_lock.synchronize do
@graceful_termination_pipe[1].close rescue nil
end
@main_loop_thread.join
end
@server_sockets.each_value do |info|
socket = info[:socket]
type = get_socket_address_type(info[:addres... | [
"def",
"cleanup",
"if",
"@main_loop_thread",
"@main_loop_thread_lock",
".",
"synchronize",
"do",
"@graceful_termination_pipe",
"[",
"1",
"]",
".",
"close",
"rescue",
"nil",
"end",
"@main_loop_thread",
".",
"join",
"end",
"@server_sockets",
".",
"each_value",
"do",
"... | Create a new RequestHandler with the given owner pipe.
+owner_pipe+ must be the readable part of a pipe IO object.
Additionally, the following options may be given:
- connect_password
Clean up temporary stuff created by the request handler.
If the main loop was started by #main_loop, then this method may only
b... | [
"Create",
"a",
"new",
"RequestHandler",
"with",
"the",
"given",
"owner",
"pipe",
".",
"+",
"owner_pipe",
"+",
"must",
"be",
"the",
"readable",
"part",
"of",
"a",
"pipe",
"IO",
"object",
"."
] | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/request_handler.rb#L140-L166 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/request_handler.rb | PhusionPassenger.RequestHandler.main_loop | def main_loop
debug("Entering request handler main loop")
reset_signal_handlers
begin
@graceful_termination_pipe = IO.pipe
@graceful_termination_pipe[0].close_on_exec!
@graceful_termination_pipe[1].close_on_exec!
@main_loop_thread_lock.synchronize do
@main_lo... | ruby | def main_loop
debug("Entering request handler main loop")
reset_signal_handlers
begin
@graceful_termination_pipe = IO.pipe
@graceful_termination_pipe[0].close_on_exec!
@graceful_termination_pipe[1].close_on_exec!
@main_loop_thread_lock.synchronize do
@main_lo... | [
"def",
"main_loop",
"debug",
"(",
"\"Entering request handler main loop\"",
")",
"reset_signal_handlers",
"begin",
"@graceful_termination_pipe",
"=",
"IO",
".",
"pipe",
"@graceful_termination_pipe",
"[",
"0",
"]",
".",
"close_on_exec!",
"@graceful_termination_pipe",
"[",
"1... | Enter the request handler's main loop. | [
"Enter",
"the",
"request",
"handler",
"s",
"main",
"loop",
"."
] | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/request_handler.rb#L176-L233 | train |
phusion/passenger | src/ruby_supportlib/phusion_passenger/request_handler.rb | PhusionPassenger.RequestHandler.reset_signal_handlers | def reset_signal_handlers
Signal.list_trappable.each_key do |signal|
begin
prev_handler = trap(signal, DEFAULT)
if prev_handler != DEFAULT
@previous_signal_handlers[signal] = prev_handler
end
rescue ArgumentError
# Signal cannot be trapped; ignor... | ruby | def reset_signal_handlers
Signal.list_trappable.each_key do |signal|
begin
prev_handler = trap(signal, DEFAULT)
if prev_handler != DEFAULT
@previous_signal_handlers[signal] = prev_handler
end
rescue ArgumentError
# Signal cannot be trapped; ignor... | [
"def",
"reset_signal_handlers",
"Signal",
".",
"list_trappable",
".",
"each_key",
"do",
"|",
"signal",
"|",
"begin",
"prev_handler",
"=",
"trap",
"(",
"signal",
",",
"DEFAULT",
")",
"if",
"prev_handler",
"!=",
"DEFAULT",
"@previous_signal_handlers",
"[",
"signal",... | Reset signal handlers to their default handler, and install some
special handlers for a few signals. The previous signal handlers
will be put back by calling revert_signal_handlers. | [
"Reset",
"signal",
"handlers",
"to",
"their",
"default",
"handler",
"and",
"install",
"some",
"special",
"handlers",
"for",
"a",
"few",
"signals",
".",
"The",
"previous",
"signal",
"handlers",
"will",
"be",
"put",
"back",
"by",
"calling",
"revert_signal_handlers... | 970964b53e0ba86959acdf40f06c99b0c4a128ca | https://github.com/phusion/passenger/blob/970964b53e0ba86959acdf40f06c99b0c4a128ca/src/ruby_supportlib/phusion_passenger/request_handler.rb#L328-L341 | train |
AaronLasseigne/active_interaction | lib/active_interaction/filter.rb | ActiveInteraction.Filter.default | def default(context = nil)
raise NoDefaultError, name unless default?
value = raw_default(context)
raise InvalidValueError if value.is_a?(GroupedInput)
cast(value, context)
rescue InvalidNestedValueError => error
raise InvalidDefaultError, "#{name}: #{value.inspect} (#{error})"
r... | ruby | def default(context = nil)
raise NoDefaultError, name unless default?
value = raw_default(context)
raise InvalidValueError if value.is_a?(GroupedInput)
cast(value, context)
rescue InvalidNestedValueError => error
raise InvalidDefaultError, "#{name}: #{value.inspect} (#{error})"
r... | [
"def",
"default",
"(",
"context",
"=",
"nil",
")",
"raise",
"NoDefaultError",
",",
"name",
"unless",
"default?",
"value",
"=",
"raw_default",
"(",
"context",
")",
"raise",
"InvalidValueError",
"if",
"value",
".",
"is_a?",
"(",
"GroupedInput",
")",
"cast",
"(... | Get the default value.
@example
ActiveInteraction::Filter.new(:example).default
# => ActiveInteraction::NoDefaultError: example
@example
ActiveInteraction::Filter.new(:example, default: nil).default
# => nil
@example
ActiveInteraction::Filter.new(:example, default: 0).default
# => ActiveInteractio... | [
"Get",
"the",
"default",
"value",
"."
] | fdc00a041e939ef48948baa2f7fd1ce2e4d66982 | https://github.com/AaronLasseigne/active_interaction/blob/fdc00a041e939ef48948baa2f7fd1ce2e4d66982/lib/active_interaction/filter.rb#L127-L138 | train |
AaronLasseigne/active_interaction | lib/active_interaction/concerns/active_recordable.rb | ActiveInteraction.ActiveRecordable.column_for_attribute | def column_for_attribute(name)
filter = self.class.filters[name]
FilterColumn.intern(filter.database_column_type) if filter
end | ruby | def column_for_attribute(name)
filter = self.class.filters[name]
FilterColumn.intern(filter.database_column_type) if filter
end | [
"def",
"column_for_attribute",
"(",
"name",
")",
"filter",
"=",
"self",
".",
"class",
".",
"filters",
"[",
"name",
"]",
"FilterColumn",
".",
"intern",
"(",
"filter",
".",
"database_column_type",
")",
"if",
"filter",
"end"
] | Returns the column object for the named filter.
@param name [Symbol] The name of a filter.
@example
class Interaction < ActiveInteraction::Base
string :email, default: nil
def execute; end
end
Interaction.new.column_for_attribute(:email)
# => #<ActiveInteraction::FilterColumn:0x007faebeb2a6c... | [
"Returns",
"the",
"column",
"object",
"for",
"the",
"named",
"filter",
"."
] | fdc00a041e939ef48948baa2f7fd1ce2e4d66982 | https://github.com/AaronLasseigne/active_interaction/blob/fdc00a041e939ef48948baa2f7fd1ce2e4d66982/lib/active_interaction/concerns/active_recordable.rb#L29-L32 | train |
gocardless/business | lib/business/calendar.rb | Business.Calendar.add_business_days | def add_business_days(date, delta)
date = roll_forward(date)
delta.times do
begin
date += day_interval_for(date)
end until business_day?(date)
end
date
end | ruby | def add_business_days(date, delta)
date = roll_forward(date)
delta.times do
begin
date += day_interval_for(date)
end until business_day?(date)
end
date
end | [
"def",
"add_business_days",
"(",
"date",
",",
"delta",
")",
"date",
"=",
"roll_forward",
"(",
"date",
")",
"delta",
".",
"times",
"do",
"begin",
"date",
"+=",
"day_interval_for",
"(",
"date",
")",
"end",
"until",
"business_day?",
"(",
"date",
")",
"end",
... | Add a number of business days to a date. If a non-business day is given,
counting will start from the next business day. So,
monday + 1 = tuesday
friday + 1 = monday
sunday + 1 = tuesday | [
"Add",
"a",
"number",
"of",
"business",
"days",
"to",
"a",
"date",
".",
"If",
"a",
"non",
"-",
"business",
"day",
"is",
"given",
"counting",
"will",
"start",
"from",
"the",
"next",
"business",
"day",
".",
"So",
"monday",
"+",
"1",
"=",
"tuesday",
"fr... | 62a2a09008095403bafa78033a8be1afe6debbf6 | https://github.com/gocardless/business/blob/62a2a09008095403bafa78033a8be1afe6debbf6/lib/business/calendar.rb#L102-L110 | train |
gocardless/business | lib/business/calendar.rb | Business.Calendar.subtract_business_days | def subtract_business_days(date, delta)
date = roll_backward(date)
delta.times do
begin
date -= day_interval_for(date)
end until business_day?(date)
end
date
end | ruby | def subtract_business_days(date, delta)
date = roll_backward(date)
delta.times do
begin
date -= day_interval_for(date)
end until business_day?(date)
end
date
end | [
"def",
"subtract_business_days",
"(",
"date",
",",
"delta",
")",
"date",
"=",
"roll_backward",
"(",
"date",
")",
"delta",
".",
"times",
"do",
"begin",
"date",
"-=",
"day_interval_for",
"(",
"date",
")",
"end",
"until",
"business_day?",
"(",
"date",
")",
"e... | Subtract a number of business days to a date. If a non-business day is
given, counting will start from the previous business day. So,
friday - 1 = thursday
monday - 1 = friday
sunday - 1 = thursday | [
"Subtract",
"a",
"number",
"of",
"business",
"days",
"to",
"a",
"date",
".",
"If",
"a",
"non",
"-",
"business",
"day",
"is",
"given",
"counting",
"will",
"start",
"from",
"the",
"previous",
"business",
"day",
".",
"So",
"friday",
"-",
"1",
"=",
"thursd... | 62a2a09008095403bafa78033a8be1afe6debbf6 | https://github.com/gocardless/business/blob/62a2a09008095403bafa78033a8be1afe6debbf6/lib/business/calendar.rb#L117-L125 | train |
gocardless/business | lib/business/calendar.rb | Business.Calendar.set_working_days | def set_working_days(working_days)
@working_days = (working_days || default_working_days).map do |day|
day.downcase.strip[0..2].tap do |normalised_day|
raise "Invalid day #{day}" unless DAY_NAMES.include?(normalised_day)
end
end
extra_working_dates_names = @extra_working_date... | ruby | def set_working_days(working_days)
@working_days = (working_days || default_working_days).map do |day|
day.downcase.strip[0..2].tap do |normalised_day|
raise "Invalid day #{day}" unless DAY_NAMES.include?(normalised_day)
end
end
extra_working_dates_names = @extra_working_date... | [
"def",
"set_working_days",
"(",
"working_days",
")",
"@working_days",
"=",
"(",
"working_days",
"||",
"default_working_days",
")",
".",
"map",
"do",
"|",
"day",
"|",
"day",
".",
"downcase",
".",
"strip",
"[",
"0",
"..",
"2",
"]",
".",
"tap",
"do",
"|",
... | Internal method for assigning working days from a calendar config. | [
"Internal",
"method",
"for",
"assigning",
"working",
"days",
"from",
"a",
"calendar",
"config",
"."
] | 62a2a09008095403bafa78033a8be1afe6debbf6 | https://github.com/gocardless/business/blob/62a2a09008095403bafa78033a8be1afe6debbf6/lib/business/calendar.rb#L167-L176 | train |
stevegraham/slanger | lib/slanger/channel.rb | Slanger.Channel.dispatch | def dispatch(message, channel)
push(Oj.dump(message, mode: :compat)) unless channel =~ /\Aslanger:/
perform_client_webhook!(message)
end | ruby | def dispatch(message, channel)
push(Oj.dump(message, mode: :compat)) unless channel =~ /\Aslanger:/
perform_client_webhook!(message)
end | [
"def",
"dispatch",
"(",
"message",
",",
"channel",
")",
"push",
"(",
"Oj",
".",
"dump",
"(",
"message",
",",
"mode",
":",
":compat",
")",
")",
"unless",
"channel",
"=~",
"/",
"\\A",
"/",
"perform_client_webhook!",
"(",
"message",
")",
"end"
] | Send an event received from Redis to the EventMachine channel
which will send it to subscribed clients. | [
"Send",
"an",
"event",
"received",
"from",
"Redis",
"to",
"the",
"EventMachine",
"channel",
"which",
"will",
"send",
"it",
"to",
"subscribed",
"clients",
"."
] | f26f80c675dc4d853bce401743779a6959981af1 | https://github.com/stevegraham/slanger/blob/f26f80c675dc4d853bce401743779a6959981af1/lib/slanger/channel.rb#L84-L88 | 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.