id
int32 0
24.9k
| 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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
9,900
|
ryym/dio
|
lib/dio/injector.rb
|
Dio.Injector.register
|
def register(key, object = nil)
assert_register_args_valid(object, block_given?)
@container.register(key) do |*args|
object = yield(*args) if block_given?
injectable?(object) ? inject(object) : object
end
self
end
|
ruby
|
def register(key, object = nil)
assert_register_args_valid(object, block_given?)
@container.register(key) do |*args|
object = yield(*args) if block_given?
injectable?(object) ? inject(object) : object
end
self
end
|
[
"def",
"register",
"(",
"key",
",",
"object",
"=",
"nil",
")",
"assert_register_args_valid",
"(",
"object",
",",
"block_given?",
")",
"@container",
".",
"register",
"(",
"key",
")",
"do",
"|",
"*",
"args",
"|",
"object",
"=",
"yield",
"(",
"args",
")",
"if",
"block_given?",
"injectable?",
"(",
"object",
")",
"?",
"inject",
"(",
"object",
")",
":",
"object",
"end",
"self",
"end"
] |
Registers a new dependency with the given key.
You can specify either an object or a factory block
that creates an object.
@param key [Object] Typically a class or a symbol.
@param object [Object]
@yield passed arguments when loading
@return [Dio::Injector] self
|
[
"Registers",
"a",
"new",
"dependency",
"with",
"the",
"given",
"key",
".",
"You",
"can",
"specify",
"either",
"an",
"object",
"or",
"a",
"factory",
"block",
"that",
"creates",
"an",
"object",
"."
] |
4547c3e75d43be7bd73335576e5e5dc3a8fa7efd
|
https://github.com/ryym/dio/blob/4547c3e75d43be7bd73335576e5e5dc3a8fa7efd/lib/dio/injector.rb#L43-L50
|
9,901
|
ryym/dio
|
lib/dio/injector.rb
|
Dio.Injector.inject
|
def inject(target)
unless injectable?(target)
raise ArgumentError, 'The given object does not include Dio module'
end
loader = @loader_factory.create(@container, target)
target.__dio_inject__(loader)
target
end
|
ruby
|
def inject(target)
unless injectable?(target)
raise ArgumentError, 'The given object does not include Dio module'
end
loader = @loader_factory.create(@container, target)
target.__dio_inject__(loader)
target
end
|
[
"def",
"inject",
"(",
"target",
")",
"unless",
"injectable?",
"(",
"target",
")",
"raise",
"ArgumentError",
",",
"'The given object does not include Dio module'",
"end",
"loader",
"=",
"@loader_factory",
".",
"create",
"(",
"@container",
",",
"target",
")",
"target",
".",
"__dio_inject__",
"(",
"loader",
")",
"target",
"end"
] |
Inject dependencies to the given object.
@param target [Object]
@return target
|
[
"Inject",
"dependencies",
"to",
"the",
"given",
"object",
"."
] |
4547c3e75d43be7bd73335576e5e5dc3a8fa7efd
|
https://github.com/ryym/dio/blob/4547c3e75d43be7bd73335576e5e5dc3a8fa7efd/lib/dio/injector.rb#L56-L63
|
9,902
|
ryym/dio
|
lib/dio/injector.rb
|
Dio.Injector.create
|
def create(clazz, *args)
raise ArgumentError, "#{clazz} is not a class" unless clazz.is_a?(Class)
inject(clazz.new(*args))
end
|
ruby
|
def create(clazz, *args)
raise ArgumentError, "#{clazz} is not a class" unless clazz.is_a?(Class)
inject(clazz.new(*args))
end
|
[
"def",
"create",
"(",
"clazz",
",",
"*",
"args",
")",
"raise",
"ArgumentError",
",",
"\"#{clazz} is not a class\"",
"unless",
"clazz",
".",
"is_a?",
"(",
"Class",
")",
"inject",
"(",
"clazz",
".",
"new",
"(",
"args",
")",
")",
"end"
] |
Creates a new instance of the given class.
Dio injects dependencies to the created instance.
@param clazz [Class]
@param args [Array]
@return Instance of clazz
|
[
"Creates",
"a",
"new",
"instance",
"of",
"the",
"given",
"class",
".",
"Dio",
"injects",
"dependencies",
"to",
"the",
"created",
"instance",
"."
] |
4547c3e75d43be7bd73335576e5e5dc3a8fa7efd
|
https://github.com/ryym/dio/blob/4547c3e75d43be7bd73335576e5e5dc3a8fa7efd/lib/dio/injector.rb#L71-L74
|
9,903
|
ryanlchan/bitmask_attributes_helpers
|
lib/bitmask_attributes_helpers.rb
|
BitmaskAttributesHelpers.ClassMethods.bitmask_scopes
|
def bitmask_scopes(bitmask)
send("values_for_#{bitmask}").each do |value|
scope value, send("with_#{bitmask}", value)
scope "not_#{value}", send("without_#{bitmask}", value)
end
end
|
ruby
|
def bitmask_scopes(bitmask)
send("values_for_#{bitmask}").each do |value|
scope value, send("with_#{bitmask}", value)
scope "not_#{value}", send("without_#{bitmask}", value)
end
end
|
[
"def",
"bitmask_scopes",
"(",
"bitmask",
")",
"send",
"(",
"\"values_for_#{bitmask}\"",
")",
".",
"each",
"do",
"|",
"value",
"|",
"scope",
"value",
",",
"send",
"(",
"\"with_#{bitmask}\"",
",",
"value",
")",
"scope",
"\"not_#{value}\"",
",",
"send",
"(",
"\"without_#{bitmask}\"",
",",
"value",
")",
"end",
"end"
] |
Setup scopes for Bitmask attributes
Scopes are setup with the same name as the value, and include both
.value and .not_value versions
@arg [Symbol] bitmask the name of the bitmask attribute
|
[
"Setup",
"scopes",
"for",
"Bitmask",
"attributes"
] |
5601e97fcb823547118d41fd2a9022e387379533
|
https://github.com/ryanlchan/bitmask_attributes_helpers/blob/5601e97fcb823547118d41fd2a9022e387379533/lib/bitmask_attributes_helpers.rb#L25-L30
|
9,904
|
ryanlchan/bitmask_attributes_helpers
|
lib/bitmask_attributes_helpers.rb
|
BitmaskAttributesHelpers.ClassMethods.bitmask_virtual_attributes
|
def bitmask_virtual_attributes(bitmask)
send("values_for_#{bitmask}").each do |value|
define_method("#{value}") { send("#{bitmask}?", value) }
define_method("#{value}=") { |arg| send("#{bitmask}=", arg.blank? || arg == "0" ? send("#{bitmask}") - [value] : send("#{bitmask}") << value) }
end
end
|
ruby
|
def bitmask_virtual_attributes(bitmask)
send("values_for_#{bitmask}").each do |value|
define_method("#{value}") { send("#{bitmask}?", value) }
define_method("#{value}=") { |arg| send("#{bitmask}=", arg.blank? || arg == "0" ? send("#{bitmask}") - [value] : send("#{bitmask}") << value) }
end
end
|
[
"def",
"bitmask_virtual_attributes",
"(",
"bitmask",
")",
"send",
"(",
"\"values_for_#{bitmask}\"",
")",
".",
"each",
"do",
"|",
"value",
"|",
"define_method",
"(",
"\"#{value}\"",
")",
"{",
"send",
"(",
"\"#{bitmask}?\"",
",",
"value",
")",
"}",
"define_method",
"(",
"\"#{value}=\"",
")",
"{",
"|",
"arg",
"|",
"send",
"(",
"\"#{bitmask}=\"",
",",
"arg",
".",
"blank?",
"||",
"arg",
"==",
"\"0\"",
"?",
"send",
"(",
"\"#{bitmask}\"",
")",
"-",
"[",
"value",
"]",
":",
"send",
"(",
"\"#{bitmask}\"",
")",
"<<",
"value",
")",
"}",
"end",
"end"
] |
Setup virtual attributes for Bitmask attributes
Allows you to set and read Bitmask attributes using #value= and
#value methods
@arg [Symbol] bitmask the name of the bitmask attribute
|
[
"Setup",
"virtual",
"attributes",
"for",
"Bitmask",
"attributes"
] |
5601e97fcb823547118d41fd2a9022e387379533
|
https://github.com/ryanlchan/bitmask_attributes_helpers/blob/5601e97fcb823547118d41fd2a9022e387379533/lib/bitmask_attributes_helpers.rb#L37-L42
|
9,905
|
fkchang/awesome_print_lite
|
lib/awesome_print_lite/formatter.rb
|
AwesomePrintLite.Formatter.awesome_hash
|
def awesome_hash(h)
return "{}" if h == {}
keys = @options[:sort_keys] ? h.keys.sort { |a, b| a.to_s <=> b.to_s } : h.keys
data = keys.map do |key|
plain_single_line do
[ @inspector.awesome(key), h[key] ]
end
end
width = data.map { |key, | key.size }.max || 0
width += @indentation if @options[:indent] > 0
data = data.map do |key, value|
indented do
align(key, width) + colorize(" => ", :hash) + @inspector.awesome(value)
end
end
data = limited(data, width, :hash => true) if should_be_limited?
if @options[:multiline]
"{\n" + data.join(",\n") + "\n#{outdent}}"
else
"{ #{data.join(', ')} }"
end
end
|
ruby
|
def awesome_hash(h)
return "{}" if h == {}
keys = @options[:sort_keys] ? h.keys.sort { |a, b| a.to_s <=> b.to_s } : h.keys
data = keys.map do |key|
plain_single_line do
[ @inspector.awesome(key), h[key] ]
end
end
width = data.map { |key, | key.size }.max || 0
width += @indentation if @options[:indent] > 0
data = data.map do |key, value|
indented do
align(key, width) + colorize(" => ", :hash) + @inspector.awesome(value)
end
end
data = limited(data, width, :hash => true) if should_be_limited?
if @options[:multiline]
"{\n" + data.join(",\n") + "\n#{outdent}}"
else
"{ #{data.join(', ')} }"
end
end
|
[
"def",
"awesome_hash",
"(",
"h",
")",
"return",
"\"{}\"",
"if",
"h",
"==",
"{",
"}",
"keys",
"=",
"@options",
"[",
":sort_keys",
"]",
"?",
"h",
".",
"keys",
".",
"sort",
"{",
"|",
"a",
",",
"b",
"|",
"a",
".",
"to_s",
"<=>",
"b",
".",
"to_s",
"}",
":",
"h",
".",
"keys",
"data",
"=",
"keys",
".",
"map",
"do",
"|",
"key",
"|",
"plain_single_line",
"do",
"[",
"@inspector",
".",
"awesome",
"(",
"key",
")",
",",
"h",
"[",
"key",
"]",
"]",
"end",
"end",
"width",
"=",
"data",
".",
"map",
"{",
"|",
"key",
",",
"|",
"key",
".",
"size",
"}",
".",
"max",
"||",
"0",
"width",
"+=",
"@indentation",
"if",
"@options",
"[",
":indent",
"]",
">",
"0",
"data",
"=",
"data",
".",
"map",
"do",
"|",
"key",
",",
"value",
"|",
"indented",
"do",
"align",
"(",
"key",
",",
"width",
")",
"+",
"colorize",
"(",
"\" => \"",
",",
":hash",
")",
"+",
"@inspector",
".",
"awesome",
"(",
"value",
")",
"end",
"end",
"data",
"=",
"limited",
"(",
"data",
",",
"width",
",",
":hash",
"=>",
"true",
")",
"if",
"should_be_limited?",
"if",
"@options",
"[",
":multiline",
"]",
"\"{\\n\"",
"+",
"data",
".",
"join",
"(",
"\",\\n\"",
")",
"+",
"\"\\n#{outdent}}\"",
"else",
"\"{ #{data.join(', ')} }\"",
"end",
"end"
] |
Format a hash. If @options[:indent] if negative left align hash keys.
------------------------------------------------------------------------------
|
[
"Format",
"a",
"hash",
".",
"If"
] |
68302eb197d95f85308afce69f7a24f31b9b7dfd
|
https://github.com/fkchang/awesome_print_lite/blob/68302eb197d95f85308afce69f7a24f31b9b7dfd/lib/awesome_print_lite/formatter.rb#L107-L132
|
9,906
|
giraffi/ruby-orchestrate.io
|
lib/orchestrate.io/client.rb
|
OrchestrateIo.Client.request
|
def request(http_method, uri, options={})
response = self.class.__send__(http_method, uri, options.merge(basic_auth))
# Add some logger.debug here ...
response
end
|
ruby
|
def request(http_method, uri, options={})
response = self.class.__send__(http_method, uri, options.merge(basic_auth))
# Add some logger.debug here ...
response
end
|
[
"def",
"request",
"(",
"http_method",
",",
"uri",
",",
"options",
"=",
"{",
"}",
")",
"response",
"=",
"self",
".",
"class",
".",
"__send__",
"(",
"http_method",
",",
"uri",
",",
"options",
".",
"merge",
"(",
"basic_auth",
")",
")",
"# Add some logger.debug here ...",
"response",
"end"
] |
Entry point to HTTP request
Set the username of basic auth to the API Key attribute.
|
[
"Entry",
"point",
"to",
"HTTP",
"request",
"Set",
"the",
"username",
"of",
"basic",
"auth",
"to",
"the",
"API",
"Key",
"attribute",
"."
] |
391b46b37c30728da106441f7f915ea7572634fc
|
https://github.com/giraffi/ruby-orchestrate.io/blob/391b46b37c30728da106441f7f915ea7572634fc/lib/orchestrate.io/client.rb#L43-L47
|
9,907
|
dgjnpr/Sloe
|
lib/sloe/ixia.rb
|
Sloe.Ixia.run_setup
|
def run_setup
setup_tcl = File.open("/var/tmp/setup-#{@buildtime}", 'w')
setup_tcl.write setup
setup_tcl.close
system "#@ixia_exe /var/tmp/setup-#{@buildtime}"
File.delete setup_tcl
end
|
ruby
|
def run_setup
setup_tcl = File.open("/var/tmp/setup-#{@buildtime}", 'w')
setup_tcl.write setup
setup_tcl.close
system "#@ixia_exe /var/tmp/setup-#{@buildtime}"
File.delete setup_tcl
end
|
[
"def",
"run_setup",
"setup_tcl",
"=",
"File",
".",
"open",
"(",
"\"/var/tmp/setup-#{@buildtime}\"",
",",
"'w'",
")",
"setup_tcl",
".",
"write",
"setup",
"setup_tcl",
".",
"close",
"system",
"\"#@ixia_exe /var/tmp/setup-#{@buildtime}\"",
"File",
".",
"delete",
"setup_tcl",
"end"
] |
Load IxN file, start all protocols and then start traffic
|
[
"Load",
"IxN",
"file",
"start",
"all",
"protocols",
"and",
"then",
"start",
"traffic"
] |
7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355
|
https://github.com/dgjnpr/Sloe/blob/7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355/lib/sloe/ixia.rb#L45-L51
|
9,908
|
dgjnpr/Sloe
|
lib/sloe/ixia.rb
|
Sloe.Ixia.clear_stats
|
def clear_stats
clear_tcl = File.open("/var/tmp/clear-#{@buildtime}", 'w')
clear_tcl.write clear_traffic_stats
clear_tcl.close
system "#{@ixia_exe} /var/tmp/clear-#{@buildtime}"
File.delete clear_tcl
end
|
ruby
|
def clear_stats
clear_tcl = File.open("/var/tmp/clear-#{@buildtime}", 'w')
clear_tcl.write clear_traffic_stats
clear_tcl.close
system "#{@ixia_exe} /var/tmp/clear-#{@buildtime}"
File.delete clear_tcl
end
|
[
"def",
"clear_stats",
"clear_tcl",
"=",
"File",
".",
"open",
"(",
"\"/var/tmp/clear-#{@buildtime}\"",
",",
"'w'",
")",
"clear_tcl",
".",
"write",
"clear_traffic_stats",
"clear_tcl",
".",
"close",
"system",
"\"#{@ixia_exe} /var/tmp/clear-#{@buildtime}\"",
"File",
".",
"delete",
"clear_tcl",
"end"
] |
Clear all Ixia stats. This removes "invalid" drops observed
|
[
"Clear",
"all",
"Ixia",
"stats",
".",
"This",
"removes",
"invalid",
"drops",
"observed"
] |
7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355
|
https://github.com/dgjnpr/Sloe/blob/7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355/lib/sloe/ixia.rb#L54-L60
|
9,909
|
dgjnpr/Sloe
|
lib/sloe/ixia.rb
|
Sloe.Ixia.run_stats_gather
|
def run_stats_gather
stats_tcl = File.open("/var/tmp/stats-#{@buildtime}", 'w')
stats_tcl.write finish
stats_tcl.close
system "#@ixia_exe /var/tmp/stats-#{@buildtime}"
File.delete stats_tcl
ftp = Net::FTP.new(@host)
ftp.login
file = "#{@csv_file}.csv"
Dir.chdir "#{$log_path}/ixia" do
ftp.get "Reports/#{file}"
end
ftp.delete "Reports/#{file}"
ftp.delete "Reports/#{file}.columns"
ftp.close
CSV.read("#{$log_path}/ixia/#{file}", headers: true)
end
|
ruby
|
def run_stats_gather
stats_tcl = File.open("/var/tmp/stats-#{@buildtime}", 'w')
stats_tcl.write finish
stats_tcl.close
system "#@ixia_exe /var/tmp/stats-#{@buildtime}"
File.delete stats_tcl
ftp = Net::FTP.new(@host)
ftp.login
file = "#{@csv_file}.csv"
Dir.chdir "#{$log_path}/ixia" do
ftp.get "Reports/#{file}"
end
ftp.delete "Reports/#{file}"
ftp.delete "Reports/#{file}.columns"
ftp.close
CSV.read("#{$log_path}/ixia/#{file}", headers: true)
end
|
[
"def",
"run_stats_gather",
"stats_tcl",
"=",
"File",
".",
"open",
"(",
"\"/var/tmp/stats-#{@buildtime}\"",
",",
"'w'",
")",
"stats_tcl",
".",
"write",
"finish",
"stats_tcl",
".",
"close",
"system",
"\"#@ixia_exe /var/tmp/stats-#{@buildtime}\"",
"File",
".",
"delete",
"stats_tcl",
"ftp",
"=",
"Net",
"::",
"FTP",
".",
"new",
"(",
"@host",
")",
"ftp",
".",
"login",
"file",
"=",
"\"#{@csv_file}.csv\"",
"Dir",
".",
"chdir",
"\"#{$log_path}/ixia\"",
"do",
"ftp",
".",
"get",
"\"Reports/#{file}\"",
"end",
"ftp",
".",
"delete",
"\"Reports/#{file}\"",
"ftp",
".",
"delete",
"\"Reports/#{file}.columns\"",
"ftp",
".",
"close",
"CSV",
".",
"read",
"(",
"\"#{$log_path}/ixia/#{file}\"",
",",
"headers",
":",
"true",
")",
"end"
] |
Stop Ixia traffic flows and gather Ixia stats
|
[
"Stop",
"Ixia",
"traffic",
"flows",
"and",
"gather",
"Ixia",
"stats"
] |
7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355
|
https://github.com/dgjnpr/Sloe/blob/7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355/lib/sloe/ixia.rb#L63-L79
|
9,910
|
dgjnpr/Sloe
|
lib/sloe/ixia.rb
|
Sloe.Ixia.run_protocols
|
def run_protocols
run_proto = File.open("/var/tmp/run-proto-#{@buildtime}", 'w')
tcl = connect
tcl << load_config
tcl << start_protocols
tcl << disconnect
run_proto.write tcl
run_proto.close
system "#{@ixia_exe} /var/tmp/run-proto-#{@buildtime}"
File.delete run_proto
end
|
ruby
|
def run_protocols
run_proto = File.open("/var/tmp/run-proto-#{@buildtime}", 'w')
tcl = connect
tcl << load_config
tcl << start_protocols
tcl << disconnect
run_proto.write tcl
run_proto.close
system "#{@ixia_exe} /var/tmp/run-proto-#{@buildtime}"
File.delete run_proto
end
|
[
"def",
"run_protocols",
"run_proto",
"=",
"File",
".",
"open",
"(",
"\"/var/tmp/run-proto-#{@buildtime}\"",
",",
"'w'",
")",
"tcl",
"=",
"connect",
"tcl",
"<<",
"load_config",
"tcl",
"<<",
"start_protocols",
"tcl",
"<<",
"disconnect",
"run_proto",
".",
"write",
"tcl",
"run_proto",
".",
"close",
"system",
"\"#{@ixia_exe} /var/tmp/run-proto-#{@buildtime}\"",
"File",
".",
"delete",
"run_proto",
"end"
] |
Just run protocols. Do not start traffic
|
[
"Just",
"run",
"protocols",
".",
"Do",
"not",
"start",
"traffic"
] |
7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355
|
https://github.com/dgjnpr/Sloe/blob/7d1b462fbd8c91e6feafa6fa64adf1ce7a78e355/lib/sloe/ixia.rb#L82-L92
|
9,911
|
levibostian/danger-ios_version_change
|
lib/ios_version_change/plugin.rb
|
Danger.DangerIosVersionChange.assert_version_changed
|
def assert_version_changed(info_plist_file_path)
unless File.file?(info_plist_file_path)
fail "Info.plist at path " + info_plist_file_path + " does not exist."
return # rubocop:disable UnreachableCode
end
unless git.diff_for_file(info_plist_file_path) # No diff found for Info.plist file.
fail "You did not edit your Info.plist file at all. Therefore, you did not change the iOS version."
return # rubocop:disable UnreachableCode
end
git_diff_string = git.diff_for_file(info_plist_file_path).patch
assert_version_changed_diff(git_diff_string)
end
|
ruby
|
def assert_version_changed(info_plist_file_path)
unless File.file?(info_plist_file_path)
fail "Info.plist at path " + info_plist_file_path + " does not exist."
return # rubocop:disable UnreachableCode
end
unless git.diff_for_file(info_plist_file_path) # No diff found for Info.plist file.
fail "You did not edit your Info.plist file at all. Therefore, you did not change the iOS version."
return # rubocop:disable UnreachableCode
end
git_diff_string = git.diff_for_file(info_plist_file_path).patch
assert_version_changed_diff(git_diff_string)
end
|
[
"def",
"assert_version_changed",
"(",
"info_plist_file_path",
")",
"unless",
"File",
".",
"file?",
"(",
"info_plist_file_path",
")",
"fail",
"\"Info.plist at path \"",
"+",
"info_plist_file_path",
"+",
"\" does not exist.\"",
"return",
"# rubocop:disable UnreachableCode",
"end",
"unless",
"git",
".",
"diff_for_file",
"(",
"info_plist_file_path",
")",
"# No diff found for Info.plist file.",
"fail",
"\"You did not edit your Info.plist file at all. Therefore, you did not change the iOS version.\"",
"return",
"# rubocop:disable UnreachableCode",
"end",
"git_diff_string",
"=",
"git",
".",
"diff_for_file",
"(",
"info_plist_file_path",
")",
".",
"patch",
"assert_version_changed_diff",
"(",
"git_diff_string",
")",
"end"
] |
Asserts the version string has been changed in your iOS XCode project.
@example Assert the version string changed for your iOS project
# Calls Danger `fail` if the version string not updated or nothing if it has changed.
ios_version_change.assert_version_changed("ProjectName/Info.plist")
@param [String] info_plist_file_path
Path to Info.plist file for XCode project.
@return [void]
|
[
"Asserts",
"the",
"version",
"string",
"has",
"been",
"changed",
"in",
"your",
"iOS",
"XCode",
"project",
"."
] |
1a263e5eb188381dbdb92d76983c56d089736907
|
https://github.com/levibostian/danger-ios_version_change/blob/1a263e5eb188381dbdb92d76983c56d089736907/lib/ios_version_change/plugin.rb#L48-L61
|
9,912
|
payout/announcer
|
lib/announcer/event.rb
|
Announcer.Event._evaluate_params
|
def _evaluate_params(params)
unless params.is_a?(Hash)
raise ArgumentError, 'event parameters must be a hash'
end
params = params.dup
@instance = params.delete(:instance)
@params = _sanitize_params(params)
end
|
ruby
|
def _evaluate_params(params)
unless params.is_a?(Hash)
raise ArgumentError, 'event parameters must be a hash'
end
params = params.dup
@instance = params.delete(:instance)
@params = _sanitize_params(params)
end
|
[
"def",
"_evaluate_params",
"(",
"params",
")",
"unless",
"params",
".",
"is_a?",
"(",
"Hash",
")",
"raise",
"ArgumentError",
",",
"'event parameters must be a hash'",
"end",
"params",
"=",
"params",
".",
"dup",
"@instance",
"=",
"params",
".",
"delete",
"(",
":instance",
")",
"@params",
"=",
"_sanitize_params",
"(",
"params",
")",
"end"
] |
Parameter Evaluation Logic
This evaluates the parameters passed to the initializer.
Root evaluation method.
|
[
"Parameter",
"Evaluation",
"Logic"
] |
2281360c368b5c024a00d447c0fc83af5f1b4ee1
|
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/event.rb#L54-L62
|
9,913
|
payout/announcer
|
lib/announcer/event.rb
|
Announcer.Event._sanitize_params
|
def _sanitize_params(params)
Hash[params.map { |key, value| [key.to_sym, _sanitize_value(key, value)] }].freeze
end
|
ruby
|
def _sanitize_params(params)
Hash[params.map { |key, value| [key.to_sym, _sanitize_value(key, value)] }].freeze
end
|
[
"def",
"_sanitize_params",
"(",
"params",
")",
"Hash",
"[",
"params",
".",
"map",
"{",
"|",
"key",
",",
"value",
"|",
"[",
"key",
".",
"to_sym",
",",
"_sanitize_value",
"(",
"key",
",",
"value",
")",
"]",
"}",
"]",
".",
"freeze",
"end"
] |
Sanitize the event params.
Prevents passing values that could cause errors later in Announcer.
|
[
"Sanitize",
"the",
"event",
"params",
".",
"Prevents",
"passing",
"values",
"that",
"could",
"cause",
"errors",
"later",
"in",
"Announcer",
"."
] |
2281360c368b5c024a00d447c0fc83af5f1b4ee1
|
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/event.rb#L68-L70
|
9,914
|
payout/announcer
|
lib/announcer/event.rb
|
Announcer.Event._sanitize_array
|
def _sanitize_array(key, array)
array.map { |value| _sanitize_value(key, value) }.freeze
end
|
ruby
|
def _sanitize_array(key, array)
array.map { |value| _sanitize_value(key, value) }.freeze
end
|
[
"def",
"_sanitize_array",
"(",
"key",
",",
"array",
")",
"array",
".",
"map",
"{",
"|",
"value",
"|",
"_sanitize_value",
"(",
"key",
",",
"value",
")",
"}",
".",
"freeze",
"end"
] |
Sanitize an array.
|
[
"Sanitize",
"an",
"array",
"."
] |
2281360c368b5c024a00d447c0fc83af5f1b4ee1
|
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/event.rb#L73-L75
|
9,915
|
payout/announcer
|
lib/announcer/event.rb
|
Announcer.Event._sanitize_value
|
def _sanitize_value(key, value)
case value
when String
value.dup.freeze
when Symbol, Integer, Float, NilClass, TrueClass, FalseClass
value
when Array
_sanitize_array(key, value)
when Hash
_sanitize_params(value)
else
raise Errors::UnsafeValueError.new(key, value)
end
end
|
ruby
|
def _sanitize_value(key, value)
case value
when String
value.dup.freeze
when Symbol, Integer, Float, NilClass, TrueClass, FalseClass
value
when Array
_sanitize_array(key, value)
when Hash
_sanitize_params(value)
else
raise Errors::UnsafeValueError.new(key, value)
end
end
|
[
"def",
"_sanitize_value",
"(",
"key",
",",
"value",
")",
"case",
"value",
"when",
"String",
"value",
".",
"dup",
".",
"freeze",
"when",
"Symbol",
",",
"Integer",
",",
"Float",
",",
"NilClass",
",",
"TrueClass",
",",
"FalseClass",
"value",
"when",
"Array",
"_sanitize_array",
"(",
"key",
",",
"value",
")",
"when",
"Hash",
"_sanitize_params",
"(",
"value",
")",
"else",
"raise",
"Errors",
"::",
"UnsafeValueError",
".",
"new",
"(",
"key",
",",
"value",
")",
"end",
"end"
] |
Sanitize an individual value.
|
[
"Sanitize",
"an",
"individual",
"value",
"."
] |
2281360c368b5c024a00d447c0fc83af5f1b4ee1
|
https://github.com/payout/announcer/blob/2281360c368b5c024a00d447c0fc83af5f1b4ee1/lib/announcer/event.rb#L78-L91
|
9,916
|
patchapps/hash-that-tree
|
lib/hashit.rb
|
HashThatTree.HashIt.validate
|
def validate
@folders.each do |item|
if(item==nil) || (item=="") || !Dir.exists?(item)
puts "a valid folder path is required as argument #{item}"
exit
end
end
end
|
ruby
|
def validate
@folders.each do |item|
if(item==nil) || (item=="") || !Dir.exists?(item)
puts "a valid folder path is required as argument #{item}"
exit
end
end
end
|
[
"def",
"validate",
"@folders",
".",
"each",
"do",
"|",
"item",
"|",
"if",
"(",
"item",
"==",
"nil",
")",
"||",
"(",
"item",
"==",
"\"\"",
")",
"||",
"!",
"Dir",
".",
"exists?",
"(",
"item",
")",
"puts",
"\"a valid folder path is required as argument #{item}\"",
"exit",
"end",
"end",
"end"
] |
the container for the files that could not be processed
initialize the class with the folders to be processed
Validates the supplied folders ensuring they exist
|
[
"the",
"container",
"for",
"the",
"files",
"that",
"could",
"not",
"be",
"processed",
"initialize",
"the",
"class",
"with",
"the",
"folders",
"to",
"be",
"processed",
"Validates",
"the",
"supplied",
"folders",
"ensuring",
"they",
"exist"
] |
05a006389340d96d13613abc60a16f83b2bfd052
|
https://github.com/patchapps/hash-that-tree/blob/05a006389340d96d13613abc60a16f83b2bfd052/lib/hashit.rb#L26-L33
|
9,917
|
nolanw/mpq
|
lib/replay_file.rb
|
MPQ.SC2ReplayFile.attributes
|
def attributes
return @attributes if defined? @attributes
data = read_file "replay.attributes.events"
data.slice! 0, (game_version[:build] < 17326 ? 4 : 5)
@attributes = []
data.slice!(0, 4).unpack("V")[0].times do
@attributes << Attribute.read(data.slice!(0, 13))
end
@attributes
end
|
ruby
|
def attributes
return @attributes if defined? @attributes
data = read_file "replay.attributes.events"
data.slice! 0, (game_version[:build] < 17326 ? 4 : 5)
@attributes = []
data.slice!(0, 4).unpack("V")[0].times do
@attributes << Attribute.read(data.slice!(0, 13))
end
@attributes
end
|
[
"def",
"attributes",
"return",
"@attributes",
"if",
"defined?",
"@attributes",
"data",
"=",
"read_file",
"\"replay.attributes.events\"",
"data",
".",
"slice!",
"0",
",",
"(",
"game_version",
"[",
":build",
"]",
"<",
"17326",
"?",
"4",
":",
"5",
")",
"@attributes",
"=",
"[",
"]",
"data",
".",
"slice!",
"(",
"0",
",",
"4",
")",
".",
"unpack",
"(",
"\"V\"",
")",
"[",
"0",
"]",
".",
"times",
"do",
"@attributes",
"<<",
"Attribute",
".",
"read",
"(",
"data",
".",
"slice!",
"(",
"0",
",",
"13",
")",
")",
"end",
"@attributes",
"end"
] |
`replay.attributes.events` has plenty of handy information. Here we
simply deserialize all the attributes, taking into account a format
change that took place in build 17326, for later processing.
|
[
"replay",
".",
"attributes",
".",
"events",
"has",
"plenty",
"of",
"handy",
"information",
".",
"Here",
"we",
"simply",
"deserialize",
"all",
"the",
"attributes",
"taking",
"into",
"account",
"a",
"format",
"change",
"that",
"took",
"place",
"in",
"build",
"17326",
"for",
"later",
"processing",
"."
] |
4584611f6cede02807257fcf7defdf93b9b7f7db
|
https://github.com/nolanw/mpq/blob/4584611f6cede02807257fcf7defdf93b9b7f7db/lib/replay_file.rb#L123-L132
|
9,918
|
nolanw/mpq
|
lib/replay_file.rb
|
MPQ.SC2ReplayFile.parse_global_attributes
|
def parse_global_attributes
attributes.each do |attr|
case attr.id.to_i
when 0x07d1
@game_type = attr.sval
@game_type = @game_type == 'Cust' ? :custom : @game_type[1, 3].to_sym
when 0x0bb8
@game_speed = ATTRIBUTES[:game_speed][attr.sval]
when 0x0bc1
@category = ATTRIBUTES[:category][attr.sval]
end
end
end
|
ruby
|
def parse_global_attributes
attributes.each do |attr|
case attr.id.to_i
when 0x07d1
@game_type = attr.sval
@game_type = @game_type == 'Cust' ? :custom : @game_type[1, 3].to_sym
when 0x0bb8
@game_speed = ATTRIBUTES[:game_speed][attr.sval]
when 0x0bc1
@category = ATTRIBUTES[:category][attr.sval]
end
end
end
|
[
"def",
"parse_global_attributes",
"attributes",
".",
"each",
"do",
"|",
"attr",
"|",
"case",
"attr",
".",
"id",
".",
"to_i",
"when",
"0x07d1",
"@game_type",
"=",
"attr",
".",
"sval",
"@game_type",
"=",
"@game_type",
"==",
"'Cust'",
"?",
":custom",
":",
"@game_type",
"[",
"1",
",",
"3",
"]",
".",
"to_sym",
"when",
"0x0bb8",
"@game_speed",
"=",
"ATTRIBUTES",
"[",
":game_speed",
"]",
"[",
"attr",
".",
"sval",
"]",
"when",
"0x0bc1",
"@category",
"=",
"ATTRIBUTES",
"[",
":category",
"]",
"[",
"attr",
".",
"sval",
"]",
"end",
"end",
"end"
] |
Several pieces of information come from `replay.attributes.events`, and
finding one of them is about as hard as finding all of them, so we just
find all of them here when asked.
|
[
"Several",
"pieces",
"of",
"information",
"come",
"from",
"replay",
".",
"attributes",
".",
"events",
"and",
"finding",
"one",
"of",
"them",
"is",
"about",
"as",
"hard",
"as",
"finding",
"all",
"of",
"them",
"so",
"we",
"just",
"find",
"all",
"of",
"them",
"here",
"when",
"asked",
"."
] |
4584611f6cede02807257fcf7defdf93b9b7f7db
|
https://github.com/nolanw/mpq/blob/4584611f6cede02807257fcf7defdf93b9b7f7db/lib/replay_file.rb#L150-L162
|
9,919
|
tether/actionpusher
|
lib/action_pusher/base.rb
|
ActionPusher.Base.push
|
def push(opts)
tokens = [opts[:tokens] || opts[:token] || opts[:to]].flatten
message = opts[:message] || ''
data = opts[:data] || {}
badge_count = opts[:badge_count] || 0
return self if message.blank?
@_notifications = Array.new.tap do |notifications|
tokens.each do |token|
notifications << Houston::Notification.new(device: token).tap do |notification|
notification.alert = message
notification.badge = badge_count
notification.custom_data = data
end
end
end
self
end
|
ruby
|
def push(opts)
tokens = [opts[:tokens] || opts[:token] || opts[:to]].flatten
message = opts[:message] || ''
data = opts[:data] || {}
badge_count = opts[:badge_count] || 0
return self if message.blank?
@_notifications = Array.new.tap do |notifications|
tokens.each do |token|
notifications << Houston::Notification.new(device: token).tap do |notification|
notification.alert = message
notification.badge = badge_count
notification.custom_data = data
end
end
end
self
end
|
[
"def",
"push",
"(",
"opts",
")",
"tokens",
"=",
"[",
"opts",
"[",
":tokens",
"]",
"||",
"opts",
"[",
":token",
"]",
"||",
"opts",
"[",
":to",
"]",
"]",
".",
"flatten",
"message",
"=",
"opts",
"[",
":message",
"]",
"||",
"''",
"data",
"=",
"opts",
"[",
":data",
"]",
"||",
"{",
"}",
"badge_count",
"=",
"opts",
"[",
":badge_count",
"]",
"||",
"0",
"return",
"self",
"if",
"message",
".",
"blank?",
"@_notifications",
"=",
"Array",
".",
"new",
".",
"tap",
"do",
"|",
"notifications",
"|",
"tokens",
".",
"each",
"do",
"|",
"token",
"|",
"notifications",
"<<",
"Houston",
"::",
"Notification",
".",
"new",
"(",
"device",
":",
"token",
")",
".",
"tap",
"do",
"|",
"notification",
"|",
"notification",
".",
"alert",
"=",
"message",
"notification",
".",
"badge",
"=",
"badge_count",
"notification",
".",
"custom_data",
"=",
"data",
"end",
"end",
"end",
"self",
"end"
] |
Create apple push notifications to be sent out
* *Args*
- +tokens+ -> User's being sent to
- +message+ -> Message sent to tokens
- +data+ -> Custom data passed through the push notification
- +badge_count+ -> Number to place in badge (default is 0)
|
[
"Create",
"apple",
"push",
"notifications",
"to",
"be",
"sent",
"out"
] |
0855a0bbe744fc87f555e49505adb49ce67f7516
|
https://github.com/tether/actionpusher/blob/0855a0bbe744fc87f555e49505adb49ce67f7516/lib/action_pusher/base.rb#L21-L40
|
9,920
|
tether/actionpusher
|
lib/action_pusher/base.rb
|
ActionPusher.Base.deliver
|
def deliver
return self if @_push_was_called
@_push_was_called = true
apn = APNCertificate.instance
@_notifications.each do |notification|
apn.push(notification)
end
end
|
ruby
|
def deliver
return self if @_push_was_called
@_push_was_called = true
apn = APNCertificate.instance
@_notifications.each do |notification|
apn.push(notification)
end
end
|
[
"def",
"deliver",
"return",
"self",
"if",
"@_push_was_called",
"@_push_was_called",
"=",
"true",
"apn",
"=",
"APNCertificate",
".",
"instance",
"@_notifications",
".",
"each",
"do",
"|",
"notification",
"|",
"apn",
".",
"push",
"(",
"notification",
")",
"end",
"end"
] |
Send out the push notifications
|
[
"Send",
"out",
"the",
"push",
"notifications"
] |
0855a0bbe744fc87f555e49505adb49ce67f7516
|
https://github.com/tether/actionpusher/blob/0855a0bbe744fc87f555e49505adb49ce67f7516/lib/action_pusher/base.rb#L48-L57
|
9,921
|
bdunn313/apexgen
|
lib/apexgen/object_factory.rb
|
Apexgen.ObjectFactory.generate
|
def generate
create_header
unless @fields.empty?
@fields.each { |field| create_field(field) }
end
create_footer
@dtd << Ox.dump(@doc).strip
end
|
ruby
|
def generate
create_header
unless @fields.empty?
@fields.each { |field| create_field(field) }
end
create_footer
@dtd << Ox.dump(@doc).strip
end
|
[
"def",
"generate",
"create_header",
"unless",
"@fields",
".",
"empty?",
"@fields",
".",
"each",
"{",
"|",
"field",
"|",
"create_field",
"(",
"field",
")",
"}",
"end",
"create_footer",
"@dtd",
"<<",
"Ox",
".",
"dump",
"(",
"@doc",
")",
".",
"strip",
"end"
] |
Initialization
Create the XML and return XML string
|
[
"Initialization",
"Create",
"the",
"XML",
"and",
"return",
"XML",
"string"
] |
b993e54b6077b89f431baa938fdca556c50a677f
|
https://github.com/bdunn313/apexgen/blob/b993e54b6077b89f431baa938fdca556c50a677f/lib/apexgen/object_factory.rb#L21-L28
|
9,922
|
bdunn313/apexgen
|
lib/apexgen/object_factory.rb
|
Apexgen.ObjectFactory.make_node
|
def make_node(name, value=nil, attributes={})
node = Ox::Element.new(name)
node << value unless value.nil?
attributes.each { |att, val| node[att] = val } unless attributes.empty?
node
end
|
ruby
|
def make_node(name, value=nil, attributes={})
node = Ox::Element.new(name)
node << value unless value.nil?
attributes.each { |att, val| node[att] = val } unless attributes.empty?
node
end
|
[
"def",
"make_node",
"(",
"name",
",",
"value",
"=",
"nil",
",",
"attributes",
"=",
"{",
"}",
")",
"node",
"=",
"Ox",
"::",
"Element",
".",
"new",
"(",
"name",
")",
"node",
"<<",
"value",
"unless",
"value",
".",
"nil?",
"attributes",
".",
"each",
"{",
"|",
"att",
",",
"val",
"|",
"node",
"[",
"att",
"]",
"=",
"val",
"}",
"unless",
"attributes",
".",
"empty?",
"node",
"end"
] |
Make and return a single node
|
[
"Make",
"and",
"return",
"a",
"single",
"node"
] |
b993e54b6077b89f431baa938fdca556c50a677f
|
https://github.com/bdunn313/apexgen/blob/b993e54b6077b89f431baa938fdca556c50a677f/lib/apexgen/object_factory.rb#L31-L38
|
9,923
|
bdunn313/apexgen
|
lib/apexgen/object_factory.rb
|
Apexgen.ObjectFactory.make_nodes
|
def make_nodes(nodes, parent_node)
nodes.each do |name, value|
if value.kind_of?(Hash)
node = Ox::Element.new(name.to_s)
make_nodes(value, node)
else
node = make_node(name.to_s, value)
end
parent_node << node
parent_node
end
end
|
ruby
|
def make_nodes(nodes, parent_node)
nodes.each do |name, value|
if value.kind_of?(Hash)
node = Ox::Element.new(name.to_s)
make_nodes(value, node)
else
node = make_node(name.to_s, value)
end
parent_node << node
parent_node
end
end
|
[
"def",
"make_nodes",
"(",
"nodes",
",",
"parent_node",
")",
"nodes",
".",
"each",
"do",
"|",
"name",
",",
"value",
"|",
"if",
"value",
".",
"kind_of?",
"(",
"Hash",
")",
"node",
"=",
"Ox",
"::",
"Element",
".",
"new",
"(",
"name",
".",
"to_s",
")",
"make_nodes",
"(",
"value",
",",
"node",
")",
"else",
"node",
"=",
"make_node",
"(",
"name",
".",
"to_s",
",",
"value",
")",
"end",
"parent_node",
"<<",
"node",
"parent_node",
"end",
"end"
] |
Make multiple nodes, appending to the parent passed to the method
|
[
"Make",
"multiple",
"nodes",
"appending",
"to",
"the",
"parent",
"passed",
"to",
"the",
"method"
] |
b993e54b6077b89f431baa938fdca556c50a677f
|
https://github.com/bdunn313/apexgen/blob/b993e54b6077b89f431baa938fdca556c50a677f/lib/apexgen/object_factory.rb#L41-L52
|
9,924
|
bdunn313/apexgen
|
lib/apexgen/object_factory.rb
|
Apexgen.ObjectFactory.create_header
|
def create_header
nodes = {
deploymentStatus: 'Deployed',
description: "A custom object named #{@name}",
enableActivities: 'true',
enableFeeds: 'false',
enableHistory: 'true',
enableReports: 'true'
}
make_nodes(nodes, @doc_root)
end
|
ruby
|
def create_header
nodes = {
deploymentStatus: 'Deployed',
description: "A custom object named #{@name}",
enableActivities: 'true',
enableFeeds: 'false',
enableHistory: 'true',
enableReports: 'true'
}
make_nodes(nodes, @doc_root)
end
|
[
"def",
"create_header",
"nodes",
"=",
"{",
"deploymentStatus",
":",
"'Deployed'",
",",
"description",
":",
"\"A custom object named #{@name}\"",
",",
"enableActivities",
":",
"'true'",
",",
"enableFeeds",
":",
"'false'",
",",
"enableHistory",
":",
"'true'",
",",
"enableReports",
":",
"'true'",
"}",
"make_nodes",
"(",
"nodes",
",",
"@doc_root",
")",
"end"
] |
Create the header for an object
|
[
"Create",
"the",
"header",
"for",
"an",
"object"
] |
b993e54b6077b89f431baa938fdca556c50a677f
|
https://github.com/bdunn313/apexgen/blob/b993e54b6077b89f431baa938fdca556c50a677f/lib/apexgen/object_factory.rb#L58-L68
|
9,925
|
waffleau/angular_rails_seo
|
lib/angular_rails_seo/view_helpers.rb
|
AngularRailsSeo.ViewHelpers.seo_data
|
def seo_data
if @seo_data.nil?
Rails.configuration.seo.each do |key, value|
regex = Regexp.new(value["regex"]).match(request.path)
unless regex.nil?
data = Rails.configuration.seo[key]
fallback = data["parent"].blank? ? seo_default : seo_default.merge(Rails.configuration.seo[data["parent"]])
unless data["model"].blank?
response = seo_dynamic(data["model"], regex[1..(regex.size - 1)])
data = response.nil? ? {} : response
end
@seo_data = fallback.merge(data)
end
end
end
@seo_data ||= seo_default
end
|
ruby
|
def seo_data
if @seo_data.nil?
Rails.configuration.seo.each do |key, value|
regex = Regexp.new(value["regex"]).match(request.path)
unless regex.nil?
data = Rails.configuration.seo[key]
fallback = data["parent"].blank? ? seo_default : seo_default.merge(Rails.configuration.seo[data["parent"]])
unless data["model"].blank?
response = seo_dynamic(data["model"], regex[1..(regex.size - 1)])
data = response.nil? ? {} : response
end
@seo_data = fallback.merge(data)
end
end
end
@seo_data ||= seo_default
end
|
[
"def",
"seo_data",
"if",
"@seo_data",
".",
"nil?",
"Rails",
".",
"configuration",
".",
"seo",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"regex",
"=",
"Regexp",
".",
"new",
"(",
"value",
"[",
"\"regex\"",
"]",
")",
".",
"match",
"(",
"request",
".",
"path",
")",
"unless",
"regex",
".",
"nil?",
"data",
"=",
"Rails",
".",
"configuration",
".",
"seo",
"[",
"key",
"]",
"fallback",
"=",
"data",
"[",
"\"parent\"",
"]",
".",
"blank?",
"?",
"seo_default",
":",
"seo_default",
".",
"merge",
"(",
"Rails",
".",
"configuration",
".",
"seo",
"[",
"data",
"[",
"\"parent\"",
"]",
"]",
")",
"unless",
"data",
"[",
"\"model\"",
"]",
".",
"blank?",
"response",
"=",
"seo_dynamic",
"(",
"data",
"[",
"\"model\"",
"]",
",",
"regex",
"[",
"1",
"..",
"(",
"regex",
".",
"size",
"-",
"1",
")",
"]",
")",
"data",
"=",
"response",
".",
"nil?",
"?",
"{",
"}",
":",
"response",
"end",
"@seo_data",
"=",
"fallback",
".",
"merge",
"(",
"data",
")",
"end",
"end",
"end",
"@seo_data",
"||=",
"seo_default",
"end"
] |
Returns SEO data as defined in in seo.json
|
[
"Returns",
"SEO",
"data",
"as",
"defined",
"in",
"in",
"seo",
".",
"json"
] |
3f8c766b1c9c09385e9af57c96cf714ca34b552f
|
https://github.com/waffleau/angular_rails_seo/blob/3f8c766b1c9c09385e9af57c96cf714ca34b552f/lib/angular_rails_seo/view_helpers.rb#L6-L26
|
9,926
|
jacquescrocker/viewfu
|
lib/view_fu/tag_helper.rb
|
ViewFu.TagHelper.add_class
|
def add_class(css_class, options = {})
return {} unless css_class
attributes = {:class => css_class}
if options.has_key?(:unless)
return options[:unless] ? {} : attributes
end
if options.has_key?(:if)
return options[:if] ? attributes : {}
end
attributes
end
|
ruby
|
def add_class(css_class, options = {})
return {} unless css_class
attributes = {:class => css_class}
if options.has_key?(:unless)
return options[:unless] ? {} : attributes
end
if options.has_key?(:if)
return options[:if] ? attributes : {}
end
attributes
end
|
[
"def",
"add_class",
"(",
"css_class",
",",
"options",
"=",
"{",
"}",
")",
"return",
"{",
"}",
"unless",
"css_class",
"attributes",
"=",
"{",
":class",
"=>",
"css_class",
"}",
"if",
"options",
".",
"has_key?",
"(",
":unless",
")",
"return",
"options",
"[",
":unless",
"]",
"?",
"{",
"}",
":",
"attributes",
"end",
"if",
"options",
".",
"has_key?",
"(",
":if",
")",
"return",
"options",
"[",
":if",
"]",
"?",
"attributes",
":",
"{",
"}",
"end",
"attributes",
"end"
] |
provides a slick way to add classes inside haml attribute collections
examples:
%div{add_class("current")}
#=> adds the "current" class to the div
%div{add_class("current", :if => current?)}
#=> adds the "current" class to the div if current? method
%div{add_class("highlight", :unless => logged_in?)}
#=> adds the "highlight" class to the div unless logged_in? method returns true
|
[
"provides",
"a",
"slick",
"way",
"to",
"add",
"classes",
"inside",
"haml",
"attribute",
"collections"
] |
a21946e74553a1e83790ba7ea2a2ef4daa729458
|
https://github.com/jacquescrocker/viewfu/blob/a21946e74553a1e83790ba7ea2a2ef4daa729458/lib/view_fu/tag_helper.rb#L57-L71
|
9,927
|
jacquescrocker/viewfu
|
lib/view_fu/tag_helper.rb
|
ViewFu.TagHelper.delete_link
|
def delete_link(*args)
options = {:method => :delete, :confirm => "Are you sure you want to delete this?"}.merge(extract_options_from_args!(args)||{})
args << options
link_to(*args)
end
|
ruby
|
def delete_link(*args)
options = {:method => :delete, :confirm => "Are you sure you want to delete this?"}.merge(extract_options_from_args!(args)||{})
args << options
link_to(*args)
end
|
[
"def",
"delete_link",
"(",
"*",
"args",
")",
"options",
"=",
"{",
":method",
"=>",
":delete",
",",
":confirm",
"=>",
"\"Are you sure you want to delete this?\"",
"}",
".",
"merge",
"(",
"extract_options_from_args!",
"(",
"args",
")",
"||",
"{",
"}",
")",
"args",
"<<",
"options",
"link_to",
"(",
"args",
")",
"end"
] |
Wrap a delete link
|
[
"Wrap",
"a",
"delete",
"link"
] |
a21946e74553a1e83790ba7ea2a2ef4daa729458
|
https://github.com/jacquescrocker/viewfu/blob/a21946e74553a1e83790ba7ea2a2ef4daa729458/lib/view_fu/tag_helper.rb#L112-L116
|
9,928
|
jonas-lantto/table_transform
|
lib/table_transform/table.rb
|
TableTransform.Table.metadata
|
def metadata
warn 'metadata is deprecated. Use column_properties[] instead'
@column_properties.inject({}){|res, (k, v)| res.merge!({k => v.to_h})}
end
|
ruby
|
def metadata
warn 'metadata is deprecated. Use column_properties[] instead'
@column_properties.inject({}){|res, (k, v)| res.merge!({k => v.to_h})}
end
|
[
"def",
"metadata",
"warn",
"'metadata is deprecated. Use column_properties[] instead'",
"@column_properties",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"res",
",",
"(",
"k",
",",
"v",
")",
"|",
"res",
".",
"merge!",
"(",
"{",
"k",
"=>",
"v",
".",
"to_h",
"}",
")",
"}",
"end"
] |
Returns meta data as Hash with header name as key
|
[
"Returns",
"meta",
"data",
"as",
"Hash",
"with",
"header",
"name",
"as",
"key"
] |
38d61dbda784210d918734231f26106cfcd9bc9c
|
https://github.com/jonas-lantto/table_transform/blob/38d61dbda784210d918734231f26106cfcd9bc9c/lib/table_transform/table.rb#L55-L58
|
9,929
|
jonas-lantto/table_transform
|
lib/table_transform/table.rb
|
TableTransform.Table.+
|
def +(table)
t2 = table.to_a
t2_header = t2.shift
raise 'Tables cannot be added due to header mismatch' unless @column_properties.keys == t2_header
raise 'Tables cannot be added due to column properties mismatch' unless column_properties_eql? table.column_properties
raise 'Tables cannot be added due to table properties mismatch' unless @table_properties.to_h == table.table_properties.to_h
TableTransform::Table.new(self.to_a + t2)
end
|
ruby
|
def +(table)
t2 = table.to_a
t2_header = t2.shift
raise 'Tables cannot be added due to header mismatch' unless @column_properties.keys == t2_header
raise 'Tables cannot be added due to column properties mismatch' unless column_properties_eql? table.column_properties
raise 'Tables cannot be added due to table properties mismatch' unless @table_properties.to_h == table.table_properties.to_h
TableTransform::Table.new(self.to_a + t2)
end
|
[
"def",
"+",
"(",
"table",
")",
"t2",
"=",
"table",
".",
"to_a",
"t2_header",
"=",
"t2",
".",
"shift",
"raise",
"'Tables cannot be added due to header mismatch'",
"unless",
"@column_properties",
".",
"keys",
"==",
"t2_header",
"raise",
"'Tables cannot be added due to column properties mismatch'",
"unless",
"column_properties_eql?",
"table",
".",
"column_properties",
"raise",
"'Tables cannot be added due to table properties mismatch'",
"unless",
"@table_properties",
".",
"to_h",
"==",
"table",
".",
"table_properties",
".",
"to_h",
"TableTransform",
"::",
"Table",
".",
"new",
"(",
"self",
".",
"to_a",
"+",
"t2",
")",
"end"
] |
Add two tables
@throws if header or properties do not match
|
[
"Add",
"two",
"tables"
] |
38d61dbda784210d918734231f26106cfcd9bc9c
|
https://github.com/jonas-lantto/table_transform/blob/38d61dbda784210d918734231f26106cfcd9bc9c/lib/table_transform/table.rb#L73-L80
|
9,930
|
jonas-lantto/table_transform
|
lib/table_transform/table.rb
|
TableTransform.Table.add_column
|
def add_column(name, column_properties = {})
validate_column_absence(name)
create_column_properties(name, column_properties)
@data_rows.each{|x|
x << (yield Row.new(@column_indexes, x))
}
@column_indexes[name] = @column_indexes.size
self # enable chaining
end
|
ruby
|
def add_column(name, column_properties = {})
validate_column_absence(name)
create_column_properties(name, column_properties)
@data_rows.each{|x|
x << (yield Row.new(@column_indexes, x))
}
@column_indexes[name] = @column_indexes.size
self # enable chaining
end
|
[
"def",
"add_column",
"(",
"name",
",",
"column_properties",
"=",
"{",
"}",
")",
"validate_column_absence",
"(",
"name",
")",
"create_column_properties",
"(",
"name",
",",
"column_properties",
")",
"@data_rows",
".",
"each",
"{",
"|",
"x",
"|",
"x",
"<<",
"(",
"yield",
"Row",
".",
"new",
"(",
"@column_indexes",
",",
"x",
")",
")",
"}",
"@column_indexes",
"[",
"name",
"]",
"=",
"@column_indexes",
".",
"size",
"self",
"# enable chaining",
"end"
] |
adds a column with given name to the far right of the table
@throws if given column name already exists
|
[
"adds",
"a",
"column",
"with",
"given",
"name",
"to",
"the",
"far",
"right",
"of",
"the",
"table"
] |
38d61dbda784210d918734231f26106cfcd9bc9c
|
https://github.com/jonas-lantto/table_transform/blob/38d61dbda784210d918734231f26106cfcd9bc9c/lib/table_transform/table.rb#L116-L124
|
9,931
|
piedoom/clyp-ruby
|
lib/clyp/client.rb
|
Clyp.Client.upload
|
def upload track
if track.playlist_id and track.playlist_token
response = JSON.parse(RestClient.post(UPLOAD_BASE, audioFile: track.file, title: track.title, playlistId: track.playlist_id,
playlistUploadToken: track.playlist_token, order: track.order, description: track.description,
longitude: track.longitude, latitude: track.latitude))
else
response = JSON.parse(RestClient.post(UPLOAD_BASE, audioFile: track.file, title: track.title,
order: track.order, description: track.description, longitude: track.longitude, latitude: track.latitude))
end
TrackUser.new(response)
end
|
ruby
|
def upload track
if track.playlist_id and track.playlist_token
response = JSON.parse(RestClient.post(UPLOAD_BASE, audioFile: track.file, title: track.title, playlistId: track.playlist_id,
playlistUploadToken: track.playlist_token, order: track.order, description: track.description,
longitude: track.longitude, latitude: track.latitude))
else
response = JSON.parse(RestClient.post(UPLOAD_BASE, audioFile: track.file, title: track.title,
order: track.order, description: track.description, longitude: track.longitude, latitude: track.latitude))
end
TrackUser.new(response)
end
|
[
"def",
"upload",
"track",
"if",
"track",
".",
"playlist_id",
"and",
"track",
".",
"playlist_token",
"response",
"=",
"JSON",
".",
"parse",
"(",
"RestClient",
".",
"post",
"(",
"UPLOAD_BASE",
",",
"audioFile",
":",
"track",
".",
"file",
",",
"title",
":",
"track",
".",
"title",
",",
"playlistId",
":",
"track",
".",
"playlist_id",
",",
"playlistUploadToken",
":",
"track",
".",
"playlist_token",
",",
"order",
":",
"track",
".",
"order",
",",
"description",
":",
"track",
".",
"description",
",",
"longitude",
":",
"track",
".",
"longitude",
",",
"latitude",
":",
"track",
".",
"latitude",
")",
")",
"else",
"response",
"=",
"JSON",
".",
"parse",
"(",
"RestClient",
".",
"post",
"(",
"UPLOAD_BASE",
",",
"audioFile",
":",
"track",
".",
"file",
",",
"title",
":",
"track",
".",
"title",
",",
"order",
":",
"track",
".",
"order",
",",
"description",
":",
"track",
".",
"description",
",",
"longitude",
":",
"track",
".",
"longitude",
",",
"latitude",
":",
"track",
".",
"latitude",
")",
")",
"end",
"TrackUser",
".",
"new",
"(",
"response",
")",
"end"
] |
uploads a TrackUpload object, returns a TrackUser object
|
[
"uploads",
"a",
"TrackUpload",
"object",
"returns",
"a",
"TrackUser",
"object"
] |
7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e
|
https://github.com/piedoom/clyp-ruby/blob/7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e/lib/clyp/client.rb#L9-L19
|
9,932
|
piedoom/clyp-ruby
|
lib/clyp/client.rb
|
Clyp.Client.get
|
def get (id:)
response = Faraday.get("#{API_BASE}/#{id}")
attributes = JSON.parse(response.body)
Track.new(attributes)
end
|
ruby
|
def get (id:)
response = Faraday.get("#{API_BASE}/#{id}")
attributes = JSON.parse(response.body)
Track.new(attributes)
end
|
[
"def",
"get",
"(",
"id",
":",
")",
"response",
"=",
"Faraday",
".",
"get",
"(",
"\"#{API_BASE}/#{id}\"",
")",
"attributes",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"Track",
".",
"new",
"(",
"attributes",
")",
"end"
] |
get song with specific id
|
[
"get",
"song",
"with",
"specific",
"id"
] |
7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e
|
https://github.com/piedoom/clyp-ruby/blob/7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e/lib/clyp/client.rb#L22-L26
|
9,933
|
piedoom/clyp-ruby
|
lib/clyp/client.rb
|
Clyp.Client.soundwave
|
def soundwave (id:)
response = Faraday.get("#{API_BASE}/#{id}/soundwave")
attributes = JSON.parse(response.body)
Soundwave.new(attributes)
end
|
ruby
|
def soundwave (id:)
response = Faraday.get("#{API_BASE}/#{id}/soundwave")
attributes = JSON.parse(response.body)
Soundwave.new(attributes)
end
|
[
"def",
"soundwave",
"(",
"id",
":",
")",
"response",
"=",
"Faraday",
".",
"get",
"(",
"\"#{API_BASE}/#{id}/soundwave\"",
")",
"attributes",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"Soundwave",
".",
"new",
"(",
"attributes",
")",
"end"
] |
returns a Soundwave object with peak data
|
[
"returns",
"a",
"Soundwave",
"object",
"with",
"peak",
"data"
] |
7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e
|
https://github.com/piedoom/clyp-ruby/blob/7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e/lib/clyp/client.rb#L29-L33
|
9,934
|
piedoom/clyp-ruby
|
lib/clyp/client.rb
|
Clyp.Client.category_list
|
def category_list
response = Faraday.get("#{API_BASE}/categorylist")
attributes = JSON.parse(response.body)
result = Array.new
attributes.each do |attrs|
result << ListItem.new(attrs)
end
result
end
|
ruby
|
def category_list
response = Faraday.get("#{API_BASE}/categorylist")
attributes = JSON.parse(response.body)
result = Array.new
attributes.each do |attrs|
result << ListItem.new(attrs)
end
result
end
|
[
"def",
"category_list",
"response",
"=",
"Faraday",
".",
"get",
"(",
"\"#{API_BASE}/categorylist\"",
")",
"attributes",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"result",
"=",
"Array",
".",
"new",
"attributes",
".",
"each",
"do",
"|",
"attrs",
"|",
"result",
"<<",
"ListItem",
".",
"new",
"(",
"attrs",
")",
"end",
"result",
"end"
] |
returns an array of ListItem objects of categories
|
[
"returns",
"an",
"array",
"of",
"ListItem",
"objects",
"of",
"categories"
] |
7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e
|
https://github.com/piedoom/clyp-ruby/blob/7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e/lib/clyp/client.rb#L36-L44
|
9,935
|
piedoom/clyp-ruby
|
lib/clyp/client.rb
|
Clyp.Client.search
|
def search term
response = Faraday.get("#{API_BASE}/categorylist/#{term}")
attributes = JSON.parse(response.body)
assemble_tracks attributes
end
|
ruby
|
def search term
response = Faraday.get("#{API_BASE}/categorylist/#{term}")
attributes = JSON.parse(response.body)
assemble_tracks attributes
end
|
[
"def",
"search",
"term",
"response",
"=",
"Faraday",
".",
"get",
"(",
"\"#{API_BASE}/categorylist/#{term}\"",
")",
"attributes",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"assemble_tracks",
"attributes",
"end"
] |
returns 20 tracks from a specified search in an array of Track objects
|
[
"returns",
"20",
"tracks",
"from",
"a",
"specified",
"search",
"in",
"an",
"array",
"of",
"Track",
"objects"
] |
7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e
|
https://github.com/piedoom/clyp-ruby/blob/7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e/lib/clyp/client.rb#L47-L51
|
9,936
|
piedoom/clyp-ruby
|
lib/clyp/client.rb
|
Clyp.Client.featured
|
def featured (count: 10)
response = Faraday.get("#{API_BASE}/featuredlist/featured?count=#{count}")
attributes = JSON.parse(response.body)
assemble_tracks attributes
end
|
ruby
|
def featured (count: 10)
response = Faraday.get("#{API_BASE}/featuredlist/featured?count=#{count}")
attributes = JSON.parse(response.body)
assemble_tracks attributes
end
|
[
"def",
"featured",
"(",
"count",
":",
"10",
")",
"response",
"=",
"Faraday",
".",
"get",
"(",
"\"#{API_BASE}/featuredlist/featured?count=#{count}\"",
")",
"attributes",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"assemble_tracks",
"attributes",
"end"
] |
returns featured tracks in an array of Track objects
|
[
"returns",
"featured",
"tracks",
"in",
"an",
"array",
"of",
"Track",
"objects"
] |
7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e
|
https://github.com/piedoom/clyp-ruby/blob/7cef96b9a6a1a2f5d67cd13aee5243b21a019c8e/lib/clyp/client.rb#L54-L58
|
9,937
|
michaelmior/mipper
|
lib/mipper/gurobi/model.rb
|
MIPPeR.GurobiModel.gurobi_status
|
def gurobi_status
intptr = FFI::MemoryPointer.new :pointer
ret = Gurobi.GRBgetintattr @ptr, Gurobi::GRB_INT_ATTR_STATUS, intptr
fail if ret != 0
case intptr.read_int
when Gurobi::GRB_OPTIMAL
:optimized
when Gurobi::GRB_INFEASIBLE, Gurobi::GRB_INF_OR_UNBD,
Gurobi::GRB_UNBOUNDED
:invalid
else
:unknown
end
end
|
ruby
|
def gurobi_status
intptr = FFI::MemoryPointer.new :pointer
ret = Gurobi.GRBgetintattr @ptr, Gurobi::GRB_INT_ATTR_STATUS, intptr
fail if ret != 0
case intptr.read_int
when Gurobi::GRB_OPTIMAL
:optimized
when Gurobi::GRB_INFEASIBLE, Gurobi::GRB_INF_OR_UNBD,
Gurobi::GRB_UNBOUNDED
:invalid
else
:unknown
end
end
|
[
"def",
"gurobi_status",
"intptr",
"=",
"FFI",
"::",
"MemoryPointer",
".",
"new",
":pointer",
"ret",
"=",
"Gurobi",
".",
"GRBgetintattr",
"@ptr",
",",
"Gurobi",
"::",
"GRB_INT_ATTR_STATUS",
",",
"intptr",
"fail",
"if",
"ret",
"!=",
"0",
"case",
"intptr",
".",
"read_int",
"when",
"Gurobi",
"::",
"GRB_OPTIMAL",
":optimized",
"when",
"Gurobi",
"::",
"GRB_INFEASIBLE",
",",
"Gurobi",
"::",
"GRB_INF_OR_UNBD",
",",
"Gurobi",
"::",
"GRB_UNBOUNDED",
":invalid",
"else",
":unknown",
"end",
"end"
] |
Get the status of the model
|
[
"Get",
"the",
"status",
"of",
"the",
"model"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/gurobi/model.rb#L75-L89
|
9,938
|
michaelmior/mipper
|
lib/mipper/gurobi/model.rb
|
MIPPeR.GurobiModel.gurobi_objective
|
def gurobi_objective
dblptr = FFI::MemoryPointer.new :pointer
ret = Gurobi.GRBgetdblattr @ptr, Gurobi::GRB_DBL_ATTR_OBJVAL, dblptr
fail if ret != 0
dblptr.read_double
end
|
ruby
|
def gurobi_objective
dblptr = FFI::MemoryPointer.new :pointer
ret = Gurobi.GRBgetdblattr @ptr, Gurobi::GRB_DBL_ATTR_OBJVAL, dblptr
fail if ret != 0
dblptr.read_double
end
|
[
"def",
"gurobi_objective",
"dblptr",
"=",
"FFI",
"::",
"MemoryPointer",
".",
"new",
":pointer",
"ret",
"=",
"Gurobi",
".",
"GRBgetdblattr",
"@ptr",
",",
"Gurobi",
"::",
"GRB_DBL_ATTR_OBJVAL",
",",
"dblptr",
"fail",
"if",
"ret",
"!=",
"0",
"dblptr",
".",
"read_double",
"end"
] |
The value of the objective function
|
[
"The",
"value",
"of",
"the",
"objective",
"function"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/gurobi/model.rb#L92-L97
|
9,939
|
michaelmior/mipper
|
lib/mipper/gurobi/model.rb
|
MIPPeR.GurobiModel.add_variable
|
def add_variable(var)
ret = Gurobi.GRBaddvar @ptr, 0, nil, nil, var.coefficient,
var.lower_bound, var.upper_bound,
gurobi_type(var.type), var.name
fail if ret != 0
store_variable var
end
|
ruby
|
def add_variable(var)
ret = Gurobi.GRBaddvar @ptr, 0, nil, nil, var.coefficient,
var.lower_bound, var.upper_bound,
gurobi_type(var.type), var.name
fail if ret != 0
store_variable var
end
|
[
"def",
"add_variable",
"(",
"var",
")",
"ret",
"=",
"Gurobi",
".",
"GRBaddvar",
"@ptr",
",",
"0",
",",
"nil",
",",
"nil",
",",
"var",
".",
"coefficient",
",",
"var",
".",
"lower_bound",
",",
"var",
".",
"upper_bound",
",",
"gurobi_type",
"(",
"var",
".",
"type",
")",
",",
"var",
".",
"name",
"fail",
"if",
"ret",
"!=",
"0",
"store_variable",
"var",
"end"
] |
Add a new variable to the model
|
[
"Add",
"a",
"new",
"variable",
"to",
"the",
"model"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/gurobi/model.rb#L125-L132
|
9,940
|
michaelmior/mipper
|
lib/mipper/gurobi/model.rb
|
MIPPeR.GurobiModel.add_constraint
|
def add_constraint(constr)
terms = constr.expression.terms
indexes_buffer = build_pointer_array(terms.each_key.map do |var|
var.index
end, :int)
values_buffer = build_pointer_array terms.values, :double
ret = Gurobi.GRBaddconstr @ptr, terms.length,
indexes_buffer, values_buffer,
gurobi_sense(constr.sense),
constr.rhs, constr.name
fail if ret != 0
constr.model = self
constr.index = @constraints.length
constr.freeze
@constraints << constr
end
|
ruby
|
def add_constraint(constr)
terms = constr.expression.terms
indexes_buffer = build_pointer_array(terms.each_key.map do |var|
var.index
end, :int)
values_buffer = build_pointer_array terms.values, :double
ret = Gurobi.GRBaddconstr @ptr, terms.length,
indexes_buffer, values_buffer,
gurobi_sense(constr.sense),
constr.rhs, constr.name
fail if ret != 0
constr.model = self
constr.index = @constraints.length
constr.freeze
@constraints << constr
end
|
[
"def",
"add_constraint",
"(",
"constr",
")",
"terms",
"=",
"constr",
".",
"expression",
".",
"terms",
"indexes_buffer",
"=",
"build_pointer_array",
"(",
"terms",
".",
"each_key",
".",
"map",
"do",
"|",
"var",
"|",
"var",
".",
"index",
"end",
",",
":int",
")",
"values_buffer",
"=",
"build_pointer_array",
"terms",
".",
"values",
",",
":double",
"ret",
"=",
"Gurobi",
".",
"GRBaddconstr",
"@ptr",
",",
"terms",
".",
"length",
",",
"indexes_buffer",
",",
"values_buffer",
",",
"gurobi_sense",
"(",
"constr",
".",
"sense",
")",
",",
"constr",
".",
"rhs",
",",
"constr",
".",
"name",
"fail",
"if",
"ret",
"!=",
"0",
"constr",
".",
"model",
"=",
"self",
"constr",
".",
"index",
"=",
"@constraints",
".",
"length",
"constr",
".",
"freeze",
"@constraints",
"<<",
"constr",
"end"
] |
Add a new constraint to the model
|
[
"Add",
"a",
"new",
"constraint",
"to",
"the",
"model"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/gurobi/model.rb#L163-L180
|
9,941
|
michaelmior/mipper
|
lib/mipper/gurobi/model.rb
|
MIPPeR.GurobiModel.build_constraint_matrix
|
def build_constraint_matrix(constrs)
cbeg = []
cind = []
cval = []
constrs.each.map do |constr|
cbeg << cind.length
constr.expression.terms.each do |var, coeff|
cind << var.index
cval << coeff
end
end
[cbeg, cind, cval]
end
|
ruby
|
def build_constraint_matrix(constrs)
cbeg = []
cind = []
cval = []
constrs.each.map do |constr|
cbeg << cind.length
constr.expression.terms.each do |var, coeff|
cind << var.index
cval << coeff
end
end
[cbeg, cind, cval]
end
|
[
"def",
"build_constraint_matrix",
"(",
"constrs",
")",
"cbeg",
"=",
"[",
"]",
"cind",
"=",
"[",
"]",
"cval",
"=",
"[",
"]",
"constrs",
".",
"each",
".",
"map",
"do",
"|",
"constr",
"|",
"cbeg",
"<<",
"cind",
".",
"length",
"constr",
".",
"expression",
".",
"terms",
".",
"each",
"do",
"|",
"var",
",",
"coeff",
"|",
"cind",
"<<",
"var",
".",
"index",
"cval",
"<<",
"coeff",
"end",
"end",
"[",
"cbeg",
",",
"cind",
",",
"cval",
"]",
"end"
] |
Construct a matrix of values for the given list of constraints
|
[
"Construct",
"a",
"matrix",
"of",
"values",
"for",
"the",
"given",
"list",
"of",
"constraints"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/gurobi/model.rb#L190-L203
|
9,942
|
michaelmior/mipper
|
lib/mipper/gurobi/model.rb
|
MIPPeR.GurobiModel.array_to_pointers_to_names
|
def array_to_pointers_to_names(arr)
arr.map do |obj|
obj.name.nil? ? nil : FFI::MemoryPointer.from_string(obj.name)
end
end
|
ruby
|
def array_to_pointers_to_names(arr)
arr.map do |obj|
obj.name.nil? ? nil : FFI::MemoryPointer.from_string(obj.name)
end
end
|
[
"def",
"array_to_pointers_to_names",
"(",
"arr",
")",
"arr",
".",
"map",
"do",
"|",
"obj",
"|",
"obj",
".",
"name",
".",
"nil?",
"?",
"nil",
":",
"FFI",
"::",
"MemoryPointer",
".",
"from_string",
"(",
"obj",
".",
"name",
")",
"end",
"end"
] |
Convert an array of objects to an FFI array of
memory pointers to the names of each object
|
[
"Convert",
"an",
"array",
"of",
"objects",
"to",
"an",
"FFI",
"array",
"of",
"memory",
"pointers",
"to",
"the",
"names",
"of",
"each",
"object"
] |
4ab7f8b32c27f33fc5121756554a0a28d2077e06
|
https://github.com/michaelmior/mipper/blob/4ab7f8b32c27f33fc5121756554a0a28d2077e06/lib/mipper/gurobi/model.rb#L243-L247
|
9,943
|
ideonetwork/lato-blog
|
app/models/lato_blog/post/serializer_helpers.rb
|
LatoBlog.Post::SerializerHelpers.serialize
|
def serialize
serialized = {}
# set basic info
serialized[:id] = id
serialized[:title] = title
serialized[:subtitle] = subtitle
serialized[:excerpt] = excerpt
serialized[:content] = content
serialized[:seo_description] = seo_description
serialized[:meta_language] = meta_language
serialized[:meta_permalink] = meta_permalink
serialized[:meta_status] = meta_status
# add fields informations
serialized[:fields] = serialize_fields
# add categories informations
serialized[:categories] = serialize_categories
# add tags informations
serialized[:tags] = serialize_tags
# add post parent informations
serialized[:other_informations] = serialize_other_informations
# return serialized post
serialized
end
|
ruby
|
def serialize
serialized = {}
# set basic info
serialized[:id] = id
serialized[:title] = title
serialized[:subtitle] = subtitle
serialized[:excerpt] = excerpt
serialized[:content] = content
serialized[:seo_description] = seo_description
serialized[:meta_language] = meta_language
serialized[:meta_permalink] = meta_permalink
serialized[:meta_status] = meta_status
# add fields informations
serialized[:fields] = serialize_fields
# add categories informations
serialized[:categories] = serialize_categories
# add tags informations
serialized[:tags] = serialize_tags
# add post parent informations
serialized[:other_informations] = serialize_other_informations
# return serialized post
serialized
end
|
[
"def",
"serialize",
"serialized",
"=",
"{",
"}",
"# set basic info",
"serialized",
"[",
":id",
"]",
"=",
"id",
"serialized",
"[",
":title",
"]",
"=",
"title",
"serialized",
"[",
":subtitle",
"]",
"=",
"subtitle",
"serialized",
"[",
":excerpt",
"]",
"=",
"excerpt",
"serialized",
"[",
":content",
"]",
"=",
"content",
"serialized",
"[",
":seo_description",
"]",
"=",
"seo_description",
"serialized",
"[",
":meta_language",
"]",
"=",
"meta_language",
"serialized",
"[",
":meta_permalink",
"]",
"=",
"meta_permalink",
"serialized",
"[",
":meta_status",
"]",
"=",
"meta_status",
"# add fields informations",
"serialized",
"[",
":fields",
"]",
"=",
"serialize_fields",
"# add categories informations",
"serialized",
"[",
":categories",
"]",
"=",
"serialize_categories",
"# add tags informations",
"serialized",
"[",
":tags",
"]",
"=",
"serialize_tags",
"# add post parent informations",
"serialized",
"[",
":other_informations",
"]",
"=",
"serialize_other_informations",
"# return serialized post",
"serialized",
"end"
] |
This function serializes a complete version of the post.
|
[
"This",
"function",
"serializes",
"a",
"complete",
"version",
"of",
"the",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/post/serializer_helpers.rb#L5-L33
|
9,944
|
ideonetwork/lato-blog
|
app/models/lato_blog/post/serializer_helpers.rb
|
LatoBlog.Post::SerializerHelpers.serialize_fields
|
def serialize_fields
serialized = {}
post_fields.visibles.roots.order('position ASC').each do |post_field|
serialized[post_field.key] = post_field.serialize_base
end
serialized
end
|
ruby
|
def serialize_fields
serialized = {}
post_fields.visibles.roots.order('position ASC').each do |post_field|
serialized[post_field.key] = post_field.serialize_base
end
serialized
end
|
[
"def",
"serialize_fields",
"serialized",
"=",
"{",
"}",
"post_fields",
".",
"visibles",
".",
"roots",
".",
"order",
"(",
"'position ASC'",
")",
".",
"each",
"do",
"|",
"post_field",
"|",
"serialized",
"[",
"post_field",
".",
"key",
"]",
"=",
"post_field",
".",
"serialize_base",
"end",
"serialized",
"end"
] |
This function serializes the list of fields for the post.
|
[
"This",
"function",
"serializes",
"the",
"list",
"of",
"fields",
"for",
"the",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/post/serializer_helpers.rb#L53-L59
|
9,945
|
ideonetwork/lato-blog
|
app/models/lato_blog/post/serializer_helpers.rb
|
LatoBlog.Post::SerializerHelpers.serialize_categories
|
def serialize_categories
serialized = {}
categories.each do |category|
serialized[category.id] = category.serialize_base
end
serialized
end
|
ruby
|
def serialize_categories
serialized = {}
categories.each do |category|
serialized[category.id] = category.serialize_base
end
serialized
end
|
[
"def",
"serialize_categories",
"serialized",
"=",
"{",
"}",
"categories",
".",
"each",
"do",
"|",
"category",
"|",
"serialized",
"[",
"category",
".",
"id",
"]",
"=",
"category",
".",
"serialize_base",
"end",
"serialized",
"end"
] |
This function serializes the list of categories for the post.
|
[
"This",
"function",
"serializes",
"the",
"list",
"of",
"categories",
"for",
"the",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/post/serializer_helpers.rb#L62-L68
|
9,946
|
ideonetwork/lato-blog
|
app/models/lato_blog/post/serializer_helpers.rb
|
LatoBlog.Post::SerializerHelpers.serialize_tags
|
def serialize_tags
serialized = {}
tags.each do |tag|
serialized[tag.id] = tag.serialize_base
end
serialized
end
|
ruby
|
def serialize_tags
serialized = {}
tags.each do |tag|
serialized[tag.id] = tag.serialize_base
end
serialized
end
|
[
"def",
"serialize_tags",
"serialized",
"=",
"{",
"}",
"tags",
".",
"each",
"do",
"|",
"tag",
"|",
"serialized",
"[",
"tag",
".",
"id",
"]",
"=",
"tag",
".",
"serialize_base",
"end",
"serialized",
"end"
] |
This function serializes the list of tags for the post.
|
[
"This",
"function",
"serializes",
"the",
"list",
"of",
"tags",
"for",
"the",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/post/serializer_helpers.rb#L71-L77
|
9,947
|
ideonetwork/lato-blog
|
app/models/lato_blog/post/serializer_helpers.rb
|
LatoBlog.Post::SerializerHelpers.serialize_other_informations
|
def serialize_other_informations
serialized = {}
# set pubblication datetime
serialized[:publication_datetime] = post_parent.publication_datetime
# set translations links
serialized[:translations] = {}
post_parent.posts.published.each do |post|
next if post.id == id
serialized[:translations][post.meta_language] = post.serialize_base
end
# return serialzed informations
serialized
end
|
ruby
|
def serialize_other_informations
serialized = {}
# set pubblication datetime
serialized[:publication_datetime] = post_parent.publication_datetime
# set translations links
serialized[:translations] = {}
post_parent.posts.published.each do |post|
next if post.id == id
serialized[:translations][post.meta_language] = post.serialize_base
end
# return serialzed informations
serialized
end
|
[
"def",
"serialize_other_informations",
"serialized",
"=",
"{",
"}",
"# set pubblication datetime",
"serialized",
"[",
":publication_datetime",
"]",
"=",
"post_parent",
".",
"publication_datetime",
"# set translations links",
"serialized",
"[",
":translations",
"]",
"=",
"{",
"}",
"post_parent",
".",
"posts",
".",
"published",
".",
"each",
"do",
"|",
"post",
"|",
"next",
"if",
"post",
".",
"id",
"==",
"id",
"serialized",
"[",
":translations",
"]",
"[",
"post",
".",
"meta_language",
"]",
"=",
"post",
".",
"serialize_base",
"end",
"# return serialzed informations",
"serialized",
"end"
] |
This function serializes other informations for the post.
|
[
"This",
"function",
"serializes",
"other",
"informations",
"for",
"the",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/models/lato_blog/post/serializer_helpers.rb#L80-L95
|
9,948
|
avishekjana/rscratch
|
app/models/rscratch/exception.rb
|
Rscratch.Exception.set_attributes_for
|
def set_attributes_for _exception, _controller, _action, _env
self.exception = _exception.class
self.message = _exception.message
self.controller = _controller
self.action = _action
self.app_environment = _env
end
|
ruby
|
def set_attributes_for _exception, _controller, _action, _env
self.exception = _exception.class
self.message = _exception.message
self.controller = _controller
self.action = _action
self.app_environment = _env
end
|
[
"def",
"set_attributes_for",
"_exception",
",",
"_controller",
",",
"_action",
",",
"_env",
"self",
".",
"exception",
"=",
"_exception",
".",
"class",
"self",
".",
"message",
"=",
"_exception",
".",
"message",
"self",
".",
"controller",
"=",
"_controller",
"self",
".",
"action",
"=",
"_action",
"self",
".",
"app_environment",
"=",
"_env",
"end"
] |
Sets Exception instance attributes.
|
[
"Sets",
"Exception",
"instance",
"attributes",
"."
] |
96493d123473efa2f252d9427455beee947949e1
|
https://github.com/avishekjana/rscratch/blob/96493d123473efa2f252d9427455beee947949e1/app/models/rscratch/exception.rb#L63-L69
|
9,949
|
sld/astar-15puzzle-solver
|
lib/fifteen_puzzle.rb
|
FifteenPuzzle.GameMatrix.moved_matrix_with_parent
|
def moved_matrix_with_parent( i, j, new_i, new_j, open_list, closed_list )
return nil if !index_exist?( new_i, new_j )
swapped_matrix = swap( i, j, new_i, new_j )
new_depth = @depth + 1
swapped_matrix = GameMatrix.new( swapped_matrix, self, new_depth )
return nil if closed_list.include?( swapped_matrix )
swapped_matrix.calculate_cost
open_list_matrix = open_list.find{ |e| e == swapped_matrix }
if open_list_matrix && open_list_matrix.cost < swapped_matrix.cost
return open_list_matrix
elsif open_list_matrix
open_list_matrix.parent = self
open_list_matrix.depth = new_depth
return open_list_matrix
else
return swapped_matrix
end
end
|
ruby
|
def moved_matrix_with_parent( i, j, new_i, new_j, open_list, closed_list )
return nil if !index_exist?( new_i, new_j )
swapped_matrix = swap( i, j, new_i, new_j )
new_depth = @depth + 1
swapped_matrix = GameMatrix.new( swapped_matrix, self, new_depth )
return nil if closed_list.include?( swapped_matrix )
swapped_matrix.calculate_cost
open_list_matrix = open_list.find{ |e| e == swapped_matrix }
if open_list_matrix && open_list_matrix.cost < swapped_matrix.cost
return open_list_matrix
elsif open_list_matrix
open_list_matrix.parent = self
open_list_matrix.depth = new_depth
return open_list_matrix
else
return swapped_matrix
end
end
|
[
"def",
"moved_matrix_with_parent",
"(",
"i",
",",
"j",
",",
"new_i",
",",
"new_j",
",",
"open_list",
",",
"closed_list",
")",
"return",
"nil",
"if",
"!",
"index_exist?",
"(",
"new_i",
",",
"new_j",
")",
"swapped_matrix",
"=",
"swap",
"(",
"i",
",",
"j",
",",
"new_i",
",",
"new_j",
")",
"new_depth",
"=",
"@depth",
"+",
"1",
"swapped_matrix",
"=",
"GameMatrix",
".",
"new",
"(",
"swapped_matrix",
",",
"self",
",",
"new_depth",
")",
"return",
"nil",
"if",
"closed_list",
".",
"include?",
"(",
"swapped_matrix",
")",
"swapped_matrix",
".",
"calculate_cost",
"open_list_matrix",
"=",
"open_list",
".",
"find",
"{",
"|",
"e",
"|",
"e",
"==",
"swapped_matrix",
"}",
"if",
"open_list_matrix",
"&&",
"open_list_matrix",
".",
"cost",
"<",
"swapped_matrix",
".",
"cost",
"return",
"open_list_matrix",
"elsif",
"open_list_matrix",
"open_list_matrix",
".",
"parent",
"=",
"self",
"open_list_matrix",
".",
"depth",
"=",
"new_depth",
"return",
"open_list_matrix",
"else",
"return",
"swapped_matrix",
"end",
"end"
] |
Get swapped matrix, check him in closed and open list
|
[
"Get",
"swapped",
"matrix",
"check",
"him",
"in",
"closed",
"and",
"open",
"list"
] |
f65cffea0a78c64e6f1f4a5dd694ccddb7fdf3ea
|
https://github.com/sld/astar-15puzzle-solver/blob/f65cffea0a78c64e6f1f4a5dd694ccddb7fdf3ea/lib/fifteen_puzzle.rb#L213-L233
|
9,950
|
sld/astar-15puzzle-solver
|
lib/fifteen_puzzle.rb
|
FifteenPuzzle.GameMatrix.neighbors
|
def neighbors( open_list=[], closed_list=[] )
i,j = free_cell
up = moved_matrix_with_parent(i, j, i-1, j, open_list, closed_list)
down = moved_matrix_with_parent(i, j, i+1, j, open_list, closed_list)
left = moved_matrix_with_parent(i, j, i, j-1, open_list, closed_list)
right = moved_matrix_with_parent(i, j, i, j+1, open_list, closed_list)
moved = []
moved << up if !up.nil?
moved << down if !down.nil?
moved << left if !left.nil?
moved << right if !right.nil?
return moved
end
|
ruby
|
def neighbors( open_list=[], closed_list=[] )
i,j = free_cell
up = moved_matrix_with_parent(i, j, i-1, j, open_list, closed_list)
down = moved_matrix_with_parent(i, j, i+1, j, open_list, closed_list)
left = moved_matrix_with_parent(i, j, i, j-1, open_list, closed_list)
right = moved_matrix_with_parent(i, j, i, j+1, open_list, closed_list)
moved = []
moved << up if !up.nil?
moved << down if !down.nil?
moved << left if !left.nil?
moved << right if !right.nil?
return moved
end
|
[
"def",
"neighbors",
"(",
"open_list",
"=",
"[",
"]",
",",
"closed_list",
"=",
"[",
"]",
")",
"i",
",",
"j",
"=",
"free_cell",
"up",
"=",
"moved_matrix_with_parent",
"(",
"i",
",",
"j",
",",
"i",
"-",
"1",
",",
"j",
",",
"open_list",
",",
"closed_list",
")",
"down",
"=",
"moved_matrix_with_parent",
"(",
"i",
",",
"j",
",",
"i",
"+",
"1",
",",
"j",
",",
"open_list",
",",
"closed_list",
")",
"left",
"=",
"moved_matrix_with_parent",
"(",
"i",
",",
"j",
",",
"i",
",",
"j",
"-",
"1",
",",
"open_list",
",",
"closed_list",
")",
"right",
"=",
"moved_matrix_with_parent",
"(",
"i",
",",
"j",
",",
"i",
",",
"j",
"+",
"1",
",",
"open_list",
",",
"closed_list",
")",
"moved",
"=",
"[",
"]",
"moved",
"<<",
"up",
"if",
"!",
"up",
".",
"nil?",
"moved",
"<<",
"down",
"if",
"!",
"down",
".",
"nil?",
"moved",
"<<",
"left",
"if",
"!",
"left",
".",
"nil?",
"moved",
"<<",
"right",
"if",
"!",
"right",
".",
"nil?",
"return",
"moved",
"end"
] |
Get all possible movement matrixes
|
[
"Get",
"all",
"possible",
"movement",
"matrixes"
] |
f65cffea0a78c64e6f1f4a5dd694ccddb7fdf3ea
|
https://github.com/sld/astar-15puzzle-solver/blob/f65cffea0a78c64e6f1f4a5dd694ccddb7fdf3ea/lib/fifteen_puzzle.rb#L237-L251
|
9,951
|
nolanw/mpq
|
lib/mpq.rb
|
MPQ.Archive.read_table
|
def read_table table
table_offset = @archive_header.send "#{table}_table_offset"
@io.seek @user_header.archive_header_offset + table_offset
table_entries = @archive_header.send "#{table}_table_entries"
data = @io.read table_entries * 16
key = Hashing::hash_for :table, "(#{table} table)"
data = Hashing::decrypt data, key
klass = table == :hash ? HashTableEntry : BlockTableEntry
(0...table_entries).map do |i|
klass.read(data[i * 16, 16])
end
end
|
ruby
|
def read_table table
table_offset = @archive_header.send "#{table}_table_offset"
@io.seek @user_header.archive_header_offset + table_offset
table_entries = @archive_header.send "#{table}_table_entries"
data = @io.read table_entries * 16
key = Hashing::hash_for :table, "(#{table} table)"
data = Hashing::decrypt data, key
klass = table == :hash ? HashTableEntry : BlockTableEntry
(0...table_entries).map do |i|
klass.read(data[i * 16, 16])
end
end
|
[
"def",
"read_table",
"table",
"table_offset",
"=",
"@archive_header",
".",
"send",
"\"#{table}_table_offset\"",
"@io",
".",
"seek",
"@user_header",
".",
"archive_header_offset",
"+",
"table_offset",
"table_entries",
"=",
"@archive_header",
".",
"send",
"\"#{table}_table_entries\"",
"data",
"=",
"@io",
".",
"read",
"table_entries",
"*",
"16",
"key",
"=",
"Hashing",
"::",
"hash_for",
":table",
",",
"\"(#{table} table)\"",
"data",
"=",
"Hashing",
"::",
"decrypt",
"data",
",",
"key",
"klass",
"=",
"table",
"==",
":hash",
"?",
"HashTableEntry",
":",
"BlockTableEntry",
"(",
"0",
"...",
"table_entries",
")",
".",
"map",
"do",
"|",
"i",
"|",
"klass",
".",
"read",
"(",
"data",
"[",
"i",
"*",
"16",
",",
"16",
"]",
")",
"end",
"end"
] |
In general, MPQ archives start with either the MPQ header, or they start
with a user header which points to the MPQ header. StarCraft 2 replays
always have a user header, so we don't even bother to check here.
The MPQ header points to two very helpful parts of the MPQ archive: the
hash table, which tells us where the contents of files are found, and the
block table, which holds said contents of files. That's all we need to
read up front.
Both the hash and block tables' contents are hashed (in the same way), so
we need to decrypt them in order to read their contents.
|
[
"In",
"general",
"MPQ",
"archives",
"start",
"with",
"either",
"the",
"MPQ",
"header",
"or",
"they",
"start",
"with",
"a",
"user",
"header",
"which",
"points",
"to",
"the",
"MPQ",
"header",
".",
"StarCraft",
"2",
"replays",
"always",
"have",
"a",
"user",
"header",
"so",
"we",
"don",
"t",
"even",
"bother",
"to",
"check",
"here",
"."
] |
4584611f6cede02807257fcf7defdf93b9b7f7db
|
https://github.com/nolanw/mpq/blob/4584611f6cede02807257fcf7defdf93b9b7f7db/lib/mpq.rb#L39-L50
|
9,952
|
nolanw/mpq
|
lib/mpq.rb
|
MPQ.Archive.read_file
|
def read_file filename
# The first block location is stored in the hash table.
hash_a = Hashing::hash_for :hash_a, filename
hash_b = Hashing::hash_for :hash_b, filename
hash_entry = @hash_table.find do |h|
[h.hash_a, h.hash_b] == [hash_a, hash_b]
end
unless hash_entry
return nil
end
block_entry = @block_table[hash_entry.block_index]
unless block_entry.file?
return nil
end
@io.seek @user_header.archive_header_offset + block_entry.block_offset
file_data = @io.read block_entry.archived_size
# Blocks can be encrypted. Decryption isn't currently implemented as none
# of the blocks in a StarCraft 2 replay are encrypted.
if block_entry.encrypted?
return nil
end
# Files can consist of one or many blocks. In either case, each block
# (or *sector*) is read and individually decompressed if needed, then
# stitched together for the final result.
if block_entry.single_unit?
if block_entry.compressed?
if file_data.bytes.next == 16
file_data = Bzip2.uncompress file_data[1, file_data.length]
end
end
return file_data
end
sector_size = 512 << @archive_header.sector_size_shift
sectors = block_entry.size / sector_size + 1
if block_entry.has_checksums
sectors += 1
end
positions = file_data[0, 4 * (sectors + 1)].unpack "V#{sectors + 1}"
sectors = []
positions.each_with_index do |pos, i|
break if i + 1 == positions.length
sector = file_data[pos, positions[i + 1] - pos]
if block_entry.compressed?
if block_entry.size > block_entry.archived_size
if sector.bytes.next == 16
sector = Bzip2.uncompress sector
end
end
end
sectors << sector
end
sectors.join ''
end
|
ruby
|
def read_file filename
# The first block location is stored in the hash table.
hash_a = Hashing::hash_for :hash_a, filename
hash_b = Hashing::hash_for :hash_b, filename
hash_entry = @hash_table.find do |h|
[h.hash_a, h.hash_b] == [hash_a, hash_b]
end
unless hash_entry
return nil
end
block_entry = @block_table[hash_entry.block_index]
unless block_entry.file?
return nil
end
@io.seek @user_header.archive_header_offset + block_entry.block_offset
file_data = @io.read block_entry.archived_size
# Blocks can be encrypted. Decryption isn't currently implemented as none
# of the blocks in a StarCraft 2 replay are encrypted.
if block_entry.encrypted?
return nil
end
# Files can consist of one or many blocks. In either case, each block
# (or *sector*) is read and individually decompressed if needed, then
# stitched together for the final result.
if block_entry.single_unit?
if block_entry.compressed?
if file_data.bytes.next == 16
file_data = Bzip2.uncompress file_data[1, file_data.length]
end
end
return file_data
end
sector_size = 512 << @archive_header.sector_size_shift
sectors = block_entry.size / sector_size + 1
if block_entry.has_checksums
sectors += 1
end
positions = file_data[0, 4 * (sectors + 1)].unpack "V#{sectors + 1}"
sectors = []
positions.each_with_index do |pos, i|
break if i + 1 == positions.length
sector = file_data[pos, positions[i + 1] - pos]
if block_entry.compressed?
if block_entry.size > block_entry.archived_size
if sector.bytes.next == 16
sector = Bzip2.uncompress sector
end
end
end
sectors << sector
end
sectors.join ''
end
|
[
"def",
"read_file",
"filename",
"# The first block location is stored in the hash table.",
"hash_a",
"=",
"Hashing",
"::",
"hash_for",
":hash_a",
",",
"filename",
"hash_b",
"=",
"Hashing",
"::",
"hash_for",
":hash_b",
",",
"filename",
"hash_entry",
"=",
"@hash_table",
".",
"find",
"do",
"|",
"h",
"|",
"[",
"h",
".",
"hash_a",
",",
"h",
".",
"hash_b",
"]",
"==",
"[",
"hash_a",
",",
"hash_b",
"]",
"end",
"unless",
"hash_entry",
"return",
"nil",
"end",
"block_entry",
"=",
"@block_table",
"[",
"hash_entry",
".",
"block_index",
"]",
"unless",
"block_entry",
".",
"file?",
"return",
"nil",
"end",
"@io",
".",
"seek",
"@user_header",
".",
"archive_header_offset",
"+",
"block_entry",
".",
"block_offset",
"file_data",
"=",
"@io",
".",
"read",
"block_entry",
".",
"archived_size",
"# Blocks can be encrypted. Decryption isn't currently implemented as none ",
"# of the blocks in a StarCraft 2 replay are encrypted.",
"if",
"block_entry",
".",
"encrypted?",
"return",
"nil",
"end",
"# Files can consist of one or many blocks. In either case, each block ",
"# (or *sector*) is read and individually decompressed if needed, then ",
"# stitched together for the final result.",
"if",
"block_entry",
".",
"single_unit?",
"if",
"block_entry",
".",
"compressed?",
"if",
"file_data",
".",
"bytes",
".",
"next",
"==",
"16",
"file_data",
"=",
"Bzip2",
".",
"uncompress",
"file_data",
"[",
"1",
",",
"file_data",
".",
"length",
"]",
"end",
"end",
"return",
"file_data",
"end",
"sector_size",
"=",
"512",
"<<",
"@archive_header",
".",
"sector_size_shift",
"sectors",
"=",
"block_entry",
".",
"size",
"/",
"sector_size",
"+",
"1",
"if",
"block_entry",
".",
"has_checksums",
"sectors",
"+=",
"1",
"end",
"positions",
"=",
"file_data",
"[",
"0",
",",
"4",
"*",
"(",
"sectors",
"+",
"1",
")",
"]",
".",
"unpack",
"\"V#{sectors + 1}\"",
"sectors",
"=",
"[",
"]",
"positions",
".",
"each_with_index",
"do",
"|",
"pos",
",",
"i",
"|",
"break",
"if",
"i",
"+",
"1",
"==",
"positions",
".",
"length",
"sector",
"=",
"file_data",
"[",
"pos",
",",
"positions",
"[",
"i",
"+",
"1",
"]",
"-",
"pos",
"]",
"if",
"block_entry",
".",
"compressed?",
"if",
"block_entry",
".",
"size",
">",
"block_entry",
".",
"archived_size",
"if",
"sector",
".",
"bytes",
".",
"next",
"==",
"16",
"sector",
"=",
"Bzip2",
".",
"uncompress",
"sector",
"end",
"end",
"end",
"sectors",
"<<",
"sector",
"end",
"sectors",
".",
"join",
"''",
"end"
] |
To read a file from the MPQ archive, we need to locate its blocks.
|
[
"To",
"read",
"a",
"file",
"from",
"the",
"MPQ",
"archive",
"we",
"need",
"to",
"locate",
"its",
"blocks",
"."
] |
4584611f6cede02807257fcf7defdf93b9b7f7db
|
https://github.com/nolanw/mpq/blob/4584611f6cede02807257fcf7defdf93b9b7f7db/lib/mpq.rb#L53-L108
|
9,953
|
Deradon/Rdcpu16
|
lib/dcpu16/assembler.rb
|
DCPU16.Assembler.assemble
|
def assemble
location = 0
@labels = {}
@body = []
lines.each do |line|
# Set label location
@labels[line.label] = location if line.label
# Skip when no op
next if line.op.empty?
op = Instruction.create(line.op, line.args, location)
@body << op
location += op.size
end
# Apply labels
begin
@body.each { |op| op.apply_labels(@labels) }
rescue Exception => e
puts @labels.inspect
raise e
end
end
|
ruby
|
def assemble
location = 0
@labels = {}
@body = []
lines.each do |line|
# Set label location
@labels[line.label] = location if line.label
# Skip when no op
next if line.op.empty?
op = Instruction.create(line.op, line.args, location)
@body << op
location += op.size
end
# Apply labels
begin
@body.each { |op| op.apply_labels(@labels) }
rescue Exception => e
puts @labels.inspect
raise e
end
end
|
[
"def",
"assemble",
"location",
"=",
"0",
"@labels",
"=",
"{",
"}",
"@body",
"=",
"[",
"]",
"lines",
".",
"each",
"do",
"|",
"line",
"|",
"# Set label location",
"@labels",
"[",
"line",
".",
"label",
"]",
"=",
"location",
"if",
"line",
".",
"label",
"# Skip when no op",
"next",
"if",
"line",
".",
"op",
".",
"empty?",
"op",
"=",
"Instruction",
".",
"create",
"(",
"line",
".",
"op",
",",
"line",
".",
"args",
",",
"location",
")",
"@body",
"<<",
"op",
"location",
"+=",
"op",
".",
"size",
"end",
"# Apply labels",
"begin",
"@body",
".",
"each",
"{",
"|",
"op",
"|",
"op",
".",
"apply_labels",
"(",
"@labels",
")",
"}",
"rescue",
"Exception",
"=>",
"e",
"puts",
"@labels",
".",
"inspect",
"raise",
"e",
"end",
"end"
] |
Assemble the given input.
|
[
"Assemble",
"the",
"given",
"input",
"."
] |
a4460927aa64c2a514c57993e8ea13f5b48377e9
|
https://github.com/Deradon/Rdcpu16/blob/a4460927aa64c2a514c57993e8ea13f5b48377e9/lib/dcpu16/assembler.rb#L16-L40
|
9,954
|
avishekjana/rscratch
|
app/models/rscratch/exception_log.rb
|
Rscratch.ExceptionLog.set_attributes_for
|
def set_attributes_for exc, request
self.backtrace = exc.backtrace.join("\n"),
self.request_url = request.original_url,
self.request_method = request.request_method,
self.parameters = request.filtered_parameters,
self.user_agent = request.user_agent,
self.client_ip = request.remote_ip,
self.status = "new",
self.description = exc.inspect
end
|
ruby
|
def set_attributes_for exc, request
self.backtrace = exc.backtrace.join("\n"),
self.request_url = request.original_url,
self.request_method = request.request_method,
self.parameters = request.filtered_parameters,
self.user_agent = request.user_agent,
self.client_ip = request.remote_ip,
self.status = "new",
self.description = exc.inspect
end
|
[
"def",
"set_attributes_for",
"exc",
",",
"request",
"self",
".",
"backtrace",
"=",
"exc",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
",",
"self",
".",
"request_url",
"=",
"request",
".",
"original_url",
",",
"self",
".",
"request_method",
"=",
"request",
".",
"request_method",
",",
"self",
".",
"parameters",
"=",
"request",
".",
"filtered_parameters",
",",
"self",
".",
"user_agent",
"=",
"request",
".",
"user_agent",
",",
"self",
".",
"client_ip",
"=",
"request",
".",
"remote_ip",
",",
"self",
".",
"status",
"=",
"\"new\"",
",",
"self",
".",
"description",
"=",
"exc",
".",
"inspect",
"end"
] |
Sets Log instance attributes.
|
[
"Sets",
"Log",
"instance",
"attributes",
"."
] |
96493d123473efa2f252d9427455beee947949e1
|
https://github.com/avishekjana/rscratch/blob/96493d123473efa2f252d9427455beee947949e1/app/models/rscratch/exception_log.rb#L41-L50
|
9,955
|
mobyinc/Cathode
|
lib/cathode/create_request.rb
|
Cathode.CreateRequest.default_action_block
|
def default_action_block
proc do
begin
create_params = instance_eval(&@strong_params)
if resource.singular
create_params["#{parent_resource_name}_id"] = parent_resource_id
end
body model.create(create_params)
rescue ActionController::ParameterMissing => error
body error.message
status :bad_request
end
end
end
|
ruby
|
def default_action_block
proc do
begin
create_params = instance_eval(&@strong_params)
if resource.singular
create_params["#{parent_resource_name}_id"] = parent_resource_id
end
body model.create(create_params)
rescue ActionController::ParameterMissing => error
body error.message
status :bad_request
end
end
end
|
[
"def",
"default_action_block",
"proc",
"do",
"begin",
"create_params",
"=",
"instance_eval",
"(",
"@strong_params",
")",
"if",
"resource",
".",
"singular",
"create_params",
"[",
"\"#{parent_resource_name}_id\"",
"]",
"=",
"parent_resource_id",
"end",
"body",
"model",
".",
"create",
"(",
"create_params",
")",
"rescue",
"ActionController",
"::",
"ParameterMissing",
"=>",
"error",
"body",
"error",
".",
"message",
"status",
":bad_request",
"end",
"end",
"end"
] |
Sets the default action to create a new resource. If the resource is
singular, sets the parent resource `id` as well.
|
[
"Sets",
"the",
"default",
"action",
"to",
"create",
"a",
"new",
"resource",
".",
"If",
"the",
"resource",
"is",
"singular",
"sets",
"the",
"parent",
"resource",
"id",
"as",
"well",
"."
] |
e17be4fb62ad61417e2a3a0a77406459015468a1
|
https://github.com/mobyinc/Cathode/blob/e17be4fb62ad61417e2a3a0a77406459015468a1/lib/cathode/create_request.rb#L6-L19
|
9,956
|
fissionxuiptz/kat
|
lib/kat/app.rb
|
Kat.App.running
|
def running
puts
set_window_width
searching = true
[
-> {
@kat.search @page
searching = false
},
-> {
i = 0
while searching
print "\rSearching...".yellow + '\\|/-'[i % 4]
i += 1
sleep 0.1
end
}
].map { |w| Thread.new { w.call } }.each(&:join)
puts((res = format_results))
if res.size > 1
case (answer = prompt)
when 'i' then @show_info = !@show_info
when 'n' then @page += 1 if next?
when 'p' then @page -= 1 if prev?
when 'q' then return false
else
if (1..@kat.results[@page].size).include?((answer = answer.to_i))
print "\nDownloading".yellow <<
": #{ @kat.results[@page][answer - 1][:title] }... "
puts download @kat.results[@page][answer - 1]
end
end
true
else
false
end
end
|
ruby
|
def running
puts
set_window_width
searching = true
[
-> {
@kat.search @page
searching = false
},
-> {
i = 0
while searching
print "\rSearching...".yellow + '\\|/-'[i % 4]
i += 1
sleep 0.1
end
}
].map { |w| Thread.new { w.call } }.each(&:join)
puts((res = format_results))
if res.size > 1
case (answer = prompt)
when 'i' then @show_info = !@show_info
when 'n' then @page += 1 if next?
when 'p' then @page -= 1 if prev?
when 'q' then return false
else
if (1..@kat.results[@page].size).include?((answer = answer.to_i))
print "\nDownloading".yellow <<
": #{ @kat.results[@page][answer - 1][:title] }... "
puts download @kat.results[@page][answer - 1]
end
end
true
else
false
end
end
|
[
"def",
"running",
"puts",
"set_window_width",
"searching",
"=",
"true",
"[",
"->",
"{",
"@kat",
".",
"search",
"@page",
"searching",
"=",
"false",
"}",
",",
"->",
"{",
"i",
"=",
"0",
"while",
"searching",
"print",
"\"\\rSearching...\"",
".",
"yellow",
"+",
"'\\\\|/-'",
"[",
"i",
"%",
"4",
"]",
"i",
"+=",
"1",
"sleep",
"0.1",
"end",
"}",
"]",
".",
"map",
"{",
"|",
"w",
"|",
"Thread",
".",
"new",
"{",
"w",
".",
"call",
"}",
"}",
".",
"each",
"(",
":join",
")",
"puts",
"(",
"(",
"res",
"=",
"format_results",
")",
")",
"if",
"res",
".",
"size",
">",
"1",
"case",
"(",
"answer",
"=",
"prompt",
")",
"when",
"'i'",
"then",
"@show_info",
"=",
"!",
"@show_info",
"when",
"'n'",
"then",
"@page",
"+=",
"1",
"if",
"next?",
"when",
"'p'",
"then",
"@page",
"-=",
"1",
"if",
"prev?",
"when",
"'q'",
"then",
"return",
"false",
"else",
"if",
"(",
"1",
"..",
"@kat",
".",
"results",
"[",
"@page",
"]",
".",
"size",
")",
".",
"include?",
"(",
"(",
"answer",
"=",
"answer",
".",
"to_i",
")",
")",
"print",
"\"\\nDownloading\"",
".",
"yellow",
"<<",
"\": #{ @kat.results[@page][answer - 1][:title] }... \"",
"puts",
"download",
"@kat",
".",
"results",
"[",
"@page",
"]",
"[",
"answer",
"-",
"1",
"]",
"end",
"end",
"true",
"else",
"false",
"end",
"end"
] |
Do the search, output the results and prompt the user for what to do next.
Returns false on error or the user enters 'q', otherwise returns true to
signify to the main loop it should run again.
|
[
"Do",
"the",
"search",
"output",
"the",
"results",
"and",
"prompt",
"the",
"user",
"for",
"what",
"to",
"do",
"next",
".",
"Returns",
"false",
"on",
"error",
"or",
"the",
"user",
"enters",
"q",
"otherwise",
"returns",
"true",
"to",
"signify",
"to",
"the",
"main",
"loop",
"it",
"should",
"run",
"again",
"."
] |
8f9e43c5dbeb2462e00fd841c208764380f6983b
|
https://github.com/fissionxuiptz/kat/blob/8f9e43c5dbeb2462e00fd841c208764380f6983b/lib/kat/app.rb#L129-L170
|
9,957
|
fissionxuiptz/kat
|
lib/kat/app.rb
|
Kat.App.format_lists
|
def format_lists(lists)
lists.inject([nil]) do |buf, (_, val)|
opts = Kat::Search.send(val[:select])
buf << val[:select].to_s.capitalize
buf << nil unless opts.values.first.is_a? Array
width = opts.keys.sort { |a, b| b.size <=> a.size }.first.size
opts.each do |k, v|
buf += if v.is_a? Array
[nil, "%#{ width }s => #{ v.shift }" % k] +
v.map { |e| ' ' * (width + 4) + e }
else
["%-#{ width }s => #{ v }" % k]
end
end
buf << nil
end
end
|
ruby
|
def format_lists(lists)
lists.inject([nil]) do |buf, (_, val)|
opts = Kat::Search.send(val[:select])
buf << val[:select].to_s.capitalize
buf << nil unless opts.values.first.is_a? Array
width = opts.keys.sort { |a, b| b.size <=> a.size }.first.size
opts.each do |k, v|
buf += if v.is_a? Array
[nil, "%#{ width }s => #{ v.shift }" % k] +
v.map { |e| ' ' * (width + 4) + e }
else
["%-#{ width }s => #{ v }" % k]
end
end
buf << nil
end
end
|
[
"def",
"format_lists",
"(",
"lists",
")",
"lists",
".",
"inject",
"(",
"[",
"nil",
"]",
")",
"do",
"|",
"buf",
",",
"(",
"_",
",",
"val",
")",
"|",
"opts",
"=",
"Kat",
"::",
"Search",
".",
"send",
"(",
"val",
"[",
":select",
"]",
")",
"buf",
"<<",
"val",
"[",
":select",
"]",
".",
"to_s",
".",
"capitalize",
"buf",
"<<",
"nil",
"unless",
"opts",
".",
"values",
".",
"first",
".",
"is_a?",
"Array",
"width",
"=",
"opts",
".",
"keys",
".",
"sort",
"{",
"|",
"a",
",",
"b",
"|",
"b",
".",
"size",
"<=>",
"a",
".",
"size",
"}",
".",
"first",
".",
"size",
"opts",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"buf",
"+=",
"if",
"v",
".",
"is_a?",
"Array",
"[",
"nil",
",",
"\"%#{ width }s => #{ v.shift }\"",
"%",
"k",
"]",
"+",
"v",
".",
"map",
"{",
"|",
"e",
"|",
"' '",
"*",
"(",
"width",
"+",
"4",
")",
"+",
"e",
"}",
"else",
"[",
"\"%-#{ width }s => #{ v }\"",
"%",
"k",
"]",
"end",
"end",
"buf",
"<<",
"nil",
"end",
"end"
] |
Format a list of options
|
[
"Format",
"a",
"list",
"of",
"options"
] |
8f9e43c5dbeb2462e00fd841c208764380f6983b
|
https://github.com/fissionxuiptz/kat/blob/8f9e43c5dbeb2462e00fd841c208764380f6983b/lib/kat/app.rb#L175-L191
|
9,958
|
fissionxuiptz/kat
|
lib/kat/app.rb
|
Kat.App.format_results
|
def format_results
main_width = @window_width - (!hide_info? || @show_info ? 42 : 4)
buf = []
if @kat.error
return ["\rConnection failed".red]
elsif !@kat.results[@page]
return ["\rNo results ".red]
end
buf << "\r#{ @kat.message[:message] }\n".red if @kat.message
buf << ("\r%-#{ main_width + 5 }s#{ ' Size Age Seeds Leeches' if !hide_info? || @show_info }" %
["Page #{ page + 1 } of #{ @kat.pages }", nil]).yellow
@kat.results[@page].each_with_index do |t, i|
age = t[:age].split "\xC2\xA0"
age = '%3d %-6s' % age
# Filter out the crap that invariably infests torrent names
title = t[:title].codepoints.map { |c| c > 31 && c < 127 ? c.chr : '?' }.join[0...main_width]
buf << ("%2d. %-#{ main_width }s#{ ' %10s %10s %7d %7d' if !hide_info? or @show_info }" %
[i + 1, title, t[:size], age, t[:seeds], t[:leeches]]).tap { |s| s.red! if t[:seeds] == 0 }
end
buf << nil
end
|
ruby
|
def format_results
main_width = @window_width - (!hide_info? || @show_info ? 42 : 4)
buf = []
if @kat.error
return ["\rConnection failed".red]
elsif !@kat.results[@page]
return ["\rNo results ".red]
end
buf << "\r#{ @kat.message[:message] }\n".red if @kat.message
buf << ("\r%-#{ main_width + 5 }s#{ ' Size Age Seeds Leeches' if !hide_info? || @show_info }" %
["Page #{ page + 1 } of #{ @kat.pages }", nil]).yellow
@kat.results[@page].each_with_index do |t, i|
age = t[:age].split "\xC2\xA0"
age = '%3d %-6s' % age
# Filter out the crap that invariably infests torrent names
title = t[:title].codepoints.map { |c| c > 31 && c < 127 ? c.chr : '?' }.join[0...main_width]
buf << ("%2d. %-#{ main_width }s#{ ' %10s %10s %7d %7d' if !hide_info? or @show_info }" %
[i + 1, title, t[:size], age, t[:seeds], t[:leeches]]).tap { |s| s.red! if t[:seeds] == 0 }
end
buf << nil
end
|
[
"def",
"format_results",
"main_width",
"=",
"@window_width",
"-",
"(",
"!",
"hide_info?",
"||",
"@show_info",
"?",
"42",
":",
"4",
")",
"buf",
"=",
"[",
"]",
"if",
"@kat",
".",
"error",
"return",
"[",
"\"\\rConnection failed\"",
".",
"red",
"]",
"elsif",
"!",
"@kat",
".",
"results",
"[",
"@page",
"]",
"return",
"[",
"\"\\rNo results \"",
".",
"red",
"]",
"end",
"buf",
"<<",
"\"\\r#{ @kat.message[:message] }\\n\"",
".",
"red",
"if",
"@kat",
".",
"message",
"buf",
"<<",
"(",
"\"\\r%-#{ main_width + 5 }s#{ ' Size Age Seeds Leeches' if !hide_info? || @show_info }\"",
"%",
"[",
"\"Page #{ page + 1 } of #{ @kat.pages }\"",
",",
"nil",
"]",
")",
".",
"yellow",
"@kat",
".",
"results",
"[",
"@page",
"]",
".",
"each_with_index",
"do",
"|",
"t",
",",
"i",
"|",
"age",
"=",
"t",
"[",
":age",
"]",
".",
"split",
"\"\\xC2\\xA0\"",
"age",
"=",
"'%3d %-6s'",
"%",
"age",
"# Filter out the crap that invariably infests torrent names",
"title",
"=",
"t",
"[",
":title",
"]",
".",
"codepoints",
".",
"map",
"{",
"|",
"c",
"|",
"c",
">",
"31",
"&&",
"c",
"<",
"127",
"?",
"c",
".",
"chr",
":",
"'?'",
"}",
".",
"join",
"[",
"0",
"...",
"main_width",
"]",
"buf",
"<<",
"(",
"\"%2d. %-#{ main_width }s#{ ' %10s %10s %7d %7d' if !hide_info? or @show_info }\"",
"%",
"[",
"i",
"+",
"1",
",",
"title",
",",
"t",
"[",
":size",
"]",
",",
"age",
",",
"t",
"[",
":seeds",
"]",
",",
"t",
"[",
":leeches",
"]",
"]",
")",
".",
"tap",
"{",
"|",
"s",
"|",
"s",
".",
"red!",
"if",
"t",
"[",
":seeds",
"]",
"==",
"0",
"}",
"end",
"buf",
"<<",
"nil",
"end"
] |
Format the list of results with header information
|
[
"Format",
"the",
"list",
"of",
"results",
"with",
"header",
"information"
] |
8f9e43c5dbeb2462e00fd841c208764380f6983b
|
https://github.com/fissionxuiptz/kat/blob/8f9e43c5dbeb2462e00fd841c208764380f6983b/lib/kat/app.rb#L196-L221
|
9,959
|
fissionxuiptz/kat
|
lib/kat/app.rb
|
Kat.App.prompt
|
def prompt
n = @kat.results[@page].size
@h.ask("1#{ "-#{n}" if n > 1}".cyan(true) << ' to download' <<
"#{ ', ' << '(n)'.cyan(true) << 'ext' if next? }" <<
"#{ ', ' << '(p)'.cyan(true) << 'rev' if prev? }" <<
"#{ ", #{ @show_info ? 'hide' : 'show' } " << '(i)'.cyan(true) << 'nfo' if hide_info? }" <<
', ' << '(q)'.cyan(true) << 'uit: ') do |q|
q.responses[:not_valid] = 'Invalid option.'
q.validate = validation_regex
end
rescue RegexpError
puts((@kat.pages > 0 ? "Error reading the page\n" : "Could not connect to the site\n").red)
return 'q'
end
|
ruby
|
def prompt
n = @kat.results[@page].size
@h.ask("1#{ "-#{n}" if n > 1}".cyan(true) << ' to download' <<
"#{ ', ' << '(n)'.cyan(true) << 'ext' if next? }" <<
"#{ ', ' << '(p)'.cyan(true) << 'rev' if prev? }" <<
"#{ ", #{ @show_info ? 'hide' : 'show' } " << '(i)'.cyan(true) << 'nfo' if hide_info? }" <<
', ' << '(q)'.cyan(true) << 'uit: ') do |q|
q.responses[:not_valid] = 'Invalid option.'
q.validate = validation_regex
end
rescue RegexpError
puts((@kat.pages > 0 ? "Error reading the page\n" : "Could not connect to the site\n").red)
return 'q'
end
|
[
"def",
"prompt",
"n",
"=",
"@kat",
".",
"results",
"[",
"@page",
"]",
".",
"size",
"@h",
".",
"ask",
"(",
"\"1#{ \"-#{n}\" if n > 1}\"",
".",
"cyan",
"(",
"true",
")",
"<<",
"' to download'",
"<<",
"\"#{ ', ' << '(n)'.cyan(true) << 'ext' if next? }\"",
"<<",
"\"#{ ', ' << '(p)'.cyan(true) << 'rev' if prev? }\"",
"<<",
"\"#{ \", #{ @show_info ? 'hide' : 'show' } \" << '(i)'.cyan(true) << 'nfo' if hide_info? }\"",
"<<",
"', '",
"<<",
"'(q)'",
".",
"cyan",
"(",
"true",
")",
"<<",
"'uit: '",
")",
"do",
"|",
"q",
"|",
"q",
".",
"responses",
"[",
":not_valid",
"]",
"=",
"'Invalid option.'",
"q",
".",
"validate",
"=",
"validation_regex",
"end",
"rescue",
"RegexpError",
"puts",
"(",
"(",
"@kat",
".",
"pages",
">",
"0",
"?",
"\"Error reading the page\\n\"",
":",
"\"Could not connect to the site\\n\"",
")",
".",
"red",
")",
"return",
"'q'",
"end"
] |
Set the prompt after the results list has been printed
|
[
"Set",
"the",
"prompt",
"after",
"the",
"results",
"list",
"has",
"been",
"printed"
] |
8f9e43c5dbeb2462e00fd841c208764380f6983b
|
https://github.com/fissionxuiptz/kat/blob/8f9e43c5dbeb2462e00fd841c208764380f6983b/lib/kat/app.rb#L239-L253
|
9,960
|
anvil-src/anvil-core
|
lib/anvil/cli.rb
|
Anvil.Cli.run
|
def run(argv)
load_tasks
return build_task(argv).run unless argv.empty?
print_help_header
print_help_body
end
|
ruby
|
def run(argv)
load_tasks
return build_task(argv).run unless argv.empty?
print_help_header
print_help_body
end
|
[
"def",
"run",
"(",
"argv",
")",
"load_tasks",
"return",
"build_task",
"(",
"argv",
")",
".",
"run",
"unless",
"argv",
".",
"empty?",
"print_help_header",
"print_help_body",
"end"
] |
Runs a task or prints its help if it needs arguments
@param argv [Array] Command line arguments
@return [Object, nil] Anything the task returns
|
[
"Runs",
"a",
"task",
"or",
"prints",
"its",
"help",
"if",
"it",
"needs",
"arguments"
] |
8322ebd6a2f002e4177b86e707d9c8d5c2a7233d
|
https://github.com/anvil-src/anvil-core/blob/8322ebd6a2f002e4177b86e707d9c8d5c2a7233d/lib/anvil/cli.rb#L19-L26
|
9,961
|
anvil-src/anvil-core
|
lib/anvil/cli.rb
|
Anvil.Cli.build_task
|
def build_task(argv)
arguments = argv.dup
task_name = arguments.shift
klazz = Task.from_name(task_name)
klazz.new(*klazz.parse_options!(arguments))
rescue NameError
task_not_found(task_name)
exit false
rescue ArgumentError
bad_arguments(task_name)
exit false
end
|
ruby
|
def build_task(argv)
arguments = argv.dup
task_name = arguments.shift
klazz = Task.from_name(task_name)
klazz.new(*klazz.parse_options!(arguments))
rescue NameError
task_not_found(task_name)
exit false
rescue ArgumentError
bad_arguments(task_name)
exit false
end
|
[
"def",
"build_task",
"(",
"argv",
")",
"arguments",
"=",
"argv",
".",
"dup",
"task_name",
"=",
"arguments",
".",
"shift",
"klazz",
"=",
"Task",
".",
"from_name",
"(",
"task_name",
")",
"klazz",
".",
"new",
"(",
"klazz",
".",
"parse_options!",
"(",
"arguments",
")",
")",
"rescue",
"NameError",
"task_not_found",
"(",
"task_name",
")",
"exit",
"false",
"rescue",
"ArgumentError",
"bad_arguments",
"(",
"task_name",
")",
"exit",
"false",
"end"
] |
Builds a task and prepares it to run
@param argv [Array] Command line arguments
@return [Anvil::Task] A task ready to run
|
[
"Builds",
"a",
"task",
"and",
"prepares",
"it",
"to",
"run"
] |
8322ebd6a2f002e4177b86e707d9c8d5c2a7233d
|
https://github.com/anvil-src/anvil-core/blob/8322ebd6a2f002e4177b86e707d9c8d5c2a7233d/lib/anvil/cli.rb#L36-L47
|
9,962
|
angdraug/syncache
|
lib/syncache/syncache.rb
|
SynCache.Cache.flush
|
def flush(base = nil)
debug { 'flush ' << base.to_s }
@sync.synchronize do
if @flush_delay
next_flush = @last_flush + @flush_delay
if next_flush > Time.now
flush_at(next_flush, base)
else
flush_now(base)
@last_flush = Time.now
end
else
flush_now(base)
end
end
end
|
ruby
|
def flush(base = nil)
debug { 'flush ' << base.to_s }
@sync.synchronize do
if @flush_delay
next_flush = @last_flush + @flush_delay
if next_flush > Time.now
flush_at(next_flush, base)
else
flush_now(base)
@last_flush = Time.now
end
else
flush_now(base)
end
end
end
|
[
"def",
"flush",
"(",
"base",
"=",
"nil",
")",
"debug",
"{",
"'flush '",
"<<",
"base",
".",
"to_s",
"}",
"@sync",
".",
"synchronize",
"do",
"if",
"@flush_delay",
"next_flush",
"=",
"@last_flush",
"+",
"@flush_delay",
"if",
"next_flush",
">",
"Time",
".",
"now",
"flush_at",
"(",
"next_flush",
",",
"base",
")",
"else",
"flush_now",
"(",
"base",
")",
"@last_flush",
"=",
"Time",
".",
"now",
"end",
"else",
"flush_now",
"(",
"base",
")",
"end",
"end",
"end"
] |
remove all values from cache
if _base_ is given, only values with keys matching the base (using
<tt>===</tt> operator) are removed
|
[
"remove",
"all",
"values",
"from",
"cache"
] |
bb289ed51cce5eff63c7b899f736c184da7922bc
|
https://github.com/angdraug/syncache/blob/bb289ed51cce5eff63c7b899f736c184da7922bc/lib/syncache/syncache.rb#L102-L121
|
9,963
|
angdraug/syncache
|
lib/syncache/syncache.rb
|
SynCache.Cache.[]=
|
def []=(key, value)
debug { '[]= ' << key.to_s }
entry = get_locked_entry(key)
begin
return entry.value = value
ensure
entry.sync.unlock
end
end
|
ruby
|
def []=(key, value)
debug { '[]= ' << key.to_s }
entry = get_locked_entry(key)
begin
return entry.value = value
ensure
entry.sync.unlock
end
end
|
[
"def",
"[]=",
"(",
"key",
",",
"value",
")",
"debug",
"{",
"'[]= '",
"<<",
"key",
".",
"to_s",
"}",
"entry",
"=",
"get_locked_entry",
"(",
"key",
")",
"begin",
"return",
"entry",
".",
"value",
"=",
"value",
"ensure",
"entry",
".",
"sync",
".",
"unlock",
"end",
"end"
] |
store new value in cache
see also Cache#fetch_or_add
|
[
"store",
"new",
"value",
"in",
"cache"
] |
bb289ed51cce5eff63c7b899f736c184da7922bc
|
https://github.com/angdraug/syncache/blob/bb289ed51cce5eff63c7b899f736c184da7922bc/lib/syncache/syncache.rb#L137-L146
|
9,964
|
angdraug/syncache
|
lib/syncache/syncache.rb
|
SynCache.Cache.debug
|
def debug
return unless @debug
message = Thread.current.to_s + ' ' + yield
if defined?(Syslog) and Syslog.opened?
Syslog.debug(message)
else
STDERR << 'syncache: ' + message + "\n"
STDERR.flush
end
end
|
ruby
|
def debug
return unless @debug
message = Thread.current.to_s + ' ' + yield
if defined?(Syslog) and Syslog.opened?
Syslog.debug(message)
else
STDERR << 'syncache: ' + message + "\n"
STDERR.flush
end
end
|
[
"def",
"debug",
"return",
"unless",
"@debug",
"message",
"=",
"Thread",
".",
"current",
".",
"to_s",
"+",
"' '",
"+",
"yield",
"if",
"defined?",
"(",
"Syslog",
")",
"and",
"Syslog",
".",
"opened?",
"Syslog",
".",
"debug",
"(",
"message",
")",
"else",
"STDERR",
"<<",
"'syncache: '",
"+",
"message",
"+",
"\"\\n\"",
"STDERR",
".",
"flush",
"end",
"end"
] |
send debug output to syslog if enabled
|
[
"send",
"debug",
"output",
"to",
"syslog",
"if",
"enabled"
] |
bb289ed51cce5eff63c7b899f736c184da7922bc
|
https://github.com/angdraug/syncache/blob/bb289ed51cce5eff63c7b899f736c184da7922bc/lib/syncache/syncache.rb#L271-L280
|
9,965
|
mooreryan/abort_if
|
lib/assert/assert.rb
|
AbortIf.Assert.assert_keys
|
def assert_keys coll, *keys
check_responds_to coll, :[]
check_not_empty keys
assert keys.all? { |key| coll[key] },
"Expected coll to include all keys"
end
|
ruby
|
def assert_keys coll, *keys
check_responds_to coll, :[]
check_not_empty keys
assert keys.all? { |key| coll[key] },
"Expected coll to include all keys"
end
|
[
"def",
"assert_keys",
"coll",
",",
"*",
"keys",
"check_responds_to",
"coll",
",",
":[]",
"check_not_empty",
"keys",
"assert",
"keys",
".",
"all?",
"{",
"|",
"key",
"|",
"coll",
"[",
"key",
"]",
"}",
",",
"\"Expected coll to include all keys\"",
"end"
] |
If any key is not present in coll, raise AssertionFailureError,
else return nil.
@example Passing
assert_keys {a: 2, b: 1}, :a, :b
#=> nil
@example Failing
assert_keys {a: 2, b: 1}, :a, :b, :c
# raises AssertionFailureError
@param coll [#[]] collection of things
@param *keys keys to check for
@raise [AssertionFailureError] if coll does include every key
@raise [ArgumentError] if coll doesn't respond to :[]
@return [nil] if coll has every key
|
[
"If",
"any",
"key",
"is",
"not",
"present",
"in",
"coll",
"raise",
"AssertionFailureError",
"else",
"return",
"nil",
"."
] |
80b4631f6722c99ec1a6bc59fe683d5b97fc5ef4
|
https://github.com/mooreryan/abort_if/blob/80b4631f6722c99ec1a6bc59fe683d5b97fc5ef4/lib/assert/assert.rb#L127-L134
|
9,966
|
mooreryan/abort_if
|
lib/assert/assert.rb
|
AbortIf.Assert.assert_length
|
def assert_length coll, len
check_responds_to coll, :length
assert coll.length == len,
"Expected coll to have %d items",
len
end
|
ruby
|
def assert_length coll, len
check_responds_to coll, :length
assert coll.length == len,
"Expected coll to have %d items",
len
end
|
[
"def",
"assert_length",
"coll",
",",
"len",
"check_responds_to",
"coll",
",",
":length",
"assert",
"coll",
".",
"length",
"==",
"len",
",",
"\"Expected coll to have %d items\"",
",",
"len",
"end"
] |
If coll is given length, return nil, else raise
AssertionFailureError.
@param coll [#length] anything that responds to :length
@param len [Number] the length to check for
@raise [AssertionFailureError] if length of coll doesn't match
given len
@raise [ArgumentError] if coll doesn't respond to :length
@return [nil] if length of coll matches given len
|
[
"If",
"coll",
"is",
"given",
"length",
"return",
"nil",
"else",
"raise",
"AssertionFailureError",
"."
] |
80b4631f6722c99ec1a6bc59fe683d5b97fc5ef4
|
https://github.com/mooreryan/abort_if/blob/80b4631f6722c99ec1a6bc59fe683d5b97fc5ef4/lib/assert/assert.rb#L196-L202
|
9,967
|
bcurren/ejs-rcompiler
|
lib/ejs/compiler.rb
|
Ejs.Compiler.js_source
|
def js_source(source_path, namespace = nil, output_as_array = false)
template_name = File.basename(source_path, ".ejs")
template_name = "#{namespace}.#{template_name}" if namespace
js_source_from_string(template_name, File.read(source_path), output_as_array)
end
|
ruby
|
def js_source(source_path, namespace = nil, output_as_array = false)
template_name = File.basename(source_path, ".ejs")
template_name = "#{namespace}.#{template_name}" if namespace
js_source_from_string(template_name, File.read(source_path), output_as_array)
end
|
[
"def",
"js_source",
"(",
"source_path",
",",
"namespace",
"=",
"nil",
",",
"output_as_array",
"=",
"false",
")",
"template_name",
"=",
"File",
".",
"basename",
"(",
"source_path",
",",
"\".ejs\"",
")",
"template_name",
"=",
"\"#{namespace}.#{template_name}\"",
"if",
"namespace",
"js_source_from_string",
"(",
"template_name",
",",
"File",
".",
"read",
"(",
"source_path",
")",
",",
"output_as_array",
")",
"end"
] |
compile a ejs file into javascript
|
[
"compile",
"a",
"ejs",
"file",
"into",
"javascript"
] |
dae7d6297ff1920a6f01e1095a939a1d54ada28e
|
https://github.com/bcurren/ejs-rcompiler/blob/dae7d6297ff1920a6f01e1095a939a1d54ada28e/lib/ejs/compiler.rb#L20-L25
|
9,968
|
bcurren/ejs-rcompiler
|
lib/ejs/compiler.rb
|
Ejs.Compiler.js_source_from_string
|
def js_source_from_string(template_name, content, output_as_array = false)
buffer = []
parsed = @parser.parse(content)
if parsed.nil?
raise ParseError.new(@parser.failure_reason, @parser.failure_line, @parser.failure_column)
end
template_namespace(buffer, template_name)
template_header(buffer, template_name)
parsed.elements.each do |element|
push_content(buffer, element)
end
template_footer(buffer)
output_as_array ? buffer : buffer.join("\n")
end
|
ruby
|
def js_source_from_string(template_name, content, output_as_array = false)
buffer = []
parsed = @parser.parse(content)
if parsed.nil?
raise ParseError.new(@parser.failure_reason, @parser.failure_line, @parser.failure_column)
end
template_namespace(buffer, template_name)
template_header(buffer, template_name)
parsed.elements.each do |element|
push_content(buffer, element)
end
template_footer(buffer)
output_as_array ? buffer : buffer.join("\n")
end
|
[
"def",
"js_source_from_string",
"(",
"template_name",
",",
"content",
",",
"output_as_array",
"=",
"false",
")",
"buffer",
"=",
"[",
"]",
"parsed",
"=",
"@parser",
".",
"parse",
"(",
"content",
")",
"if",
"parsed",
".",
"nil?",
"raise",
"ParseError",
".",
"new",
"(",
"@parser",
".",
"failure_reason",
",",
"@parser",
".",
"failure_line",
",",
"@parser",
".",
"failure_column",
")",
"end",
"template_namespace",
"(",
"buffer",
",",
"template_name",
")",
"template_header",
"(",
"buffer",
",",
"template_name",
")",
"parsed",
".",
"elements",
".",
"each",
"do",
"|",
"element",
"|",
"push_content",
"(",
"buffer",
",",
"element",
")",
"end",
"template_footer",
"(",
"buffer",
")",
"output_as_array",
"?",
"buffer",
":",
"buffer",
".",
"join",
"(",
"\"\\n\"",
")",
"end"
] |
compile a string containing ejs source into javascript
|
[
"compile",
"a",
"string",
"containing",
"ejs",
"source",
"into",
"javascript"
] |
dae7d6297ff1920a6f01e1095a939a1d54ada28e
|
https://github.com/bcurren/ejs-rcompiler/blob/dae7d6297ff1920a6f01e1095a939a1d54ada28e/lib/ejs/compiler.rb#L28-L43
|
9,969
|
darrenleeweber/rdf-resource
|
lib/rdf-resource/resource.rb
|
RDFResource.Resource.provenance
|
def provenance
s = [rdf_uri, RDF::PROV.SoftwareAgent, @@agent]
rdf.insert(s)
s = [rdf_uri, RDF::PROV.generatedAtTime, rdf_now]
rdf.insert(s)
end
|
ruby
|
def provenance
s = [rdf_uri, RDF::PROV.SoftwareAgent, @@agent]
rdf.insert(s)
s = [rdf_uri, RDF::PROV.generatedAtTime, rdf_now]
rdf.insert(s)
end
|
[
"def",
"provenance",
"s",
"=",
"[",
"rdf_uri",
",",
"RDF",
"::",
"PROV",
".",
"SoftwareAgent",
",",
"@@agent",
"]",
"rdf",
".",
"insert",
"(",
"s",
")",
"s",
"=",
"[",
"rdf_uri",
",",
"RDF",
"::",
"PROV",
".",
"generatedAtTime",
",",
"rdf_now",
"]",
"rdf",
".",
"insert",
"(",
"s",
")",
"end"
] |
Assert PROV.SoftwareAgent and PROV.generatedAtTime
|
[
"Assert",
"PROV",
".",
"SoftwareAgent",
"and",
"PROV",
".",
"generatedAtTime"
] |
132b2b5356d08bc37d873c807e1048a6b7cc7bee
|
https://github.com/darrenleeweber/rdf-resource/blob/132b2b5356d08bc37d873c807e1048a6b7cc7bee/lib/rdf-resource/resource.rb#L53-L58
|
9,970
|
darrenleeweber/rdf-resource
|
lib/rdf-resource/resource.rb
|
RDFResource.Resource.rdf_find_object
|
def rdf_find_object(id)
return nil unless rdf_valid?
rdf.each_statement do |s|
if s.subject == @iri.to_s
return s.object if s.object.to_s =~ Regexp.new(id, Regexp::IGNORECASE)
end
end
nil
end
|
ruby
|
def rdf_find_object(id)
return nil unless rdf_valid?
rdf.each_statement do |s|
if s.subject == @iri.to_s
return s.object if s.object.to_s =~ Regexp.new(id, Regexp::IGNORECASE)
end
end
nil
end
|
[
"def",
"rdf_find_object",
"(",
"id",
")",
"return",
"nil",
"unless",
"rdf_valid?",
"rdf",
".",
"each_statement",
"do",
"|",
"s",
"|",
"if",
"s",
".",
"subject",
"==",
"@iri",
".",
"to_s",
"return",
"s",
".",
"object",
"if",
"s",
".",
"object",
".",
"to_s",
"=~",
"Regexp",
".",
"new",
"(",
"id",
",",
"Regexp",
"::",
"IGNORECASE",
")",
"end",
"end",
"nil",
"end"
] |
Regexp search to find an object matching a string, if it belongs to @iri
@param id [String] A string literal used to construct a Regexp
@return [RDF::URI] The first object matching the Regexp
|
[
"Regexp",
"search",
"to",
"find",
"an",
"object",
"matching",
"a",
"string",
"if",
"it",
"belongs",
"to"
] |
132b2b5356d08bc37d873c807e1048a6b7cc7bee
|
https://github.com/darrenleeweber/rdf-resource/blob/132b2b5356d08bc37d873c807e1048a6b7cc7bee/lib/rdf-resource/resource.rb#L101-L109
|
9,971
|
darrenleeweber/rdf-resource
|
lib/rdf-resource/resource.rb
|
RDFResource.Resource.rdf_find_subject
|
def rdf_find_subject(id)
return nil unless rdf_valid?
rdf.each_subject do |s|
return s if s.to_s =~ Regexp.new(id, Regexp::IGNORECASE)
end
nil
end
|
ruby
|
def rdf_find_subject(id)
return nil unless rdf_valid?
rdf.each_subject do |s|
return s if s.to_s =~ Regexp.new(id, Regexp::IGNORECASE)
end
nil
end
|
[
"def",
"rdf_find_subject",
"(",
"id",
")",
"return",
"nil",
"unless",
"rdf_valid?",
"rdf",
".",
"each_subject",
"do",
"|",
"s",
"|",
"return",
"s",
"if",
"s",
".",
"to_s",
"=~",
"Regexp",
".",
"new",
"(",
"id",
",",
"Regexp",
"::",
"IGNORECASE",
")",
"end",
"nil",
"end"
] |
Regexp search to find a subject matching a string
@param id [String] A string literal used to construct a Regexp
@return [RDF::URI] The first subject matching the Regexp
|
[
"Regexp",
"search",
"to",
"find",
"a",
"subject",
"matching",
"a",
"string"
] |
132b2b5356d08bc37d873c807e1048a6b7cc7bee
|
https://github.com/darrenleeweber/rdf-resource/blob/132b2b5356d08bc37d873c807e1048a6b7cc7bee/lib/rdf-resource/resource.rb#L114-L120
|
9,972
|
CDLUC3/merritt-manifest
|
lib/merritt/manifest.rb
|
Merritt.Manifest.write_to
|
def write_to(io)
write_sc(io, conformance)
write_sc(io, 'profile', profile)
prefixes.each { |prefix, url| write_sc(io, 'prefix', "#{prefix}:", url) }
write_sc(io, 'fields', *fields)
entries.each { |entry| io.puts(entry_line(entry)) }
write_sc(io, 'eof')
end
|
ruby
|
def write_to(io)
write_sc(io, conformance)
write_sc(io, 'profile', profile)
prefixes.each { |prefix, url| write_sc(io, 'prefix', "#{prefix}:", url) }
write_sc(io, 'fields', *fields)
entries.each { |entry| io.puts(entry_line(entry)) }
write_sc(io, 'eof')
end
|
[
"def",
"write_to",
"(",
"io",
")",
"write_sc",
"(",
"io",
",",
"conformance",
")",
"write_sc",
"(",
"io",
",",
"'profile'",
",",
"profile",
")",
"prefixes",
".",
"each",
"{",
"|",
"prefix",
",",
"url",
"|",
"write_sc",
"(",
"io",
",",
"'prefix'",
",",
"\"#{prefix}:\"",
",",
"url",
")",
"}",
"write_sc",
"(",
"io",
",",
"'fields'",
",",
"fields",
")",
"entries",
".",
"each",
"{",
"|",
"entry",
"|",
"io",
".",
"puts",
"(",
"entry_line",
"(",
"entry",
")",
")",
"}",
"write_sc",
"(",
"io",
",",
"'eof'",
")",
"end"
] |
Creates a new manifest. Note that the prefix, field, and entry arrays are
copied on initialization, as are the individual entry hashes.
@param conformance [String] the conformance level. Defaults to {CHECKM_0_7}.
@param profile [URI, String] the profile URI. Must begin with
@param prefixes [Hash{String,Symbol => URI, String}] a map from namespace prefixes to their URIs
@param fields Array<String> a list of field names, in the form prefix:fieldname
@param entries [Array<Hash<String, Object><] A list of entries, each of which is a hash keyed by
a prefixed fieldname defined in `fields`. Nil values are allowed.
@raise [ArgumentError] if `profile` does not begin with {PROFILE_BASE_URI}
@raise [ArgumentError] if `fields` cannot be parsed as prefix:fieldname, or if one or more prefixes
is not mapped to a URI in `prefixes`
@raise [URI::InvalidURIError] if `profile` cannot be parsed as a URI
Writes this manifest to the specified IO
@param io [IO] the IO to write to
|
[
"Creates",
"a",
"new",
"manifest",
".",
"Note",
"that",
"the",
"prefix",
"field",
"and",
"entry",
"arrays",
"are",
"copied",
"on",
"initialization",
"as",
"are",
"the",
"individual",
"entry",
"hashes",
"."
] |
395832ace3d2954d71e5dc053ea238dcfda42a48
|
https://github.com/CDLUC3/merritt-manifest/blob/395832ace3d2954d71e5dc053ea238dcfda42a48/lib/merritt/manifest.rb#L51-L58
|
9,973
|
CDLUC3/merritt-manifest
|
lib/merritt/manifest.rb
|
Merritt.Manifest.write_sc
|
def write_sc(io, comment, *columns)
io << '#%' << comment
io << COLSEP << columns.join(COLSEP) unless columns.empty?
io << "\n"
end
|
ruby
|
def write_sc(io, comment, *columns)
io << '#%' << comment
io << COLSEP << columns.join(COLSEP) unless columns.empty?
io << "\n"
end
|
[
"def",
"write_sc",
"(",
"io",
",",
"comment",
",",
"*",
"columns",
")",
"io",
"<<",
"'#%'",
"<<",
"comment",
"io",
"<<",
"COLSEP",
"<<",
"columns",
".",
"join",
"(",
"COLSEP",
")",
"unless",
"columns",
".",
"empty?",
"io",
"<<",
"\"\\n\"",
"end"
] |
writes a checkm "structured comment"
@param io [IO] the IO to write to
@param comment [String] the comment
@param columns [nil, Array<String>] columns to follow the initial comment
|
[
"writes",
"a",
"checkm",
"structured",
"comment"
] |
395832ace3d2954d71e5dc053ea238dcfda42a48
|
https://github.com/CDLUC3/merritt-manifest/blob/395832ace3d2954d71e5dc053ea238dcfda42a48/lib/merritt/manifest.rb#L81-L85
|
9,974
|
bernerdschaefer/uninhibited
|
lib/uninhibited/feature.rb
|
Uninhibited.Feature.Scenario
|
def Scenario(*args, &example_group_block)
args << {} unless args.last.is_a?(Hash)
args.last.update(:scenario => true)
describe("Scenario:", *args, &example_group_block)
end
|
ruby
|
def Scenario(*args, &example_group_block)
args << {} unless args.last.is_a?(Hash)
args.last.update(:scenario => true)
describe("Scenario:", *args, &example_group_block)
end
|
[
"def",
"Scenario",
"(",
"*",
"args",
",",
"&",
"example_group_block",
")",
"args",
"<<",
"{",
"}",
"unless",
"args",
".",
"last",
".",
"is_a?",
"(",
"Hash",
")",
"args",
".",
"last",
".",
"update",
"(",
":scenario",
"=>",
"true",
")",
"describe",
"(",
"\"Scenario:\"",
",",
"args",
",",
"example_group_block",
")",
"end"
] |
Defines a new Scenario group
Feature "User signs in" do
Scenario "success" do
Given "I on the login page"
When "I fill in my email and password"
end
end
This will be printed like so:
Feature: User signs in
Scenario: success
Given I am on the login page
When I fill in my email and password
@param args the description, metadata, etc. as RSpec's #describe method
takes.
@param example_group_block the block to be executed within the feature
|
[
"Defines",
"a",
"new",
"Scenario",
"group"
] |
a45297e127f529ee10719f0306b1ae6721450a33
|
https://github.com/bernerdschaefer/uninhibited/blob/a45297e127f529ee10719f0306b1ae6721450a33/lib/uninhibited/feature.rb#L26-L30
|
9,975
|
bernerdschaefer/uninhibited
|
lib/uninhibited/feature.rb
|
Uninhibited.Feature.skip_examples_after
|
def skip_examples_after(example, example_group = self)
examples = example_group.descendant_filtered_examples.flatten
examples[examples.index(example)..-1].each do |e|
e.metadata[:pending] = true
e.metadata[:skipped] = true
end
end
|
ruby
|
def skip_examples_after(example, example_group = self)
examples = example_group.descendant_filtered_examples.flatten
examples[examples.index(example)..-1].each do |e|
e.metadata[:pending] = true
e.metadata[:skipped] = true
end
end
|
[
"def",
"skip_examples_after",
"(",
"example",
",",
"example_group",
"=",
"self",
")",
"examples",
"=",
"example_group",
".",
"descendant_filtered_examples",
".",
"flatten",
"examples",
"[",
"examples",
".",
"index",
"(",
"example",
")",
"..",
"-",
"1",
"]",
".",
"each",
"do",
"|",
"e",
"|",
"e",
".",
"metadata",
"[",
":pending",
"]",
"=",
"true",
"e",
".",
"metadata",
"[",
":skipped",
"]",
"=",
"true",
"end",
"end"
] |
Skip examples after the example provided.
@param [Example] example the example to skip after
@param [ExampleGroup] example_group the example group of example
@api private
|
[
"Skip",
"examples",
"after",
"the",
"example",
"provided",
"."
] |
a45297e127f529ee10719f0306b1ae6721450a33
|
https://github.com/bernerdschaefer/uninhibited/blob/a45297e127f529ee10719f0306b1ae6721450a33/lib/uninhibited/feature.rb#L136-L142
|
9,976
|
bernerdschaefer/uninhibited
|
lib/uninhibited/feature.rb
|
Uninhibited.Feature.handle_exception
|
def handle_exception(example)
if example.instance_variable_get(:@exception)
if metadata[:background]
skip_examples_after(example, ancestors[1])
else
skip_examples_after(example)
end
end
end
|
ruby
|
def handle_exception(example)
if example.instance_variable_get(:@exception)
if metadata[:background]
skip_examples_after(example, ancestors[1])
else
skip_examples_after(example)
end
end
end
|
[
"def",
"handle_exception",
"(",
"example",
")",
"if",
"example",
".",
"instance_variable_get",
"(",
":@exception",
")",
"if",
"metadata",
"[",
":background",
"]",
"skip_examples_after",
"(",
"example",
",",
"ancestors",
"[",
"1",
"]",
")",
"else",
"skip_examples_after",
"(",
"example",
")",
"end",
"end",
"end"
] |
If the example failed or got an error, then skip the dependent examples.
If the failure occurred in a background example group, then skip all
examples in the feature.
@param [Example] example the current example
@api private
|
[
"If",
"the",
"example",
"failed",
"or",
"got",
"an",
"error",
"then",
"skip",
"the",
"dependent",
"examples",
".",
"If",
"the",
"failure",
"occurred",
"in",
"a",
"background",
"example",
"group",
"then",
"skip",
"all",
"examples",
"in",
"the",
"feature",
"."
] |
a45297e127f529ee10719f0306b1ae6721450a33
|
https://github.com/bernerdschaefer/uninhibited/blob/a45297e127f529ee10719f0306b1ae6721450a33/lib/uninhibited/feature.rb#L150-L158
|
9,977
|
santaux/colonel
|
lib/colonel/builder.rb
|
Colonel.Builder.update_job
|
def update_job(opts={})
index = get_job_index(opts[:id])
job = find_job(opts[:id])
@jobs[index] = job.update(opts)
end
|
ruby
|
def update_job(opts={})
index = get_job_index(opts[:id])
job = find_job(opts[:id])
@jobs[index] = job.update(opts)
end
|
[
"def",
"update_job",
"(",
"opts",
"=",
"{",
"}",
")",
"index",
"=",
"get_job_index",
"(",
"opts",
"[",
":id",
"]",
")",
"job",
"=",
"find_job",
"(",
"opts",
"[",
":id",
"]",
")",
"@jobs",
"[",
"index",
"]",
"=",
"job",
".",
"update",
"(",
"opts",
")",
"end"
] |
Replace job with specified id
@param (Integer) :id is index of the job into @jobs array
TODO: Refactor it! To complicated!
|
[
"Replace",
"job",
"with",
"specified",
"id"
] |
b457c77cf509b0b436d85048a60fc8c8e55a3828
|
https://github.com/santaux/colonel/blob/b457c77cf509b0b436d85048a60fc8c8e55a3828/lib/colonel/builder.rb#L48-L52
|
9,978
|
santaux/colonel
|
lib/colonel/builder.rb
|
Colonel.Builder.add_job
|
def add_job(opts={})
@jobs << Job.new( Parser::Schedule.new(opts[:schedule]), Parser::Command.new(opts[:command]))
end
|
ruby
|
def add_job(opts={})
@jobs << Job.new( Parser::Schedule.new(opts[:schedule]), Parser::Command.new(opts[:command]))
end
|
[
"def",
"add_job",
"(",
"opts",
"=",
"{",
"}",
")",
"@jobs",
"<<",
"Job",
".",
"new",
"(",
"Parser",
"::",
"Schedule",
".",
"new",
"(",
"opts",
"[",
":schedule",
"]",
")",
",",
"Parser",
"::",
"Command",
".",
"new",
"(",
"opts",
"[",
":command",
"]",
")",
")",
"end"
] |
Adds a job to @jobs array
@param (Parser::Schedule) :schedule is object of Parser::Schedule class
@param (Parser::Command) :command is object of Parser::Command class
|
[
"Adds",
"a",
"job",
"to"
] |
b457c77cf509b0b436d85048a60fc8c8e55a3828
|
https://github.com/santaux/colonel/blob/b457c77cf509b0b436d85048a60fc8c8e55a3828/lib/colonel/builder.rb#L57-L59
|
9,979
|
NUBIC/aker
|
lib/aker/rack/setup.rb
|
Aker::Rack.Setup.call
|
def call(env)
env['aker.configuration'] = @configuration
env['aker.authority'] = @configuration.composite_authority
env['aker.interactive'] = interactive?(env)
@app.call(env)
end
|
ruby
|
def call(env)
env['aker.configuration'] = @configuration
env['aker.authority'] = @configuration.composite_authority
env['aker.interactive'] = interactive?(env)
@app.call(env)
end
|
[
"def",
"call",
"(",
"env",
")",
"env",
"[",
"'aker.configuration'",
"]",
"=",
"@configuration",
"env",
"[",
"'aker.authority'",
"]",
"=",
"@configuration",
".",
"composite_authority",
"env",
"[",
"'aker.interactive'",
"]",
"=",
"interactive?",
"(",
"env",
")",
"@app",
".",
"call",
"(",
"env",
")",
"end"
] |
Creates a new instance of the middleware.
@param [#call] app the application this middleware is being
wrapped around.
@param [Aker::Configuration] configuration the configuration to use for
this instance.
@see Aker::Rack.use_in
Implements the rack middleware behavior.
This class exposes three environment variables to downstream
middleware and the app:
* `"aker.configuration"`: the {Aker::Configuration configuration}
for this application.
* `"aker.authority"`: the {Aker::Authorities authority} for
this application.
* `"aker.interactive"`: a boolean indicating whether this
request is being treated as an interactive (UI) or
non-interactive (API) request
[There is a related fourth environment variable:
* `"aker.check"`: an instance of {Aker::Rack::Facade}
permitting authentication and authorization queries about the
current user (if any).
This fourth variable is added by the {Authenticate} middleware;
see its documentation for more.]
@param [Hash] env the rack env
@return [Array] the standard rack return
|
[
"Creates",
"a",
"new",
"instance",
"of",
"the",
"middleware",
"."
] |
ff43606a8812e38f96bbe71b46e7f631cbeacf1c
|
https://github.com/NUBIC/aker/blob/ff43606a8812e38f96bbe71b46e7f631cbeacf1c/lib/aker/rack/setup.rb#L58-L64
|
9,980
|
ahmadhasankhan/canvas_interactor
|
lib/canvas_interactor/canvas_api.rb
|
CanvasInteractor.CanvasApi.hash_csv
|
def hash_csv(csv_string)
require 'csv'
csv = CSV.parse(csv_string)
headers = csv.shift
output = []
csv.each do |row|
hash = {}
headers.each do |header|
hash[header] = row.shift.to_s
end
output << hash
end
return output
end
|
ruby
|
def hash_csv(csv_string)
require 'csv'
csv = CSV.parse(csv_string)
headers = csv.shift
output = []
csv.each do |row|
hash = {}
headers.each do |header|
hash[header] = row.shift.to_s
end
output << hash
end
return output
end
|
[
"def",
"hash_csv",
"(",
"csv_string",
")",
"require",
"'csv'",
"csv",
"=",
"CSV",
".",
"parse",
"(",
"csv_string",
")",
"headers",
"=",
"csv",
".",
"shift",
"output",
"=",
"[",
"]",
"csv",
".",
"each",
"do",
"|",
"row",
"|",
"hash",
"=",
"{",
"}",
"headers",
".",
"each",
"do",
"|",
"header",
"|",
"hash",
"[",
"header",
"]",
"=",
"row",
".",
"shift",
".",
"to_s",
"end",
"output",
"<<",
"hash",
"end",
"return",
"output",
"end"
] |
Needs to be refactored to somewhere more generic
|
[
"Needs",
"to",
"be",
"refactored",
"to",
"somewhere",
"more",
"generic"
] |
458c058f1345643bfe8b1e1422d9155e49790193
|
https://github.com/ahmadhasankhan/canvas_interactor/blob/458c058f1345643bfe8b1e1422d9155e49790193/lib/canvas_interactor/canvas_api.rb#L96-L112
|
9,981
|
plexus/analects
|
lib/analects/source.rb
|
Analects.Source.retrieve_save
|
def retrieve_save(data)
File.open(location, 'w') do |f|
f << (data.respond_to?(:read) ? data.read : data)
end
end
|
ruby
|
def retrieve_save(data)
File.open(location, 'w') do |f|
f << (data.respond_to?(:read) ? data.read : data)
end
end
|
[
"def",
"retrieve_save",
"(",
"data",
")",
"File",
".",
"open",
"(",
"location",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"f",
"<<",
"(",
"data",
".",
"respond_to?",
"(",
":read",
")",
"?",
"data",
".",
"read",
":",
"data",
")",
"end",
"end"
] |
stream|string -> create data file
|
[
"stream|string",
"-",
">",
"create",
"data",
"file"
] |
3ef5c9b54b5d31fd1c3b7143f9e5e4ae40185dd9
|
https://github.com/plexus/analects/blob/3ef5c9b54b5d31fd1c3b7143f9e5e4ae40185dd9/lib/analects/source.rb#L80-L84
|
9,982
|
markus/breeze
|
lib/breeze/tasks/server.rb
|
Breeze.Server.wait_until_host_is_available
|
def wait_until_host_is_available(host, get_ip=false)
resolved_host = Resolv.getaddresses(host).first
if resolved_host.nil?
print("Waiting for #{host} to resolve")
wait_until('ready!') { resolved_host = Resolv.getaddresses(host).first }
end
host = resolved_host if get_ip
unless remote_is_available?(host)
print("Waiting for #{host} to accept connections")
wait_until('ready!') { remote_is_available?(host) }
end
return host
end
|
ruby
|
def wait_until_host_is_available(host, get_ip=false)
resolved_host = Resolv.getaddresses(host).first
if resolved_host.nil?
print("Waiting for #{host} to resolve")
wait_until('ready!') { resolved_host = Resolv.getaddresses(host).first }
end
host = resolved_host if get_ip
unless remote_is_available?(host)
print("Waiting for #{host} to accept connections")
wait_until('ready!') { remote_is_available?(host) }
end
return host
end
|
[
"def",
"wait_until_host_is_available",
"(",
"host",
",",
"get_ip",
"=",
"false",
")",
"resolved_host",
"=",
"Resolv",
".",
"getaddresses",
"(",
"host",
")",
".",
"first",
"if",
"resolved_host",
".",
"nil?",
"print",
"(",
"\"Waiting for #{host} to resolve\"",
")",
"wait_until",
"(",
"'ready!'",
")",
"{",
"resolved_host",
"=",
"Resolv",
".",
"getaddresses",
"(",
"host",
")",
".",
"first",
"}",
"end",
"host",
"=",
"resolved_host",
"if",
"get_ip",
"unless",
"remote_is_available?",
"(",
"host",
")",
"print",
"(",
"\"Waiting for #{host} to accept connections\"",
")",
"wait_until",
"(",
"'ready!'",
")",
"{",
"remote_is_available?",
"(",
"host",
")",
"}",
"end",
"return",
"host",
"end"
] |
Can take a host name or an ip address. Resolves the host name
and returns the ip address if get_ip is passed in as true.
|
[
"Can",
"take",
"a",
"host",
"name",
"or",
"an",
"ip",
"address",
".",
"Resolves",
"the",
"host",
"name",
"and",
"returns",
"the",
"ip",
"address",
"if",
"get_ip",
"is",
"passed",
"in",
"as",
"true",
"."
] |
a633783946ed4270354fa1491a9beda4f2bac1f6
|
https://github.com/markus/breeze/blob/a633783946ed4270354fa1491a9beda4f2bac1f6/lib/breeze/tasks/server.rb#L42-L54
|
9,983
|
colbell/bitsa
|
lib/bitsa/contacts_cache.rb
|
Bitsa.ContactsCache.search
|
def search(qry)
rg = Regexp.new(qry || '', Regexp::IGNORECASE)
# Flatten to an array with [email1, name1, email2, name2] etc.
results = @addresses.values.flatten.each_slice(2).find_all do |e, n|
e.match(rg) || n.match(rg)
end
# Sort by case-insensitive email address
results.sort { |a, b| a[0].downcase <=> b[0].downcase }
end
|
ruby
|
def search(qry)
rg = Regexp.new(qry || '', Regexp::IGNORECASE)
# Flatten to an array with [email1, name1, email2, name2] etc.
results = @addresses.values.flatten.each_slice(2).find_all do |e, n|
e.match(rg) || n.match(rg)
end
# Sort by case-insensitive email address
results.sort { |a, b| a[0].downcase <=> b[0].downcase }
end
|
[
"def",
"search",
"(",
"qry",
")",
"rg",
"=",
"Regexp",
".",
"new",
"(",
"qry",
"||",
"''",
",",
"Regexp",
"::",
"IGNORECASE",
")",
"# Flatten to an array with [email1, name1, email2, name2] etc.",
"results",
"=",
"@addresses",
".",
"values",
".",
"flatten",
".",
"each_slice",
"(",
"2",
")",
".",
"find_all",
"do",
"|",
"e",
",",
"n",
"|",
"e",
".",
"match",
"(",
"rg",
")",
"||",
"n",
".",
"match",
"(",
"rg",
")",
"end",
"# Sort by case-insensitive email address",
"results",
".",
"sort",
"{",
"|",
"a",
",",
"b",
"|",
"a",
"[",
"0",
"]",
".",
"downcase",
"<=>",
"b",
"[",
"0",
"]",
".",
"downcase",
"}",
"end"
] |
Retrieves name and email addresses that contain the passed string sorted
by email adddress
@param qry [String] search string
@return [[[String, String]]] Array of email addresses and names found.
Each element consists of a 2 element array. The first is the email
address and the second is the name
@example
cache.search("smi") #=>
[["e1@acompany.com", "Mr Smith"], ["e2@bsomewhere.com", "Mr Smith"]]
|
[
"Retrieves",
"name",
"and",
"email",
"addresses",
"that",
"contain",
"the",
"passed",
"string",
"sorted",
"by",
"email",
"adddress"
] |
8b73c4988bde1bf8e64d9cb999164c3e5988dba5
|
https://github.com/colbell/bitsa/blob/8b73c4988bde1bf8e64d9cb999164c3e5988dba5/lib/bitsa/contacts_cache.rb#L117-L127
|
9,984
|
colbell/bitsa
|
lib/bitsa/contacts_cache.rb
|
Bitsa.ContactsCache.update
|
def update(id, name, addresses)
@cache_last_modified = DateTime.now.to_s
@addresses[id] = addresses.map { |a| [a, name] }
end
|
ruby
|
def update(id, name, addresses)
@cache_last_modified = DateTime.now.to_s
@addresses[id] = addresses.map { |a| [a, name] }
end
|
[
"def",
"update",
"(",
"id",
",",
"name",
",",
"addresses",
")",
"@cache_last_modified",
"=",
"DateTime",
".",
"now",
".",
"to_s",
"@addresses",
"[",
"id",
"]",
"=",
"addresses",
".",
"map",
"{",
"|",
"a",
"|",
"[",
"a",
",",
"name",
"]",
"}",
"end"
] |
Update the name and email addresses for the passed GMail ID.
@param [String] id ID of contact to be updated
@param [String] name new name for contact
@param [String[]] addresses array of email addresses
@return [[String, String]] Array of email addresses for the <tt>id</tt>
after update.
Each element consists of a 2 element array. The
first is the email address and the second is
the name
|
[
"Update",
"the",
"name",
"and",
"email",
"addresses",
"for",
"the",
"passed",
"GMail",
"ID",
"."
] |
8b73c4988bde1bf8e64d9cb999164c3e5988dba5
|
https://github.com/colbell/bitsa/blob/8b73c4988bde1bf8e64d9cb999164c3e5988dba5/lib/bitsa/contacts_cache.rb#L140-L143
|
9,985
|
rails-info/rails_info
|
lib/rails_info/routing.rb
|
ActionDispatch::Routing.Mapper.mount_rails_info
|
def mount_rails_info
match '/rails/info' => 'rails_info/properties#index', via: :get, via: :get, as: 'rails_info'
match '/rails/info/properties' => 'rails_info/properties#index', via: :get, via: :get, as: 'rails_info_properties'
match '/rails/info/routes' => 'rails_info/routes#index', via: :get, as: 'rails_info_routes'
match '/rails/info/model' => 'rails_info/model#index', via: :get, as: 'rails_info_model'
match '/rails/info/data' => 'rails_info/data#index', via: :get, as: 'rails_info_data', via: :get, as: 'rails_info_data'
post '/rails/info/data/update_multiple' => 'rails_info/data#update_multiple', via: :post, as: 'rails_update_multiple_rails_info_data'
match '/rails/info/logs/server' => 'rails_info/logs/server#new', via: :get, as: 'new_rails_info_server_log'
put '/rails/info/logs/server' => 'rails_info/logs/server#update', via: :put, as: 'rails_info_server_log'
get '/rails/info/logs/server/big' => 'rails_info/logs/server#big'
match '/rails/info/logs/test/rspec' => 'rails_info/logs/test/rspec#new', via: :get, as: 'new_rails_info_rspec_log'
put '/rails/info/logs/test/rspec' => 'rails_info/logs/test/rspec#update', via: :put, as: 'rails_info_rspec_log'
match '/rails/info/stack_traces/new' => 'rails_info/stack_traces#new', via: :get, as: 'new_rails_info_stack_trace'
post '/rails/info/stack_traces' => 'rails_info/stack_traces#create', via: :post, as: 'rails_info_stack_trace'
namespace 'rails_info', path: 'rails/info' do
namespace 'system' do
resources :directories, only: :index
end
namespace 'version_control' do
resources :filters, only: [:new, :create]
resources :diffs, only: :new
end
end
end
|
ruby
|
def mount_rails_info
match '/rails/info' => 'rails_info/properties#index', via: :get, via: :get, as: 'rails_info'
match '/rails/info/properties' => 'rails_info/properties#index', via: :get, via: :get, as: 'rails_info_properties'
match '/rails/info/routes' => 'rails_info/routes#index', via: :get, as: 'rails_info_routes'
match '/rails/info/model' => 'rails_info/model#index', via: :get, as: 'rails_info_model'
match '/rails/info/data' => 'rails_info/data#index', via: :get, as: 'rails_info_data', via: :get, as: 'rails_info_data'
post '/rails/info/data/update_multiple' => 'rails_info/data#update_multiple', via: :post, as: 'rails_update_multiple_rails_info_data'
match '/rails/info/logs/server' => 'rails_info/logs/server#new', via: :get, as: 'new_rails_info_server_log'
put '/rails/info/logs/server' => 'rails_info/logs/server#update', via: :put, as: 'rails_info_server_log'
get '/rails/info/logs/server/big' => 'rails_info/logs/server#big'
match '/rails/info/logs/test/rspec' => 'rails_info/logs/test/rspec#new', via: :get, as: 'new_rails_info_rspec_log'
put '/rails/info/logs/test/rspec' => 'rails_info/logs/test/rspec#update', via: :put, as: 'rails_info_rspec_log'
match '/rails/info/stack_traces/new' => 'rails_info/stack_traces#new', via: :get, as: 'new_rails_info_stack_trace'
post '/rails/info/stack_traces' => 'rails_info/stack_traces#create', via: :post, as: 'rails_info_stack_trace'
namespace 'rails_info', path: 'rails/info' do
namespace 'system' do
resources :directories, only: :index
end
namespace 'version_control' do
resources :filters, only: [:new, :create]
resources :diffs, only: :new
end
end
end
|
[
"def",
"mount_rails_info",
"match",
"'/rails/info'",
"=>",
"'rails_info/properties#index'",
",",
"via",
":",
":get",
",",
"via",
":",
":get",
",",
"as",
":",
"'rails_info'",
"match",
"'/rails/info/properties'",
"=>",
"'rails_info/properties#index'",
",",
"via",
":",
":get",
",",
"via",
":",
":get",
",",
"as",
":",
"'rails_info_properties'",
"match",
"'/rails/info/routes'",
"=>",
"'rails_info/routes#index'",
",",
"via",
":",
":get",
",",
"as",
":",
"'rails_info_routes'",
"match",
"'/rails/info/model'",
"=>",
"'rails_info/model#index'",
",",
"via",
":",
":get",
",",
"as",
":",
"'rails_info_model'",
"match",
"'/rails/info/data'",
"=>",
"'rails_info/data#index'",
",",
"via",
":",
":get",
",",
"as",
":",
"'rails_info_data'",
",",
"via",
":",
":get",
",",
"as",
":",
"'rails_info_data'",
"post",
"'/rails/info/data/update_multiple'",
"=>",
"'rails_info/data#update_multiple'",
",",
"via",
":",
":post",
",",
"as",
":",
"'rails_update_multiple_rails_info_data'",
"match",
"'/rails/info/logs/server'",
"=>",
"'rails_info/logs/server#new'",
",",
"via",
":",
":get",
",",
"as",
":",
"'new_rails_info_server_log'",
"put",
"'/rails/info/logs/server'",
"=>",
"'rails_info/logs/server#update'",
",",
"via",
":",
":put",
",",
"as",
":",
"'rails_info_server_log'",
"get",
"'/rails/info/logs/server/big'",
"=>",
"'rails_info/logs/server#big'",
"match",
"'/rails/info/logs/test/rspec'",
"=>",
"'rails_info/logs/test/rspec#new'",
",",
"via",
":",
":get",
",",
"as",
":",
"'new_rails_info_rspec_log'",
"put",
"'/rails/info/logs/test/rspec'",
"=>",
"'rails_info/logs/test/rspec#update'",
",",
"via",
":",
":put",
",",
"as",
":",
"'rails_info_rspec_log'",
"match",
"'/rails/info/stack_traces/new'",
"=>",
"'rails_info/stack_traces#new'",
",",
"via",
":",
":get",
",",
"as",
":",
"'new_rails_info_stack_trace'",
"post",
"'/rails/info/stack_traces'",
"=>",
"'rails_info/stack_traces#create'",
",",
"via",
":",
":post",
",",
"as",
":",
"'rails_info_stack_trace'",
"namespace",
"'rails_info'",
",",
"path",
":",
"'rails/info'",
"do",
"namespace",
"'system'",
"do",
"resources",
":directories",
",",
"only",
":",
":index",
"end",
"namespace",
"'version_control'",
"do",
"resources",
":filters",
",",
"only",
":",
"[",
":new",
",",
":create",
"]",
"resources",
":diffs",
",",
"only",
":",
":new",
"end",
"end",
"end"
] |
Includes mount_sextant method for routes. This method is responsible to
generate all needed routes for sextant
|
[
"Includes",
"mount_sextant",
"method",
"for",
"routes",
".",
"This",
"method",
"is",
"responsible",
"to",
"generate",
"all",
"needed",
"routes",
"for",
"sextant"
] |
a940d618043e0707c2c16d2cfe0c10609d54536b
|
https://github.com/rails-info/rails_info/blob/a940d618043e0707c2c16d2cfe0c10609d54536b/lib/rails_info/routing.rb#L5-L38
|
9,986
|
fauxparse/matchy_matchy
|
lib/matchy_matchy/matchbook.rb
|
MatchyMatchy.Matchbook.build_candidates
|
def build_candidates(candidates)
candidates.to_a.map do |object, preferences|
candidate(object).tap do |c|
c.prefer(*preferences.map { |t| target(t) })
end
end
end
|
ruby
|
def build_candidates(candidates)
candidates.to_a.map do |object, preferences|
candidate(object).tap do |c|
c.prefer(*preferences.map { |t| target(t) })
end
end
end
|
[
"def",
"build_candidates",
"(",
"candidates",
")",
"candidates",
".",
"to_a",
".",
"map",
"do",
"|",
"object",
",",
"preferences",
"|",
"candidate",
"(",
"object",
")",
".",
"tap",
"do",
"|",
"c",
"|",
"c",
".",
"prefer",
"(",
"preferences",
".",
"map",
"{",
"|",
"t",
"|",
"target",
"(",
"t",
")",
"}",
")",
"end",
"end",
"end"
] |
Builds a list of candidates for the +MatchMaker+.
The parameter is a hash of unwrapped canditate objects to their preferred
targets.
@example
matchbook.build_candidates(
'Harry' => ['Gryffindor', 'Slytherin'],
'Hermione' => ['Ravenclaw', 'Gryffindor'],
'Ron' => ['Gryffindor'],
'Neville' => ['Hufflepuff', 'Gryffindor', 'Ravenclaw', 'Slytherin']
)
@param candidates [Hash<Object, Array<Object>>]
Hash of candidate objects to a list of their preferred targets
|
[
"Builds",
"a",
"list",
"of",
"candidates",
"for",
"the",
"+",
"MatchMaker",
"+",
".",
"The",
"parameter",
"is",
"a",
"hash",
"of",
"unwrapped",
"canditate",
"objects",
"to",
"their",
"preferred",
"targets",
"."
] |
4e11ea438e08c0cc4d04836ffe0c61f196a70b94
|
https://github.com/fauxparse/matchy_matchy/blob/4e11ea438e08c0cc4d04836ffe0c61f196a70b94/lib/matchy_matchy/matchbook.rb#L65-L71
|
9,987
|
dyoung522/nosequel
|
lib/nosequel/configuration.rb
|
NoSequel.Configuration.sequel_url
|
def sequel_url
return '' unless db_type
# Start our connection string
connect_string = db_type + '://'
# Add user:password if supplied
unless db_user.nil?
connect_string += db_user
# Add either a @ or / depending on if a host was provided too
connect_string += db_host ? '@' : '/'
# Add host:port if supplied
connect_string += db_host + '/' if db_host
end
connect_string + db_name
end
|
ruby
|
def sequel_url
return '' unless db_type
# Start our connection string
connect_string = db_type + '://'
# Add user:password if supplied
unless db_user.nil?
connect_string += db_user
# Add either a @ or / depending on if a host was provided too
connect_string += db_host ? '@' : '/'
# Add host:port if supplied
connect_string += db_host + '/' if db_host
end
connect_string + db_name
end
|
[
"def",
"sequel_url",
"return",
"''",
"unless",
"db_type",
"# Start our connection string",
"connect_string",
"=",
"db_type",
"+",
"'://'",
"# Add user:password if supplied",
"unless",
"db_user",
".",
"nil?",
"connect_string",
"+=",
"db_user",
"# Add either a @ or / depending on if a host was provided too",
"connect_string",
"+=",
"db_host",
"?",
"'@'",
":",
"'/'",
"# Add host:port if supplied",
"connect_string",
"+=",
"db_host",
"+",
"'/'",
"if",
"db_host",
"end",
"connect_string",
"+",
"db_name",
"end"
] |
Converts the object into a textual string that can be sent to sequel
@return
A string representing the object in a sequel-connect string format
|
[
"Converts",
"the",
"object",
"into",
"a",
"textual",
"string",
"that",
"can",
"be",
"sent",
"to",
"sequel"
] |
b8788846a36ce03d426bfe3e575a81a6fb3c5c76
|
https://github.com/dyoung522/nosequel/blob/b8788846a36ce03d426bfe3e575a81a6fb3c5c76/lib/nosequel/configuration.rb#L30-L49
|
9,988
|
finn-francis/ruby-edit
|
lib/ruby_edit/find.rb
|
RubyEdit.Find.execute
|
def execute(output: $stdout, errors: $stderr)
if empty_name?
output.puts 'No name given'
return false
end
result = run "find #{@path} #{type} -name '#{@name}'" do |_out, err|
errors << err if err
end
# The following line makes the output into something readable
#
# Before the output would have looked like this:
## ./lib/my_file.rb
## ./lib/folder/my_file.rb
#
# Whereas it will now look like this:
## ./lib/my_file.rbi NEW_NAME=> ./lib/my_file.rb
## ./lib/folder/my_file.rb NEW_NAME=> ./lib/folder/my_file.rb
#
# Making it more obvious that the original path is on the left
# and the path to edit is on the right
@result = result.out.split("\n").map { |path| "#{path} NEW_NAME=> #{path}" }.join("\n")
rescue TTY::Command::ExitError => error
output.puts error
end
|
ruby
|
def execute(output: $stdout, errors: $stderr)
if empty_name?
output.puts 'No name given'
return false
end
result = run "find #{@path} #{type} -name '#{@name}'" do |_out, err|
errors << err if err
end
# The following line makes the output into something readable
#
# Before the output would have looked like this:
## ./lib/my_file.rb
## ./lib/folder/my_file.rb
#
# Whereas it will now look like this:
## ./lib/my_file.rbi NEW_NAME=> ./lib/my_file.rb
## ./lib/folder/my_file.rb NEW_NAME=> ./lib/folder/my_file.rb
#
# Making it more obvious that the original path is on the left
# and the path to edit is on the right
@result = result.out.split("\n").map { |path| "#{path} NEW_NAME=> #{path}" }.join("\n")
rescue TTY::Command::ExitError => error
output.puts error
end
|
[
"def",
"execute",
"(",
"output",
":",
"$stdout",
",",
"errors",
":",
"$stderr",
")",
"if",
"empty_name?",
"output",
".",
"puts",
"'No name given'",
"return",
"false",
"end",
"result",
"=",
"run",
"\"find #{@path} #{type} -name '#{@name}'\"",
"do",
"|",
"_out",
",",
"err",
"|",
"errors",
"<<",
"err",
"if",
"err",
"end",
"# The following line makes the output into something readable",
"#",
"# Before the output would have looked like this:",
"## ./lib/my_file.rb",
"## ./lib/folder/my_file.rb",
"#",
"# Whereas it will now look like this:",
"## ./lib/my_file.rbi NEW_NAME=> ./lib/my_file.rb",
"## ./lib/folder/my_file.rb NEW_NAME=> ./lib/folder/my_file.rb",
"#",
"# Making it more obvious that the original path is on the left",
"# and the path to edit is on the right",
"@result",
"=",
"result",
".",
"out",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"map",
"{",
"|",
"path",
"|",
"\"#{path} NEW_NAME=> #{path}\"",
"}",
".",
"join",
"(",
"\"\\n\"",
")",
"rescue",
"TTY",
"::",
"Command",
"::",
"ExitError",
"=>",
"error",
"output",
".",
"puts",
"error",
"end"
] |
Performs the find unless no name provided
@param output [IO]
@param errors [IO]
|
[
"Performs",
"the",
"find",
"unless",
"no",
"name",
"provided"
] |
90022f4de01b420f5321f12c490566d0a1e19a29
|
https://github.com/finn-francis/ruby-edit/blob/90022f4de01b420f5321f12c490566d0a1e19a29/lib/ruby_edit/find.rb#L22-L45
|
9,989
|
mcspring/denglu
|
lib/denglu/comment.rb
|
Denglu.Comment.list
|
def list(comment_id=0, max=50)
req_method = :GET
req_uri = '/api/v4/get_comment_list'
req_options = {
:commentid => comment_id,
:count => max
}
response = request_api(req_method, req_uri, req_options)
normalize_comments JSON.parse(response)
end
|
ruby
|
def list(comment_id=0, max=50)
req_method = :GET
req_uri = '/api/v4/get_comment_list'
req_options = {
:commentid => comment_id,
:count => max
}
response = request_api(req_method, req_uri, req_options)
normalize_comments JSON.parse(response)
end
|
[
"def",
"list",
"(",
"comment_id",
"=",
"0",
",",
"max",
"=",
"50",
")",
"req_method",
"=",
":GET",
"req_uri",
"=",
"'/api/v4/get_comment_list'",
"req_options",
"=",
"{",
":commentid",
"=>",
"comment_id",
",",
":count",
"=>",
"max",
"}",
"response",
"=",
"request_api",
"(",
"req_method",
",",
"req_uri",
",",
"req_options",
")",
"normalize_comments",
"JSON",
".",
"parse",
"(",
"response",
")",
"end"
] |
Get comment list
This will contains comments' relations in response.
Example:
>> comment = Denglu::Comment.new
=> #<#Denglu::Comment...>
>> comments = comment.list
=> [{...}, {...}]
Arguments:
comment_id: (Integer) The offset marker of response, default to 0 mains from the begining
max: (Integer) The max records of response, default to 50
|
[
"Get",
"comment",
"list",
"This",
"will",
"contains",
"comments",
"relations",
"in",
"response",
"."
] |
0b8fa7083eb877a20f3eda4119df23b96ada291d
|
https://github.com/mcspring/denglu/blob/0b8fa7083eb877a20f3eda4119df23b96ada291d/lib/denglu/comment.rb#L20-L31
|
9,990
|
mcspring/denglu
|
lib/denglu/comment.rb
|
Denglu.Comment.total
|
def total(resource=nil)
req_method = :GET
req_uri = '/api/v4/get_comment_count'
req_options = {}
case
when resource.is_a?(Integer)
req_options[:postid] = resource
when resource.is_a?(String)
req_options[:url] = resource
end
response = request_api(req_method, req_uri, req_options)
response = JSON.parse(response)
unless resource.nil?
response = response[0]
end
response
end
|
ruby
|
def total(resource=nil)
req_method = :GET
req_uri = '/api/v4/get_comment_count'
req_options = {}
case
when resource.is_a?(Integer)
req_options[:postid] = resource
when resource.is_a?(String)
req_options[:url] = resource
end
response = request_api(req_method, req_uri, req_options)
response = JSON.parse(response)
unless resource.nil?
response = response[0]
end
response
end
|
[
"def",
"total",
"(",
"resource",
"=",
"nil",
")",
"req_method",
"=",
":GET",
"req_uri",
"=",
"'/api/v4/get_comment_count'",
"req_options",
"=",
"{",
"}",
"case",
"when",
"resource",
".",
"is_a?",
"(",
"Integer",
")",
"req_options",
"[",
":postid",
"]",
"=",
"resource",
"when",
"resource",
".",
"is_a?",
"(",
"String",
")",
"req_options",
"[",
":url",
"]",
"=",
"resource",
"end",
"response",
"=",
"request_api",
"(",
"req_method",
",",
"req_uri",
",",
"req_options",
")",
"response",
"=",
"JSON",
".",
"parse",
"(",
"response",
")",
"unless",
"resource",
".",
"nil?",
"response",
"=",
"response",
"[",
"0",
"]",
"end",
"response",
"end"
] |
Get comment count
If resource is nil it will return all posts comment count in an array, otherwise just return a hash object.
Example:
>> comment = Denglu::Comment.new
=> #<#Denglu::Comment...>
>> comments = comment.total
=> [{"id"=>..., "count"=>..., "url"=>...},
=> {...}]
Arguments:
resource: (Mixed) Integer for resource id or string for uri.
|
[
"Get",
"comment",
"count",
"If",
"resource",
"is",
"nil",
"it",
"will",
"return",
"all",
"posts",
"comment",
"count",
"in",
"an",
"array",
"otherwise",
"just",
"return",
"a",
"hash",
"object",
"."
] |
0b8fa7083eb877a20f3eda4119df23b96ada291d
|
https://github.com/mcspring/denglu/blob/0b8fa7083eb877a20f3eda4119df23b96ada291d/lib/denglu/comment.rb#L70-L89
|
9,991
|
ideonetwork/lato-blog
|
app/controllers/lato_blog/back/posts_controller.rb
|
LatoBlog.Back::PostsController.index
|
def index
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:posts])
# find correct status to show
@posts_status = 'published'
@posts_status = 'drafted' if params[:status] && params[:status] === 'drafted'
@posts_status = 'deleted' if params[:status] && params[:status] === 'deleted'
# find informations data
@posts_informations = {
published_length: LatoBlog::Post.published.where(meta_language: cookies[:lato_blog__current_language]).length,
drafted_length: LatoBlog::Post.drafted.where(meta_language: cookies[:lato_blog__current_language]).length,
deleted_length: LatoBlog::Post.deleted.where(meta_language: cookies[:lato_blog__current_language]).length
}
# find posts to show
@posts = LatoBlog::Post.where(meta_status: @posts_status,
meta_language: cookies[:lato_blog__current_language]).joins(:post_parent).order('lato_blog_post_parents.publication_datetime DESC')
@widget_index_posts = core__widgets_index(@posts, search: 'title', pagination: 10)
end
|
ruby
|
def index
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:posts])
# find correct status to show
@posts_status = 'published'
@posts_status = 'drafted' if params[:status] && params[:status] === 'drafted'
@posts_status = 'deleted' if params[:status] && params[:status] === 'deleted'
# find informations data
@posts_informations = {
published_length: LatoBlog::Post.published.where(meta_language: cookies[:lato_blog__current_language]).length,
drafted_length: LatoBlog::Post.drafted.where(meta_language: cookies[:lato_blog__current_language]).length,
deleted_length: LatoBlog::Post.deleted.where(meta_language: cookies[:lato_blog__current_language]).length
}
# find posts to show
@posts = LatoBlog::Post.where(meta_status: @posts_status,
meta_language: cookies[:lato_blog__current_language]).joins(:post_parent).order('lato_blog_post_parents.publication_datetime DESC')
@widget_index_posts = core__widgets_index(@posts, search: 'title', pagination: 10)
end
|
[
"def",
"index",
"core__set_header_active_page_title",
"(",
"LANGUAGES",
"[",
":lato_blog",
"]",
"[",
":pages",
"]",
"[",
":posts",
"]",
")",
"# find correct status to show",
"@posts_status",
"=",
"'published'",
"@posts_status",
"=",
"'drafted'",
"if",
"params",
"[",
":status",
"]",
"&&",
"params",
"[",
":status",
"]",
"===",
"'drafted'",
"@posts_status",
"=",
"'deleted'",
"if",
"params",
"[",
":status",
"]",
"&&",
"params",
"[",
":status",
"]",
"===",
"'deleted'",
"# find informations data",
"@posts_informations",
"=",
"{",
"published_length",
":",
"LatoBlog",
"::",
"Post",
".",
"published",
".",
"where",
"(",
"meta_language",
":",
"cookies",
"[",
":lato_blog__current_language",
"]",
")",
".",
"length",
",",
"drafted_length",
":",
"LatoBlog",
"::",
"Post",
".",
"drafted",
".",
"where",
"(",
"meta_language",
":",
"cookies",
"[",
":lato_blog__current_language",
"]",
")",
".",
"length",
",",
"deleted_length",
":",
"LatoBlog",
"::",
"Post",
".",
"deleted",
".",
"where",
"(",
"meta_language",
":",
"cookies",
"[",
":lato_blog__current_language",
"]",
")",
".",
"length",
"}",
"# find posts to show",
"@posts",
"=",
"LatoBlog",
"::",
"Post",
".",
"where",
"(",
"meta_status",
":",
"@posts_status",
",",
"meta_language",
":",
"cookies",
"[",
":lato_blog__current_language",
"]",
")",
".",
"joins",
"(",
":post_parent",
")",
".",
"order",
"(",
"'lato_blog_post_parents.publication_datetime DESC'",
")",
"@widget_index_posts",
"=",
"core__widgets_index",
"(",
"@posts",
",",
"search",
":",
"'title'",
",",
"pagination",
":",
"10",
")",
"end"
] |
This function shows the list of published posts.
|
[
"This",
"function",
"shows",
"the",
"list",
"of",
"published",
"posts",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/posts_controller.rb#L9-L26
|
9,992
|
ideonetwork/lato-blog
|
app/controllers/lato_blog/back/posts_controller.rb
|
LatoBlog.Back::PostsController.new
|
def new
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:posts_new])
@post = LatoBlog::Post.new
set_current_language params[:language] if params[:language]
if params[:parent]
@post_parent = LatoBlog::PostParent.find_by(id: params[:parent])
end
fetch_external_objects
end
|
ruby
|
def new
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:posts_new])
@post = LatoBlog::Post.new
set_current_language params[:language] if params[:language]
if params[:parent]
@post_parent = LatoBlog::PostParent.find_by(id: params[:parent])
end
fetch_external_objects
end
|
[
"def",
"new",
"core__set_header_active_page_title",
"(",
"LANGUAGES",
"[",
":lato_blog",
"]",
"[",
":pages",
"]",
"[",
":posts_new",
"]",
")",
"@post",
"=",
"LatoBlog",
"::",
"Post",
".",
"new",
"set_current_language",
"params",
"[",
":language",
"]",
"if",
"params",
"[",
":language",
"]",
"if",
"params",
"[",
":parent",
"]",
"@post_parent",
"=",
"LatoBlog",
"::",
"PostParent",
".",
"find_by",
"(",
"id",
":",
"params",
"[",
":parent",
"]",
")",
"end",
"fetch_external_objects",
"end"
] |
This function shows the view to create a new post.
|
[
"This",
"function",
"shows",
"the",
"view",
"to",
"create",
"a",
"new",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/posts_controller.rb#L35-L46
|
9,993
|
ideonetwork/lato-blog
|
app/controllers/lato_blog/back/posts_controller.rb
|
LatoBlog.Back::PostsController.create
|
def create
@post = LatoBlog::Post.new(new_post_params)
unless @post.save
flash[:danger] = @post.errors.full_messages.to_sentence
redirect_to lato_blog.new_post_path
return
end
flash[:success] = LANGUAGES[:lato_blog][:flashes][:post_create_success]
redirect_to lato_blog.post_path(@post.id)
end
|
ruby
|
def create
@post = LatoBlog::Post.new(new_post_params)
unless @post.save
flash[:danger] = @post.errors.full_messages.to_sentence
redirect_to lato_blog.new_post_path
return
end
flash[:success] = LANGUAGES[:lato_blog][:flashes][:post_create_success]
redirect_to lato_blog.post_path(@post.id)
end
|
[
"def",
"create",
"@post",
"=",
"LatoBlog",
"::",
"Post",
".",
"new",
"(",
"new_post_params",
")",
"unless",
"@post",
".",
"save",
"flash",
"[",
":danger",
"]",
"=",
"@post",
".",
"errors",
".",
"full_messages",
".",
"to_sentence",
"redirect_to",
"lato_blog",
".",
"new_post_path",
"return",
"end",
"flash",
"[",
":success",
"]",
"=",
"LANGUAGES",
"[",
":lato_blog",
"]",
"[",
":flashes",
"]",
"[",
":post_create_success",
"]",
"redirect_to",
"lato_blog",
".",
"post_path",
"(",
"@post",
".",
"id",
")",
"end"
] |
This function creates a new post.
|
[
"This",
"function",
"creates",
"a",
"new",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/posts_controller.rb#L49-L60
|
9,994
|
ideonetwork/lato-blog
|
app/controllers/lato_blog/back/posts_controller.rb
|
LatoBlog.Back::PostsController.edit
|
def edit
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:posts_edit])
@post = LatoBlog::Post.find_by(id: params[:id])
return unless check_post_presence
if @post.meta_language != cookies[:lato_blog__current_language]
set_current_language @post.meta_language
end
fetch_external_objects
end
|
ruby
|
def edit
core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:posts_edit])
@post = LatoBlog::Post.find_by(id: params[:id])
return unless check_post_presence
if @post.meta_language != cookies[:lato_blog__current_language]
set_current_language @post.meta_language
end
fetch_external_objects
end
|
[
"def",
"edit",
"core__set_header_active_page_title",
"(",
"LANGUAGES",
"[",
":lato_blog",
"]",
"[",
":pages",
"]",
"[",
":posts_edit",
"]",
")",
"@post",
"=",
"LatoBlog",
"::",
"Post",
".",
"find_by",
"(",
"id",
":",
"params",
"[",
":id",
"]",
")",
"return",
"unless",
"check_post_presence",
"if",
"@post",
".",
"meta_language",
"!=",
"cookies",
"[",
":lato_blog__current_language",
"]",
"set_current_language",
"@post",
".",
"meta_language",
"end",
"fetch_external_objects",
"end"
] |
This function show the view to edit a post.
|
[
"This",
"function",
"show",
"the",
"view",
"to",
"edit",
"a",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/posts_controller.rb#L63-L73
|
9,995
|
ideonetwork/lato-blog
|
app/controllers/lato_blog/back/posts_controller.rb
|
LatoBlog.Back::PostsController.update
|
def update
@post = LatoBlog::Post.find_by(id: params[:id])
return unless check_post_presence
# update for autosaving
autosaving = params[:autosave] && params[:autosave] == 'true'
if autosaving
@post.update(edit_post_params)
update_fields
render status: 200, json: {} # render something positive :)
return
end
# check post data update
unless @post.update(edit_post_params)
flash[:danger] = @post.errors.full_messages.to_sentence
redirect_to lato_blog.edit_post_path(@post.id)
return
end
# update single fields
unless update_fields
flash[:warning] = LANGUAGES[:lato_blog][:flashes][:post_update_fields_warning]
redirect_to lato_blog.edit_post_path(@post.id)
return
end
# render positive response
flash[:success] = LANGUAGES[:lato_blog][:flashes][:post_update_success]
redirect_to lato_blog.post_path(@post.id)
end
|
ruby
|
def update
@post = LatoBlog::Post.find_by(id: params[:id])
return unless check_post_presence
# update for autosaving
autosaving = params[:autosave] && params[:autosave] == 'true'
if autosaving
@post.update(edit_post_params)
update_fields
render status: 200, json: {} # render something positive :)
return
end
# check post data update
unless @post.update(edit_post_params)
flash[:danger] = @post.errors.full_messages.to_sentence
redirect_to lato_blog.edit_post_path(@post.id)
return
end
# update single fields
unless update_fields
flash[:warning] = LANGUAGES[:lato_blog][:flashes][:post_update_fields_warning]
redirect_to lato_blog.edit_post_path(@post.id)
return
end
# render positive response
flash[:success] = LANGUAGES[:lato_blog][:flashes][:post_update_success]
redirect_to lato_blog.post_path(@post.id)
end
|
[
"def",
"update",
"@post",
"=",
"LatoBlog",
"::",
"Post",
".",
"find_by",
"(",
"id",
":",
"params",
"[",
":id",
"]",
")",
"return",
"unless",
"check_post_presence",
"# update for autosaving",
"autosaving",
"=",
"params",
"[",
":autosave",
"]",
"&&",
"params",
"[",
":autosave",
"]",
"==",
"'true'",
"if",
"autosaving",
"@post",
".",
"update",
"(",
"edit_post_params",
")",
"update_fields",
"render",
"status",
":",
"200",
",",
"json",
":",
"{",
"}",
"# render something positive :)",
"return",
"end",
"# check post data update",
"unless",
"@post",
".",
"update",
"(",
"edit_post_params",
")",
"flash",
"[",
":danger",
"]",
"=",
"@post",
".",
"errors",
".",
"full_messages",
".",
"to_sentence",
"redirect_to",
"lato_blog",
".",
"edit_post_path",
"(",
"@post",
".",
"id",
")",
"return",
"end",
"# update single fields",
"unless",
"update_fields",
"flash",
"[",
":warning",
"]",
"=",
"LANGUAGES",
"[",
":lato_blog",
"]",
"[",
":flashes",
"]",
"[",
":post_update_fields_warning",
"]",
"redirect_to",
"lato_blog",
".",
"edit_post_path",
"(",
"@post",
".",
"id",
")",
"return",
"end",
"# render positive response",
"flash",
"[",
":success",
"]",
"=",
"LANGUAGES",
"[",
":lato_blog",
"]",
"[",
":flashes",
"]",
"[",
":post_update_success",
"]",
"redirect_to",
"lato_blog",
".",
"post_path",
"(",
"@post",
".",
"id",
")",
"end"
] |
This function updates a post.
|
[
"This",
"function",
"updates",
"a",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/posts_controller.rb#L76-L106
|
9,996
|
ideonetwork/lato-blog
|
app/controllers/lato_blog/back/posts_controller.rb
|
LatoBlog.Back::PostsController.update_status
|
def update_status
@post = LatoBlog::Post.find_by(id: params[:id])
return unless check_post_presence
@post.update(meta_status: params[:status])
end
|
ruby
|
def update_status
@post = LatoBlog::Post.find_by(id: params[:id])
return unless check_post_presence
@post.update(meta_status: params[:status])
end
|
[
"def",
"update_status",
"@post",
"=",
"LatoBlog",
"::",
"Post",
".",
"find_by",
"(",
"id",
":",
"params",
"[",
":id",
"]",
")",
"return",
"unless",
"check_post_presence",
"@post",
".",
"update",
"(",
"meta_status",
":",
"params",
"[",
":status",
"]",
")",
"end"
] |
This function updates the status of a post.
|
[
"This",
"function",
"updates",
"the",
"status",
"of",
"a",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/posts_controller.rb#L109-L114
|
9,997
|
ideonetwork/lato-blog
|
app/controllers/lato_blog/back/posts_controller.rb
|
LatoBlog.Back::PostsController.update_categories
|
def update_categories
@post = LatoBlog::Post.find_by(id: params[:id])
return unless check_post_presence
params[:categories].each do |category_id, value|
category = LatoBlog::Category.find_by(id: category_id)
next if !category || category.meta_language != @post.meta_language
category_post = LatoBlog::CategoryPost.find_by(lato_blog_post_id: @post.id, lato_blog_category_id: category.id)
if value == 'true'
LatoBlog::CategoryPost.create(lato_blog_post_id: @post.id, lato_blog_category_id: category.id) unless category_post
else
category_post.destroy if category_post
end
end
end
|
ruby
|
def update_categories
@post = LatoBlog::Post.find_by(id: params[:id])
return unless check_post_presence
params[:categories].each do |category_id, value|
category = LatoBlog::Category.find_by(id: category_id)
next if !category || category.meta_language != @post.meta_language
category_post = LatoBlog::CategoryPost.find_by(lato_blog_post_id: @post.id, lato_blog_category_id: category.id)
if value == 'true'
LatoBlog::CategoryPost.create(lato_blog_post_id: @post.id, lato_blog_category_id: category.id) unless category_post
else
category_post.destroy if category_post
end
end
end
|
[
"def",
"update_categories",
"@post",
"=",
"LatoBlog",
"::",
"Post",
".",
"find_by",
"(",
"id",
":",
"params",
"[",
":id",
"]",
")",
"return",
"unless",
"check_post_presence",
"params",
"[",
":categories",
"]",
".",
"each",
"do",
"|",
"category_id",
",",
"value",
"|",
"category",
"=",
"LatoBlog",
"::",
"Category",
".",
"find_by",
"(",
"id",
":",
"category_id",
")",
"next",
"if",
"!",
"category",
"||",
"category",
".",
"meta_language",
"!=",
"@post",
".",
"meta_language",
"category_post",
"=",
"LatoBlog",
"::",
"CategoryPost",
".",
"find_by",
"(",
"lato_blog_post_id",
":",
"@post",
".",
"id",
",",
"lato_blog_category_id",
":",
"category",
".",
"id",
")",
"if",
"value",
"==",
"'true'",
"LatoBlog",
"::",
"CategoryPost",
".",
"create",
"(",
"lato_blog_post_id",
":",
"@post",
".",
"id",
",",
"lato_blog_category_id",
":",
"category",
".",
"id",
")",
"unless",
"category_post",
"else",
"category_post",
".",
"destroy",
"if",
"category_post",
"end",
"end",
"end"
] |
This function updates the categories of a post.
|
[
"This",
"function",
"updates",
"the",
"categories",
"of",
"a",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/posts_controller.rb#L125-L140
|
9,998
|
ideonetwork/lato-blog
|
app/controllers/lato_blog/back/posts_controller.rb
|
LatoBlog.Back::PostsController.update_tags
|
def update_tags
@post = LatoBlog::Post.find_by(id: params[:id])
return unless check_post_presence
params_tags = params[:tags].map(&:to_i)
tag_posts = LatoBlog::TagPost.where(lato_blog_post_id: @post.id)
params_tags.each do |tag_id|
tag = LatoBlog::Tag.find_by(id: tag_id)
next if !tag || tag.meta_language != @post.meta_language
tag_post = tag_posts.find_by(lato_blog_tag_id: tag.id)
LatoBlog::TagPost.create(lato_blog_post_id: @post.id, lato_blog_tag_id: tag.id) unless tag_post
end
tag_ids = tag_posts.pluck(:lato_blog_tag_id)
tag_ids.each do |tag_id|
next if params_tags.include?(tag_id)
tag_post = tag_posts.find_by(lato_blog_tag_id: tag_id)
tag_post.destroy if tag_post
end
end
|
ruby
|
def update_tags
@post = LatoBlog::Post.find_by(id: params[:id])
return unless check_post_presence
params_tags = params[:tags].map(&:to_i)
tag_posts = LatoBlog::TagPost.where(lato_blog_post_id: @post.id)
params_tags.each do |tag_id|
tag = LatoBlog::Tag.find_by(id: tag_id)
next if !tag || tag.meta_language != @post.meta_language
tag_post = tag_posts.find_by(lato_blog_tag_id: tag.id)
LatoBlog::TagPost.create(lato_blog_post_id: @post.id, lato_blog_tag_id: tag.id) unless tag_post
end
tag_ids = tag_posts.pluck(:lato_blog_tag_id)
tag_ids.each do |tag_id|
next if params_tags.include?(tag_id)
tag_post = tag_posts.find_by(lato_blog_tag_id: tag_id)
tag_post.destroy if tag_post
end
end
|
[
"def",
"update_tags",
"@post",
"=",
"LatoBlog",
"::",
"Post",
".",
"find_by",
"(",
"id",
":",
"params",
"[",
":id",
"]",
")",
"return",
"unless",
"check_post_presence",
"params_tags",
"=",
"params",
"[",
":tags",
"]",
".",
"map",
"(",
":to_i",
")",
"tag_posts",
"=",
"LatoBlog",
"::",
"TagPost",
".",
"where",
"(",
"lato_blog_post_id",
":",
"@post",
".",
"id",
")",
"params_tags",
".",
"each",
"do",
"|",
"tag_id",
"|",
"tag",
"=",
"LatoBlog",
"::",
"Tag",
".",
"find_by",
"(",
"id",
":",
"tag_id",
")",
"next",
"if",
"!",
"tag",
"||",
"tag",
".",
"meta_language",
"!=",
"@post",
".",
"meta_language",
"tag_post",
"=",
"tag_posts",
".",
"find_by",
"(",
"lato_blog_tag_id",
":",
"tag",
".",
"id",
")",
"LatoBlog",
"::",
"TagPost",
".",
"create",
"(",
"lato_blog_post_id",
":",
"@post",
".",
"id",
",",
"lato_blog_tag_id",
":",
"tag",
".",
"id",
")",
"unless",
"tag_post",
"end",
"tag_ids",
"=",
"tag_posts",
".",
"pluck",
"(",
":lato_blog_tag_id",
")",
"tag_ids",
".",
"each",
"do",
"|",
"tag_id",
"|",
"next",
"if",
"params_tags",
".",
"include?",
"(",
"tag_id",
")",
"tag_post",
"=",
"tag_posts",
".",
"find_by",
"(",
"lato_blog_tag_id",
":",
"tag_id",
")",
"tag_post",
".",
"destroy",
"if",
"tag_post",
"end",
"end"
] |
This function updates the tags of a post.
|
[
"This",
"function",
"updates",
"the",
"tags",
"of",
"a",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/posts_controller.rb#L143-L164
|
9,999
|
ideonetwork/lato-blog
|
app/controllers/lato_blog/back/posts_controller.rb
|
LatoBlog.Back::PostsController.update_seo_description
|
def update_seo_description
@post = LatoBlog::Post.find_by(id: params[:id])
return unless check_post_presence
@post.update(seo_description: params[:seo_description])
end
|
ruby
|
def update_seo_description
@post = LatoBlog::Post.find_by(id: params[:id])
return unless check_post_presence
@post.update(seo_description: params[:seo_description])
end
|
[
"def",
"update_seo_description",
"@post",
"=",
"LatoBlog",
"::",
"Post",
".",
"find_by",
"(",
"id",
":",
"params",
"[",
":id",
"]",
")",
"return",
"unless",
"check_post_presence",
"@post",
".",
"update",
"(",
"seo_description",
":",
"params",
"[",
":seo_description",
"]",
")",
"end"
] |
This function updates the seo description of a post.
|
[
"This",
"function",
"updates",
"the",
"seo",
"description",
"of",
"a",
"post",
"."
] |
a0d92de299a0e285851743b9d4a902f611187cba
|
https://github.com/ideonetwork/lato-blog/blob/a0d92de299a0e285851743b9d4a902f611187cba/app/controllers/lato_blog/back/posts_controller.rb#L167-L172
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.