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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
benlund/ascii_charts | lib/ascii_charts.rb | AsciiCharts.Chart.round_value | def round_value(val)
remainder = val % self.step_size
unprecised = if (remainder * 2) >= self.step_size
(val - remainder) + self.step_size
else
val - remainder
end
if self.step_size < 1
precision = -Math.log10(... | ruby | def round_value(val)
remainder = val % self.step_size
unprecised = if (remainder * 2) >= self.step_size
(val - remainder) + self.step_size
else
val - remainder
end
if self.step_size < 1
precision = -Math.log10(... | [
"def",
"round_value",
"(",
"val",
")",
"remainder",
"=",
"val",
"%",
"self",
".",
"step_size",
"unprecised",
"=",
"if",
"(",
"remainder",
"*",
"2",
")",
">=",
"self",
".",
"step_size",
"(",
"val",
"-",
"remainder",
")",
"+",
"self",
".",
"step_size",
... | round to nearest step size, making sure we curtail precision to same order of magnitude as the step size to avoid 0.4 + 0.2 = 0.6000000000000001 | [
"round",
"to",
"nearest",
"step",
"size",
"making",
"sure",
"we",
"curtail",
"precision",
"to",
"same",
"order",
"of",
"magnitude",
"as",
"the",
"step",
"size",
"to",
"avoid",
"0",
".",
"4",
"+",
"0",
".",
"2",
"=",
"0",
".",
"6000000000000001"
] | c391b738c633910c22b96e04a36164a1fc4e1f22 | https://github.com/benlund/ascii_charts/blob/c391b738c633910c22b96e04a36164a1fc4e1f22/lib/ascii_charts.rb#L107-L120 | train |
sdalu/ruby-ble | lib/ble/characteristic.rb | BLE.Characteristic._deserialize_value | def _deserialize_value(val, raw: false)
val = val.pack('C*')
val = @desc.post_process(val) if !raw && @desc.read_processors?
val
end | ruby | def _deserialize_value(val, raw: false)
val = val.pack('C*')
val = @desc.post_process(val) if !raw && @desc.read_processors?
val
end | [
"def",
"_deserialize_value",
"(",
"val",
",",
"raw",
":",
"false",
")",
"val",
"=",
"val",
".",
"pack",
"(",
"'C*'",
")",
"val",
"=",
"@desc",
".",
"post_process",
"(",
"val",
")",
"if",
"!",
"raw",
"&&",
"@desc",
".",
"read_processors?",
"val",
"end... | Convert Arrays of bytes returned by DBus to Strings of bytes. | [
"Convert",
"Arrays",
"of",
"bytes",
"returned",
"by",
"DBus",
"to",
"Strings",
"of",
"bytes",
"."
] | 4c3b32d0ee65f787be235f1a5ee3878e6dcd995a | https://github.com/sdalu/ruby-ble/blob/4c3b32d0ee65f787be235f1a5ee3878e6dcd995a/lib/ble/characteristic.rb#L97-L101 | train |
PublicHealthEngland/ndr_ui | app/helpers/ndr_ui/css_helper.rb | NdrUi.CssHelper.css_class_options_merge | def css_class_options_merge(options, css_classes = [], &block)
options.symbolize_keys!
css_classes += options[:class].split(' ') if options.include?(:class)
yield(css_classes) if block_given?
options[:class] = css_classes.join(' ') unless css_classes.empty?
unless css_classes == css_classe... | ruby | def css_class_options_merge(options, css_classes = [], &block)
options.symbolize_keys!
css_classes += options[:class].split(' ') if options.include?(:class)
yield(css_classes) if block_given?
options[:class] = css_classes.join(' ') unless css_classes.empty?
unless css_classes == css_classe... | [
"def",
"css_class_options_merge",
"(",
"options",
",",
"css_classes",
"=",
"[",
"]",
",",
"&",
"block",
")",
"options",
".",
"symbolize_keys!",
"css_classes",
"+=",
"options",
"[",
":class",
"]",
".",
"split",
"(",
"' '",
")",
"if",
"options",
".",
"includ... | This method merges the specified css_classes into the options hash | [
"This",
"method",
"merges",
"the",
"specified",
"css_classes",
"into",
"the",
"options",
"hash"
] | 1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec | https://github.com/PublicHealthEngland/ndr_ui/blob/1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec/app/helpers/ndr_ui/css_helper.rb#L5-L15 | train |
sdalu/ruby-ble | lib/ble/adapter.rb | BLE.Adapter.filter | def filter(uuids, rssi: nil, pathloss: nil, transport: :le)
unless [:auto, :bredr, :le].include?(transport)
raise ArgumentError,
"transport must be one of :auto, :bredr, :le"
end
filter = { }
unless uuids.nil? || uuids.empty?
filter['UUI... | ruby | def filter(uuids, rssi: nil, pathloss: nil, transport: :le)
unless [:auto, :bredr, :le].include?(transport)
raise ArgumentError,
"transport must be one of :auto, :bredr, :le"
end
filter = { }
unless uuids.nil? || uuids.empty?
filter['UUI... | [
"def",
"filter",
"(",
"uuids",
",",
"rssi",
":",
"nil",
",",
"pathloss",
":",
"nil",
",",
"transport",
":",
":le",
")",
"unless",
"[",
":auto",
",",
":bredr",
",",
":le",
"]",
".",
"include?",
"(",
"transport",
")",
"raise",
"ArgumentError",
",",
"\"... | This method sets the device discovery filter for the caller.
When this method is called with +nil+ or an empty list of UUIDs,
filter is removed.
@todo Need to sync with the adapter-api.txt
@param uuids a list of uuid to filter on
@param rssi RSSI threshold
@param pathloss pathloss threshold
@param tr... | [
"This",
"method",
"sets",
"the",
"device",
"discovery",
"filter",
"for",
"the",
"caller",
".",
"When",
"this",
"method",
"is",
"called",
"with",
"+",
"nil",
"+",
"or",
"an",
"empty",
"list",
"of",
"UUIDs",
"filter",
"is",
"removed",
"."
] | 4c3b32d0ee65f787be235f1a5ee3878e6dcd995a | https://github.com/sdalu/ruby-ble/blob/4c3b32d0ee65f787be235f1a5ee3878e6dcd995a/lib/ble/adapter.rb#L90-L113 | train |
cheezy/service_mock | lib/service_mock/server.rb | ServiceMock.Server.stub_with_file | def stub_with_file(filename)
return if ::ServiceMock.disable_stubs
yield self if block_given?
content = File.open(filename, 'rb') { |file| file.read }
stub(content)
end | ruby | def stub_with_file(filename)
return if ::ServiceMock.disable_stubs
yield self if block_given?
content = File.open(filename, 'rb') { |file| file.read }
stub(content)
end | [
"def",
"stub_with_file",
"(",
"filename",
")",
"return",
"if",
"::",
"ServiceMock",
".",
"disable_stubs",
"yield",
"self",
"if",
"block_given?",
"content",
"=",
"File",
".",
"open",
"(",
"filename",
",",
"'rb'",
")",
"{",
"|",
"file",
"|",
"file",
".",
"... | Create a stub using the information in the provided filename. | [
"Create",
"a",
"stub",
"using",
"the",
"information",
"in",
"the",
"provided",
"filename",
"."
] | 8ca498008a02b3bd3be2e6327b051caac6112f52 | https://github.com/cheezy/service_mock/blob/8ca498008a02b3bd3be2e6327b051caac6112f52/lib/service_mock/server.rb#L119-L124 | train |
cheezy/service_mock | lib/service_mock/server.rb | ServiceMock.Server.stub_with_erb | def stub_with_erb(filename, hsh={})
return if ::ServiceMock.disable_stubs
yield self if block_given?
template = File.open(filename, 'rb') { |file| file.read }
erb_content = ERB.new(template).result(data_binding(hsh))
stub(erb_content)
end | ruby | def stub_with_erb(filename, hsh={})
return if ::ServiceMock.disable_stubs
yield self if block_given?
template = File.open(filename, 'rb') { |file| file.read }
erb_content = ERB.new(template).result(data_binding(hsh))
stub(erb_content)
end | [
"def",
"stub_with_erb",
"(",
"filename",
",",
"hsh",
"=",
"{",
"}",
")",
"return",
"if",
"::",
"ServiceMock",
".",
"disable_stubs",
"yield",
"self",
"if",
"block_given?",
"template",
"=",
"File",
".",
"open",
"(",
"filename",
",",
"'rb'",
")",
"{",
"|",
... | Create a stub using the erb template provided. The +Hash+ second
parameter contains the values to be inserted into the +ERB+. | [
"Create",
"a",
"stub",
"using",
"the",
"erb",
"template",
"provided",
".",
"The",
"+",
"Hash",
"+",
"second",
"parameter",
"contains",
"the",
"values",
"to",
"be",
"inserted",
"into",
"the",
"+",
"ERB",
"+",
"."
] | 8ca498008a02b3bd3be2e6327b051caac6112f52 | https://github.com/cheezy/service_mock/blob/8ca498008a02b3bd3be2e6327b051caac6112f52/lib/service_mock/server.rb#L130-L136 | train |
cheezy/service_mock | lib/service_mock/server.rb | ServiceMock.Server.count | def count(request_criteria)
return if ::ServiceMock.disable_stubs
yield self if block_given?
JSON.parse(http.post('/__admin/requests/count', request_criteria).body)['count']
end | ruby | def count(request_criteria)
return if ::ServiceMock.disable_stubs
yield self if block_given?
JSON.parse(http.post('/__admin/requests/count', request_criteria).body)['count']
end | [
"def",
"count",
"(",
"request_criteria",
")",
"return",
"if",
"::",
"ServiceMock",
".",
"disable_stubs",
"yield",
"self",
"if",
"block_given?",
"JSON",
".",
"parse",
"(",
"http",
".",
"post",
"(",
"'/__admin/requests/count'",
",",
"request_criteria",
")",
".",
... | Get the count for the request criteria | [
"Get",
"the",
"count",
"for",
"the",
"request",
"criteria"
] | 8ca498008a02b3bd3be2e6327b051caac6112f52 | https://github.com/cheezy/service_mock/blob/8ca498008a02b3bd3be2e6327b051caac6112f52/lib/service_mock/server.rb#L141-L145 | train |
cheezy/service_mock | lib/service_mock/server.rb | ServiceMock.Server.count_with_file | def count_with_file(filename)
return if ::ServiceMock.disable_stubs
yield self if block_given?
content = File.open(filename, 'rb') { |file| file.read }
count(content)
end | ruby | def count_with_file(filename)
return if ::ServiceMock.disable_stubs
yield self if block_given?
content = File.open(filename, 'rb') { |file| file.read }
count(content)
end | [
"def",
"count_with_file",
"(",
"filename",
")",
"return",
"if",
"::",
"ServiceMock",
".",
"disable_stubs",
"yield",
"self",
"if",
"block_given?",
"content",
"=",
"File",
".",
"open",
"(",
"filename",
",",
"'rb'",
")",
"{",
"|",
"file",
"|",
"file",
".",
... | Get the count for the request criteria in the provided filename. | [
"Get",
"the",
"count",
"for",
"the",
"request",
"criteria",
"in",
"the",
"provided",
"filename",
"."
] | 8ca498008a02b3bd3be2e6327b051caac6112f52 | https://github.com/cheezy/service_mock/blob/8ca498008a02b3bd3be2e6327b051caac6112f52/lib/service_mock/server.rb#L150-L155 | train |
cheezy/service_mock | lib/service_mock/server.rb | ServiceMock.Server.count_with_erb | def count_with_erb(filename, hsh={})
return if ::ServiceMock.disable_stubs
yield self if block_given?
template = File.open(filename, 'rb') { |file| file.read }
erb_content = ERB.new(template).result(data_binding(hsh))
count(erb_content)
end | ruby | def count_with_erb(filename, hsh={})
return if ::ServiceMock.disable_stubs
yield self if block_given?
template = File.open(filename, 'rb') { |file| file.read }
erb_content = ERB.new(template).result(data_binding(hsh))
count(erb_content)
end | [
"def",
"count_with_erb",
"(",
"filename",
",",
"hsh",
"=",
"{",
"}",
")",
"return",
"if",
"::",
"ServiceMock",
".",
"disable_stubs",
"yield",
"self",
"if",
"block_given?",
"template",
"=",
"File",
".",
"open",
"(",
"filename",
",",
"'rb'",
")",
"{",
"|",... | Get the count for the request criteria using the erb template
provided. The +Hash+ second parameter contains the values to be
inserted into the +ERB+. | [
"Get",
"the",
"count",
"for",
"the",
"request",
"criteria",
"using",
"the",
"erb",
"template",
"provided",
".",
"The",
"+",
"Hash",
"+",
"second",
"parameter",
"contains",
"the",
"values",
"to",
"be",
"inserted",
"into",
"the",
"+",
"ERB",
"+",
"."
] | 8ca498008a02b3bd3be2e6327b051caac6112f52 | https://github.com/cheezy/service_mock/blob/8ca498008a02b3bd3be2e6327b051caac6112f52/lib/service_mock/server.rb#L162-L168 | train |
gosu/ashton | lib/ashton/texture.rb | Ashton.Texture.clear | def clear(options = {})
options = {
color: [0.0, 0.0, 0.0, 0.0],
}.merge! options
color = options[:color]
color = color.to_opengl if color.is_a? Gosu::Color
Gl.glBindFramebufferEXT Gl::GL_FRAMEBUFFER_EXT, fbo_id unless rendering?
Gl.glDisable Gl::GL_BLEND # Need to repla... | ruby | def clear(options = {})
options = {
color: [0.0, 0.0, 0.0, 0.0],
}.merge! options
color = options[:color]
color = color.to_opengl if color.is_a? Gosu::Color
Gl.glBindFramebufferEXT Gl::GL_FRAMEBUFFER_EXT, fbo_id unless rendering?
Gl.glDisable Gl::GL_BLEND # Need to repla... | [
"def",
"clear",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"color",
":",
"[",
"0.0",
",",
"0.0",
",",
"0.0",
",",
"0.0",
"]",
",",
"}",
".",
"merge!",
"options",
"color",
"=",
"options",
"[",
":color",
"]",
"color",
"=",
"color",
... | Clears the buffer, optionally to a specific color.
@option options :color [Gosu::Color, Array<Float>] (transparent) | [
"Clears",
"the",
"buffer",
"optionally",
"to",
"a",
"specific",
"color",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/texture.rb#L93-L111 | train |
mguinada/vlc-client | lib/vlc-client/connection.rb | VLC.Connection.write | def write(data, fire_and_forget = true)
raise NotConnectedError, "no connection to server" unless connected?
@socket.puts(data)
@socket.flush
return true if fire_and_forget
read
rescue Errno::EPIPE
disconnect
raise BrokenConnectionError, "the connection to the server is l... | ruby | def write(data, fire_and_forget = true)
raise NotConnectedError, "no connection to server" unless connected?
@socket.puts(data)
@socket.flush
return true if fire_and_forget
read
rescue Errno::EPIPE
disconnect
raise BrokenConnectionError, "the connection to the server is l... | [
"def",
"write",
"(",
"data",
",",
"fire_and_forget",
"=",
"true",
")",
"raise",
"NotConnectedError",
",",
"\"no connection to server\"",
"unless",
"connected?",
"@socket",
".",
"puts",
"(",
"data",
")",
"@socket",
".",
"flush",
"return",
"true",
"if",
"fire_and_... | Writes data to the TCP server socket
@param data the data to write
@param fire_and_forget if true, no response response is expected from server,
when false, a response from the server will be returned.
@return the server response data if there is one | [
"Writes",
"data",
"to",
"the",
"TCP",
"server",
"socket"
] | e619bc11ab40deb8ae40878e011d67d05d6db73d | https://github.com/mguinada/vlc-client/blob/e619bc11ab40deb8ae40878e011d67d05d6db73d/lib/vlc-client/connection.rb#L52-L63 | train |
mguinada/vlc-client | lib/vlc-client/connection.rb | VLC.Connection.read | def read(timeout=nil)
timeout = read_timeout if timeout.nil?
raw_data = nil
Timeout.timeout(timeout) do
raw_data = @socket.gets.chomp
end
if (data = parse_raw_data(raw_data))
data[1]
else
raise VLC::ProtocolError, "could not interpret the playload: #{raw_dat... | ruby | def read(timeout=nil)
timeout = read_timeout if timeout.nil?
raw_data = nil
Timeout.timeout(timeout) do
raw_data = @socket.gets.chomp
end
if (data = parse_raw_data(raw_data))
data[1]
else
raise VLC::ProtocolError, "could not interpret the playload: #{raw_dat... | [
"def",
"read",
"(",
"timeout",
"=",
"nil",
")",
"timeout",
"=",
"read_timeout",
"if",
"timeout",
".",
"nil?",
"raw_data",
"=",
"nil",
"Timeout",
".",
"timeout",
"(",
"timeout",
")",
"do",
"raw_data",
"=",
"@socket",
".",
"gets",
".",
"chomp",
"end",
"i... | Reads data from the TCP server
@param timeout read timeout value for a read operation.
If omited the configured value or DEFAULT_READ_TIMEOUT will be used.
@return [String] the data | [
"Reads",
"data",
"from",
"the",
"TCP",
"server"
] | e619bc11ab40deb8ae40878e011d67d05d6db73d | https://github.com/mguinada/vlc-client/blob/e619bc11ab40deb8ae40878e011d67d05d6db73d/lib/vlc-client/connection.rb#L73-L88 | train |
gosu/ashton | lib/ashton/gosu_ext/window.rb | Gosu.Window.post_process | def post_process(*shaders)
raise ArgumentError, "Block required" unless block_given?
raise TypeError, "Can only process with Shaders" unless shaders.all? {|s| s.is_a? Ashton::Shader }
# In case no shaders are passed, just run the contents of the block.
unless shaders.size > 0
yield
... | ruby | def post_process(*shaders)
raise ArgumentError, "Block required" unless block_given?
raise TypeError, "Can only process with Shaders" unless shaders.all? {|s| s.is_a? Ashton::Shader }
# In case no shaders are passed, just run the contents of the block.
unless shaders.size > 0
yield
... | [
"def",
"post_process",
"(",
"*",
"shaders",
")",
"raise",
"ArgumentError",
",",
"\"Block required\"",
"unless",
"block_given?",
"raise",
"TypeError",
",",
"\"Can only process with Shaders\"",
"unless",
"shaders",
".",
"all?",
"{",
"|",
"s",
"|",
"s",
".",
"is_a?",... | Full screen post-processing using a fragment shader.
Variables set for you in the fragment shader:
uniform sampler2D in_Texture; // Texture containing the screen image. | [
"Full",
"screen",
"post",
"-",
"processing",
"using",
"a",
"fragment",
"shader",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/gosu_ext/window.rb#L45-L77 | train |
joeyAghion/spidey | lib/spidey/abstract_spider.rb | Spidey.AbstractSpider.each_url | def each_url(&_block)
index = 0
while index < urls.count # urls grows dynamically, don't use &:each
url = urls[index]
next unless url
yield url, handlers[url].first, handlers[url].last
index += 1
end
end | ruby | def each_url(&_block)
index = 0
while index < urls.count # urls grows dynamically, don't use &:each
url = urls[index]
next unless url
yield url, handlers[url].first, handlers[url].last
index += 1
end
end | [
"def",
"each_url",
"(",
"&",
"_block",
")",
"index",
"=",
"0",
"while",
"index",
"<",
"urls",
".",
"count",
"url",
"=",
"urls",
"[",
"index",
"]",
"next",
"unless",
"url",
"yield",
"url",
",",
"handlers",
"[",
"url",
"]",
".",
"first",
",",
"handle... | Override this for custom storage or prioritization of crawled URLs.
Iterates through URL queue, yielding the URL, handler, and default data. | [
"Override",
"this",
"for",
"custom",
"storage",
"or",
"prioritization",
"of",
"crawled",
"URLs",
".",
"Iterates",
"through",
"URL",
"queue",
"yielding",
"the",
"URL",
"handler",
"and",
"default",
"data",
"."
] | 4fe6daf8bd6b1c1c96a3f3de4ffeb4fe1d3c24ac | https://github.com/joeyAghion/spidey/blob/4fe6daf8bd6b1c1c96a3f3de4ffeb4fe1d3c24ac/lib/spidey/abstract_spider.rb#L56-L64 | train |
gosu/ashton | lib/ashton/gosu_ext/image.rb | Gosu.Image.draw_as_points | def draw_as_points(points, z, options = {})
color = options[:color] || DEFAULT_DRAW_COLOR
scale = options[:scale] || 1.0
shader = options[:shader]
mode = options[:mode] || :default
if shader
shader.enable z
$window.gl z do
shader.image = self
shader.col... | ruby | def draw_as_points(points, z, options = {})
color = options[:color] || DEFAULT_DRAW_COLOR
scale = options[:scale] || 1.0
shader = options[:shader]
mode = options[:mode] || :default
if shader
shader.enable z
$window.gl z do
shader.image = self
shader.col... | [
"def",
"draw_as_points",
"(",
"points",
",",
"z",
",",
"options",
"=",
"{",
"}",
")",
"color",
"=",
"options",
"[",
":color",
"]",
"||",
"DEFAULT_DRAW_COLOR",
"scale",
"=",
"options",
"[",
":scale",
"]",
"||",
"1.0",
"shader",
"=",
"options",
"[",
":sh... | Draw a list of centred sprites by position.
@param points [Array<Array>] Array of [x, y] positions
@param z [Float] Z-order to draw - Ignored if shader is used.
@option options :scale [Float] (1.0) Relative size of the sprites
@option options :shader [Ashton::Shader] Shader to apply to all sprites.
TODO: Need to... | [
"Draw",
"a",
"list",
"of",
"centred",
"sprites",
"by",
"position",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/gosu_ext/image.rb#L64-L85 | train |
gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.sample_distance | def sample_distance(x, y)
x = [[x, width - 1].min, 0].max
y = [[y, height - 1].min, 0].max
# Could be checking any of red/blue/green.
@field.red((x / @scale).round, (y / @scale).round) - ZERO_DISTANCE
end | ruby | def sample_distance(x, y)
x = [[x, width - 1].min, 0].max
y = [[y, height - 1].min, 0].max
# Could be checking any of red/blue/green.
@field.red((x / @scale).round, (y / @scale).round) - ZERO_DISTANCE
end | [
"def",
"sample_distance",
"(",
"x",
",",
"y",
")",
"x",
"=",
"[",
"[",
"x",
",",
"width",
"-",
"1",
"]",
".",
"min",
",",
"0",
"]",
".",
"max",
"y",
"=",
"[",
"[",
"y",
",",
"height",
"-",
"1",
"]",
".",
"min",
",",
"0",
"]",
".",
"max"... | If positive, distance, in pixels, to the nearest opaque pixel.
If negative, distance in pixels to the nearest transparent pixel. | [
"If",
"positive",
"distance",
"in",
"pixels",
"to",
"the",
"nearest",
"opaque",
"pixel",
".",
"If",
"negative",
"distance",
"in",
"pixels",
"to",
"the",
"nearest",
"transparent",
"pixel",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L47-L52 | train |
gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.sample_gradient | def sample_gradient(x, y)
d0 = sample_distance x, y - 1
d1 = sample_distance x - 1, y
d2 = sample_distance x + 1, y
d3 = sample_distance x, y + 1
[(d2 - d1) / @scale, (d3 - d0) / @scale]
end | ruby | def sample_gradient(x, y)
d0 = sample_distance x, y - 1
d1 = sample_distance x - 1, y
d2 = sample_distance x + 1, y
d3 = sample_distance x, y + 1
[(d2 - d1) / @scale, (d3 - d0) / @scale]
end | [
"def",
"sample_gradient",
"(",
"x",
",",
"y",
")",
"d0",
"=",
"sample_distance",
"x",
",",
"y",
"-",
"1",
"d1",
"=",
"sample_distance",
"x",
"-",
"1",
",",
"y",
"d2",
"=",
"sample_distance",
"x",
"+",
"1",
",",
"y",
"d3",
"=",
"sample_distance",
"x... | Gets the gradient of the field at a given point.
@return [Float, Float] gradient_x, gradient_y | [
"Gets",
"the",
"gradient",
"of",
"the",
"field",
"at",
"a",
"given",
"point",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L56-L63 | train |
gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.sample_normal | def sample_normal(x, y)
gradient_x, gradient_y = sample_gradient x, y
length = Gosu::distance 0, 0, gradient_x, gradient_y
if length == 0
[0, 0] # This could be NaN in edge cases.
else
[gradient_x / length, gradient_y / length]
end
end | ruby | def sample_normal(x, y)
gradient_x, gradient_y = sample_gradient x, y
length = Gosu::distance 0, 0, gradient_x, gradient_y
if length == 0
[0, 0] # This could be NaN in edge cases.
else
[gradient_x / length, gradient_y / length]
end
end | [
"def",
"sample_normal",
"(",
"x",
",",
"y",
")",
"gradient_x",
",",
"gradient_y",
"=",
"sample_gradient",
"x",
",",
"y",
"length",
"=",
"Gosu",
"::",
"distance",
"0",
",",
"0",
",",
"gradient_x",
",",
"gradient_y",
"if",
"length",
"==",
"0",
"[",
"0",
... | Get the normal at a given point.
@return [Float, Float] normal_x, normal_y | [
"Get",
"the",
"normal",
"at",
"a",
"given",
"point",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L67-L75 | train |
gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.line_of_sight_blocked_at | def line_of_sight_blocked_at(x1, y1, x2, y2)
distance_to_travel = Gosu::distance x1, y1, x2, y2
distance_x, distance_y = x2 - x1, y2 - y1
distance_travelled = 0
x, y = x1, y1
loop do
distance = sample_distance x, y
# Blocked?
return [x, y] if distance <= 0
... | ruby | def line_of_sight_blocked_at(x1, y1, x2, y2)
distance_to_travel = Gosu::distance x1, y1, x2, y2
distance_x, distance_y = x2 - x1, y2 - y1
distance_travelled = 0
x, y = x1, y1
loop do
distance = sample_distance x, y
# Blocked?
return [x, y] if distance <= 0
... | [
"def",
"line_of_sight_blocked_at",
"(",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
")",
"distance_to_travel",
"=",
"Gosu",
"::",
"distance",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
"distance_x",
",",
"distance_y",
"=",
"x2",
"-",
"x1",
",",
"y2",
"-",
"y1... | Returns blocking position, else nil if line of sight isn't blocked. | [
"Returns",
"blocking",
"position",
"else",
"nil",
"if",
"line",
"of",
"sight",
"isn",
"t",
"blocked",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L83-L104 | train |
gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.render_field | def render_field
raise ArgumentError, "Block required" unless block_given?
@mask.render do
@mask.clear
$window.scale 1.0 / @scale do
yield self
end
end
@shader.enable do
@field.render do
@mask.draw 0, 0, 0
end
end
nil
... | ruby | def render_field
raise ArgumentError, "Block required" unless block_given?
@mask.render do
@mask.clear
$window.scale 1.0 / @scale do
yield self
end
end
@shader.enable do
@field.render do
@mask.draw 0, 0, 0
end
end
nil
... | [
"def",
"render_field",
"raise",
"ArgumentError",
",",
"\"Block required\"",
"unless",
"block_given?",
"@mask",
".",
"render",
"do",
"@mask",
".",
"clear",
"$window",
".",
"scale",
"1.0",
"/",
"@scale",
"do",
"yield",
"self",
"end",
"end",
"@shader",
".",
"enab... | Update the SDF should the image have changed.
Draw the mask in the passed block. | [
"Update",
"the",
"SDF",
"should",
"the",
"image",
"have",
"changed",
".",
"Draw",
"the",
"mask",
"in",
"the",
"passed",
"block",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L108-L125 | train |
gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.draw | def draw(x, y, z, options = {})
options = {
mode: :add,
}.merge! options
$window.scale @scale do
@field.draw x, y, z, options
end
nil
end | ruby | def draw(x, y, z, options = {})
options = {
mode: :add,
}.merge! options
$window.scale @scale do
@field.draw x, y, z, options
end
nil
end | [
"def",
"draw",
"(",
"x",
",",
"y",
",",
"z",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"mode",
":",
":add",
",",
"}",
".",
"merge!",
"options",
"$window",
".",
"scale",
"@scale",
"do",
"@field",
".",
"draw",
"x",
",",
"y",
",",
... | Draw the field, usually for debugging purposes.
@see Ashton::Texture#draw | [
"Draw",
"the",
"field",
"usually",
"for",
"debugging",
"purposes",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L129-L139 | train |
gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.to_a | def to_a
width.times.map do |x|
height.times.map do |y|
sample_distance x, y
end
end
end | ruby | def to_a
width.times.map do |x|
height.times.map do |y|
sample_distance x, y
end
end
end | [
"def",
"to_a",
"width",
".",
"times",
".",
"map",
"do",
"|",
"x",
"|",
"height",
".",
"times",
".",
"map",
"do",
"|",
"y",
"|",
"sample_distance",
"x",
",",
"y",
"end",
"end",
"end"
] | Convert into a nested array of sample values.
@return [Array<Array<Integer>>] | [
"Convert",
"into",
"a",
"nested",
"array",
"of",
"sample",
"values",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L143-L149 | train |
mguinada/vlc-client | lib/vlc-client/server.rb | VLC.Server.start | def start(detached = false)
return @pid if running?
detached ? @deamon = true : setup_traps
@pid = RUBY_VERSION >= '1.9' ? process_spawn(detached) : process_spawn_ruby_1_8(detached)
end | ruby | def start(detached = false)
return @pid if running?
detached ? @deamon = true : setup_traps
@pid = RUBY_VERSION >= '1.9' ? process_spawn(detached) : process_spawn_ruby_1_8(detached)
end | [
"def",
"start",
"(",
"detached",
"=",
"false",
")",
"return",
"@pid",
"if",
"running?",
"detached",
"?",
"@deamon",
"=",
"true",
":",
"setup_traps",
"@pid",
"=",
"RUBY_VERSION",
">=",
"'1.9'",
"?",
"process_spawn",
"(",
"detached",
")",
":",
"process_spawn_r... | Starts a VLC instance in a subprocess
@param [Boolean] detached if true VLC will be started as a deamon process.
Defaults to false.
@return [Integer] the subprocess PID
@see #daemonize | [
"Starts",
"a",
"VLC",
"instance",
"in",
"a",
"subprocess"
] | e619bc11ab40deb8ae40878e011d67d05d6db73d | https://github.com/mguinada/vlc-client/blob/e619bc11ab40deb8ae40878e011d67d05d6db73d/lib/vlc-client/server.rb#L48-L54 | train |
mguinada/vlc-client | lib/vlc-client/server.rb | VLC.Server.process_spawn_ruby_1_8 | def process_spawn_ruby_1_8(detached)
rd, wr = IO.pipe
if Process.fork #parent
wr.close
pid = rd.read.to_i
rd.close
return pid
else #child
rd.close
detach if detached #daemonization
wr.write(Process.pid)
wr.close
... | ruby | def process_spawn_ruby_1_8(detached)
rd, wr = IO.pipe
if Process.fork #parent
wr.close
pid = rd.read.to_i
rd.close
return pid
else #child
rd.close
detach if detached #daemonization
wr.write(Process.pid)
wr.close
... | [
"def",
"process_spawn_ruby_1_8",
"(",
"detached",
")",
"rd",
",",
"wr",
"=",
"IO",
".",
"pipe",
"if",
"Process",
".",
"fork",
"wr",
".",
"close",
"pid",
"=",
"rd",
".",
"read",
".",
"to_i",
"rd",
".",
"close",
"return",
"pid",
"else",
"rd",
".",
"c... | For ruby 1.8 | [
"For",
"ruby",
"1",
".",
"8"
] | e619bc11ab40deb8ae40878e011d67d05d6db73d | https://github.com/mguinada/vlc-client/blob/e619bc11ab40deb8ae40878e011d67d05d6db73d/lib/vlc-client/server.rb#L118-L140 | train |
shoes/furoshiki | lib/furoshiki/configuration.rb | Furoshiki.Configuration.merge_config | def merge_config(config)
defaults = {
name: 'Ruby App',
version: '0.0.0',
release: 'Rookie',
ignore: 'pkg',
# TODO: Establish these default icons and paths. These would be
# default icons for generic Ruby apps.
icons: {
#osx: 'path/to/default/App.i... | ruby | def merge_config(config)
defaults = {
name: 'Ruby App',
version: '0.0.0',
release: 'Rookie',
ignore: 'pkg',
# TODO: Establish these default icons and paths. These would be
# default icons for generic Ruby apps.
icons: {
#osx: 'path/to/default/App.i... | [
"def",
"merge_config",
"(",
"config",
")",
"defaults",
"=",
"{",
"name",
":",
"'Ruby App'",
",",
"version",
":",
"'0.0.0'",
",",
"release",
":",
"'Rookie'",
",",
"ignore",
":",
"'pkg'",
",",
"icons",
":",
"{",
"}",
",",
"template_urls",
":",
"{",
"jar_... | Overwrite defaults with supplied config | [
"Overwrite",
"defaults",
"with",
"supplied",
"config"
] | ead3a1d38bcac23cc13f1bf3e31cc40fdd75b2eb | https://github.com/shoes/furoshiki/blob/ead3a1d38bcac23cc13f1bf3e31cc40fdd75b2eb/lib/furoshiki/configuration.rb#L103-L125 | train |
gosu/ashton | lib/ashton/window_buffer.rb | Ashton.WindowBuffer.capture | def capture
Gl.glBindTexture Gl::GL_TEXTURE_2D, id
Gl.glCopyTexImage2D Gl::GL_TEXTURE_2D, 0, Gl::GL_RGBA8, 0, 0, width, height, 0
self
end | ruby | def capture
Gl.glBindTexture Gl::GL_TEXTURE_2D, id
Gl.glCopyTexImage2D Gl::GL_TEXTURE_2D, 0, Gl::GL_RGBA8, 0, 0, width, height, 0
self
end | [
"def",
"capture",
"Gl",
".",
"glBindTexture",
"Gl",
"::",
"GL_TEXTURE_2D",
",",
"id",
"Gl",
".",
"glCopyTexImage2D",
"Gl",
"::",
"GL_TEXTURE_2D",
",",
"0",
",",
"Gl",
"::",
"GL_RGBA8",
",",
"0",
",",
"0",
",",
"width",
",",
"height",
",",
"0",
"self",
... | Copy the window contents into the buffer. | [
"Copy",
"the",
"window",
"contents",
"into",
"the",
"buffer",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/window_buffer.rb#L10-L14 | train |
gosu/ashton | lib/ashton/shader.rb | Ashton.Shader.[]= | def []=(uniform, value)
uniform = uniform_name_from_symbol(uniform) if uniform.is_a? Symbol
# Ensure that the program is current before setting values.
needs_use = !current?
enable if needs_use
set_uniform uniform_location(uniform), value
disable if needs_use
value
end | ruby | def []=(uniform, value)
uniform = uniform_name_from_symbol(uniform) if uniform.is_a? Symbol
# Ensure that the program is current before setting values.
needs_use = !current?
enable if needs_use
set_uniform uniform_location(uniform), value
disable if needs_use
value
end | [
"def",
"[]=",
"(",
"uniform",
",",
"value",
")",
"uniform",
"=",
"uniform_name_from_symbol",
"(",
"uniform",
")",
"if",
"uniform",
".",
"is_a?",
"Symbol",
"needs_use",
"=",
"!",
"current?",
"enable",
"if",
"needs_use",
"set_uniform",
"uniform_location",
"(",
"... | Set the value of a uniform.
@param uniform [String, Symbol] If a Symbol, :frog_paste is looked up as "in_FrogPaste", otherwise the Sting is used directly.
@param value [Any] Value to set the uniform to
@raise ShaderUniformError unless requested uniform is defined in vertex or fragment shaders. | [
"Set",
"the",
"value",
"of",
"a",
"uniform",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/shader.rb#L159-L169 | train |
gosu/ashton | lib/ashton/shader.rb | Ashton.Shader.set_uniform | def set_uniform(location, value)
raise ShaderUniformError, "Shader uniform #{location.inspect} could not be set, since shader is not current" unless current?
return if location == INVALID_LOCATION # Not for end-users :)
case value
when true, Gl::GL_TRUE
Gl.glUniform1i location, 1
... | ruby | def set_uniform(location, value)
raise ShaderUniformError, "Shader uniform #{location.inspect} could not be set, since shader is not current" unless current?
return if location == INVALID_LOCATION # Not for end-users :)
case value
when true, Gl::GL_TRUE
Gl.glUniform1i location, 1
... | [
"def",
"set_uniform",
"(",
"location",
",",
"value",
")",
"raise",
"ShaderUniformError",
",",
"\"Shader uniform #{location.inspect} could not be set, since shader is not current\"",
"unless",
"current?",
"return",
"if",
"location",
"==",
"INVALID_LOCATION",
"case",
"value",
"... | Set uniform without trying to force use of the program. | [
"Set",
"uniform",
"without",
"trying",
"to",
"force",
"use",
"of",
"the",
"program",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/shader.rb#L173-L235 | train |
gosu/ashton | lib/ashton/shader.rb | Ashton.Shader.process_source | def process_source(shader, extension)
source = if shader.is_a? Symbol
file = File.expand_path "#{shader}#{extension}", BUILT_IN_SHADER_PATH
unless File.exist? file
raise ShaderLoadError, "Failed to load built-in shader: #{shader.inspect}"
end
... | ruby | def process_source(shader, extension)
source = if shader.is_a? Symbol
file = File.expand_path "#{shader}#{extension}", BUILT_IN_SHADER_PATH
unless File.exist? file
raise ShaderLoadError, "Failed to load built-in shader: #{shader.inspect}"
end
... | [
"def",
"process_source",
"(",
"shader",
",",
"extension",
")",
"source",
"=",
"if",
"shader",
".",
"is_a?",
"Symbol",
"file",
"=",
"File",
".",
"expand_path",
"\"#{shader}#{extension}\"",
",",
"BUILT_IN_SHADER_PATH",
"unless",
"File",
".",
"exist?",
"file",
"rai... | Symbol => load a built-in
Filename => load file
Source => use directly.
Also recursively replaces #include
TODO: What about line numbers getting messed up by #include? | [
"Symbol",
"=",
">",
"load",
"a",
"built",
"-",
"in",
"Filename",
"=",
">",
"load",
"file",
"Source",
"=",
">",
"use",
"directly",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/shader.rb#L352-L367 | train |
shoes/furoshiki | lib/furoshiki/util.rb | Furoshiki.Util.deep_set_symbol_key | def deep_set_symbol_key(hash, key, value)
if value.kind_of? Hash
hash[key.to_sym] = value.inject({}) { |inner_hash, (inner_key, inner_value)| deep_set_symbol_key(inner_hash, inner_key, inner_value) }
else
hash[key.to_sym] = value
end
hash
end | ruby | def deep_set_symbol_key(hash, key, value)
if value.kind_of? Hash
hash[key.to_sym] = value.inject({}) { |inner_hash, (inner_key, inner_value)| deep_set_symbol_key(inner_hash, inner_key, inner_value) }
else
hash[key.to_sym] = value
end
hash
end | [
"def",
"deep_set_symbol_key",
"(",
"hash",
",",
"key",
",",
"value",
")",
"if",
"value",
".",
"kind_of?",
"Hash",
"hash",
"[",
"key",
".",
"to_sym",
"]",
"=",
"value",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"inner_hash",
",",
"(",
"inner_key",
... | Ensure symbol keys, even in nested hashes
@param [Hash] config the hash to set (key: value) on
@param [#to_sym] k the key
@param [Object] v the value
@return [Hash] an updated hash | [
"Ensure",
"symbol",
"keys",
"even",
"in",
"nested",
"hashes"
] | ead3a1d38bcac23cc13f1bf3e31cc40fdd75b2eb | https://github.com/shoes/furoshiki/blob/ead3a1d38bcac23cc13f1bf3e31cc40fdd75b2eb/lib/furoshiki/util.rb#L9-L16 | train |
shoes/furoshiki | lib/furoshiki/util.rb | Furoshiki.Util.merge_with_symbolized_keys | def merge_with_symbolized_keys(defaults, hash)
hash.inject(defaults) { |symbolized, (k, v)| deep_set_symbol_key(symbolized, k, v) }
end | ruby | def merge_with_symbolized_keys(defaults, hash)
hash.inject(defaults) { |symbolized, (k, v)| deep_set_symbol_key(symbolized, k, v) }
end | [
"def",
"merge_with_symbolized_keys",
"(",
"defaults",
",",
"hash",
")",
"hash",
".",
"inject",
"(",
"defaults",
")",
"{",
"|",
"symbolized",
",",
"(",
"k",
",",
"v",
")",
"|",
"deep_set_symbol_key",
"(",
"symbolized",
",",
"k",
",",
"v",
")",
"}",
"end... | Assumes that defaults already has symbolized keys | [
"Assumes",
"that",
"defaults",
"already",
"has",
"symbolized",
"keys"
] | ead3a1d38bcac23cc13f1bf3e31cc40fdd75b2eb | https://github.com/shoes/furoshiki/blob/ead3a1d38bcac23cc13f1bf3e31cc40fdd75b2eb/lib/furoshiki/util.rb#L23-L25 | train |
abates/ruby_expect | lib/ruby_expect/expect.rb | RubyExpect.Expect.expect | def expect *patterns, &block
@logger.debug("Expecting: #{patterns.inspect}") if @logger.debug?
patterns = pattern_escape(*patterns)
@end_time = 0
if (@timeout != 0)
@end_time = Time.now + @timeout
end
@before = ''
matched_index = nil
while (@end_time == 0 || Time... | ruby | def expect *patterns, &block
@logger.debug("Expecting: #{patterns.inspect}") if @logger.debug?
patterns = pattern_escape(*patterns)
@end_time = 0
if (@timeout != 0)
@end_time = Time.now + @timeout
end
@before = ''
matched_index = nil
while (@end_time == 0 || Time... | [
"def",
"expect",
"*",
"patterns",
",",
"&",
"block",
"@logger",
".",
"debug",
"(",
"\"Expecting: #{patterns.inspect}\"",
")",
"if",
"@logger",
".",
"debug?",
"patterns",
"=",
"pattern_escape",
"(",
"*",
"patterns",
")",
"@end_time",
"=",
"0",
"if",
"(",
"@ti... | Wait until either the timeout occurs or one of the given patterns is seen
in the input. Upon a match, the property before is assigned all input in
the accumulator before the match, the matched string itself is assigned to
the match property and an optional block is called
The method will return the index of the m... | [
"Wait",
"until",
"either",
"the",
"timeout",
"occurs",
"or",
"one",
"of",
"the",
"given",
"patterns",
"is",
"seen",
"in",
"the",
"input",
".",
"Upon",
"a",
"match",
"the",
"property",
"before",
"is",
"assigned",
"all",
"input",
"in",
"the",
"accumulator",
... | 3c0cf66b90f79173b799f2df4195cf60815ea242 | https://github.com/abates/ruby_expect/blob/3c0cf66b90f79173b799f2df4195cf60815ea242/lib/ruby_expect/expect.rb#L260-L294 | train |
abates/ruby_expect | lib/ruby_expect/expect.rb | RubyExpect.Expect.pattern_escape | def pattern_escape *patterns
escaped_patterns = []
patterns.each do |pattern|
if (pattern.is_a?(String))
pattern = Regexp.new(Regexp.escape(pattern))
elsif (! pattern.is_a?(Regexp))
raise "Don't know how to match on a #{pattern.class}"
end
... | ruby | def pattern_escape *patterns
escaped_patterns = []
patterns.each do |pattern|
if (pattern.is_a?(String))
pattern = Regexp.new(Regexp.escape(pattern))
elsif (! pattern.is_a?(Regexp))
raise "Don't know how to match on a #{pattern.class}"
end
... | [
"def",
"pattern_escape",
"*",
"patterns",
"escaped_patterns",
"=",
"[",
"]",
"patterns",
".",
"each",
"do",
"|",
"pattern",
"|",
"if",
"(",
"pattern",
".",
"is_a?",
"(",
"String",
")",
")",
"pattern",
"=",
"Regexp",
".",
"new",
"(",
"Regexp",
".",
"esc... | This method will convert any strings in the argument list to regular
expressions that search for the literal string
+patterns+::
List of patterns to escape | [
"This",
"method",
"will",
"convert",
"any",
"strings",
"in",
"the",
"argument",
"list",
"to",
"regular",
"expressions",
"that",
"search",
"for",
"the",
"literal",
"string"
] | 3c0cf66b90f79173b799f2df4195cf60815ea242 | https://github.com/abates/ruby_expect/blob/3c0cf66b90f79173b799f2df4195cf60815ea242/lib/ruby_expect/expect.rb#L409-L420 | train |
mech/filemaker-ruby | lib/filemaker/server.rb | Filemaker.Server.serialize_args | def serialize_args(args)
return {} if args.nil?
args.each do |key, value|
case value
when DateTime, Time
args[key] = value.strftime('%m/%d/%Y %H:%M:%S')
when Date
args[key] = value.strftime('%m/%d/%Y')
else
# Especially for range operator (...),... | ruby | def serialize_args(args)
return {} if args.nil?
args.each do |key, value|
case value
when DateTime, Time
args[key] = value.strftime('%m/%d/%Y %H:%M:%S')
when Date
args[key] = value.strftime('%m/%d/%Y')
else
# Especially for range operator (...),... | [
"def",
"serialize_args",
"(",
"args",
")",
"return",
"{",
"}",
"if",
"args",
".",
"nil?",
"args",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"value",
"when",
"DateTime",
",",
"Time",
"args",
"[",
"key",
"]",
"=",
"value",
".",
"strft... | {"-db"=>"mydb", "-lay"=>"mylay", "email"=>"a@b.com", "updated_at": Date}
Take Ruby type and serialize into a form FileMaker can understand | [
"{",
"-",
"db",
"=",
">",
"mydb",
"-",
"lay",
"=",
">",
"mylay",
"email",
"=",
">",
"a"
] | 75bb9eaf467546b2404bcb79267f2434090f2c88 | https://github.com/mech/filemaker-ruby/blob/75bb9eaf467546b2404bcb79267f2434090f2c88/lib/filemaker/server.rb#L101-L117 | train |
oggy/cast | lib/cast/parse.rb | C.NodeList.match? | def match?(arr, parser=nil)
arr = arr.to_a
return false if arr.length != self.length
each_with_index do |node, i|
node.match?(arr[i], parser) or return false
end
return true
end | ruby | def match?(arr, parser=nil)
arr = arr.to_a
return false if arr.length != self.length
each_with_index do |node, i|
node.match?(arr[i], parser) or return false
end
return true
end | [
"def",
"match?",
"(",
"arr",
",",
"parser",
"=",
"nil",
")",
"arr",
"=",
"arr",
".",
"to_a",
"return",
"false",
"if",
"arr",
".",
"length",
"!=",
"self",
".",
"length",
"each_with_index",
"do",
"|",
"node",
",",
"i",
"|",
"node",
".",
"match?",
"("... | As defined in Node. | [
"As",
"defined",
"in",
"Node",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/parse.rb#L40-L47 | train |
oggy/cast | lib/cast/node.rb | C.Node.assert_invariants | def assert_invariants(testcase)
fields.each do |field|
if val = send(field.reader)
assert_same(self, node.parent, "field.reader is #{field.reader}")
if field.child?
assert_same(field, val.instance_variable_get(:@parent_field), "field.reader is #{field.reader}")
en... | ruby | def assert_invariants(testcase)
fields.each do |field|
if val = send(field.reader)
assert_same(self, node.parent, "field.reader is #{field.reader}")
if field.child?
assert_same(field, val.instance_variable_get(:@parent_field), "field.reader is #{field.reader}")
en... | [
"def",
"assert_invariants",
"(",
"testcase",
")",
"fields",
".",
"each",
"do",
"|",
"field",
"|",
"if",
"val",
"=",
"send",
"(",
"field",
".",
"reader",
")",
"assert_same",
"(",
"self",
",",
"node",
".",
"parent",
",",
"\"field.reader is #{field.reader}\"",
... | Called by the test suite to ensure all invariants are true. | [
"Called",
"by",
"the",
"test",
"suite",
"to",
"ensure",
"all",
"invariants",
"are",
"true",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node.rb#L15-L24 | train |
oggy/cast | lib/cast/node.rb | C.Node.each | def each(&blk)
fields.each do |field|
if field.child?
val = self.send(field.reader)
yield val unless val.nil?
end
end
return self
end | ruby | def each(&blk)
fields.each do |field|
if field.child?
val = self.send(field.reader)
yield val unless val.nil?
end
end
return self
end | [
"def",
"each",
"(",
"&",
"blk",
")",
"fields",
".",
"each",
"do",
"|",
"field",
"|",
"if",
"field",
".",
"child?",
"val",
"=",
"self",
".",
"send",
"(",
"field",
".",
"reader",
")",
"yield",
"val",
"unless",
"val",
".",
"nil?",
"end",
"end",
"ret... | Yield each child in field order. | [
"Yield",
"each",
"child",
"in",
"field",
"order",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node.rb#L107-L115 | train |
oggy/cast | lib/cast/node.rb | C.Node.swap_with | def swap_with node
return self if node.equal? self
if self.attached?
if node.attached?
# both attached -- use placeholder
placeholder = Default.new
my_parent = @parent
my_parent.replace_node(self, placeholder)
node.parent.replace_node(node, self)
... | ruby | def swap_with node
return self if node.equal? self
if self.attached?
if node.attached?
# both attached -- use placeholder
placeholder = Default.new
my_parent = @parent
my_parent.replace_node(self, placeholder)
node.parent.replace_node(node, self)
... | [
"def",
"swap_with",
"node",
"return",
"self",
"if",
"node",
".",
"equal?",
"self",
"if",
"self",
".",
"attached?",
"if",
"node",
".",
"attached?",
"placeholder",
"=",
"Default",
".",
"new",
"my_parent",
"=",
"@parent",
"my_parent",
".",
"replace_node",
"(",
... | Swap this node with `node' in their trees. If either node is
detached, the other will become detached as a result of calling
this method. | [
"Swap",
"this",
"node",
"with",
"node",
"in",
"their",
"trees",
".",
"If",
"either",
"node",
"is",
"detached",
"the",
"other",
"will",
"become",
"detached",
"as",
"a",
"result",
"of",
"calling",
"this",
"method",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node.rb#L318-L341 | train |
oggy/cast | lib/cast/node.rb | C.Node.node_before | def node_before(node)
node.parent.equal? self or
raise ArgumentError, "node is not a child"
fields = self.fields
i = node.instance_variable_get(:@parent_field).index - 1
i.downto(0) do |i|
f = fields[i]
if f.child? && (val = self.send(f.reader))
return val
... | ruby | def node_before(node)
node.parent.equal? self or
raise ArgumentError, "node is not a child"
fields = self.fields
i = node.instance_variable_get(:@parent_field).index - 1
i.downto(0) do |i|
f = fields[i]
if f.child? && (val = self.send(f.reader))
return val
... | [
"def",
"node_before",
"(",
"node",
")",
"node",
".",
"parent",
".",
"equal?",
"self",
"or",
"raise",
"ArgumentError",
",",
"\"node is not a child\"",
"fields",
"=",
"self",
".",
"fields",
"i",
"=",
"node",
".",
"instance_variable_get",
"(",
":@parent_field",
"... | Return the Node that comes before the given Node in tree
preorder. | [
"Return",
"the",
"Node",
"that",
"comes",
"before",
"the",
"given",
"Node",
"in",
"tree",
"preorder",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node.rb#L634-L646 | train |
oggy/cast | lib/cast/node.rb | C.Node.remove_node | def remove_node(node)
node.parent.equal? self or
raise ArgumentError, "node is not a child"
field = node.instance_variable_get(:@parent_field)
node.instance_variable_set(:@parent, nil)
node.instance_variable_set(:@parent_field, nil)
self.instance_variable_set(field.var, nil)
... | ruby | def remove_node(node)
node.parent.equal? self or
raise ArgumentError, "node is not a child"
field = node.instance_variable_get(:@parent_field)
node.instance_variable_set(:@parent, nil)
node.instance_variable_set(:@parent_field, nil)
self.instance_variable_set(field.var, nil)
... | [
"def",
"remove_node",
"(",
"node",
")",
"node",
".",
"parent",
".",
"equal?",
"self",
"or",
"raise",
"ArgumentError",
",",
"\"node is not a child\"",
"field",
"=",
"node",
".",
"instance_variable_get",
"(",
":@parent_field",
")",
"node",
".",
"instance_variable_se... | Remove the given Node. | [
"Remove",
"the",
"given",
"Node",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node.rb#L651-L659 | train |
oggy/cast | lib/cast/node.rb | C.Node.replace_node | def replace_node(node, newnode=nil)
node.parent.equal? self or
raise ArgumentError, "node is not a child"
field = node.instance_variable_get(:@parent_field)
self.send(field.writer, newnode)
return self
end | ruby | def replace_node(node, newnode=nil)
node.parent.equal? self or
raise ArgumentError, "node is not a child"
field = node.instance_variable_get(:@parent_field)
self.send(field.writer, newnode)
return self
end | [
"def",
"replace_node",
"(",
"node",
",",
"newnode",
"=",
"nil",
")",
"node",
".",
"parent",
".",
"equal?",
"self",
"or",
"raise",
"ArgumentError",
",",
"\"node is not a child\"",
"field",
"=",
"node",
".",
"instance_variable_get",
"(",
":@parent_field",
")",
"... | Replace `node' with `newnode'. | [
"Replace",
"node",
"with",
"newnode",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node.rb#L664-L670 | train |
oggy/cast | lib/cast/node_list.rb | C.NodeChain.link_ | def link_(a, nodes, b)
if nodes.empty?
if a.nil?
@first = b
else
a.instance_variable_set(:@next, b)
end
if b.nil?
@last = a
else
b.instance_variable_set(:@prev, a)
end
else
# connect `a' and `b'
first = n... | ruby | def link_(a, nodes, b)
if nodes.empty?
if a.nil?
@first = b
else
a.instance_variable_set(:@next, b)
end
if b.nil?
@last = a
else
b.instance_variable_set(:@prev, a)
end
else
# connect `a' and `b'
first = n... | [
"def",
"link_",
"(",
"a",
",",
"nodes",
",",
"b",
")",
"if",
"nodes",
".",
"empty?",
"if",
"a",
".",
"nil?",
"@first",
"=",
"b",
"else",
"a",
".",
"instance_variable_set",
"(",
":@next",
",",
"b",
")",
"end",
"if",
"b",
".",
"nil?",
"@last",
"=",... | Link up `nodes' between `a' and `b'. | [
"Link",
"up",
"nodes",
"between",
"a",
"and",
"b",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node_list.rb#L763-L807 | train |
oggy/cast | lib/cast/node_list.rb | C.NodeChain.link2_ | def link2_(a, b)
if a.nil?
@first = b
else
a.instance_variable_set(:@next, b) unless a.nil?
end
if b.nil?
@last = a
else
b.instance_variable_set(:@prev, a) unless b.nil?
end
end | ruby | def link2_(a, b)
if a.nil?
@first = b
else
a.instance_variable_set(:@next, b) unless a.nil?
end
if b.nil?
@last = a
else
b.instance_variable_set(:@prev, a) unless b.nil?
end
end | [
"def",
"link2_",
"(",
"a",
",",
"b",
")",
"if",
"a",
".",
"nil?",
"@first",
"=",
"b",
"else",
"a",
".",
"instance_variable_set",
"(",
":@next",
",",
"b",
")",
"unless",
"a",
".",
"nil?",
"end",
"if",
"b",
".",
"nil?",
"@last",
"=",
"a",
"else",
... | Special case for 2 | [
"Special",
"case",
"for",
"2"
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node_list.rb#L811-L822 | train |
oggy/cast | lib/cast/node_list.rb | C.NodeChain.get_ | def get_(i)
# return a Node
if i < (@length >> 1)
# go from the beginning
node = @first
i.times{node = node.next}
else
# go from the end
node = @last
(@length - 1 - i).times{node = node.prev}
end
return node
end | ruby | def get_(i)
# return a Node
if i < (@length >> 1)
# go from the beginning
node = @first
i.times{node = node.next}
else
# go from the end
node = @last
(@length - 1 - i).times{node = node.prev}
end
return node
end | [
"def",
"get_",
"(",
"i",
")",
"if",
"i",
"<",
"(",
"@length",
">>",
"1",
")",
"node",
"=",
"@first",
"i",
".",
"times",
"{",
"node",
"=",
"node",
".",
"next",
"}",
"else",
"node",
"=",
"@last",
"(",
"@length",
"-",
"1",
"-",
"i",
")",
".",
... | Return the `i'th Node. Assume `i' is in 0...length. | [
"Return",
"the",
"i",
"th",
"Node",
".",
"Assume",
"i",
"is",
"in",
"0",
"...",
"length",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node_list.rb#L827-L839 | train |
spraints/resqued | lib/resqued/listener.rb | Resqued.Listener.exec | def exec
socket_fd = @socket.to_i
ENV['RESQUED_SOCKET'] = socket_fd.to_s
ENV['RESQUED_CONFIG_PATH'] = @config_paths.join(':')
ENV['RESQUED_STATE'] = (@old_workers.map { |r| "#{r[:pid]}|#{r[:queue]}" }.join('||'))
ENV['RESQUED_LISTENER_ID'] = @listener_id.to_s
ENV['RESQUED_... | ruby | def exec
socket_fd = @socket.to_i
ENV['RESQUED_SOCKET'] = socket_fd.to_s
ENV['RESQUED_CONFIG_PATH'] = @config_paths.join(':')
ENV['RESQUED_STATE'] = (@old_workers.map { |r| "#{r[:pid]}|#{r[:queue]}" }.join('||'))
ENV['RESQUED_LISTENER_ID'] = @listener_id.to_s
ENV['RESQUED_... | [
"def",
"exec",
"socket_fd",
"=",
"@socket",
".",
"to_i",
"ENV",
"[",
"'RESQUED_SOCKET'",
"]",
"=",
"socket_fd",
".",
"to_s",
"ENV",
"[",
"'RESQUED_CONFIG_PATH'",
"]",
"=",
"@config_paths",
".",
"join",
"(",
"':'",
")",
"ENV",
"[",
"'RESQUED_STATE'",
"]",
"... | Configure a new listener object.
Runs in the master process.
Public: As an alternative to #run, exec a new ruby instance for this listener.
Runs in the master process. | [
"Configure",
"a",
"new",
"listener",
"object",
"."
] | 5d95bdfe009ce99ae745af552b6446b1465a3eb8 | https://github.com/spraints/resqued/blob/5d95bdfe009ce99ae745af552b6446b1465a3eb8/lib/resqued/listener.rb#L31-L45 | train |
chemistrykit/chemistrykit | lib/chemistrykit/chemist.rb | ChemistryKit.Chemist.method_missing | def method_missing(name, *arguments)
value = arguments[0]
name = name.to_s
if name[-1, 1] == '='
key = name[/(.+)\s?=/, 1]
@data[key.to_sym] = value unless instance_variables.include? "@#{key}".to_sym
else
@data[name.to_sym]
end
end | ruby | def method_missing(name, *arguments)
value = arguments[0]
name = name.to_s
if name[-1, 1] == '='
key = name[/(.+)\s?=/, 1]
@data[key.to_sym] = value unless instance_variables.include? "@#{key}".to_sym
else
@data[name.to_sym]
end
end | [
"def",
"method_missing",
"(",
"name",
",",
"*",
"arguments",
")",
"value",
"=",
"arguments",
"[",
"0",
"]",
"name",
"=",
"name",
".",
"to_s",
"if",
"name",
"[",
"-",
"1",
",",
"1",
"]",
"==",
"'='",
"key",
"=",
"name",
"[",
"/",
"\\s",
"/",
","... | allow this object to be set with arbitrary key value data | [
"allow",
"this",
"object",
"to",
"be",
"set",
"with",
"arbitrary",
"key",
"value",
"data"
] | 99f0fe213c69595eb1f3efee514fd88c415ca34b | https://github.com/chemistrykit/chemistrykit/blob/99f0fe213c69595eb1f3efee514fd88c415ca34b/lib/chemistrykit/chemist.rb#L28-L37 | train |
jsl/placemaker | lib/placemaker/client.rb | Placemaker.Client.fetch! | def fetch!
fields = POST_FIELDS.reject{|f| @options[f].nil? }.map do |f|
# Change ruby-form fields to url type, e.g., document_content => documentContent
cgi_param = f.to_s.gsub(/\_(.)/) {|s| s.upcase}.gsub('_', '').sub(/url/i, 'URL')
Curl::PostField.content(cgi_param, @options[f])
e... | ruby | def fetch!
fields = POST_FIELDS.reject{|f| @options[f].nil? }.map do |f|
# Change ruby-form fields to url type, e.g., document_content => documentContent
cgi_param = f.to_s.gsub(/\_(.)/) {|s| s.upcase}.gsub('_', '').sub(/url/i, 'URL')
Curl::PostField.content(cgi_param, @options[f])
e... | [
"def",
"fetch!",
"fields",
"=",
"POST_FIELDS",
".",
"reject",
"{",
"|",
"f",
"|",
"@options",
"[",
"f",
"]",
".",
"nil?",
"}",
".",
"map",
"do",
"|",
"f",
"|",
"cgi_param",
"=",
"f",
".",
"to_s",
".",
"gsub",
"(",
"/",
"\\_",
"/",
")",
"{",
"... | Fetches the place information for input parameters from the Yahoo Placemaker service | [
"Fetches",
"the",
"place",
"information",
"for",
"input",
"parameters",
"from",
"the",
"Yahoo",
"Placemaker",
"service"
] | 5391ace291d94ffc77c0fa23322b1cdd46a753db | https://github.com/jsl/placemaker/blob/5391ace291d94ffc77c0fa23322b1cdd46a753db/lib/placemaker/client.rb#L21-L30 | train |
code-and-effect/effective_email_templates | lib/effective_email_templates/liquid_resolver.rb | EffectiveEmailTemplates.LiquidResolver.decorate | def decorate(templates, path_info, details, locals)
templates.each do |t|
t.locals = locals
end
end | ruby | def decorate(templates, path_info, details, locals)
templates.each do |t|
t.locals = locals
end
end | [
"def",
"decorate",
"(",
"templates",
",",
"path_info",
",",
"details",
",",
"locals",
")",
"templates",
".",
"each",
"do",
"|",
"t",
"|",
"t",
".",
"locals",
"=",
"locals",
"end",
"end"
] | Ensures all the resolver information is set in the template. | [
"Ensures",
"all",
"the",
"resolver",
"information",
"is",
"set",
"in",
"the",
"template",
"."
] | 1f76a16b1ce3d0db126c90056507302f66ff6d9e | https://github.com/code-and-effect/effective_email_templates/blob/1f76a16b1ce3d0db126c90056507302f66ff6d9e/lib/effective_email_templates/liquid_resolver.rb#L25-L29 | train |
pmviva/mention_system | lib/mention_system/mention_processor.rb | MentionSystem.MentionProcessor.extract_handles_from_mentioner | def extract_handles_from_mentioner(mentioner)
content = extract_mentioner_content(mentioner)
handles = content.scan(handle_regexp).map { |handle| handle.gsub("#{mention_prefix}","") }
end | ruby | def extract_handles_from_mentioner(mentioner)
content = extract_mentioner_content(mentioner)
handles = content.scan(handle_regexp).map { |handle| handle.gsub("#{mention_prefix}","") }
end | [
"def",
"extract_handles_from_mentioner",
"(",
"mentioner",
")",
"content",
"=",
"extract_mentioner_content",
"(",
"mentioner",
")",
"handles",
"=",
"content",
".",
"scan",
"(",
"handle_regexp",
")",
".",
"map",
"{",
"|",
"handle",
"|",
"handle",
".",
"gsub",
"... | Extract handles from mentioner
@param [Mentioner] mentioner - the {Mentioner} to extract handles from
@return [Array] | [
"Extract",
"handles",
"from",
"mentioner"
] | f5418c576b2e299539b10f8d4c9a49009a9662b7 | https://github.com/pmviva/mention_system/blob/f5418c576b2e299539b10f8d4c9a49009a9662b7/lib/mention_system/mention_processor.rb#L44-L47 | train |
pmviva/mention_system | lib/mention_system/mention_processor.rb | MentionSystem.MentionProcessor.process_after_callbacks | def process_after_callbacks(mentioner, mentionee)
result = true
@callbacks[:after].each do |callback|
unless callback.call(mentioner, mentionee)
result = false
break
end
end
result
end | ruby | def process_after_callbacks(mentioner, mentionee)
result = true
@callbacks[:after].each do |callback|
unless callback.call(mentioner, mentionee)
result = false
break
end
end
result
end | [
"def",
"process_after_callbacks",
"(",
"mentioner",
",",
"mentionee",
")",
"result",
"=",
"true",
"@callbacks",
"[",
":after",
"]",
".",
"each",
"do",
"|",
"callback",
"|",
"unless",
"callback",
".",
"call",
"(",
"mentioner",
",",
"mentionee",
")",
"result",... | Process after callbacks
@param [Mentioner] mentioner - the mentioner of the callback
@param [Mentionee] mentionee - the mentionee of the callback | [
"Process",
"after",
"callbacks"
] | f5418c576b2e299539b10f8d4c9a49009a9662b7 | https://github.com/pmviva/mention_system/blob/f5418c576b2e299539b10f8d4c9a49009a9662b7/lib/mention_system/mention_processor.rb#L112-L121 | train |
bjjb/ebayr | lib/ebayr/request.rb | Ebayr.Request.headers | def headers
{
'X-EBAY-API-COMPATIBILITY-LEVEL' => @compatability_level.to_s,
'X-EBAY-API-DEV-NAME' => dev_id.to_s,
'X-EBAY-API-APP-NAME' => app_id.to_s,
'X-EBAY-API-CERT-NAME' => cert_id.to_s,
'X-EBAY-API-CALL-NAME' => @command.to_s,
'X-EBAY-API-SITEID' => @site_id.... | ruby | def headers
{
'X-EBAY-API-COMPATIBILITY-LEVEL' => @compatability_level.to_s,
'X-EBAY-API-DEV-NAME' => dev_id.to_s,
'X-EBAY-API-APP-NAME' => app_id.to_s,
'X-EBAY-API-CERT-NAME' => cert_id.to_s,
'X-EBAY-API-CALL-NAME' => @command.to_s,
'X-EBAY-API-SITEID' => @site_id.... | [
"def",
"headers",
"{",
"'X-EBAY-API-COMPATIBILITY-LEVEL'",
"=>",
"@compatability_level",
".",
"to_s",
",",
"'X-EBAY-API-DEV-NAME'",
"=>",
"dev_id",
".",
"to_s",
",",
"'X-EBAY-API-APP-NAME'",
"=>",
"app_id",
".",
"to_s",
",",
"'X-EBAY-API-CERT-NAME'",
"=>",
"cert_id",
... | Gets the headers that will be sent with this request. | [
"Gets",
"the",
"headers",
"that",
"will",
"be",
"sent",
"with",
"this",
"request",
"."
] | 7dcfc95608399a0b2ad5e1ee625556200d5733e7 | https://github.com/bjjb/ebayr/blob/7dcfc95608399a0b2ad5e1ee625556200d5733e7/lib/ebayr/request.rb#L33-L43 | train |
bjjb/ebayr | lib/ebayr/request.rb | Ebayr.Request.http | def http(&block)
http = Net::HTTP.new(@uri.host, @uri.port)
if @uri.port == 443
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
return http.start(&block) if block_given?
http
end | ruby | def http(&block)
http = Net::HTTP.new(@uri.host, @uri.port)
if @uri.port == 443
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
return http.start(&block) if block_given?
http
end | [
"def",
"http",
"(",
"&",
"block",
")",
"http",
"=",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"@uri",
".",
"host",
",",
"@uri",
".",
"port",
")",
"if",
"@uri",
".",
"port",
"==",
"443",
"http",
".",
"use_ssl",
"=",
"true",
"http",
".",
"verify_mode",... | Gets a HTTP connection for this request. If you pass in a block, it will
be run on that HTTP connection. | [
"Gets",
"a",
"HTTP",
"connection",
"for",
"this",
"request",
".",
"If",
"you",
"pass",
"in",
"a",
"block",
"it",
"will",
"be",
"run",
"on",
"that",
"HTTP",
"connection",
"."
] | 7dcfc95608399a0b2ad5e1ee625556200d5733e7 | https://github.com/bjjb/ebayr/blob/7dcfc95608399a0b2ad5e1ee625556200d5733e7/lib/ebayr/request.rb#L144-L152 | train |
rightscale/right_api_client | lib/right_api_client/client.rb | RightApi.Client.retry_request | def retry_request(is_read_only = false)
attempts = 0
begin
yield
rescue OpenSSL::SSL::SSLError => e
raise e unless @enable_retry
# These errors pertain to the SSL handshake. Since no data has been
# exchanged its always safe to retry
raise e if attempts >= @max... | ruby | def retry_request(is_read_only = false)
attempts = 0
begin
yield
rescue OpenSSL::SSL::SSLError => e
raise e unless @enable_retry
# These errors pertain to the SSL handshake. Since no data has been
# exchanged its always safe to retry
raise e if attempts >= @max... | [
"def",
"retry_request",
"(",
"is_read_only",
"=",
"false",
")",
"attempts",
"=",
"0",
"begin",
"yield",
"rescue",
"OpenSSL",
"::",
"SSL",
"::",
"SSLError",
"=>",
"e",
"raise",
"e",
"unless",
"@enable_retry",
"raise",
"e",
"if",
"attempts",
">=",
"@max_attemp... | Users shouldn't need to call the following methods directly | [
"Users",
"shouldn",
"t",
"need",
"to",
"call",
"the",
"following",
"methods",
"directly"
] | 29534dcebbc96fc0727e2d57bac73e349a910f08 | https://github.com/rightscale/right_api_client/blob/29534dcebbc96fc0727e2d57bac73e349a910f08/lib/right_api_client/client.rb#L234-L269 | train |
rightscale/right_api_client | lib/right_api_client/client.rb | RightApi.Client.do_get | def do_get(path, params={})
login if need_login?
# Resource id is a special param as it needs to be added to the path
path = add_id_and_params_to_path(path, params)
req, res, resource_type, body = nil
begin
retry_request(true) do
# Return content type so the resulting ... | ruby | def do_get(path, params={})
login if need_login?
# Resource id is a special param as it needs to be added to the path
path = add_id_and_params_to_path(path, params)
req, res, resource_type, body = nil
begin
retry_request(true) do
# Return content type so the resulting ... | [
"def",
"do_get",
"(",
"path",
",",
"params",
"=",
"{",
"}",
")",
"login",
"if",
"need_login?",
"path",
"=",
"add_id_and_params_to_path",
"(",
"path",
",",
"params",
")",
"req",
",",
"res",
",",
"resource_type",
",",
"body",
"=",
"nil",
"begin",
"retry_re... | Generic get
params are NOT read only | [
"Generic",
"get",
"params",
"are",
"NOT",
"read",
"only"
] | 29534dcebbc96fc0727e2d57bac73e349a910f08 | https://github.com/rightscale/right_api_client/blob/29534dcebbc96fc0727e2d57bac73e349a910f08/lib/right_api_client/client.rb#L351-L412 | train |
rightscale/right_api_client | lib/right_api_client/client.rb | RightApi.Client.re_login? | def re_login?(e)
auth_error =
(e.response_code == 403 && e.message =~ %r(.*cookie is expired or invalid)) ||
e.response_code == 401
renewable_creds =
(@instance_token || (@email && (@password || @password_base64)) || @refresh_token)
auth_error && renewable_creds
end | ruby | def re_login?(e)
auth_error =
(e.response_code == 403 && e.message =~ %r(.*cookie is expired or invalid)) ||
e.response_code == 401
renewable_creds =
(@instance_token || (@email && (@password || @password_base64)) || @refresh_token)
auth_error && renewable_creds
end | [
"def",
"re_login?",
"(",
"e",
")",
"auth_error",
"=",
"(",
"e",
".",
"response_code",
"==",
"403",
"&&",
"e",
".",
"message",
"=~",
"%r(",
")",
")",
"||",
"e",
".",
"response_code",
"==",
"401",
"renewable_creds",
"=",
"(",
"@instance_token",
"||",
"("... | Determine whether an exception can be fixed by logging in again.
@param e [ApiError] the exception to check
@return [Boolean] true if re-login is appropriate | [
"Determine",
"whether",
"an",
"exception",
"can",
"be",
"fixed",
"by",
"logging",
"in",
"again",
"."
] | 29534dcebbc96fc0727e2d57bac73e349a910f08 | https://github.com/rightscale/right_api_client/blob/29534dcebbc96fc0727e2d57bac73e349a910f08/lib/right_api_client/client.rb#L576-L585 | train |
voxpupuli/ra10ke | lib/ra10ke/solve.rb | Ra10ke::Solve.RakeTask.get_version_req | def get_version_req(dep)
req = get_key_or_sym(dep, :version_requirement)
req = get_key_or_sym(dep, :version_range) unless req
req
end | ruby | def get_version_req(dep)
req = get_key_or_sym(dep, :version_requirement)
req = get_key_or_sym(dep, :version_range) unless req
req
end | [
"def",
"get_version_req",
"(",
"dep",
")",
"req",
"=",
"get_key_or_sym",
"(",
"dep",
",",
":version_requirement",
")",
"req",
"=",
"get_key_or_sym",
"(",
"dep",
",",
":version_range",
")",
"unless",
"req",
"req",
"end"
] | At least puppet-extlib has malformed metadata | [
"At",
"least",
"puppet",
"-",
"extlib",
"has",
"malformed",
"metadata"
] | b3955a76ee4f9200e5bfd046eb5a1dfdbd46f897 | https://github.com/voxpupuli/ra10ke/blob/b3955a76ee4f9200e5bfd046eb5a1dfdbd46f897/lib/ra10ke/solve.rb#L148-L152 | train |
prometheus-ev/jekyll-rendering | lib/jekyll/rendering.rb | Jekyll.Convertible.do_layout | def do_layout(payload, layouts)
info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
payload['pygments_prefix'] = converter.pygments_prefix
payload['pygments_suffix'] = converter.pygments_suffix
# render and transform content (this becomes the final content of the object)
... | ruby | def do_layout(payload, layouts)
info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
payload['pygments_prefix'] = converter.pygments_prefix
payload['pygments_suffix'] = converter.pygments_suffix
# render and transform content (this becomes the final content of the object)
... | [
"def",
"do_layout",
"(",
"payload",
",",
"layouts",
")",
"info",
"=",
"{",
":filters",
"=>",
"[",
"Jekyll",
"::",
"Filters",
"]",
",",
":registers",
"=>",
"{",
":site",
"=>",
"site",
"}",
"}",
"payload",
"[",
"'pygments_prefix'",
"]",
"=",
"converter",
... | Overwrites the original method to use the configured rendering engine. | [
"Overwrites",
"the",
"original",
"method",
"to",
"use",
"the",
"configured",
"rendering",
"engine",
"."
] | 977c1ac2260f9e12a7eeb803ed52bf1bef57ff21 | https://github.com/prometheus-ev/jekyll-rendering/blob/977c1ac2260f9e12a7eeb803ed52bf1bef57ff21/lib/jekyll/rendering.rb#L55-L75 | train |
socketry/lightio | lib/lightio/watchers/io.rb | LightIO::Watchers.IO.monitor | def monitor(interests=:rw)
@monitor ||= begin
raise @error if @error
monitor = @ioloop.add_io_wait(@io, interests) {callback_on_waiting}
ObjectSpace.define_finalizer(self, self.class.finalizer(monitor))
monitor
end
end | ruby | def monitor(interests=:rw)
@monitor ||= begin
raise @error if @error
monitor = @ioloop.add_io_wait(@io, interests) {callback_on_waiting}
ObjectSpace.define_finalizer(self, self.class.finalizer(monitor))
monitor
end
end | [
"def",
"monitor",
"(",
"interests",
"=",
":rw",
")",
"@monitor",
"||=",
"begin",
"raise",
"@error",
"if",
"@error",
"monitor",
"=",
"@ioloop",
".",
"add_io_wait",
"(",
"@io",
",",
"interests",
")",
"{",
"callback_on_waiting",
"}",
"ObjectSpace",
".",
"define... | Create a io watcher
@param [Socket] io An IO-able object
@param [Symbol] interests :r, :w, :rw - Is io readable? writeable? or both
@return [LightIO::Watchers::IO]
NIO::Monitor | [
"Create",
"a",
"io",
"watcher"
] | dd99c751a003d68234dd5ce1e3ecf1b7530b98b4 | https://github.com/socketry/lightio/blob/dd99c751a003d68234dd5ce1e3ecf1b7530b98b4/lib/lightio/watchers/io.rb#L31-L38 | train |
socketry/lightio | lib/lightio/watchers/io.rb | LightIO::Watchers.IO.wait_in_ioloop | def wait_in_ioloop
raise LightIO::Error, "Watchers::IO can't cross threads" if @ioloop != LightIO::Core::IOloop.current
raise EOFError, "can't wait closed IO watcher" if @monitor.closed?
@ioloop.wait(self)
end | ruby | def wait_in_ioloop
raise LightIO::Error, "Watchers::IO can't cross threads" if @ioloop != LightIO::Core::IOloop.current
raise EOFError, "can't wait closed IO watcher" if @monitor.closed?
@ioloop.wait(self)
end | [
"def",
"wait_in_ioloop",
"raise",
"LightIO",
"::",
"Error",
",",
"\"Watchers::IO can't cross threads\"",
"if",
"@ioloop",
"!=",
"LightIO",
"::",
"Core",
"::",
"IOloop",
".",
"current",
"raise",
"EOFError",
",",
"\"can't wait closed IO watcher\"",
"if",
"@monitor",
"."... | Blocking until io interests is satisfied | [
"Blocking",
"until",
"io",
"interests",
"is",
"satisfied"
] | dd99c751a003d68234dd5ce1e3ecf1b7530b98b4 | https://github.com/socketry/lightio/blob/dd99c751a003d68234dd5ce1e3ecf1b7530b98b4/lib/lightio/watchers/io.rb#L155-L159 | train |
code-and-effect/effective_orders | app/models/effective/order.rb | Effective.Order.assign_confirmed_if_valid! | def assign_confirmed_if_valid!
return unless pending?
self.state = EffectiveOrders::CONFIRMED
return true if valid?
self.errors.clear
self.state = EffectiveOrders::PENDING
false
end | ruby | def assign_confirmed_if_valid!
return unless pending?
self.state = EffectiveOrders::CONFIRMED
return true if valid?
self.errors.clear
self.state = EffectiveOrders::PENDING
false
end | [
"def",
"assign_confirmed_if_valid!",
"return",
"unless",
"pending?",
"self",
".",
"state",
"=",
"EffectiveOrders",
"::",
"CONFIRMED",
"return",
"true",
"if",
"valid?",
"self",
".",
"errors",
".",
"clear",
"self",
".",
"state",
"=",
"EffectiveOrders",
"::",
"PEND... | This lets us skip to the confirmed workflow for an admin... | [
"This",
"lets",
"us",
"skip",
"to",
"the",
"confirmed",
"workflow",
"for",
"an",
"admin",
"..."
] | 60eb8570b41080795448ae9c75e7da4da9edae9b | https://github.com/code-and-effect/effective_orders/blob/60eb8570b41080795448ae9c75e7da4da9edae9b/app/models/effective/order.rb#L300-L309 | train |
code-and-effect/effective_orders | app/models/effective/subscripter.rb | Effective.Subscripter.create_stripe_token! | def create_stripe_token!
return if stripe_token.blank?
Rails.logger.info "[STRIPE] update source: #{stripe_token}"
customer.stripe_customer.source = stripe_token
customer.stripe_customer.save
return if customer.stripe_customer.default_source.blank?
card = customer.stripe_customer.... | ruby | def create_stripe_token!
return if stripe_token.blank?
Rails.logger.info "[STRIPE] update source: #{stripe_token}"
customer.stripe_customer.source = stripe_token
customer.stripe_customer.save
return if customer.stripe_customer.default_source.blank?
card = customer.stripe_customer.... | [
"def",
"create_stripe_token!",
"return",
"if",
"stripe_token",
".",
"blank?",
"Rails",
".",
"logger",
".",
"info",
"\"[STRIPE] update source: #{stripe_token}\"",
"customer",
".",
"stripe_customer",
".",
"source",
"=",
"stripe_token",
"customer",
".",
"stripe_customer",
... | Update stripe customer card | [
"Update",
"stripe",
"customer",
"card"
] | 60eb8570b41080795448ae9c75e7da4da9edae9b | https://github.com/code-and-effect/effective_orders/blob/60eb8570b41080795448ae9c75e7da4da9edae9b/app/models/effective/subscripter.rb#L87-L99 | train |
code-and-effect/effective_orders | app/models/effective/subscripter.rb | Effective.Subscripter.metadata | def metadata
{
:user_id => user.id.to_s,
:user => user.to_s.truncate(500),
(subscription.subscribable_type.downcase + '_id').to_sym => subscription.subscribable.id.to_s,
subscription.subscribable_type.downcase.to_sym => subscription.subscribable.to_s
}
end | ruby | def metadata
{
:user_id => user.id.to_s,
:user => user.to_s.truncate(500),
(subscription.subscribable_type.downcase + '_id').to_sym => subscription.subscribable.id.to_s,
subscription.subscribable_type.downcase.to_sym => subscription.subscribable.to_s
}
end | [
"def",
"metadata",
"{",
":user_id",
"=>",
"user",
".",
"id",
".",
"to_s",
",",
":user",
"=>",
"user",
".",
"to_s",
".",
"truncate",
"(",
"500",
")",
",",
"(",
"subscription",
".",
"subscribable_type",
".",
"downcase",
"+",
"'_id'",
")",
".",
"to_sym",
... | The stripe metadata limit is 500 characters | [
"The",
"stripe",
"metadata",
"limit",
"is",
"500",
"characters"
] | 60eb8570b41080795448ae9c75e7da4da9edae9b | https://github.com/code-and-effect/effective_orders/blob/60eb8570b41080795448ae9c75e7da4da9edae9b/app/models/effective/subscripter.rb#L176-L183 | train |
futurechimp/plissken | lib/plissken/methods.rb | Plissken.Methods.to_snake_keys | def to_snake_keys(value = self)
case value
when Array
value.map { |v| to_snake_keys(v) }
when Hash
snake_hash(value)
else
value
end
end | ruby | def to_snake_keys(value = self)
case value
when Array
value.map { |v| to_snake_keys(v) }
when Hash
snake_hash(value)
else
value
end
end | [
"def",
"to_snake_keys",
"(",
"value",
"=",
"self",
")",
"case",
"value",
"when",
"Array",
"value",
".",
"map",
"{",
"|",
"v",
"|",
"to_snake_keys",
"(",
"v",
")",
"}",
"when",
"Hash",
"snake_hash",
"(",
"value",
")",
"else",
"value",
"end",
"end"
] | Recursively converts CamelCase and camelBack JSON-style hash keys to
Rubyish snake_case, suitable for use during instantiation of Ruby
model attributes. | [
"Recursively",
"converts",
"CamelCase",
"and",
"camelBack",
"JSON",
"-",
"style",
"hash",
"keys",
"to",
"Rubyish",
"snake_case",
"suitable",
"for",
"use",
"during",
"instantiation",
"of",
"Ruby",
"model",
"attributes",
"."
] | ec4cc2f9005e2b4bde421243918d7c75be04b679 | https://github.com/futurechimp/plissken/blob/ec4cc2f9005e2b4bde421243918d7c75be04b679/lib/plissken/methods.rb#L9-L18 | train |
code-and-effect/effective_orders | app/controllers/effective/orders_controller.rb | Effective.OrdersController.new | def new
@order ||= Effective::Order.new(view_context.current_cart)
EffectiveOrders.authorize!(self, :new, @order)
unless @order.valid?
flash[:danger] = "Unable to proceed: #{flash_errors(@order)}. Please try again."
redirect_to(effective_orders.cart_path)
return
end
... | ruby | def new
@order ||= Effective::Order.new(view_context.current_cart)
EffectiveOrders.authorize!(self, :new, @order)
unless @order.valid?
flash[:danger] = "Unable to proceed: #{flash_errors(@order)}. Please try again."
redirect_to(effective_orders.cart_path)
return
end
... | [
"def",
"new",
"@order",
"||=",
"Effective",
"::",
"Order",
".",
"new",
"(",
"view_context",
".",
"current_cart",
")",
"EffectiveOrders",
".",
"authorize!",
"(",
"self",
",",
":new",
",",
"@order",
")",
"unless",
"@order",
".",
"valid?",
"flash",
"[",
":dan... | If you want to use the Add to Cart -> Checkout flow
Add one or more items however you do.
redirect_to effective_orders.new_order_path, which is here.
This is the entry point for any Checkout button.
It displayes an order based on the cart
Always step1 | [
"If",
"you",
"want",
"to",
"use",
"the",
"Add",
"to",
"Cart",
"-",
">",
"Checkout",
"flow",
"Add",
"one",
"or",
"more",
"items",
"however",
"you",
"do",
".",
"redirect_to",
"effective_orders",
".",
"new_order_path",
"which",
"is",
"here",
".",
"This",
"i... | 60eb8570b41080795448ae9c75e7da4da9edae9b | https://github.com/code-and-effect/effective_orders/blob/60eb8570b41080795448ae9c75e7da4da9edae9b/app/controllers/effective/orders_controller.rb#L25-L35 | train |
code-and-effect/effective_orders | app/controllers/effective/orders_controller.rb | Effective.OrdersController.create | def create
@order ||= Effective::Order.new(view_context.current_cart)
EffectiveOrders.authorize!(self, :create, @order)
@order.assign_attributes(checkout_params)
if (@order.confirm! rescue false)
redirect_to(effective_orders.order_path(@order))
else
flash.now[:danger] = "... | ruby | def create
@order ||= Effective::Order.new(view_context.current_cart)
EffectiveOrders.authorize!(self, :create, @order)
@order.assign_attributes(checkout_params)
if (@order.confirm! rescue false)
redirect_to(effective_orders.order_path(@order))
else
flash.now[:danger] = "... | [
"def",
"create",
"@order",
"||=",
"Effective",
"::",
"Order",
".",
"new",
"(",
"view_context",
".",
"current_cart",
")",
"EffectiveOrders",
".",
"authorize!",
"(",
"self",
",",
":create",
",",
"@order",
")",
"@order",
".",
"assign_attributes",
"(",
"checkout_p... | Confirms an order from the cart. | [
"Confirms",
"an",
"order",
"from",
"the",
"cart",
"."
] | 60eb8570b41080795448ae9c75e7da4da9edae9b | https://github.com/code-and-effect/effective_orders/blob/60eb8570b41080795448ae9c75e7da4da9edae9b/app/controllers/effective/orders_controller.rb#L38-L50 | train |
code-and-effect/effective_orders | app/controllers/effective/orders_controller.rb | Effective.OrdersController.update | def update
@order ||= Effective::Order.find(params[:id])
EffectiveOrders.authorize!(self, :update, @order)
@order.assign_attributes(checkout_params)
if (@order.confirm! rescue false)
redirect_to(effective_orders.order_path(@order))
else
flash.now[:danger] = "Unable to pro... | ruby | def update
@order ||= Effective::Order.find(params[:id])
EffectiveOrders.authorize!(self, :update, @order)
@order.assign_attributes(checkout_params)
if (@order.confirm! rescue false)
redirect_to(effective_orders.order_path(@order))
else
flash.now[:danger] = "Unable to pro... | [
"def",
"update",
"@order",
"||=",
"Effective",
"::",
"Order",
".",
"find",
"(",
"params",
"[",
":id",
"]",
")",
"EffectiveOrders",
".",
"authorize!",
"(",
"self",
",",
":update",
",",
"@order",
")",
"@order",
".",
"assign_attributes",
"(",
"checkout_params",... | Confirms the order from existing order | [
"Confirms",
"the",
"order",
"from",
"existing",
"order"
] | 60eb8570b41080795448ae9c75e7da4da9edae9b | https://github.com/code-and-effect/effective_orders/blob/60eb8570b41080795448ae9c75e7da4da9edae9b/app/controllers/effective/orders_controller.rb#L71-L83 | train |
code-and-effect/effective_orders | app/controllers/effective/orders_controller.rb | Effective.OrdersController.index | def index
@orders = Effective::Order.deep.purchased.where(user: current_user)
@pending_orders = Effective::Order.deep.pending.where(user: current_user)
EffectiveOrders.authorize!(self, :index, Effective::Order.new(user: current_user))
end | ruby | def index
@orders = Effective::Order.deep.purchased.where(user: current_user)
@pending_orders = Effective::Order.deep.pending.where(user: current_user)
EffectiveOrders.authorize!(self, :index, Effective::Order.new(user: current_user))
end | [
"def",
"index",
"@orders",
"=",
"Effective",
"::",
"Order",
".",
"deep",
".",
"purchased",
".",
"where",
"(",
"user",
":",
"current_user",
")",
"@pending_orders",
"=",
"Effective",
"::",
"Order",
".",
"deep",
".",
"pending",
".",
"where",
"(",
"user",
":... | My Orders History | [
"My",
"Orders",
"History"
] | 60eb8570b41080795448ae9c75e7da4da9edae9b | https://github.com/code-and-effect/effective_orders/blob/60eb8570b41080795448ae9c75e7da4da9edae9b/app/controllers/effective/orders_controller.rb#L86-L91 | train |
code-and-effect/effective_orders | app/controllers/effective/orders_controller.rb | Effective.OrdersController.purchased | def purchased # Thank You!
@order = if params[:id].present?
Effective::Order.find(params[:id])
elsif current_user.present?
Effective::Order.sorted.purchased_by(current_user).last
end
if @order.blank?
redirect_to(effective_orders.orders_path) and return
end
E... | ruby | def purchased # Thank You!
@order = if params[:id].present?
Effective::Order.find(params[:id])
elsif current_user.present?
Effective::Order.sorted.purchased_by(current_user).last
end
if @order.blank?
redirect_to(effective_orders.orders_path) and return
end
E... | [
"def",
"purchased",
"@order",
"=",
"if",
"params",
"[",
":id",
"]",
".",
"present?",
"Effective",
"::",
"Order",
".",
"find",
"(",
"params",
"[",
":id",
"]",
")",
"elsif",
"current_user",
".",
"present?",
"Effective",
"::",
"Order",
".",
"sorted",
".",
... | Thank you for Purchasing this Order. This is where a successfully purchased order ends up | [
"Thank",
"you",
"for",
"Purchasing",
"this",
"Order",
".",
"This",
"is",
"where",
"a",
"successfully",
"purchased",
"order",
"ends",
"up"
] | 60eb8570b41080795448ae9c75e7da4da9edae9b | https://github.com/code-and-effect/effective_orders/blob/60eb8570b41080795448ae9c75e7da4da9edae9b/app/controllers/effective/orders_controller.rb#L94-L108 | train |
code-and-effect/effective_orders | app/models/effective/cart.rb | Effective.Cart.add | def add(item, quantity: 1, unique: true)
raise 'expecting an acts_as_purchasable object' unless item.kind_of?(ActsAsPurchasable)
existing = (
if unique.kind_of?(Proc)
cart_items.find { |cart_item| instance_exec(item, cart_item.purchasable, &unique) }
elsif unique.kind_of?(Symbol) ... | ruby | def add(item, quantity: 1, unique: true)
raise 'expecting an acts_as_purchasable object' unless item.kind_of?(ActsAsPurchasable)
existing = (
if unique.kind_of?(Proc)
cart_items.find { |cart_item| instance_exec(item, cart_item.purchasable, &unique) }
elsif unique.kind_of?(Symbol) ... | [
"def",
"add",
"(",
"item",
",",
"quantity",
":",
"1",
",",
"unique",
":",
"true",
")",
"raise",
"'expecting an acts_as_purchasable object'",
"unless",
"item",
".",
"kind_of?",
"(",
"ActsAsPurchasable",
")",
"existing",
"=",
"(",
"if",
"unique",
".",
"kind_of?"... | cart.add(@product, unique: -> (a, b) { a.kind_of?(Product) && b.kind_of?(Product) && a.category == b.category })
cart.add(@product, unique: :category)
cart.add(@product, unique: false) # Add as many as you want | [
"cart",
".",
"add",
"("
] | 60eb8570b41080795448ae9c75e7da4da9edae9b | https://github.com/code-and-effect/effective_orders/blob/60eb8570b41080795448ae9c75e7da4da9edae9b/app/models/effective/cart.rb#L19-L47 | train |
code-and-effect/effective_orders | app/mailers/effective/orders_mailer.rb | Effective.OrdersMailer.pending_order_invoice_to_buyer | def pending_order_invoice_to_buyer(order_param)
return true unless EffectiveOrders.mailer[:send_pending_order_invoice_to_buyer]
@order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
@user = @order.user
@subject = subject_for(@order, :pending_order... | ruby | def pending_order_invoice_to_buyer(order_param)
return true unless EffectiveOrders.mailer[:send_pending_order_invoice_to_buyer]
@order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
@user = @order.user
@subject = subject_for(@order, :pending_order... | [
"def",
"pending_order_invoice_to_buyer",
"(",
"order_param",
")",
"return",
"true",
"unless",
"EffectiveOrders",
".",
"mailer",
"[",
":send_pending_order_invoice_to_buyer",
"]",
"@order",
"=",
"(",
"order_param",
".",
"kind_of?",
"(",
"Effective",
"::",
"Order",
")",
... | This is sent when someone chooses to Pay by Cheque | [
"This",
"is",
"sent",
"when",
"someone",
"chooses",
"to",
"Pay",
"by",
"Cheque"
] | 60eb8570b41080795448ae9c75e7da4da9edae9b | https://github.com/code-and-effect/effective_orders/blob/60eb8570b41080795448ae9c75e7da4da9edae9b/app/mailers/effective/orders_mailer.rb#L44-L53 | train |
code-and-effect/effective_orders | app/mailers/effective/orders_mailer.rb | Effective.OrdersMailer.subscription_payment_succeeded | def subscription_payment_succeeded(customer_param)
return true unless EffectiveOrders.mailer[:send_subscription_payment_succeeded]
@customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
@subscriptions = @customer.subscriptions
@use... | ruby | def subscription_payment_succeeded(customer_param)
return true unless EffectiveOrders.mailer[:send_subscription_payment_succeeded]
@customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
@subscriptions = @customer.subscriptions
@use... | [
"def",
"subscription_payment_succeeded",
"(",
"customer_param",
")",
"return",
"true",
"unless",
"EffectiveOrders",
".",
"mailer",
"[",
":send_subscription_payment_succeeded",
"]",
"@customer",
"=",
"(",
"customer_param",
".",
"kind_of?",
"(",
"Effective",
"::",
"Custom... | Sent by the invoice.payment_succeeded webhook event | [
"Sent",
"by",
"the",
"invoice",
".",
"payment_succeeded",
"webhook",
"event"
] | 60eb8570b41080795448ae9c75e7da4da9edae9b | https://github.com/code-and-effect/effective_orders/blob/60eb8570b41080795448ae9c75e7da4da9edae9b/app/mailers/effective/orders_mailer.rb#L56-L66 | train |
molybdenum-99/infoboxer | lib/infoboxer/media_wiki.rb | Infoboxer.MediaWiki.get | def get(*titles, interwiki: nil, &processor)
return interwikis(interwiki).get(*titles, &processor) if interwiki
pages = get_h(*titles, &processor).values.compact
titles.count == 1 ? pages.first : Tree::Nodes[*pages]
end | ruby | def get(*titles, interwiki: nil, &processor)
return interwikis(interwiki).get(*titles, &processor) if interwiki
pages = get_h(*titles, &processor).values.compact
titles.count == 1 ? pages.first : Tree::Nodes[*pages]
end | [
"def",
"get",
"(",
"*",
"titles",
",",
"interwiki",
":",
"nil",
",",
"&",
"processor",
")",
"return",
"interwikis",
"(",
"interwiki",
")",
".",
"get",
"(",
"*",
"titles",
",",
"&",
"processor",
")",
"if",
"interwiki",
"pages",
"=",
"get_h",
"(",
"*",... | Receive list of parsed MediaWiki pages for list of titles provided.
All pages are received with single query to MediaWiki API.
**NB**: if you are requesting more than 50 titles at once
(MediaWiki limitation for single request), Infoboxer will do as
many queries as necessary to extract them all (it will be like
`(... | [
"Receive",
"list",
"of",
"parsed",
"MediaWiki",
"pages",
"for",
"list",
"of",
"titles",
"provided",
".",
"All",
"pages",
"are",
"received",
"with",
"single",
"query",
"to",
"MediaWiki",
"API",
"."
] | 17038b385dbd2ee6e8e8b3744d0c908ef9abdd38 | https://github.com/molybdenum-99/infoboxer/blob/17038b385dbd2ee6e8e8b3744d0c908ef9abdd38/lib/infoboxer/media_wiki.rb#L128-L133 | train |
molybdenum-99/infoboxer | lib/infoboxer/media_wiki.rb | Infoboxer.MediaWiki.category | def category(title, limit: 'max', &processor)
title = normalize_category_title(title)
list(@api.query.generator(:categorymembers).title(title), limit, &processor)
end | ruby | def category(title, limit: 'max', &processor)
title = normalize_category_title(title)
list(@api.query.generator(:categorymembers).title(title), limit, &processor)
end | [
"def",
"category",
"(",
"title",
",",
"limit",
":",
"'max'",
",",
"&",
"processor",
")",
"title",
"=",
"normalize_category_title",
"(",
"title",
")",
"list",
"(",
"@api",
".",
"query",
".",
"generator",
"(",
":categorymembers",
")",
".",
"title",
"(",
"t... | Receive list of parsed MediaWiki pages from specified category.
@param title [String] Category title. You can use namespaceless title (like
`"Countries in South America"`), title with namespace (like
`"Category:Countries in South America"`) or title with local
namespace (like `"Catégorie:Argentine"` fo... | [
"Receive",
"list",
"of",
"parsed",
"MediaWiki",
"pages",
"from",
"specified",
"category",
"."
] | 17038b385dbd2ee6e8e8b3744d0c908ef9abdd38 | https://github.com/molybdenum-99/infoboxer/blob/17038b385dbd2ee6e8e8b3744d0c908ef9abdd38/lib/infoboxer/media_wiki.rb#L176-L180 | train |
socketry/lightio | lib/lightio/core/beam.rb | LightIO::Core.Beam.join | def join(limit=nil)
# try directly get result
if !alive? || limit.nil? || limit <= 0
# call value to raise error
value
return self
end
# return to current beam if beam done within time limit
origin_parent = parent
self.parent = Beam.current
# set a tran... | ruby | def join(limit=nil)
# try directly get result
if !alive? || limit.nil? || limit <= 0
# call value to raise error
value
return self
end
# return to current beam if beam done within time limit
origin_parent = parent
self.parent = Beam.current
# set a tran... | [
"def",
"join",
"(",
"limit",
"=",
"nil",
")",
"if",
"!",
"alive?",
"||",
"limit",
".",
"nil?",
"||",
"limit",
"<=",
"0",
"value",
"return",
"self",
"end",
"origin_parent",
"=",
"parent",
"self",
".",
"parent",
"=",
"Beam",
".",
"current",
"timer",
"=... | Block and wait beam dead
@param [Numeric] limit wait limit seconds if limit > 0, return nil if beam still alive, else return beam self
@return [Beam, nil] | [
"Block",
"and",
"wait",
"beam",
"dead"
] | dd99c751a003d68234dd5ce1e3ecf1b7530b98b4 | https://github.com/socketry/lightio/blob/dd99c751a003d68234dd5ce1e3ecf1b7530b98b4/lib/lightio/core/beam.rb#L83-L113 | train |
socketry/lightio | lib/lightio/core/beam.rb | LightIO::Core.Beam.raise | def raise(error, message=nil, backtrace=nil)
unless error.is_a?(BeamError)
message ||= error.respond_to?(:message) ? error.message : nil
backtrace ||= error.respond_to?(:backtrace) ? error.backtrace : nil
super(error, message, backtrace)
end
self.parent = error.parent if error.... | ruby | def raise(error, message=nil, backtrace=nil)
unless error.is_a?(BeamError)
message ||= error.respond_to?(:message) ? error.message : nil
backtrace ||= error.respond_to?(:backtrace) ? error.backtrace : nil
super(error, message, backtrace)
end
self.parent = error.parent if error.... | [
"def",
"raise",
"(",
"error",
",",
"message",
"=",
"nil",
",",
"backtrace",
"=",
"nil",
")",
"unless",
"error",
".",
"is_a?",
"(",
"BeamError",
")",
"message",
"||=",
"error",
".",
"respond_to?",
"(",
":message",
")",
"?",
"error",
".",
"message",
":",... | Fiber not provide raise method, so we have to simulate one
@param [BeamError] error currently only support raise BeamError | [
"Fiber",
"not",
"provide",
"raise",
"method",
"so",
"we",
"have",
"to",
"simulate",
"one"
] | dd99c751a003d68234dd5ce1e3ecf1b7530b98b4 | https://github.com/socketry/lightio/blob/dd99c751a003d68234dd5ce1e3ecf1b7530b98b4/lib/lightio/core/beam.rb#L126-L138 | train |
socketry/lightio | lib/lightio/wrap.rb | LightIO::Wrap.IOWrapper.wait_nonblock | def wait_nonblock(method, *args)
loop do
result = __send__(method, *args, exception: false)
case result
when :wait_readable
io_watcher.wait_readable
when :wait_writable
io_watcher.wait_writable
else
return result
end
e... | ruby | def wait_nonblock(method, *args)
loop do
result = __send__(method, *args, exception: false)
case result
when :wait_readable
io_watcher.wait_readable
when :wait_writable
io_watcher.wait_writable
else
return result
end
e... | [
"def",
"wait_nonblock",
"(",
"method",
",",
"*",
"args",
")",
"loop",
"do",
"result",
"=",
"__send__",
"(",
"method",
",",
"*",
"args",
",",
"exception",
":",
"false",
")",
"case",
"result",
"when",
":wait_readable",
"io_watcher",
".",
"wait_readable",
"wh... | wait io nonblock method
@param [Symbol] method method name, example: wait_nonblock
@param [args] args arguments pass to method | [
"wait",
"io",
"nonblock",
"method"
] | dd99c751a003d68234dd5ce1e3ecf1b7530b98b4 | https://github.com/socketry/lightio/blob/dd99c751a003d68234dd5ce1e3ecf1b7530b98b4/lib/lightio/wrap.rb#L37-L49 | train |
sosedoff/app-config | lib/app-config/processor.rb | AppConfig.Processor.process_array | def process_array(value)
value.split("\n").map { |s| s.to_s.strip }.compact.select { |s| !s.empty? }
end | ruby | def process_array(value)
value.split("\n").map { |s| s.to_s.strip }.compact.select { |s| !s.empty? }
end | [
"def",
"process_array",
"(",
"value",
")",
"value",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"map",
"{",
"|",
"s",
"|",
"s",
".",
"to_s",
".",
"strip",
"}",
".",
"compact",
".",
"select",
"{",
"|",
"s",
"|",
"!",
"s",
".",
"empty?",
"}",
"end"
] | Process array of strings | [
"Process",
"array",
"of",
"strings"
] | 3349f64539b8896da226060ca7263f929173b1e0 | https://github.com/sosedoff/app-config/blob/3349f64539b8896da226060ca7263f929173b1e0/lib/app-config/processor.rb#L9-L11 | train |
sosedoff/app-config | lib/app-config/processor.rb | AppConfig.Processor.process | def process(data, type)
raise InvalidType, 'Type is invalid!' unless FORMATS.include?(type)
send("process_#{type}".to_sym, data.to_s)
end | ruby | def process(data, type)
raise InvalidType, 'Type is invalid!' unless FORMATS.include?(type)
send("process_#{type}".to_sym, data.to_s)
end | [
"def",
"process",
"(",
"data",
",",
"type",
")",
"raise",
"InvalidType",
",",
"'Type is invalid!'",
"unless",
"FORMATS",
".",
"include?",
"(",
"type",
")",
"send",
"(",
"\"process_#{type}\"",
".",
"to_sym",
",",
"data",
".",
"to_s",
")",
"end"
] | Process data value for the format | [
"Process",
"data",
"value",
"for",
"the",
"format"
] | 3349f64539b8896da226060ca7263f929173b1e0 | https://github.com/sosedoff/app-config/blob/3349f64539b8896da226060ca7263f929173b1e0/lib/app-config/processor.rb#L33-L36 | train |
StemboltHQ/solidus-adyen | lib/solidus_adyen/account_locator.rb | SolidusAdyen.AccountLocator.by_reference | def by_reference(psp_reference)
code = Spree::Store.
joins(orders: :payments).
find_by(spree_payments: { response_code: psp_reference }).
try!(:code)
by_store_code(code)
end | ruby | def by_reference(psp_reference)
code = Spree::Store.
joins(orders: :payments).
find_by(spree_payments: { response_code: psp_reference }).
try!(:code)
by_store_code(code)
end | [
"def",
"by_reference",
"(",
"psp_reference",
")",
"code",
"=",
"Spree",
"::",
"Store",
".",
"joins",
"(",
"orders",
":",
":payments",
")",
".",
"find_by",
"(",
"spree_payments",
":",
"{",
"response_code",
":",
"psp_reference",
"}",
")",
".",
"try!",
"(",
... | Creates a new merchant account locator.
@param store_account_map [Hash] a hash mapping store codes to merchant accounts
@param default_account [String] the default merchant account to use
Tries to find a store that has a payment with the given psp reference. If
one exists, returns the merchant account for that sto... | [
"Creates",
"a",
"new",
"merchant",
"account",
"locator",
"."
] | 68dd710b0a23435eedc3cc0b4b0ec5b45aa37180 | https://github.com/StemboltHQ/solidus-adyen/blob/68dd710b0a23435eedc3cc0b4b0ec5b45aa37180/lib/solidus_adyen/account_locator.rb#L28-L35 | train |
robertwahler/win32-autogui | lib/win32/autogui/window.rb | Autogui.Window.close | def close(options={})
PostMessage(handle, WM_SYSCOMMAND, SC_CLOSE, 0)
wait_for_close(options) if (options[:wait_for_close] == true)
end | ruby | def close(options={})
PostMessage(handle, WM_SYSCOMMAND, SC_CLOSE, 0)
wait_for_close(options) if (options[:wait_for_close] == true)
end | [
"def",
"close",
"(",
"options",
"=",
"{",
"}",
")",
"PostMessage",
"(",
"handle",
",",
"WM_SYSCOMMAND",
",",
"SC_CLOSE",
",",
"0",
")",
"wait_for_close",
"(",
"options",
")",
"if",
"(",
"options",
"[",
":wait_for_close",
"]",
"==",
"true",
")",
"end"
] | PostMessage SC_CLOSE and optionally wait for the window to close
@param [Hash] options
@option options [Boolean] :wait_for_close (true) sleep while waiting for timeout or close
@option options [Boolean] :timeout (5) wait_for_close timeout in seconds | [
"PostMessage",
"SC_CLOSE",
"and",
"optionally",
"wait",
"for",
"the",
"window",
"to",
"close"
] | f36dc7ed9d7389893b0960b2c5740338f0d38117 | https://github.com/robertwahler/win32-autogui/blob/f36dc7ed9d7389893b0960b2c5740338f0d38117/lib/win32/autogui/window.rb#L116-L119 | train |
robertwahler/win32-autogui | lib/win32/autogui/window.rb | Autogui.Window.wait_for_close | def wait_for_close(options={})
seconds = options[:timeout] || 5
timeout(seconds) do
begin
yield if block_given?
sleep 0.05
end until 0 == IsWindow(handle)
end
end | ruby | def wait_for_close(options={})
seconds = options[:timeout] || 5
timeout(seconds) do
begin
yield if block_given?
sleep 0.05
end until 0 == IsWindow(handle)
end
end | [
"def",
"wait_for_close",
"(",
"options",
"=",
"{",
"}",
")",
"seconds",
"=",
"options",
"[",
":timeout",
"]",
"||",
"5",
"timeout",
"(",
"seconds",
")",
"do",
"begin",
"yield",
"if",
"block_given?",
"sleep",
"0.05",
"end",
"until",
"0",
"==",
"IsWindow",... | Wait for the window to close
@param [Hash] options
@option options [Boolean] :timeout (5) timeout in seconds | [
"Wait",
"for",
"the",
"window",
"to",
"close"
] | f36dc7ed9d7389893b0960b2c5740338f0d38117 | https://github.com/robertwahler/win32-autogui/blob/f36dc7ed9d7389893b0960b2c5740338f0d38117/lib/win32/autogui/window.rb#L126-L134 | train |
robertwahler/win32-autogui | lib/win32/autogui/window.rb | Autogui.Window.set_focus | def set_focus
if is_window?
# if current process was the last to receive input, we can be sure that
# SetForegroundWindow will be allowed. Send the shift key to whatever has
# the focus now. This allows IRB to set_focus.
keystroke(VK_SHIFT)
ret = SetForegroundWindow(handl... | ruby | def set_focus
if is_window?
# if current process was the last to receive input, we can be sure that
# SetForegroundWindow will be allowed. Send the shift key to whatever has
# the focus now. This allows IRB to set_focus.
keystroke(VK_SHIFT)
ret = SetForegroundWindow(handl... | [
"def",
"set_focus",
"if",
"is_window?",
"keystroke",
"(",
"VK_SHIFT",
")",
"ret",
"=",
"SetForegroundWindow",
"(",
"handle",
")",
"logger",
".",
"warn",
"(",
"\"SetForegroundWindow failed\"",
")",
"if",
"ret",
"==",
"0",
"end",
"end"
] | Brings the window into the foreground and activates it.
Keyboard input is directed to the window, and various visual cues
are changed for the user.
A process can set the foreground window only if one of the following conditions is true:
* The process is the foreground process.
* The process was started by ... | [
"Brings",
"the",
"window",
"into",
"the",
"foreground",
"and",
"activates",
"it",
".",
"Keyboard",
"input",
"is",
"directed",
"to",
"the",
"window",
"and",
"various",
"visual",
"cues",
"are",
"changed",
"for",
"the",
"user",
"."
] | f36dc7ed9d7389893b0960b2c5740338f0d38117 | https://github.com/robertwahler/win32-autogui/blob/f36dc7ed9d7389893b0960b2c5740338f0d38117/lib/win32/autogui/window.rb#L203-L212 | train |
robertwahler/win32-autogui | lib/win32/autogui/window.rb | Autogui.Window.combined_text | def combined_text
return unless is_window?
t = []
t << text unless text == ''
children.each do |w|
t << w.combined_text unless w.combined_text == ''
end
t.join("\n")
end | ruby | def combined_text
return unless is_window?
t = []
t << text unless text == ''
children.each do |w|
t << w.combined_text unless w.combined_text == ''
end
t.join("\n")
end | [
"def",
"combined_text",
"return",
"unless",
"is_window?",
"t",
"=",
"[",
"]",
"t",
"<<",
"text",
"unless",
"text",
"==",
"''",
"children",
".",
"each",
"do",
"|",
"w",
"|",
"t",
"<<",
"w",
".",
"combined_text",
"unless",
"w",
".",
"combined_text",
"=="... | The window text including all child windows
joined together with newlines. Faciliates matching text.
Text from any given window is limited to 2048 characters
@example partial match of the Window's calulator's about dialog copywrite text
dialog_about = @calculator.dialog_about
dialog_about.title.should == "Ab... | [
"The",
"window",
"text",
"including",
"all",
"child",
"windows",
"joined",
"together",
"with",
"newlines",
".",
"Faciliates",
"matching",
"text",
".",
"Text",
"from",
"any",
"given",
"window",
"is",
"limited",
"to",
"2048",
"characters"
] | f36dc7ed9d7389893b0960b2c5740338f0d38117 | https://github.com/robertwahler/win32-autogui/blob/f36dc7ed9d7389893b0960b2c5740338f0d38117/lib/win32/autogui/window.rb#L246-L254 | train |
StemboltHQ/solidus-adyen | app/controllers/spree/adyen_redirect_controller.rb | Spree.AdyenRedirectController.authorise3d | def authorise3d
payment = Spree::Adyen::RedirectResponse.find_by(md: params[:MD]).payment
payment.request_env = request.env
payment_method = payment.payment_method
@order = payment.order
payment_method.authorize_3d_secure_payment(payment, adyen_3d_params)
payment.capture! if payment... | ruby | def authorise3d
payment = Spree::Adyen::RedirectResponse.find_by(md: params[:MD]).payment
payment.request_env = request.env
payment_method = payment.payment_method
@order = payment.order
payment_method.authorize_3d_secure_payment(payment, adyen_3d_params)
payment.capture! if payment... | [
"def",
"authorise3d",
"payment",
"=",
"Spree",
"::",
"Adyen",
"::",
"RedirectResponse",
".",
"find_by",
"(",
"md",
":",
"params",
"[",
":MD",
"]",
")",
".",
"payment",
"payment",
".",
"request_env",
"=",
"request",
".",
"env",
"payment_method",
"=",
"payme... | This is the entry point after returning from the 3DS page for credit cards
that support it. MD is a unique payment session identifier returned
by the card issuer. | [
"This",
"is",
"the",
"entry",
"point",
"after",
"returning",
"from",
"the",
"3DS",
"page",
"for",
"credit",
"cards",
"that",
"support",
"it",
".",
"MD",
"is",
"a",
"unique",
"payment",
"session",
"identifier",
"returned",
"by",
"the",
"card",
"issuer",
"."... | 68dd710b0a23435eedc3cc0b4b0ec5b45aa37180 | https://github.com/StemboltHQ/solidus-adyen/blob/68dd710b0a23435eedc3cc0b4b0ec5b45aa37180/app/controllers/spree/adyen_redirect_controller.rb#L27-L44 | train |
StemboltHQ/solidus-adyen | app/controllers/spree/adyen_redirect_controller.rb | Spree.AdyenRedirectController.confirm_order_already_completed | def confirm_order_already_completed
if psp_reference
payment = @order.payments.find_by!(response_code: psp_reference)
else
# If no psp_reference is present but the order is complete then the
# notification must have completed the order and created the payment.
# Therefore sel... | ruby | def confirm_order_already_completed
if psp_reference
payment = @order.payments.find_by!(response_code: psp_reference)
else
# If no psp_reference is present but the order is complete then the
# notification must have completed the order and created the payment.
# Therefore sel... | [
"def",
"confirm_order_already_completed",
"if",
"psp_reference",
"payment",
"=",
"@order",
".",
"payments",
".",
"find_by!",
"(",
"response_code",
":",
"psp_reference",
")",
"else",
"payment",
"=",
"@order",
".",
"payments",
".",
"where",
"(",
"source_type",
":",
... | If an authorization notification is received before the redirection the
payment is created there. In this case we just need to assign the addition
parameters received about the source.
We do this because there is a chance that we never get redirected back
so we need to make sure we complete the payment and order. | [
"If",
"an",
"authorization",
"notification",
"is",
"received",
"before",
"the",
"redirection",
"the",
"payment",
"is",
"created",
"there",
".",
"In",
"this",
"case",
"we",
"just",
"need",
"to",
"assign",
"the",
"addition",
"parameters",
"received",
"about",
"t... | 68dd710b0a23435eedc3cc0b4b0ec5b45aa37180 | https://github.com/StemboltHQ/solidus-adyen/blob/68dd710b0a23435eedc3cc0b4b0ec5b45aa37180/app/controllers/spree/adyen_redirect_controller.rb#L83-L97 | train |
StemboltHQ/solidus-adyen | app/controllers/spree/adyen_redirect_controller.rb | Spree.AdyenRedirectController.restore_session | def restore_session
guest_token, payment_method_id =
params.fetch(:merchantReturnData).split("|")
cookies.permanent.signed[:guest_token] = guest_token
@payment_method = Spree::PaymentMethod.find(payment_method_id)
@order = Spree::Order.find_by!(number: order_number)
end | ruby | def restore_session
guest_token, payment_method_id =
params.fetch(:merchantReturnData).split("|")
cookies.permanent.signed[:guest_token] = guest_token
@payment_method = Spree::PaymentMethod.find(payment_method_id)
@order = Spree::Order.find_by!(number: order_number)
end | [
"def",
"restore_session",
"guest_token",
",",
"payment_method_id",
"=",
"params",
".",
"fetch",
"(",
":merchantReturnData",
")",
".",
"split",
"(",
"\"|\"",
")",
"cookies",
".",
"permanent",
".",
"signed",
"[",
":guest_token",
"]",
"=",
"guest_token",
"@payment_... | We pass the guest token and payment method id in, pipe seperated in the
merchantReturnData parameter so that we can recover the session. | [
"We",
"pass",
"the",
"guest",
"token",
"and",
"payment",
"method",
"id",
"in",
"pipe",
"seperated",
"in",
"the",
"merchantReturnData",
"parameter",
"so",
"that",
"we",
"can",
"recover",
"the",
"session",
"."
] | 68dd710b0a23435eedc3cc0b4b0ec5b45aa37180 | https://github.com/StemboltHQ/solidus-adyen/blob/68dd710b0a23435eedc3cc0b4b0ec5b45aa37180/app/controllers/spree/adyen_redirect_controller.rb#L114-L123 | train |
smacgaha/chromedriver-screenshot | lib/chromedriver-screenshot/tile.rb | ChromedriverScreenshot.Tile.get_offset | def get_offset
platform = ChromedriverScreenshot::Platforms.platform
offset_x = @x - platform.window_x
offset_y = @y - platform.window_y
[offset_x, offset_y]
end | ruby | def get_offset
platform = ChromedriverScreenshot::Platforms.platform
offset_x = @x - platform.window_x
offset_y = @y - platform.window_y
[offset_x, offset_y]
end | [
"def",
"get_offset",
"platform",
"=",
"ChromedriverScreenshot",
"::",
"Platforms",
".",
"platform",
"offset_x",
"=",
"@x",
"-",
"platform",
".",
"window_x",
"offset_y",
"=",
"@y",
"-",
"platform",
".",
"window_y",
"[",
"offset_x",
",",
"offset_y",
"]",
"end"
] | can't scroll past ends of page, so sometimes position won't be accurate | [
"can",
"t",
"scroll",
"past",
"ends",
"of",
"page",
"so",
"sometimes",
"position",
"won",
"t",
"be",
"accurate"
] | 0d768ecc325706f9603fc7b62a45995960464b23 | https://github.com/smacgaha/chromedriver-screenshot/blob/0d768ecc325706f9603fc7b62a45995960464b23/lib/chromedriver-screenshot/tile.rb#L34-L39 | train |
enzinia/hangouts-chat | lib/hangouts_chat.rb | HangoutsChat.Sender.card | def card(header, sections)
payload = { cards: [header: header, sections: sections] }
send_request(payload)
end | ruby | def card(header, sections)
payload = { cards: [header: header, sections: sections] }
send_request(payload)
end | [
"def",
"card",
"(",
"header",
",",
"sections",
")",
"payload",
"=",
"{",
"cards",
":",
"[",
"header",
":",
"header",
",",
"sections",
":",
"sections",
"]",
"}",
"send_request",
"(",
"payload",
")",
"end"
] | Sends Card Message
@since 0.0.4
@param header [Hash] card header content
@param sections [Array<Hash>] card widgets array
@return [Net::HTTPResponse] response object | [
"Sends",
"Card",
"Message"
] | fea2fccdc2d1142746a88943d5f9c4f6af2af5a8 | https://github.com/enzinia/hangouts-chat/blob/fea2fccdc2d1142746a88943d5f9c4f6af2af5a8/lib/hangouts_chat.rb#L32-L35 | train |
enzinia/hangouts-chat | lib/hangouts_chat.rb | HangoutsChat.Sender.send_request | def send_request(payload)
response = @http.post payload
raise APIError, response unless response.is_a?(Net::HTTPSuccess)
response
end | ruby | def send_request(payload)
response = @http.post payload
raise APIError, response unless response.is_a?(Net::HTTPSuccess)
response
end | [
"def",
"send_request",
"(",
"payload",
")",
"response",
"=",
"@http",
".",
"post",
"payload",
"raise",
"APIError",
",",
"response",
"unless",
"response",
".",
"is_a?",
"(",
"Net",
"::",
"HTTPSuccess",
")",
"response",
"end"
] | Sends payload and check response
@param payload [Hash] data to send by POST
@return [Net::HTTPResponse] response object
@raise [APIError] if got unsuccessful response | [
"Sends",
"payload",
"and",
"check",
"response"
] | fea2fccdc2d1142746a88943d5f9c4f6af2af5a8 | https://github.com/enzinia/hangouts-chat/blob/fea2fccdc2d1142746a88943d5f9c4f6af2af5a8/lib/hangouts_chat.rb#L43-L47 | train |
nthj/ignorable | lib/ignorable.rb | Ignorable.ClassMethods.ignore_columns | def ignore_columns(*columns)
self.ignored_columns ||= []
self.ignored_columns += columns.map(&:to_s)
reset_column_information
descendants.each(&:reset_column_information)
self.ignored_columns.tap(&:uniq!)
end | ruby | def ignore_columns(*columns)
self.ignored_columns ||= []
self.ignored_columns += columns.map(&:to_s)
reset_column_information
descendants.each(&:reset_column_information)
self.ignored_columns.tap(&:uniq!)
end | [
"def",
"ignore_columns",
"(",
"*",
"columns",
")",
"self",
".",
"ignored_columns",
"||=",
"[",
"]",
"self",
".",
"ignored_columns",
"+=",
"columns",
".",
"map",
"(",
"&",
":to_s",
")",
"reset_column_information",
"descendants",
".",
"each",
"(",
"&",
":reset... | Prevent Rails from loading a table column.
Useful for legacy database schemas with problematic column names,
like 'class' or 'attributes'.
class Topic < ActiveRecord::Base
ignore_columns :attributes, :class
end
Topic.new.respond_to?(:attributes) => false | [
"Prevent",
"Rails",
"from",
"loading",
"a",
"table",
"column",
".",
"Useful",
"for",
"legacy",
"database",
"schemas",
"with",
"problematic",
"column",
"names",
"like",
"class",
"or",
"attributes",
"."
] | 1fa6dada7ae0e2c4d4ae5c78f62234a2a1cae94e | https://github.com/nthj/ignorable/blob/1fa6dada7ae0e2c4d4ae5c78f62234a2a1cae94e/lib/ignorable.rb#L29-L35 | train |
robertwahler/win32-autogui | lib/win32/autogui/input.rb | Autogui.Input.keystroke | def keystroke(*keys)
return if keys.empty?
keybd_event keys.first, 0, KEYBD_EVENT_KEYDOWN, 0
sleep KEYBD_KEYDELAY
keystroke *keys[1..-1]
sleep KEYBD_KEYDELAY
keybd_event keys.first, 0, KEYBD_EVENT_KEYUP, 0
end | ruby | def keystroke(*keys)
return if keys.empty?
keybd_event keys.first, 0, KEYBD_EVENT_KEYDOWN, 0
sleep KEYBD_KEYDELAY
keystroke *keys[1..-1]
sleep KEYBD_KEYDELAY
keybd_event keys.first, 0, KEYBD_EVENT_KEYUP, 0
end | [
"def",
"keystroke",
"(",
"*",
"keys",
")",
"return",
"if",
"keys",
".",
"empty?",
"keybd_event",
"keys",
".",
"first",
",",
"0",
",",
"KEYBD_EVENT_KEYDOWN",
",",
"0",
"sleep",
"KEYBD_KEYDELAY",
"keystroke",
"*",
"keys",
"[",
"1",
"..",
"-",
"1",
"]",
"... | Send keystroke to the focused window, keystrokes are virtual keycodes
@example send 2+2<CR>
keystroke(VK_2, VK_ADD, VK_2, VK_RETURN) | [
"Send",
"keystroke",
"to",
"the",
"focused",
"window",
"keystrokes",
"are",
"virtual",
"keycodes"
] | f36dc7ed9d7389893b0960b2c5740338f0d38117 | https://github.com/robertwahler/win32-autogui/blob/f36dc7ed9d7389893b0960b2c5740338f0d38117/lib/win32/autogui/input.rb#L156-L164 | train |
robertwahler/win32-autogui | lib/win32/autogui/input.rb | Autogui.Input.char_to_virtual_keycode | def char_to_virtual_keycode(char)
unless char.size == 1
raise "virtual keycode conversion is for single characters only"
end
code = char.unpack('U')[0]
case char
when '0'..'9'
[code - ?0.ord + 0x30]
when 'A'..'Z'
[VK_SHIFT, code]
when 'a'..'... | ruby | def char_to_virtual_keycode(char)
unless char.size == 1
raise "virtual keycode conversion is for single characters only"
end
code = char.unpack('U')[0]
case char
when '0'..'9'
[code - ?0.ord + 0x30]
when 'A'..'Z'
[VK_SHIFT, code]
when 'a'..'... | [
"def",
"char_to_virtual_keycode",
"(",
"char",
")",
"unless",
"char",
".",
"size",
"==",
"1",
"raise",
"\"virtual keycode conversion is for single characters only\"",
"end",
"code",
"=",
"char",
".",
"unpack",
"(",
"'U'",
")",
"[",
"0",
"]",
"case",
"char",
"whe... | convert a single character to a virtual keycode
@param [Char] char is the character to convert
@return [Array] of virtual keycodes | [
"convert",
"a",
"single",
"character",
"to",
"a",
"virtual",
"keycode"
] | f36dc7ed9d7389893b0960b2c5740338f0d38117 | https://github.com/robertwahler/win32-autogui/blob/f36dc7ed9d7389893b0960b2c5740338f0d38117/lib/win32/autogui/input.rb#L191-L275 | train |
TimPetricola/Credy | lib/credy/rules.rb | Credy.Rules.all | def all
rules = []
raw.each do |type, details|
# Add general rules
Array(details['prefix']).each do |prefix|
rules.push({
prefix: prefix.to_s,
length: details['length'],
type: type
})
end
# Process each country
... | ruby | def all
rules = []
raw.each do |type, details|
# Add general rules
Array(details['prefix']).each do |prefix|
rules.push({
prefix: prefix.to_s,
length: details['length'],
type: type
})
end
# Process each country
... | [
"def",
"all",
"rules",
"=",
"[",
"]",
"raw",
".",
"each",
"do",
"|",
"type",
",",
"details",
"|",
"Array",
"(",
"details",
"[",
"'prefix'",
"]",
")",
".",
"each",
"do",
"|",
"prefix",
"|",
"rules",
".",
"push",
"(",
"{",
"prefix",
":",
"prefix",
... | Change hash format to process rules | [
"Change",
"hash",
"format",
"to",
"process",
"rules"
] | c1ba2d51da95b8885d6c446736b5455b6ee5d200 | https://github.com/TimPetricola/Credy/blob/c1ba2d51da95b8885d6c446736b5455b6ee5d200/lib/credy/rules.rb#L13-L43 | train |
TimPetricola/Credy | lib/credy/rules.rb | Credy.Rules.filter | def filter(filters = {})
all.select do |rule|
[:country, :type].each do |condition|
break false if filters[condition] && filters[condition] != rule[condition]
true
end
end
end | ruby | def filter(filters = {})
all.select do |rule|
[:country, :type].each do |condition|
break false if filters[condition] && filters[condition] != rule[condition]
true
end
end
end | [
"def",
"filter",
"(",
"filters",
"=",
"{",
"}",
")",
"all",
".",
"select",
"do",
"|",
"rule",
"|",
"[",
":country",
",",
":type",
"]",
".",
"each",
"do",
"|",
"condition",
"|",
"break",
"false",
"if",
"filters",
"[",
"condition",
"]",
"&&",
"filter... | Returns rules according to given filters | [
"Returns",
"rules",
"according",
"to",
"given",
"filters"
] | c1ba2d51da95b8885d6c446736b5455b6ee5d200 | https://github.com/TimPetricola/Credy/blob/c1ba2d51da95b8885d6c446736b5455b6ee5d200/lib/credy/rules.rb#L46-L53 | train |
TimPetricola/Credy | lib/credy.rb | Credy.CreditCard.generate | def generate(options = {})
rule = find_rule(options) || return
number = generate_from_rule(rule)
{
number: number,
type: rule[:type],
country: rule[:country]
}
end | ruby | def generate(options = {})
rule = find_rule(options) || return
number = generate_from_rule(rule)
{
number: number,
type: rule[:type],
country: rule[:country]
}
end | [
"def",
"generate",
"(",
"options",
"=",
"{",
"}",
")",
"rule",
"=",
"find_rule",
"(",
"options",
")",
"||",
"return",
"number",
"=",
"generate_from_rule",
"(",
"rule",
")",
"{",
"number",
":",
"number",
",",
"type",
":",
"rule",
"[",
":type",
"]",
",... | Generate a credit card number | [
"Generate",
"a",
"credit",
"card",
"number"
] | c1ba2d51da95b8885d6c446736b5455b6ee5d200 | https://github.com/TimPetricola/Credy/blob/c1ba2d51da95b8885d6c446736b5455b6ee5d200/lib/credy.rb#L15-L24 | train |
TimPetricola/Credy | lib/credy.rb | Credy.CreditCard.infos | def infos(number)
rules = Rules.all.select do |rule|
valid = true
# Check number of digits
lengths = rule[:length].is_a?(Array) ? rule[:length] : [rule[:length]]
valid = false unless lengths.include? number.length
# Check prefix
valid = false unless !(number =~ Re... | ruby | def infos(number)
rules = Rules.all.select do |rule|
valid = true
# Check number of digits
lengths = rule[:length].is_a?(Array) ? rule[:length] : [rule[:length]]
valid = false unless lengths.include? number.length
# Check prefix
valid = false unless !(number =~ Re... | [
"def",
"infos",
"(",
"number",
")",
"rules",
"=",
"Rules",
".",
"all",
".",
"select",
"do",
"|",
"rule",
"|",
"valid",
"=",
"true",
"lengths",
"=",
"rule",
"[",
":length",
"]",
".",
"is_a?",
"(",
"Array",
")",
"?",
"rule",
"[",
":length",
"]",
":... | Returns information about a number | [
"Returns",
"information",
"about",
"a",
"number"
] | c1ba2d51da95b8885d6c446736b5455b6ee5d200 | https://github.com/TimPetricola/Credy/blob/c1ba2d51da95b8885d6c446736b5455b6ee5d200/lib/credy.rb#L27-L45 | train |
TimPetricola/Credy | lib/credy.rb | Credy.CreditCard.validate | def validate(number)
criterii = {}
criterii[:luhn] = Check.luhn number
criterii[:type] = !!infos(number)
valid = criterii.all? { |_, v| v == true }
{
valid: valid,
details: criterii
}
end | ruby | def validate(number)
criterii = {}
criterii[:luhn] = Check.luhn number
criterii[:type] = !!infos(number)
valid = criterii.all? { |_, v| v == true }
{
valid: valid,
details: criterii
}
end | [
"def",
"validate",
"(",
"number",
")",
"criterii",
"=",
"{",
"}",
"criterii",
"[",
":luhn",
"]",
"=",
"Check",
".",
"luhn",
"number",
"criterii",
"[",
":type",
"]",
"=",
"!",
"!",
"infos",
"(",
"number",
")",
"valid",
"=",
"criterii",
".",
"all?",
... | Validates a number | [
"Validates",
"a",
"number"
] | c1ba2d51da95b8885d6c446736b5455b6ee5d200 | https://github.com/TimPetricola/Credy/blob/c1ba2d51da95b8885d6c446736b5455b6ee5d200/lib/credy.rb#L48-L59 | train |
robertwahler/win32-autogui | lib/win32/autogui/application.rb | Autogui.Clipboard.text= | def text=(str)
data = str.nil? ? "" : str.dup
Win32::Clipboard.set_data(data)
end | ruby | def text=(str)
data = str.nil? ? "" : str.dup
Win32::Clipboard.set_data(data)
end | [
"def",
"text",
"=",
"(",
"str",
")",
"data",
"=",
"str",
".",
"nil?",
"?",
"\"\"",
":",
"str",
".",
"dup",
"Win32",
"::",
"Clipboard",
".",
"set_data",
"(",
"data",
")",
"end"
] | Clipboard text setter
@param [String] str text to load onto the clipboard | [
"Clipboard",
"text",
"setter"
] | f36dc7ed9d7389893b0960b2c5740338f0d38117 | https://github.com/robertwahler/win32-autogui/blob/f36dc7ed9d7389893b0960b2c5740338f0d38117/lib/win32/autogui/application.rb#L26-L29 | train |
jonahb/akismet | lib/akismet/client.rb | Akismet.Client.spam | def spam(user_ip, user_agent, params = {})
response = invoke_comment_method('submit-spam',
user_ip,
user_agent,
params)
unless response.body == 'Thanks for making the web a better place.'
raise_with_response response
end
end | ruby | def spam(user_ip, user_agent, params = {})
response = invoke_comment_method('submit-spam',
user_ip,
user_agent,
params)
unless response.body == 'Thanks for making the web a better place.'
raise_with_response response
end
end | [
"def",
"spam",
"(",
"user_ip",
",",
"user_agent",
",",
"params",
"=",
"{",
"}",
")",
"response",
"=",
"invoke_comment_method",
"(",
"'submit-spam'",
",",
"user_ip",
",",
"user_agent",
",",
"params",
")",
"unless",
"response",
".",
"body",
"==",
"'Thanks for ... | Submits a comment that has been identified as spam.
@!macro akismet_method
@return [void] | [
"Submits",
"a",
"comment",
"that",
"has",
"been",
"identified",
"as",
"spam",
"."
] | b03f7fd58181d962c2ac842b16e67752e7c7f023 | https://github.com/jonahb/akismet/blob/b03f7fd58181d962c2ac842b16e67752e7c7f023/lib/akismet/client.rb#L238-L247 | train |
nickcharlton/boxes | lib/boxes/builder.rb | Boxes.Builder.run | def run # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
original_directory = FileUtils.pwd
box_name = ''
# render the template
rendered_template = template.render(name: name,
provider: provider,
scripts:... | ruby | def run # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
original_directory = FileUtils.pwd
box_name = ''
# render the template
rendered_template = template.render(name: name,
provider: provider,
scripts:... | [
"def",
"run",
"original_directory",
"=",
"FileUtils",
".",
"pwd",
"box_name",
"=",
"''",
"rendered_template",
"=",
"template",
".",
"render",
"(",
"name",
":",
"name",
",",
"provider",
":",
"provider",
",",
"scripts",
":",
"scripts",
")",
"File",
".",
"ope... | Initialise a new build.
@param env [Boxes::Environment] environment to operate in.
@param args [Hash]
@param template [String] the name of the template.
@param scripts [Array] scripts to include in the build.
Run the build. | [
"Initialise",
"a",
"new",
"build",
"."
] | d5558d6f2c4f98c6e453f8b960f28c7540433936 | https://github.com/nickcharlton/boxes/blob/d5558d6f2c4f98c6e453f8b960f28c7540433936/lib/boxes/builder.rb#L30-L71 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.