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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
24,000 | bguthrie/handshake | lib/handshake/block_contract.rb | Handshake.ClauseMethods.Block | def Block(contract_hash)
pc = Handshake::ProcContract.new
pc.signature = contract_hash
pc
end | ruby | def Block(contract_hash)
pc = Handshake::ProcContract.new
pc.signature = contract_hash
pc
end | [
"def",
"Block",
"(",
"contract_hash",
")",
"pc",
"=",
"Handshake",
"::",
"ProcContract",
".",
"new",
"pc",
".",
"signature",
"=",
"contract_hash",
"pc",
"end"
] | Block signature definition. Returns a ProcContract with the given
attributes | [
"Block",
"signature",
"definition",
".",
"Returns",
"a",
"ProcContract",
"with",
"the",
"given",
"attributes"
] | 5fd50a814be5c1df02854fb62d851584273ce813 | https://github.com/bguthrie/handshake/blob/5fd50a814be5c1df02854fb62d851584273ce813/lib/handshake/block_contract.rb#L41-L45 |
24,001 | takanamito/openapi2ruby | lib/openapi2ruby/openapi/schema.rb | Openapi2ruby.Openapi::Schema.properties | def properties
return [] if @definition['properties'].nil?
@definition['properties'].each_with_object([]) do |(key, value), results|
content = { name: key, definition: value }
results << Openapi2ruby::Openapi::Schema::Property.new(content)
end
end | ruby | def properties
return [] if @definition['properties'].nil?
@definition['properties'].each_with_object([]) do |(key, value), results|
content = { name: key, definition: value }
results << Openapi2ruby::Openapi::Schema::Property.new(content)
end
end | [
"def",
"properties",
"return",
"[",
"]",
"if",
"@definition",
"[",
"'properties'",
"]",
".",
"nil?",
"@definition",
"[",
"'properties'",
"]",
".",
"each_with_object",
"(",
"[",
"]",
")",
"do",
"|",
"(",
"key",
",",
"value",
")",
",",
"results",
"|",
"c... | OpenAPI schema properties
@return [Array[Openapi2ruby::Openapi::Schema]] | [
"OpenAPI",
"schema",
"properties"
] | 1c971a814248600bd302809a912a527328164dc5 | https://github.com/takanamito/openapi2ruby/blob/1c971a814248600bd302809a912a527328164dc5/lib/openapi2ruby/openapi/schema.rb#L22-L28 |
24,002 | gstark/tesla-api | lib/tesla-api/connection.rb | TeslaAPI.Connection.vehicles | def vehicles
@vehicles ||= begin
_, json = get_json("/vehicles")
json.map { |data| Vehicle.new(self, data) }
end
end | ruby | def vehicles
@vehicles ||= begin
_, json = get_json("/vehicles")
json.map { |data| Vehicle.new(self, data) }
end
end | [
"def",
"vehicles",
"@vehicles",
"||=",
"begin",
"_",
",",
"json",
"=",
"get_json",
"(",
"\"/vehicles\"",
")",
"json",
".",
"map",
"{",
"|",
"data",
"|",
"Vehicle",
".",
"new",
"(",
"self",
",",
"data",
")",
"}",
"end",
"end"
] | Returns Vehicle objects for all vehicles the account contains | [
"Returns",
"Vehicle",
"objects",
"for",
"all",
"vehicles",
"the",
"account",
"contains"
] | b094ec01232415c3b6a1777fa875e4e53fecb7b4 | https://github.com/gstark/tesla-api/blob/b094ec01232415c3b6a1777fa875e4e53fecb7b4/lib/tesla-api/connection.rb#L40-L45 |
24,003 | Digi-Cazter/omniship | lib/omniship/carrier.rb | Omniship.Carrier.valid_credentials? | def valid_credentials?
location = self.class.default_location
find_rates(location,location,Package.new(100, [5,15,30]), :test => test_mode)
rescue Omniship::ResponseError
false
else
true
end | ruby | def valid_credentials?
location = self.class.default_location
find_rates(location,location,Package.new(100, [5,15,30]), :test => test_mode)
rescue Omniship::ResponseError
false
else
true
end | [
"def",
"valid_credentials?",
"location",
"=",
"self",
".",
"class",
".",
"default_location",
"find_rates",
"(",
"location",
",",
"location",
",",
"Package",
".",
"new",
"(",
"100",
",",
"[",
"5",
",",
"15",
",",
"30",
"]",
")",
",",
":test",
"=>",
"tes... | Validate credentials with a call to the API. By default this just does a find_rates call
with the orgin and destination both as the carrier's default_location. Override to provide
alternate functionality, such as checking for test_mode to use test servers, etc. | [
"Validate",
"credentials",
"with",
"a",
"call",
"to",
"the",
"API",
".",
"By",
"default",
"this",
"just",
"does",
"a",
"find_rates",
"call",
"with",
"the",
"orgin",
"and",
"destination",
"both",
"as",
"the",
"carrier",
"s",
"default_location",
".",
"Override... | a8c3ffca548fc2f00a06e4593d363439512ce6ae | https://github.com/Digi-Cazter/omniship/blob/a8c3ffca548fc2f00a06e4593d363439512ce6ae/lib/omniship/carrier.rb#L33-L40 |
24,004 | pius/rdf-mongo | lib/rdf/mongo.rb | RDF.Statement.to_mongo | def to_mongo
self.to_hash.inject({}) do |hash, (place_in_statement, entity)|
hash.merge(RDF::Mongo::Conversion.to_mongo(entity, place_in_statement))
end
end | ruby | def to_mongo
self.to_hash.inject({}) do |hash, (place_in_statement, entity)|
hash.merge(RDF::Mongo::Conversion.to_mongo(entity, place_in_statement))
end
end | [
"def",
"to_mongo",
"self",
".",
"to_hash",
".",
"inject",
"(",
"{",
"}",
")",
"do",
"|",
"hash",
",",
"(",
"place_in_statement",
",",
"entity",
")",
"|",
"hash",
".",
"merge",
"(",
"RDF",
"::",
"Mongo",
"::",
"Conversion",
".",
"to_mongo",
"(",
"enti... | Creates a BSON representation of the statement.
@return [Hash] | [
"Creates",
"a",
"BSON",
"representation",
"of",
"the",
"statement",
"."
] | bd877be4e902496c8b5625d9d293d4b8cd1bc8cc | https://github.com/pius/rdf-mongo/blob/bd877be4e902496c8b5625d9d293d4b8cd1bc8cc/lib/rdf/mongo.rb#L10-L14 |
24,005 | cryptape/ruby-rlp | lib/rlp/decode_lazy.rb | RLP.DecodeLazy.decode_lazy | def decode_lazy(rlp, sedes: nil, sedes_options: {})
item, next_start = consume_item_lazy(rlp, 0)
raise DecodingError.new("RLP length prefix announced wrong length", rlp) if next_start != rlp.size
if item.instance_of?(LazyList)
item.sedes = sedes
item.sedes_options = sedes_options
... | ruby | def decode_lazy(rlp, sedes: nil, sedes_options: {})
item, next_start = consume_item_lazy(rlp, 0)
raise DecodingError.new("RLP length prefix announced wrong length", rlp) if next_start != rlp.size
if item.instance_of?(LazyList)
item.sedes = sedes
item.sedes_options = sedes_options
... | [
"def",
"decode_lazy",
"(",
"rlp",
",",
"sedes",
":",
"nil",
",",
"sedes_options",
":",
"{",
"}",
")",
"item",
",",
"next_start",
"=",
"consume_item_lazy",
"(",
"rlp",
",",
"0",
")",
"raise",
"DecodingError",
".",
"new",
"(",
"\"RLP length prefix announced wr... | Decode an RLP encoded object in a lazy fashion.
If the encoded object is a byte string, this function acts similar to
{RLP::Decode#decode}. If it is a list however, a {LazyList} is returned
instead. This object will decode the string lazily, avoiding both
horizontal and vertical traversing as much as possible.
T... | [
"Decode",
"an",
"RLP",
"encoded",
"object",
"in",
"a",
"lazy",
"fashion",
"."
] | 49c11eaee9f0f58d8028e5f1a291504c22dc947c | https://github.com/cryptape/ruby-rlp/blob/49c11eaee9f0f58d8028e5f1a291504c22dc947c/lib/rlp/decode_lazy.rb#L31-L48 |
24,006 | cryptape/ruby-rlp | lib/rlp/decode_lazy.rb | RLP.DecodeLazy.consume_item_lazy | def consume_item_lazy(rlp, start)
t, l, s = consume_length_prefix(rlp, start)
if t == :str
consume_payload(rlp, s, :str, l)
elsif t == :list
[LazyList.new(rlp, s, s+l), s+l]
else
raise "Invalid item type: #{t}"
end
end | ruby | def consume_item_lazy(rlp, start)
t, l, s = consume_length_prefix(rlp, start)
if t == :str
consume_payload(rlp, s, :str, l)
elsif t == :list
[LazyList.new(rlp, s, s+l), s+l]
else
raise "Invalid item type: #{t}"
end
end | [
"def",
"consume_item_lazy",
"(",
"rlp",
",",
"start",
")",
"t",
",",
"l",
",",
"s",
"=",
"consume_length_prefix",
"(",
"rlp",
",",
"start",
")",
"if",
"t",
"==",
":str",
"consume_payload",
"(",
"rlp",
",",
"s",
",",
":str",
",",
"l",
")",
"elsif",
... | Read an item from an RLP string lazily.
If the length prefix announces a string, the string is read; if it
announces a list, a {LazyList} is created.
@param rlp [String] the rlp string to read from
@param start [Integer] the position at which to start reading
@return [Array] A pair `[item, next_start]` where `i... | [
"Read",
"an",
"item",
"from",
"an",
"RLP",
"string",
"lazily",
"."
] | 49c11eaee9f0f58d8028e5f1a291504c22dc947c | https://github.com/cryptape/ruby-rlp/blob/49c11eaee9f0f58d8028e5f1a291504c22dc947c/lib/rlp/decode_lazy.rb#L63-L72 |
24,007 | cryptape/ruby-rlp | lib/rlp/decode_lazy.rb | RLP.DecodeLazy.peek | def peek(rlp, index, sedes: nil)
ll = decode_lazy(rlp)
index = Array(index)
index.each do |i|
raise IndexError, "Too many indices given" if primitive?(ll)
ll = ll.fetch(i)
end
sedes ? sedes.deserialize(ll) : ll
end | ruby | def peek(rlp, index, sedes: nil)
ll = decode_lazy(rlp)
index = Array(index)
index.each do |i|
raise IndexError, "Too many indices given" if primitive?(ll)
ll = ll.fetch(i)
end
sedes ? sedes.deserialize(ll) : ll
end | [
"def",
"peek",
"(",
"rlp",
",",
"index",
",",
"sedes",
":",
"nil",
")",
"ll",
"=",
"decode_lazy",
"(",
"rlp",
")",
"index",
"=",
"Array",
"(",
"index",
")",
"index",
".",
"each",
"do",
"|",
"i",
"|",
"raise",
"IndexError",
",",
"\"Too many indices gi... | Get a specific element from an rlp encoded nested list.
This method uses {RLP::DecodeLazy#decode_lazy} and, thus, decodes only
the necessary parts of the string.
@example Usage
rlpdata = RLP.encode([1, 2, [3, [4, 5]]])
RLP.peek(rlpdata, 0, sedes: RLP::Sedes.big_endian_int) # => 1
RLP.peek(rlpdata, [2, 0],... | [
"Get",
"a",
"specific",
"element",
"from",
"an",
"rlp",
"encoded",
"nested",
"list",
"."
] | 49c11eaee9f0f58d8028e5f1a291504c22dc947c | https://github.com/cryptape/ruby-rlp/blob/49c11eaee9f0f58d8028e5f1a291504c22dc947c/lib/rlp/decode_lazy.rb#L93-L103 |
24,008 | bguthrie/handshake | lib/handshake.rb | Handshake.ClassMethods.contract_reader | def contract_reader(meth_to_clause)
attr_reader(*(meth_to_clause.keys))
meth_to_clause.each do |meth, cls|
contract meth, nil => cls
end
end | ruby | def contract_reader(meth_to_clause)
attr_reader(*(meth_to_clause.keys))
meth_to_clause.each do |meth, cls|
contract meth, nil => cls
end
end | [
"def",
"contract_reader",
"(",
"meth_to_clause",
")",
"attr_reader",
"(",
"(",
"meth_to_clause",
".",
"keys",
")",
")",
"meth_to_clause",
".",
"each",
"do",
"|",
"meth",
",",
"cls",
"|",
"contract",
"meth",
",",
"nil",
"=>",
"cls",
"end",
"end"
] | Defines contract-checked attribute readers with the given hash of method
name to clause. | [
"Defines",
"contract",
"-",
"checked",
"attribute",
"readers",
"with",
"the",
"given",
"hash",
"of",
"method",
"name",
"to",
"clause",
"."
] | 5fd50a814be5c1df02854fb62d851584273ce813 | https://github.com/bguthrie/handshake/blob/5fd50a814be5c1df02854fb62d851584273ce813/lib/handshake.rb#L251-L256 |
24,009 | bguthrie/handshake | lib/handshake.rb | Handshake.ClassMethods.contract_writer | def contract_writer(meth_to_clause)
attr_writer(*(meth_to_clause.keys))
meth_to_clause.each do |meth, cls|
contract "#{meth}=".to_sym, cls => anything
end
end | ruby | def contract_writer(meth_to_clause)
attr_writer(*(meth_to_clause.keys))
meth_to_clause.each do |meth, cls|
contract "#{meth}=".to_sym, cls => anything
end
end | [
"def",
"contract_writer",
"(",
"meth_to_clause",
")",
"attr_writer",
"(",
"(",
"meth_to_clause",
".",
"keys",
")",
")",
"meth_to_clause",
".",
"each",
"do",
"|",
"meth",
",",
"cls",
"|",
"contract",
"\"#{meth}=\"",
".",
"to_sym",
",",
"cls",
"=>",
"anything"... | Defines contract-checked attribute writers with the given hash of method
name to clause. | [
"Defines",
"contract",
"-",
"checked",
"attribute",
"writers",
"with",
"the",
"given",
"hash",
"of",
"method",
"name",
"to",
"clause",
"."
] | 5fd50a814be5c1df02854fb62d851584273ce813 | https://github.com/bguthrie/handshake/blob/5fd50a814be5c1df02854fb62d851584273ce813/lib/handshake.rb#L260-L265 |
24,010 | bguthrie/handshake | lib/handshake.rb | Handshake.ClassMethods.method_added | def method_added(meth_name)
@deferred ||= {}
unless @deferred.empty?
@deferred.each do |k, v|
case k
when :before, :after, :around
define_condition meth_name, k, v
when :contract
define_contract meth_name, v
end
end
@def... | ruby | def method_added(meth_name)
@deferred ||= {}
unless @deferred.empty?
@deferred.each do |k, v|
case k
when :before, :after, :around
define_condition meth_name, k, v
when :contract
define_contract meth_name, v
end
end
@def... | [
"def",
"method_added",
"(",
"meth_name",
")",
"@deferred",
"||=",
"{",
"}",
"unless",
"@deferred",
".",
"empty?",
"@deferred",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"case",
"k",
"when",
":before",
",",
":after",
",",
":around",
"define_condition",
... | Callback from method add event. If a previous method contract
declaration was deferred, complete it now with the name of the newly-
added method. | [
"Callback",
"from",
"method",
"add",
"event",
".",
"If",
"a",
"previous",
"method",
"contract",
"declaration",
"was",
"deferred",
"complete",
"it",
"now",
"with",
"the",
"name",
"of",
"the",
"newly",
"-",
"added",
"method",
"."
] | 5fd50a814be5c1df02854fb62d851584273ce813 | https://github.com/bguthrie/handshake/blob/5fd50a814be5c1df02854fb62d851584273ce813/lib/handshake.rb#L277-L290 |
24,011 | bguthrie/handshake | lib/handshake.rb | Handshake.MethodContract.accepts= | def accepts=(args)
if args.last == Block # Transform into a ProcContract
args.pop
@block_contract = ProcContract.new
@block_contract.accepts = ClauseMethods::ANYTHING
@block_contract.returns = ClauseMethods::ANYTHING
elsif args.last.is_a?(ProcContract)
@block_... | ruby | def accepts=(args)
if args.last == Block # Transform into a ProcContract
args.pop
@block_contract = ProcContract.new
@block_contract.accepts = ClauseMethods::ANYTHING
@block_contract.returns = ClauseMethods::ANYTHING
elsif args.last.is_a?(ProcContract)
@block_... | [
"def",
"accepts",
"=",
"(",
"args",
")",
"if",
"args",
".",
"last",
"==",
"Block",
"# Transform into a ProcContract",
"args",
".",
"pop",
"@block_contract",
"=",
"ProcContract",
".",
"new",
"@block_contract",
".",
"accepts",
"=",
"ClauseMethods",
"::",
"ANYTHING... | If the last argument is a Block, handle it as a special case. We
do this to ensure that there's no conflict with any real arguments
which may accept Procs. | [
"If",
"the",
"last",
"argument",
"is",
"a",
"Block",
"handle",
"it",
"as",
"a",
"special",
"case",
".",
"We",
"do",
"this",
"to",
"ensure",
"that",
"there",
"s",
"no",
"conflict",
"with",
"any",
"real",
"arguments",
"which",
"may",
"accept",
"Procs",
"... | 5fd50a814be5c1df02854fb62d851584273ce813 | https://github.com/bguthrie/handshake/blob/5fd50a814be5c1df02854fb62d851584273ce813/lib/handshake.rb#L447-L461 |
24,012 | github/rack-statsd | lib/rack-statsd.rb | RackStatsD.RequestStatus.call | def call(env)
if env[REQUEST_METHOD] == GET
if env[PATH_INFO] == @status_path
if @callback.respond_to?(:call)
return @callback.call
else
return [200, HEADERS, [@callback.to_s]]
end
end
end
@app.call env
end | ruby | def call(env)
if env[REQUEST_METHOD] == GET
if env[PATH_INFO] == @status_path
if @callback.respond_to?(:call)
return @callback.call
else
return [200, HEADERS, [@callback.to_s]]
end
end
end
@app.call env
end | [
"def",
"call",
"(",
"env",
")",
"if",
"env",
"[",
"REQUEST_METHOD",
"]",
"==",
"GET",
"if",
"env",
"[",
"PATH_INFO",
"]",
"==",
"@status_path",
"if",
"@callback",
".",
"respond_to?",
"(",
":call",
")",
"return",
"@callback",
".",
"call",
"else",
"return"... | Initializes the middleware.
# Responds with "OK" on /status
use RequestStatus, "OK"
You can change what URL to look for:
use RequestStatus, "OK", "/ping"
You can also check internal systems and return something more informative.
use RequestStatus, lambda {
status = MyApp.status # A Has... | [
"Initializes",
"the",
"middleware",
"."
] | f03b18ef5c27df861384930c206d797be540e956 | https://github.com/github/rack-statsd/blob/f03b18ef5c27df861384930c206d797be540e956/lib/rack-statsd.rb#L40-L52 |
24,013 | github/rack-statsd | lib/rack-statsd.rb | RackStatsD.RequestHostname.call | def call(env)
status, headers, body = @app.call(env)
headers['X-Node'] = @host if @host
headers['X-Revision'] = @sha
[status, headers, body]
end | ruby | def call(env)
status, headers, body = @app.call(env)
headers['X-Node'] = @host if @host
headers['X-Revision'] = @sha
[status, headers, body]
end | [
"def",
"call",
"(",
"env",
")",
"status",
",",
"headers",
",",
"body",
"=",
"@app",
".",
"call",
"(",
"env",
")",
"headers",
"[",
"'X-Node'",
"]",
"=",
"@host",
"if",
"@host",
"headers",
"[",
"'X-Revision'",
"]",
"=",
"@sha",
"[",
"status",
",",
"h... | Initializes the middlware.
app - The next Rack app in the pipeline.
options - Hash of options.
:host - String hostname.
:revision - String SHA that describes the version of code
this process is running.
Returns nothing. | [
"Initializes",
"the",
"middlware",
"."
] | f03b18ef5c27df861384930c206d797be540e956 | https://github.com/github/rack-statsd/blob/f03b18ef5c27df861384930c206d797be540e956/lib/rack-statsd.rb#L74-L79 |
24,014 | github/rack-statsd | lib/rack-statsd.rb | RackStatsD.ProcessUtilization.procline | def procline
"unicorn %s[%s] worker[%02d]: %5d reqs, %4.1f req/s, %4dms avg, %5.1f%% util" % [
domain,
revision,
worker_number.to_i,
total_requests.to_i,
requests_per_second.to_f,
average_response_time.to_i,
percentage_active.to_f
]
end | ruby | def procline
"unicorn %s[%s] worker[%02d]: %5d reqs, %4.1f req/s, %4dms avg, %5.1f%% util" % [
domain,
revision,
worker_number.to_i,
total_requests.to_i,
requests_per_second.to_f,
average_response_time.to_i,
percentage_active.to_f
]
end | [
"def",
"procline",
"\"unicorn %s[%s] worker[%02d]: %5d reqs, %4.1f req/s, %4dms avg, %5.1f%% util\"",
"%",
"[",
"domain",
",",
"revision",
",",
"worker_number",
".",
"to_i",
",",
"total_requests",
".",
"to_i",
",",
"requests_per_second",
".",
"to_f",
",",
"average_response_... | the generated procline | [
"the",
"generated",
"procline"
] | f03b18ef5c27df861384930c206d797be540e956 | https://github.com/github/rack-statsd/blob/f03b18ef5c27df861384930c206d797be540e956/lib/rack-statsd.rb#L206-L216 |
24,015 | github/rack-statsd | lib/rack-statsd.rb | RackStatsD.ProcessUtilization.record_request | def record_request(status, env)
now = Time.now
diff = (now - @start)
@active_time += diff
@requests += 1
$0 = procline
if @stats
@stats.timing("#{@stats_prefix}.response_time", diff * 1000)
if VALID_METHODS.include?(env[REQUEST_METHOD])
stat = "#{@stats_pr... | ruby | def record_request(status, env)
now = Time.now
diff = (now - @start)
@active_time += diff
@requests += 1
$0 = procline
if @stats
@stats.timing("#{@stats_prefix}.response_time", diff * 1000)
if VALID_METHODS.include?(env[REQUEST_METHOD])
stat = "#{@stats_pr... | [
"def",
"record_request",
"(",
"status",
",",
"env",
")",
"now",
"=",
"Time",
".",
"now",
"diff",
"=",
"(",
"now",
"-",
"@start",
")",
"@active_time",
"+=",
"diff",
"@requests",
"+=",
"1",
"$0",
"=",
"procline",
"if",
"@stats",
"@stats",
".",
"timing",
... | called immediately after a request to record statistics, update the
procline, and dump information to the logfile | [
"called",
"immediately",
"after",
"a",
"request",
"to",
"record",
"statistics",
"update",
"the",
"procline",
"and",
"dump",
"information",
"to",
"the",
"logfile"
] | f03b18ef5c27df861384930c206d797be540e956 | https://github.com/github/rack-statsd/blob/f03b18ef5c27df861384930c206d797be540e956/lib/rack-statsd.rb#L220-L247 |
24,016 | github/rack-statsd | lib/rack-statsd.rb | RackStatsD.ProcessUtilization.call | def call(env)
@start = Time.now
GC.clear_stats if @track_gc
@total_requests += 1
first_request if @total_requests == 1
env['process.request_start'] = @start.to_f
env['process.total_requests'] = total_requests
# newrelic X-Request-Start
env.delete('HTTP_X_REQUEST_START'... | ruby | def call(env)
@start = Time.now
GC.clear_stats if @track_gc
@total_requests += 1
first_request if @total_requests == 1
env['process.request_start'] = @start.to_f
env['process.total_requests'] = total_requests
# newrelic X-Request-Start
env.delete('HTTP_X_REQUEST_START'... | [
"def",
"call",
"(",
"env",
")",
"@start",
"=",
"Time",
".",
"now",
"GC",
".",
"clear_stats",
"if",
"@track_gc",
"@total_requests",
"+=",
"1",
"first_request",
"if",
"@total_requests",
"==",
"1",
"env",
"[",
"'process.request_start'",
"]",
"=",
"@start",
".",... | Rack entry point. | [
"Rack",
"entry",
"point",
"."
] | f03b18ef5c27df861384930c206d797be540e956 | https://github.com/github/rack-statsd/blob/f03b18ef5c27df861384930c206d797be540e956/lib/rack-statsd.rb#L298-L314 |
24,017 | theforeman/hammer-cli-foreman-tasks | lib/hammer_cli_foreman_tasks/helper.rb | HammerCLIForemanTasks.Helper.task_progress | def task_progress(task_or_id)
task_id = task_or_id.is_a?(Hash) ? task_or_id['id'] : task_or_id
if !task_id.empty?
options = { verbosity: @context[:verbosity] || HammerCLI::V_VERBOSE }
task_progress = TaskProgress.new(task_id, options) { |id| load_task(id) }
task_progress.render
... | ruby | def task_progress(task_or_id)
task_id = task_or_id.is_a?(Hash) ? task_or_id['id'] : task_or_id
if !task_id.empty?
options = { verbosity: @context[:verbosity] || HammerCLI::V_VERBOSE }
task_progress = TaskProgress.new(task_id, options) { |id| load_task(id) }
task_progress.render
... | [
"def",
"task_progress",
"(",
"task_or_id",
")",
"task_id",
"=",
"task_or_id",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"task_or_id",
"[",
"'id'",
"]",
":",
"task_or_id",
"if",
"!",
"task_id",
".",
"empty?",
"options",
"=",
"{",
"verbosity",
":",
"@context",
... | render the progress of the task using polling to the task API | [
"render",
"the",
"progress",
"of",
"the",
"task",
"using",
"polling",
"to",
"the",
"task",
"API"
] | 1b928158014fc51142aaf434fd32c37d893d0966 | https://github.com/theforeman/hammer-cli-foreman-tasks/blob/1b928158014fc51142aaf434fd32c37d893d0966/lib/hammer_cli_foreman_tasks/helper.rb#L4-L14 |
24,018 | cryptape/ruby-rlp | lib/rlp/decode.rb | RLP.Decode.decode | def decode(rlp, **options)
rlp = str_to_bytes(rlp)
sedes = options.delete(:sedes)
strict = options.has_key?(:strict) ? options.delete(:strict) : true
begin
item, next_start = consume_item(rlp, 0)
rescue Exception => e
raise DecodingError.new("Cannot decode rlp string: #{e}... | ruby | def decode(rlp, **options)
rlp = str_to_bytes(rlp)
sedes = options.delete(:sedes)
strict = options.has_key?(:strict) ? options.delete(:strict) : true
begin
item, next_start = consume_item(rlp, 0)
rescue Exception => e
raise DecodingError.new("Cannot decode rlp string: #{e}... | [
"def",
"decode",
"(",
"rlp",
",",
"**",
"options",
")",
"rlp",
"=",
"str_to_bytes",
"(",
"rlp",
")",
"sedes",
"=",
"options",
".",
"delete",
"(",
":sedes",
")",
"strict",
"=",
"options",
".",
"has_key?",
"(",
":strict",
")",
"?",
"options",
".",
"del... | Decode an RLP encoded object.
If the deserialized result `obj` has an attribute `_cached_rlp` (e.g. if
`sedes` is a subclass of {RLP::Sedes::Serializable}), it will be set to
`rlp`, which will improve performance on subsequent {RLP::Encode#encode}
calls. Bear in mind however that `obj` needs to make sure that this... | [
"Decode",
"an",
"RLP",
"encoded",
"object",
"."
] | 49c11eaee9f0f58d8028e5f1a291504c22dc947c | https://github.com/cryptape/ruby-rlp/blob/49c11eaee9f0f58d8028e5f1a291504c22dc947c/lib/rlp/decode.rb#L35-L62 |
24,019 | cryptape/ruby-rlp | lib/rlp/decode.rb | RLP.Decode.consume_item | def consume_item(rlp, start)
t, l, s = consume_length_prefix(rlp, start)
consume_payload(rlp, s, t, l)
end | ruby | def consume_item(rlp, start)
t, l, s = consume_length_prefix(rlp, start)
consume_payload(rlp, s, t, l)
end | [
"def",
"consume_item",
"(",
"rlp",
",",
"start",
")",
"t",
",",
"l",
",",
"s",
"=",
"consume_length_prefix",
"(",
"rlp",
",",
"start",
")",
"consume_payload",
"(",
"rlp",
",",
"s",
",",
"t",
",",
"l",
")",
"end"
] | Read an item from an RLP string.
* `rlp` - the string to read from
* `start` - the position at which to start reading`
Returns a pair `[item, end]` where `item` is the read item and `end` is
the position of the first unprocessed byte. | [
"Read",
"an",
"item",
"from",
"an",
"RLP",
"string",
"."
] | 49c11eaee9f0f58d8028e5f1a291504c22dc947c | https://github.com/cryptape/ruby-rlp/blob/49c11eaee9f0f58d8028e5f1a291504c22dc947c/lib/rlp/decode.rb#L159-L162 |
24,020 | cryptape/ruby-rlp | lib/rlp/decode.rb | RLP.Decode.consume_payload | def consume_payload(rlp, start, type, length)
case type
when :str
[rlp[start...(start+length)], start+length]
when :list
items = []
next_item_start = start
payload_end = next_item_start + length
while next_item_start < payload_end
item, next_item_star... | ruby | def consume_payload(rlp, start, type, length)
case type
when :str
[rlp[start...(start+length)], start+length]
when :list
items = []
next_item_start = start
payload_end = next_item_start + length
while next_item_start < payload_end
item, next_item_star... | [
"def",
"consume_payload",
"(",
"rlp",
",",
"start",
",",
"type",
",",
"length",
")",
"case",
"type",
"when",
":str",
"[",
"rlp",
"[",
"start",
"...",
"(",
"start",
"+",
"length",
")",
"]",
",",
"start",
"+",
"length",
"]",
"when",
":list",
"items",
... | Read the payload of an item from an RLP string.
* `rlp` - the rlp string to read from
* `type` - the type of the payload (`:str` or `:list`)
* `start` - the position at which to start reading
* `length` - the length of the payload in bytes
Returns a pair `[item, end]`, where `item` is the read item and `end` is
... | [
"Read",
"the",
"payload",
"of",
"an",
"item",
"from",
"an",
"RLP",
"string",
"."
] | 49c11eaee9f0f58d8028e5f1a291504c22dc947c | https://github.com/cryptape/ruby-rlp/blob/49c11eaee9f0f58d8028e5f1a291504c22dc947c/lib/rlp/decode.rb#L216-L236 |
24,021 | codequest-eu/codequest_pipes | lib/codequest_pipes/context.rb | Pipes.Context.add | def add(values)
values.each do |key, val|
k_sym = key.to_sym
fail Override, "Property :#{key} already present" if respond_to?(k_sym)
define_singleton_method(k_sym) { val }
end
end | ruby | def add(values)
values.each do |key, val|
k_sym = key.to_sym
fail Override, "Property :#{key} already present" if respond_to?(k_sym)
define_singleton_method(k_sym) { val }
end
end | [
"def",
"add",
"(",
"values",
")",
"values",
".",
"each",
"do",
"|",
"key",
",",
"val",
"|",
"k_sym",
"=",
"key",
".",
"to_sym",
"fail",
"Override",
",",
"\"Property :#{key} already present\"",
"if",
"respond_to?",
"(",
"k_sym",
")",
"define_singleton_method",
... | Context constructor.
@param values [Hash]
Method `add` allows adding new properties (as a Hash) to the Context.
@param values [Hash] | [
"Context",
"constructor",
"."
] | 3da315a1d789b8ccca16261d5c68506671df2c80 | https://github.com/codequest-eu/codequest_pipes/blob/3da315a1d789b8ccca16261d5c68506671df2c80/lib/codequest_pipes/context.rb#L27-L33 |
24,022 | adhearsion/ruby_fs | lib/ruby_fs/stream.rb | RubyFS.Stream.run | def run
logger.debug "Starting up..."
@socket = TCPSocket.from_ruby_socket ::TCPSocket.new(@host, @port)
post_init
loop { receive_data @socket.readpartial(4096) }
rescue EOFError, IOError, Errno::ECONNREFUSED => e
logger.info "Client socket closed due to (#{e.class}) #{e.message}!"
... | ruby | def run
logger.debug "Starting up..."
@socket = TCPSocket.from_ruby_socket ::TCPSocket.new(@host, @port)
post_init
loop { receive_data @socket.readpartial(4096) }
rescue EOFError, IOError, Errno::ECONNREFUSED => e
logger.info "Client socket closed due to (#{e.class}) #{e.message}!"
... | [
"def",
"run",
"logger",
".",
"debug",
"\"Starting up...\"",
"@socket",
"=",
"TCPSocket",
".",
"from_ruby_socket",
"::",
"TCPSocket",
".",
"new",
"(",
"@host",
",",
"@port",
")",
"post_init",
"loop",
"{",
"receive_data",
"@socket",
".",
"readpartial",
"(",
"409... | Connect to the server and begin handling data | [
"Connect",
"to",
"the",
"server",
"and",
"begin",
"handling",
"data"
] | 8a282ec6e2c2ada3d472976fcc6c3ec48b98d358 | https://github.com/adhearsion/ruby_fs/blob/8a282ec6e2c2ada3d472976fcc6c3ec48b98d358/lib/ruby_fs/stream.rb#L37-L45 |
24,023 | adhearsion/ruby_fs | lib/ruby_fs/stream.rb | RubyFS.Stream.command | def command(command, options = {}, &callback)
uuid = SecureRandom.uuid
@command_callbacks << (callback || lambda { |reply| signal uuid, reply })
string = "#{command}\n"
body_value = options.delete :command_body_value
options.each_pair do |key, value|
string << "#{key.to_s.gsub '_',... | ruby | def command(command, options = {}, &callback)
uuid = SecureRandom.uuid
@command_callbacks << (callback || lambda { |reply| signal uuid, reply })
string = "#{command}\n"
body_value = options.delete :command_body_value
options.each_pair do |key, value|
string << "#{key.to_s.gsub '_',... | [
"def",
"command",
"(",
"command",
",",
"options",
"=",
"{",
"}",
",",
"&",
"callback",
")",
"uuid",
"=",
"SecureRandom",
".",
"uuid",
"@command_callbacks",
"<<",
"(",
"callback",
"||",
"lambda",
"{",
"|",
"reply",
"|",
"signal",
"uuid",
",",
"reply",
"... | Send a FreeSWITCH command with options and a callback for the response
@param [#to_s] command the command to run
@param [optional, Hash] options the command's options, where keys have _ substituted for -
@return [RubyFS::Response] response the command's response object | [
"Send",
"a",
"FreeSWITCH",
"command",
"with",
"options",
"and",
"a",
"callback",
"for",
"the",
"response"
] | 8a282ec6e2c2ada3d472976fcc6c3ec48b98d358 | https://github.com/adhearsion/ruby_fs/blob/8a282ec6e2c2ada3d472976fcc6c3ec48b98d358/lib/ruby_fs/stream.rb#L63-L75 |
24,024 | adhearsion/ruby_fs | lib/ruby_fs/stream.rb | RubyFS.Stream.application | def application(call, appname, options = nil)
opts = {call_command: 'execute', execute_app_name: appname}
if options
opts[:content_type] = 'text/plain'
opts[:content_length] = options.bytesize
opts[:command_body_value] = options
end
sendmsg call, opts
end | ruby | def application(call, appname, options = nil)
opts = {call_command: 'execute', execute_app_name: appname}
if options
opts[:content_type] = 'text/plain'
opts[:content_length] = options.bytesize
opts[:command_body_value] = options
end
sendmsg call, opts
end | [
"def",
"application",
"(",
"call",
",",
"appname",
",",
"options",
"=",
"nil",
")",
"opts",
"=",
"{",
"call_command",
":",
"'execute'",
",",
"execute_app_name",
":",
"appname",
"}",
"if",
"options",
"opts",
"[",
":content_type",
"]",
"=",
"'text/plain'",
"... | Execute an application on a particular call
@param [#to_s] call the call ID on which to execute the application
@param [#to_s] appname the app to execute
@param [optional, String] options the application options
@return [RubyFS::Response] response the application's response object | [
"Execute",
"an",
"application",
"on",
"a",
"particular",
"call"
] | 8a282ec6e2c2ada3d472976fcc6c3ec48b98d358 | https://github.com/adhearsion/ruby_fs/blob/8a282ec6e2c2ada3d472976fcc6c3ec48b98d358/lib/ruby_fs/stream.rb#L116-L124 |
24,025 | epfl-exts/rails-gdpr-export | lib/gdpr_exporter.rb | GdprExporter.ClassMethods.gdpr_collect | def gdpr_collect(*args)
# Params handling
if args.class == Hash # when user provides the hash_params only
simple_fields, hash_params = [[], args]
else
simple_fields, hash_params = [args[0..-2], args.last]
end
unless hash_params.class == Hash
raise ArgumentError.new... | ruby | def gdpr_collect(*args)
# Params handling
if args.class == Hash # when user provides the hash_params only
simple_fields, hash_params = [[], args]
else
simple_fields, hash_params = [args[0..-2], args.last]
end
unless hash_params.class == Hash
raise ArgumentError.new... | [
"def",
"gdpr_collect",
"(",
"*",
"args",
")",
"# Params handling",
"if",
"args",
".",
"class",
"==",
"Hash",
"# when user provides the hash_params only",
"simple_fields",
",",
"hash_params",
"=",
"[",
"[",
"]",
",",
"args",
"]",
"else",
"simple_fields",
",",
"ha... | Declared in each model class with interest in collecting gdpr data.
Instruments the singleton of those classes so that gdpr data can be
collected and exported to csv.
Arguments are:
- set of simple fields: i.e. fields that will be output as is
- a hash of params:
{renamed_fields: {<field_from_db> => <field_name_... | [
"Declared",
"in",
"each",
"model",
"class",
"with",
"interest",
"in",
"collecting",
"gdpr",
"data",
".",
"Instruments",
"the",
"singleton",
"of",
"those",
"classes",
"so",
"that",
"gdpr",
"data",
"can",
"be",
"collected",
"and",
"exported",
"to",
"csv",
"."
... | 3a7130da5c53ae65fb6aa3d544a8876bbb388c3c | https://github.com/epfl-exts/rails-gdpr-export/blob/3a7130da5c53ae65fb6aa3d544a8876bbb388c3c/lib/gdpr_exporter.rb#L51-L137 |
24,026 | prydonius/spinning_cursor | lib/spinning_cursor/console_helpers.rb | SpinningCursor.ConsoleHelpers.reset_line | def reset_line(text = "")
# Initialise ANSI escape string
escape = ""
# Get terminal window width
cols = console_columns
# The number of lines the previous message spanned
lines = @@prev / cols
# If cols == 80 and @@prev == 80, @@prev / cols == 1 but we don't want to
#... | ruby | def reset_line(text = "")
# Initialise ANSI escape string
escape = ""
# Get terminal window width
cols = console_columns
# The number of lines the previous message spanned
lines = @@prev / cols
# If cols == 80 and @@prev == 80, @@prev / cols == 1 but we don't want to
#... | [
"def",
"reset_line",
"(",
"text",
"=",
"\"\"",
")",
"# Initialise ANSI escape string",
"escape",
"=",
"\"\"",
"# Get terminal window width",
"cols",
"=",
"console_columns",
"# The number of lines the previous message spanned",
"lines",
"=",
"@@prev",
"/",
"cols",
"# If cols... | Manages line reset in the console | [
"Manages",
"line",
"reset",
"in",
"the",
"console"
] | e0f2a9a1c5e3461586ac08417cc82c8ccafb4a12 | https://github.com/prydonius/spinning_cursor/blob/e0f2a9a1c5e3461586ac08417cc82c8ccafb4a12/lib/spinning_cursor/console_helpers.rb#L32-L57 |
24,027 | kt3k/bmp | lib/bump/domain/bump_info.rb | Bump.BumpInfo.valid? | def valid?
create_update_rules.each do |rule|
return false if !rule.file_exists || !rule.pattern_exists
end
true
end | ruby | def valid?
create_update_rules.each do |rule|
return false if !rule.file_exists || !rule.pattern_exists
end
true
end | [
"def",
"valid?",
"create_update_rules",
".",
"each",
"do",
"|",
"rule",
"|",
"return",
"false",
"if",
"!",
"rule",
".",
"file_exists",
"||",
"!",
"rule",
".",
"pattern_exists",
"end",
"true",
"end"
] | Checks the all the version patterns are available
@return [Boolean] | [
"Checks",
"the",
"all",
"the",
"version",
"patterns",
"are",
"available"
] | 24c16fa8bcea5da8a72370b537b6dd92002011ee | https://github.com/kt3k/bmp/blob/24c16fa8bcea5da8a72370b537b6dd92002011ee/lib/bump/domain/bump_info.rb#L66-L72 |
24,028 | ImmaculatePine/hermitage | lib/hermitage/rails_render_core.rb | Hermitage.RailsRenderCore.render | def render
# Initialize the resulting tag
tag_parts = []
# Slice objects into separate lists
lists = slice_objects
# Render each list into `tag` variable
lists.each do |list|
items = list.collect { |item| render_link_for(item) }
tag_parts << render_content_tag_for(i... | ruby | def render
# Initialize the resulting tag
tag_parts = []
# Slice objects into separate lists
lists = slice_objects
# Render each list into `tag` variable
lists.each do |list|
items = list.collect { |item| render_link_for(item) }
tag_parts << render_content_tag_for(i... | [
"def",
"render",
"# Initialize the resulting tag",
"tag_parts",
"=",
"[",
"]",
"# Slice objects into separate lists",
"lists",
"=",
"slice_objects",
"# Render each list into `tag` variable",
"lists",
".",
"each",
"do",
"|",
"list",
"|",
"items",
"=",
"list",
".",
"colle... | Renders gallery markup | [
"Renders",
"gallery",
"markup"
] | 262c4d759691e7e11255e31f1eccf7a28d273d42 | https://github.com/ImmaculatePine/hermitage/blob/262c4d759691e7e11255e31f1eccf7a28d273d42/lib/hermitage/rails_render_core.rb#L13-L27 |
24,029 | ImmaculatePine/hermitage | lib/hermitage/rails_render_core.rb | Hermitage.RailsRenderCore.value_for | def value_for(item, option)
attribute = @options[option]
if attribute.is_a? Proc
attribute.call(item)
else
eval("item.#{attribute}")
end
end | ruby | def value_for(item, option)
attribute = @options[option]
if attribute.is_a? Proc
attribute.call(item)
else
eval("item.#{attribute}")
end
end | [
"def",
"value_for",
"(",
"item",
",",
"option",
")",
"attribute",
"=",
"@options",
"[",
"option",
"]",
"if",
"attribute",
".",
"is_a?",
"Proc",
"attribute",
".",
"call",
"(",
"item",
")",
"else",
"eval",
"(",
"\"item.#{attribute}\"",
")",
"end",
"end"
] | Returns value of item's attribute | [
"Returns",
"value",
"of",
"item",
"s",
"attribute"
] | 262c4d759691e7e11255e31f1eccf7a28d273d42 | https://github.com/ImmaculatePine/hermitage/blob/262c4d759691e7e11255e31f1eccf7a28d273d42/lib/hermitage/rails_render_core.rb#L41-L48 |
24,030 | ImmaculatePine/hermitage | lib/hermitage/rails_render_core.rb | Hermitage.RailsRenderCore.render_link_for | def render_link_for(item)
original_path = value_for(item, :original)
thumbnail_path = value_for(item, :thumbnail)
title = @options[:title] ? value_for(item, :title) : nil
image = @template.image_tag(thumbnail_path, class: @options[:image_class])
@template.link_to(image, original_path, rel:... | ruby | def render_link_for(item)
original_path = value_for(item, :original)
thumbnail_path = value_for(item, :thumbnail)
title = @options[:title] ? value_for(item, :title) : nil
image = @template.image_tag(thumbnail_path, class: @options[:image_class])
@template.link_to(image, original_path, rel:... | [
"def",
"render_link_for",
"(",
"item",
")",
"original_path",
"=",
"value_for",
"(",
"item",
",",
":original",
")",
"thumbnail_path",
"=",
"value_for",
"(",
"item",
",",
":thumbnail",
")",
"title",
"=",
"@options",
"[",
":title",
"]",
"?",
"value_for",
"(",
... | Renders link to the specific image in a gallery | [
"Renders",
"link",
"to",
"the",
"specific",
"image",
"in",
"a",
"gallery"
] | 262c4d759691e7e11255e31f1eccf7a28d273d42 | https://github.com/ImmaculatePine/hermitage/blob/262c4d759691e7e11255e31f1eccf7a28d273d42/lib/hermitage/rails_render_core.rb#L51-L59 |
24,031 | cryptape/ruby-rlp | lib/rlp/encode.rb | RLP.Encode.encode | def encode(obj, sedes: nil, infer_serializer: true, cache: false)
return obj._cached_rlp if obj.is_a?(Sedes::Serializable) && obj._cached_rlp && sedes.nil?
really_cache = obj.is_a?(Sedes::Serializable) && sedes.nil? && cache
if sedes
item = sedes.serialize(obj)
elsif infer_serializer
... | ruby | def encode(obj, sedes: nil, infer_serializer: true, cache: false)
return obj._cached_rlp if obj.is_a?(Sedes::Serializable) && obj._cached_rlp && sedes.nil?
really_cache = obj.is_a?(Sedes::Serializable) && sedes.nil? && cache
if sedes
item = sedes.serialize(obj)
elsif infer_serializer
... | [
"def",
"encode",
"(",
"obj",
",",
"sedes",
":",
"nil",
",",
"infer_serializer",
":",
"true",
",",
"cache",
":",
"false",
")",
"return",
"obj",
".",
"_cached_rlp",
"if",
"obj",
".",
"is_a?",
"(",
"Sedes",
"::",
"Serializable",
")",
"&&",
"obj",
".",
"... | Encode a Ruby object in RLP format.
By default, the object is serialized in a suitable way first (using
{RLP::Sedes.infer}) and then encoded. Serialization can be explicitly
suppressed by setting {RLP::Sedes.infer} to `false` and not passing an
alternative as `sedes`.
If `obj` has an attribute `_cached_rlp` (as,... | [
"Encode",
"a",
"Ruby",
"object",
"in",
"RLP",
"format",
"."
] | 49c11eaee9f0f58d8028e5f1a291504c22dc947c | https://github.com/cryptape/ruby-rlp/blob/49c11eaee9f0f58d8028e5f1a291504c22dc947c/lib/rlp/encode.rb#L43-L64 |
24,032 | kt3k/bmp | lib/bump/application.rb | Bump.Application.create_bump_info | def create_bump_info
repo = BumpInfoRepository.new @file
begin
bump_info = repo.from_file
rescue Errno::ENOENT
log_red "Error: the file `#{@file}` not found."
return nil
end
bump_info
end | ruby | def create_bump_info
repo = BumpInfoRepository.new @file
begin
bump_info = repo.from_file
rescue Errno::ENOENT
log_red "Error: the file `#{@file}` not found."
return nil
end
bump_info
end | [
"def",
"create_bump_info",
"repo",
"=",
"BumpInfoRepository",
".",
"new",
"@file",
"begin",
"bump_info",
"=",
"repo",
".",
"from_file",
"rescue",
"Errno",
"::",
"ENOENT",
"log_red",
"\"Error: the file `#{@file}` not found.\"",
"return",
"nil",
"end",
"bump_info",
"end... | Gets the bump info
@private
@return [Bump::BumpInfo] | [
"Gets",
"the",
"bump",
"info"
] | 24c16fa8bcea5da8a72370b537b6dd92002011ee | https://github.com/kt3k/bmp/blob/24c16fa8bcea5da8a72370b537b6dd92002011ee/lib/bump/application.rb#L64-L75 |
24,033 | kt3k/bmp | lib/bump/application.rb | Bump.Application.print_version_patterns | def print_version_patterns(bump_info)
log 'Current Version:', false
log_green " #{bump_info.before_version}"
log 'Version patterns:'
bump_info.update_rules.each do |rule|
print_rule rule
end
end | ruby | def print_version_patterns(bump_info)
log 'Current Version:', false
log_green " #{bump_info.before_version}"
log 'Version patterns:'
bump_info.update_rules.each do |rule|
print_rule rule
end
end | [
"def",
"print_version_patterns",
"(",
"bump_info",
")",
"log",
"'Current Version:'",
",",
"false",
"log_green",
"\" #{bump_info.before_version}\"",
"log",
"'Version patterns:'",
"bump_info",
".",
"update_rules",
".",
"each",
"do",
"|",
"rule",
"|",
"print_rule",
"rule",... | Shows the version patterns.
@param [Bump::BumpInfo] bumpInfo
@return [void] | [
"Shows",
"the",
"version",
"patterns",
"."
] | 24c16fa8bcea5da8a72370b537b6dd92002011ee | https://github.com/kt3k/bmp/blob/24c16fa8bcea5da8a72370b537b6dd92002011ee/lib/bump/application.rb#L89-L98 |
24,034 | kt3k/bmp | lib/bump/application.rb | Bump.Application.print_rule | def print_rule(rule)
unless rule.file_exists
log_red " #{rule.file}:", false
log_red " '#{rule.before_pattern}' (file not found)"
return
end
log " #{rule.file}:", false
unless rule.pattern_exists
log_red " '#{rule.before_pattern}' (pattern not found)"
... | ruby | def print_rule(rule)
unless rule.file_exists
log_red " #{rule.file}:", false
log_red " '#{rule.before_pattern}' (file not found)"
return
end
log " #{rule.file}:", false
unless rule.pattern_exists
log_red " '#{rule.before_pattern}' (pattern not found)"
... | [
"def",
"print_rule",
"(",
"rule",
")",
"unless",
"rule",
".",
"file_exists",
"log_red",
"\" #{rule.file}:\"",
",",
"false",
"log_red",
"\" '#{rule.before_pattern}' (file not found)\"",
"return",
"end",
"log",
"\" #{rule.file}:\"",
",",
"false",
"unless",
"rule",
".",
... | Prints the pattern info for the given rule
@param [Bump::FileUpdateRule] rule The rule | [
"Prints",
"the",
"pattern",
"info",
"for",
"the",
"given",
"rule"
] | 24c16fa8bcea5da8a72370b537b6dd92002011ee | https://github.com/kt3k/bmp/blob/24c16fa8bcea5da8a72370b537b6dd92002011ee/lib/bump/application.rb#L102-L119 |
24,035 | kt3k/bmp | lib/bump/application.rb | Bump.Application.report | def report(bump_info)
bump_info.update_rules.each do |rule|
log rule.file.to_s
log ' Performed pattern replacement:'
log_green " '#{rule.before_pattern}' => '#{rule.after_pattern}'"
log
end
end | ruby | def report(bump_info)
bump_info.update_rules.each do |rule|
log rule.file.to_s
log ' Performed pattern replacement:'
log_green " '#{rule.before_pattern}' => '#{rule.after_pattern}'"
log
end
end | [
"def",
"report",
"(",
"bump_info",
")",
"bump_info",
".",
"update_rules",
".",
"each",
"do",
"|",
"rule",
"|",
"log",
"rule",
".",
"file",
".",
"to_s",
"log",
"' Performed pattern replacement:'",
"log_green",
"\" '#{rule.before_pattern}' => '#{rule.after_pattern}'\"... | Reports the bumping details.
@param [Bump::BumpInfo] bumpInfo | [
"Reports",
"the",
"bumping",
"details",
"."
] | 24c16fa8bcea5da8a72370b537b6dd92002011ee | https://github.com/kt3k/bmp/blob/24c16fa8bcea5da8a72370b537b6dd92002011ee/lib/bump/application.rb#L147-L154 |
24,036 | kt3k/bmp | lib/bump/application.rb | Bump.Application.action_bump | def action_bump
bump_info = create_bump_info
return false if bump_info.nil?
print_bump_plan bump_info
unless bump_info.valid?
print_invalid_bump_info bump_info
return false
end
bump_info.perform_update
report bump_info
save_bump_info bump_info
... | ruby | def action_bump
bump_info = create_bump_info
return false if bump_info.nil?
print_bump_plan bump_info
unless bump_info.valid?
print_invalid_bump_info bump_info
return false
end
bump_info.perform_update
report bump_info
save_bump_info bump_info
... | [
"def",
"action_bump",
"bump_info",
"=",
"create_bump_info",
"return",
"false",
"if",
"bump_info",
".",
"nil?",
"print_bump_plan",
"bump_info",
"unless",
"bump_info",
".",
"valid?",
"print_invalid_bump_info",
"bump_info",
"return",
"false",
"end",
"bump_info",
".",
"pe... | The bump action
@return [Boolean] true iff success | [
"The",
"bump",
"action"
] | 24c16fa8bcea5da8a72370b537b6dd92002011ee | https://github.com/kt3k/bmp/blob/24c16fa8bcea5da8a72370b537b6dd92002011ee/lib/bump/application.rb#L158-L180 |
24,037 | kt3k/bmp | lib/bump/application.rb | Bump.Application.print_bump_plan | def print_bump_plan(bump_info)
level = bump_level
print_bump_plan_level level, bump_info unless level.nil?
preid = @options[:preid]
print_bump_plan_preid preid, bump_info unless preid.nil?
print_bump_plan_release bump_info if @options[:release]
log
end | ruby | def print_bump_plan(bump_info)
level = bump_level
print_bump_plan_level level, bump_info unless level.nil?
preid = @options[:preid]
print_bump_plan_preid preid, bump_info unless preid.nil?
print_bump_plan_release bump_info if @options[:release]
log
end | [
"def",
"print_bump_plan",
"(",
"bump_info",
")",
"level",
"=",
"bump_level",
"print_bump_plan_level",
"level",
",",
"bump_info",
"unless",
"level",
".",
"nil?",
"preid",
"=",
"@options",
"[",
":preid",
"]",
"print_bump_plan_preid",
"preid",
",",
"bump_info",
"unle... | Prints the version bump plan.
@param [Bump::BumpInfo] bump_info The bump info | [
"Prints",
"the",
"version",
"bump",
"plan",
"."
] | 24c16fa8bcea5da8a72370b537b6dd92002011ee | https://github.com/kt3k/bmp/blob/24c16fa8bcea5da8a72370b537b6dd92002011ee/lib/bump/application.rb#L192-L202 |
24,038 | kt3k/bmp | lib/bump/application.rb | Bump.Application.print_bump_plan_preid | def print_bump_plan_preid(preid, bump_info)
bump_info.preid = preid
log 'Set pre-release version id: ', false
log_green preid
print_version_transition bump_info
end | ruby | def print_bump_plan_preid(preid, bump_info)
bump_info.preid = preid
log 'Set pre-release version id: ', false
log_green preid
print_version_transition bump_info
end | [
"def",
"print_bump_plan_preid",
"(",
"preid",
",",
"bump_info",
")",
"bump_info",
".",
"preid",
"=",
"preid",
"log",
"'Set pre-release version id: '",
",",
"false",
"log_green",
"preid",
"print_version_transition",
"bump_info",
"end"
] | Prints the bump plan for the give preid.
@param [Bump::BumpInfo] bump_info The bump info | [
"Prints",
"the",
"bump",
"plan",
"for",
"the",
"give",
"preid",
"."
] | 24c16fa8bcea5da8a72370b537b6dd92002011ee | https://github.com/kt3k/bmp/blob/24c16fa8bcea5da8a72370b537b6dd92002011ee/lib/bump/application.rb#L216-L222 |
24,039 | Digi-Cazter/omniship | lib/omniship/carriers/ups.rb | Omniship.UPS.create_shipment | def create_shipment(origin, destination, packages, options={})
@options = @options.merge(options)
origin, destination = upsified_location(origin), upsified_location(destination)
options = @options.merge(options)
options[:test] = options[:test].nil? ? true : option... | ruby | def create_shipment(origin, destination, packages, options={})
@options = @options.merge(options)
origin, destination = upsified_location(origin), upsified_location(destination)
options = @options.merge(options)
options[:test] = options[:test].nil? ? true : option... | [
"def",
"create_shipment",
"(",
"origin",
",",
"destination",
",",
"packages",
",",
"options",
"=",
"{",
"}",
")",
"@options",
"=",
"@options",
".",
"merge",
"(",
"options",
")",
"origin",
",",
"destination",
"=",
"upsified_location",
"(",
"origin",
")",
",... | Creating shipping functionality for UPS | [
"Creating",
"shipping",
"functionality",
"for",
"UPS"
] | a8c3ffca548fc2f00a06e4593d363439512ce6ae | https://github.com/Digi-Cazter/omniship/blob/a8c3ffca548fc2f00a06e4593d363439512ce6ae/lib/omniship/carriers/ups.rb#L123-L133 |
24,040 | tpickett66/ansible-vault-rb | lib/ansible/vault.rb | Ansible.Vault.write | def write
file = FileWriter.new(@path)
encryptor = Encryptor.new(password: @password, file: file)
encryptor.encrypt(@plaintext)
file.write
end | ruby | def write
file = FileWriter.new(@path)
encryptor = Encryptor.new(password: @password, file: file)
encryptor.encrypt(@plaintext)
file.write
end | [
"def",
"write",
"file",
"=",
"FileWriter",
".",
"new",
"(",
"@path",
")",
"encryptor",
"=",
"Encryptor",
".",
"new",
"(",
"password",
":",
"@password",
",",
"file",
":",
"file",
")",
"encryptor",
".",
"encrypt",
"(",
"@plaintext",
")",
"file",
".",
"wr... | Write the plaintext to the file specified
@return [File] The closed file handle the vault was written to | [
"Write",
"the",
"plaintext",
"to",
"the",
"file",
"specified"
] | 06d7239f10b3fdc074d45523705309ebf5efc2ab | https://github.com/tpickett66/ansible-vault-rb/blob/06d7239f10b3fdc074d45523705309ebf5efc2ab/lib/ansible/vault.rb#L116-L121 |
24,041 | tpickett66/ansible-vault-rb | lib/ansible/vault.rb | Ansible.Vault.read | def read
file = FileReader.new(@path)
return File.read(@path) unless file.encrypted?
decryptor = Decryptor.new(password: @password, file: file)
decryptor.plaintext
end | ruby | def read
file = FileReader.new(@path)
return File.read(@path) unless file.encrypted?
decryptor = Decryptor.new(password: @password, file: file)
decryptor.plaintext
end | [
"def",
"read",
"file",
"=",
"FileReader",
".",
"new",
"(",
"@path",
")",
"return",
"File",
".",
"read",
"(",
"@path",
")",
"unless",
"file",
".",
"encrypted?",
"decryptor",
"=",
"Decryptor",
".",
"new",
"(",
"password",
":",
"@password",
",",
"file",
"... | Extract the plaintext from a previously written vault file
If the file does not appear to be encrypted the raw contents will be
returned.
@return [String] The plaintext contents of the vault, this is marked for
zeroing before the GC reaps the object. Any data extracted/parsed from
this string should be simil... | [
"Extract",
"the",
"plaintext",
"from",
"a",
"previously",
"written",
"vault",
"file"
] | 06d7239f10b3fdc074d45523705309ebf5efc2ab | https://github.com/tpickett66/ansible-vault-rb/blob/06d7239f10b3fdc074d45523705309ebf5efc2ab/lib/ansible/vault.rb#L131-L136 |
24,042 | soylent/jschema | lib/jschema/validation_helpers.rb | JSchema.ValidationHelpers.non_empty_array? | def non_empty_array?(value, uniqueness_check = true)
result = value.is_a?(Array) && !value.empty?
if uniqueness_check
result && value.size == value.uniq.size
else
result
end
end | ruby | def non_empty_array?(value, uniqueness_check = true)
result = value.is_a?(Array) && !value.empty?
if uniqueness_check
result && value.size == value.uniq.size
else
result
end
end | [
"def",
"non_empty_array?",
"(",
"value",
",",
"uniqueness_check",
"=",
"true",
")",
"result",
"=",
"value",
".",
"is_a?",
"(",
"Array",
")",
"&&",
"!",
"value",
".",
"empty?",
"if",
"uniqueness_check",
"result",
"&&",
"value",
".",
"size",
"==",
"value",
... | Returns true if a given value is a non-empty array
@param value [Object]
@return [Boolean] | [
"Returns",
"true",
"if",
"a",
"given",
"value",
"is",
"a",
"non",
"-",
"empty",
"array"
] | 57df9daf333fafb9d0d2bf15df65d4c044a612ea | https://github.com/soylent/jschema/blob/57df9daf333fafb9d0d2bf15df65d4c044a612ea/lib/jschema/validation_helpers.rb#L45-L52 |
24,043 | soylent/jschema | lib/jschema/validation_helpers.rb | JSchema.ValidationHelpers.schema_array? | def schema_array?(value, id, uniqueness_check = true)
non_empty_array?(value, uniqueness_check) &&
value.to_enum.with_index.all? do |schema, index|
full_id = [id, index].join('/')
valid_schema? schema, full_id
end
end | ruby | def schema_array?(value, id, uniqueness_check = true)
non_empty_array?(value, uniqueness_check) &&
value.to_enum.with_index.all? do |schema, index|
full_id = [id, index].join('/')
valid_schema? schema, full_id
end
end | [
"def",
"schema_array?",
"(",
"value",
",",
"id",
",",
"uniqueness_check",
"=",
"true",
")",
"non_empty_array?",
"(",
"value",
",",
"uniqueness_check",
")",
"&&",
"value",
".",
"to_enum",
".",
"with_index",
".",
"all?",
"do",
"|",
"schema",
",",
"index",
"|... | Returns true if a given value is a list of valid JSON schemas
@param value [Object]
@param id [String] parent schema id
@param uniqueness_check [Boolean] check that all schemas are unique
@return [Boolean] | [
"Returns",
"true",
"if",
"a",
"given",
"value",
"is",
"a",
"list",
"of",
"valid",
"JSON",
"schemas"
] | 57df9daf333fafb9d0d2bf15df65d4c044a612ea | https://github.com/soylent/jschema/blob/57df9daf333fafb9d0d2bf15df65d4c044a612ea/lib/jschema/validation_helpers.rb#L60-L66 |
24,044 | soylent/jschema | lib/jschema/validation_helpers.rb | JSchema.ValidationHelpers.valid_schema? | def valid_schema?(schema, id)
schema.is_a?(Hash) && Schema.build(schema, parent, id)
rescue InvalidSchema
false
end | ruby | def valid_schema?(schema, id)
schema.is_a?(Hash) && Schema.build(schema, parent, id)
rescue InvalidSchema
false
end | [
"def",
"valid_schema?",
"(",
"schema",
",",
"id",
")",
"schema",
".",
"is_a?",
"(",
"Hash",
")",
"&&",
"Schema",
".",
"build",
"(",
"schema",
",",
"parent",
",",
"id",
")",
"rescue",
"InvalidSchema",
"false",
"end"
] | Returns true if a given JSON schema is valid
@param schema [Object] schema
@param id [String] schema id
@return [Boolean] | [
"Returns",
"true",
"if",
"a",
"given",
"JSON",
"schema",
"is",
"valid"
] | 57df9daf333fafb9d0d2bf15df65d4c044a612ea | https://github.com/soylent/jschema/blob/57df9daf333fafb9d0d2bf15df65d4c044a612ea/lib/jschema/validation_helpers.rb#L73-L77 |
24,045 | avdgaag/redmine-api | lib/redmine/accept_json.rb | Redmine.AcceptJson.get | def get(path, headers = {})
response = super(path, { 'Accept' => ACCEPT }.merge(headers.to_h))
case response.content_type
when CONTENT_TYPE then [parse_response(response), response]
else raise "Unknown content type #{response.content_type.inspect}"
end
end | ruby | def get(path, headers = {})
response = super(path, { 'Accept' => ACCEPT }.merge(headers.to_h))
case response.content_type
when CONTENT_TYPE then [parse_response(response), response]
else raise "Unknown content type #{response.content_type.inspect}"
end
end | [
"def",
"get",
"(",
"path",
",",
"headers",
"=",
"{",
"}",
")",
"response",
"=",
"super",
"(",
"path",
",",
"{",
"'Accept'",
"=>",
"ACCEPT",
"}",
".",
"merge",
"(",
"headers",
".",
"to_h",
")",
")",
"case",
"response",
".",
"content_type",
"when",
"... | Wrap requests to add an `Accept` header to ask for JSON, and parse
response bodies as JSON data. | [
"Wrap",
"requests",
"to",
"add",
"an",
"Accept",
"header",
"to",
"ask",
"for",
"JSON",
"and",
"parse",
"response",
"bodies",
"as",
"JSON",
"data",
"."
] | 4417b801c4ad8ab1442ad557ddaa282239910153 | https://github.com/avdgaag/redmine-api/blob/4417b801c4ad8ab1442ad557ddaa282239910153/lib/redmine/accept_json.rb#L22-L28 |
24,046 | sonots/kondate | lib/kondate/hash_ext.rb | Kondate.HashExt.deep_merge! | def deep_merge!(other_hash, &block)
other_hash.each_pair do |current_key, other_value|
this_value = self[current_key]
self[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
_this_value = HashExt.new.replace(this_value)
_this_value.deep_merge(other_value, &blo... | ruby | def deep_merge!(other_hash, &block)
other_hash.each_pair do |current_key, other_value|
this_value = self[current_key]
self[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
_this_value = HashExt.new.replace(this_value)
_this_value.deep_merge(other_value, &blo... | [
"def",
"deep_merge!",
"(",
"other_hash",
",",
"&",
"block",
")",
"other_hash",
".",
"each_pair",
"do",
"|",
"current_key",
",",
"other_value",
"|",
"this_value",
"=",
"self",
"[",
"current_key",
"]",
"self",
"[",
"current_key",
"]",
"=",
"if",
"this_value",
... | Same as +deep_merge+, but modifies +self+. | [
"Same",
"as",
"+",
"deep_merge",
"+",
"but",
"modifies",
"+",
"self",
"+",
"."
] | a56d520b08a1a2bf2d992067ef017175401684ef | https://github.com/sonots/kondate/blob/a56d520b08a1a2bf2d992067ef017175401684ef/lib/kondate/hash_ext.rb#L23-L40 |
24,047 | carwow/restful_resource | lib/restful_resource/request.rb | RestfulResource.Request.format_headers | def format_headers
@headers.stringify_keys.each_with_object({}) do |key_with_value, headers|
headers[format_key(key_with_value.first)] = key_with_value.last
end
end | ruby | def format_headers
@headers.stringify_keys.each_with_object({}) do |key_with_value, headers|
headers[format_key(key_with_value.first)] = key_with_value.last
end
end | [
"def",
"format_headers",
"@headers",
".",
"stringify_keys",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"key_with_value",
",",
"headers",
"|",
"headers",
"[",
"format_key",
"(",
"key_with_value",
".",
"first",
")",
"]",
"=",
"key_with_value",
".",
... | Formats all keys in Word-Word format | [
"Formats",
"all",
"keys",
"in",
"Word",
"-",
"Word",
"format"
] | b9224aaad76e24cff231616ffa048859770deb9e | https://github.com/carwow/restful_resource/blob/b9224aaad76e24cff231616ffa048859770deb9e/lib/restful_resource/request.rb#L21-L25 |
24,048 | cloudfoundry-attic/cfoundry | lib/cfoundry/zip.rb | CFoundry.Zip.unpack | def unpack(file, dest)
::Zip::ZipFile.foreach(file) do |zentry|
epath = "#{dest}/#{zentry}"
dirname = File.dirname(epath)
FileUtils.mkdir_p(dirname) unless File.exists?(dirname)
zentry.extract(epath) unless File.exists?(epath)
end
end | ruby | def unpack(file, dest)
::Zip::ZipFile.foreach(file) do |zentry|
epath = "#{dest}/#{zentry}"
dirname = File.dirname(epath)
FileUtils.mkdir_p(dirname) unless File.exists?(dirname)
zentry.extract(epath) unless File.exists?(epath)
end
end | [
"def",
"unpack",
"(",
"file",
",",
"dest",
")",
"::",
"Zip",
"::",
"ZipFile",
".",
"foreach",
"(",
"file",
")",
"do",
"|",
"zentry",
"|",
"epath",
"=",
"\"#{dest}/#{zentry}\"",
"dirname",
"=",
"File",
".",
"dirname",
"(",
"epath",
")",
"FileUtils",
"."... | Unpack a zip +file+ to directory +dest+. | [
"Unpack",
"a",
"zip",
"+",
"file",
"+",
"to",
"directory",
"+",
"dest",
"+",
"."
] | 028576968a054e2524be0b6e00b1400a831db9f4 | https://github.com/cloudfoundry-attic/cfoundry/blob/028576968a054e2524be0b6e00b1400a831db9f4/lib/cfoundry/zip.rb#L23-L30 |
24,049 | cloudfoundry-attic/cfoundry | lib/cfoundry/zip.rb | CFoundry.Zip.files_to_pack | def files_to_pack(dir)
Dir.glob("#{dir}/**/*", File::FNM_DOTMATCH).select do |f|
File.exists?(f) &&
PACK_EXCLUSION_GLOBS.none? do |e|
File.fnmatch(e, File.basename(f))
end
end
end | ruby | def files_to_pack(dir)
Dir.glob("#{dir}/**/*", File::FNM_DOTMATCH).select do |f|
File.exists?(f) &&
PACK_EXCLUSION_GLOBS.none? do |e|
File.fnmatch(e, File.basename(f))
end
end
end | [
"def",
"files_to_pack",
"(",
"dir",
")",
"Dir",
".",
"glob",
"(",
"\"#{dir}/**/*\"",
",",
"File",
"::",
"FNM_DOTMATCH",
")",
".",
"select",
"do",
"|",
"f",
"|",
"File",
".",
"exists?",
"(",
"f",
")",
"&&",
"PACK_EXCLUSION_GLOBS",
".",
"none?",
"do",
"|... | Determine what files in +dir+ to pack. | [
"Determine",
"what",
"files",
"in",
"+",
"dir",
"+",
"to",
"pack",
"."
] | 028576968a054e2524be0b6e00b1400a831db9f4 | https://github.com/cloudfoundry-attic/cfoundry/blob/028576968a054e2524be0b6e00b1400a831db9f4/lib/cfoundry/zip.rb#L33-L40 |
24,050 | cloudfoundry-attic/cfoundry | lib/cfoundry/zip.rb | CFoundry.Zip.pack | def pack(dir, zipfile)
files = files_to_pack(dir)
return false if files.empty?
::Zip::ZipFile.open(zipfile, true) do |zf|
files.each do |f|
zf.add(f.sub("#{dir}/",''), f)
end
end
true
end | ruby | def pack(dir, zipfile)
files = files_to_pack(dir)
return false if files.empty?
::Zip::ZipFile.open(zipfile, true) do |zf|
files.each do |f|
zf.add(f.sub("#{dir}/",''), f)
end
end
true
end | [
"def",
"pack",
"(",
"dir",
",",
"zipfile",
")",
"files",
"=",
"files_to_pack",
"(",
"dir",
")",
"return",
"false",
"if",
"files",
".",
"empty?",
"::",
"Zip",
"::",
"ZipFile",
".",
"open",
"(",
"zipfile",
",",
"true",
")",
"do",
"|",
"zf",
"|",
"fil... | Package directory +dir+ as file +zipfile+. | [
"Package",
"directory",
"+",
"dir",
"+",
"as",
"file",
"+",
"zipfile",
"+",
"."
] | 028576968a054e2524be0b6e00b1400a831db9f4 | https://github.com/cloudfoundry-attic/cfoundry/blob/028576968a054e2524be0b6e00b1400a831db9f4/lib/cfoundry/zip.rb#L43-L54 |
24,051 | code-and-effect/effective_bootstrap | app/models/effective/form_builder.rb | Effective.FormBuilder.remote_link_to | def remote_link_to(name, url, options = {}, &block)
options[:href] ||= url
Effective::FormInputs::RemoteLinkTo.new(name, options, builder: self).to_html(&block)
end | ruby | def remote_link_to(name, url, options = {}, &block)
options[:href] ||= url
Effective::FormInputs::RemoteLinkTo.new(name, options, builder: self).to_html(&block)
end | [
"def",
"remote_link_to",
"(",
"name",
",",
"url",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"options",
"[",
":href",
"]",
"||=",
"url",
"Effective",
"::",
"FormInputs",
"::",
"RemoteLinkTo",
".",
"new",
"(",
"name",
",",
"options",
",",
... | This is gonna be a post? | [
"This",
"is",
"gonna",
"be",
"a",
"post?"
] | d2f4641b08a40a4017117cf55331099ef3333b54 | https://github.com/code-and-effect/effective_bootstrap/blob/d2f4641b08a40a4017117cf55331099ef3333b54/app/models/effective/form_builder.rb#L84-L87 |
24,052 | rlister/slackbotsy | lib/slackbotsy/api.rb | Slackbotsy.Api.get_objects | def get_objects(method, key)
self.class.get("/#{method}", query: { token: @token }).tap do |response|
raise "error retrieving #{key} from #{method}: #{response.fetch('error', 'unknown error')}" unless response['ok']
end.fetch(key)
end | ruby | def get_objects(method, key)
self.class.get("/#{method}", query: { token: @token }).tap do |response|
raise "error retrieving #{key} from #{method}: #{response.fetch('error', 'unknown error')}" unless response['ok']
end.fetch(key)
end | [
"def",
"get_objects",
"(",
"method",
",",
"key",
")",
"self",
".",
"class",
".",
"get",
"(",
"\"/#{method}\"",
",",
"query",
":",
"{",
"token",
":",
"@token",
"}",
")",
".",
"tap",
"do",
"|",
"response",
"|",
"raise",
"\"error retrieving #{key} from #{meth... | get a channel, group, im or user list | [
"get",
"a",
"channel",
"group",
"im",
"or",
"user",
"list"
] | 198b9e3316630f4ae76f6c3e7da71ffae89ec4ed | https://github.com/rlister/slackbotsy/blob/198b9e3316630f4ae76f6c3e7da71ffae89ec4ed/lib/slackbotsy/api.rb#L14-L18 |
24,053 | rlister/slackbotsy | lib/slackbotsy/api.rb | Slackbotsy.Api.join | def join(channel)
self.class.post('/channels.join', body: {name: channel, token: @token}).tap do |response|
raise "error posting message: #{response.fetch('error', 'unknown error')}" unless response['ok']
end
end | ruby | def join(channel)
self.class.post('/channels.join', body: {name: channel, token: @token}).tap do |response|
raise "error posting message: #{response.fetch('error', 'unknown error')}" unless response['ok']
end
end | [
"def",
"join",
"(",
"channel",
")",
"self",
".",
"class",
".",
"post",
"(",
"'/channels.join'",
",",
"body",
":",
"{",
"name",
":",
"channel",
",",
"token",
":",
"@token",
"}",
")",
".",
"tap",
"do",
"|",
"response",
"|",
"raise",
"\"error posting mess... | join a channel, needed to post to channel | [
"join",
"a",
"channel",
"needed",
"to",
"post",
"to",
"channel"
] | 198b9e3316630f4ae76f6c3e7da71ffae89ec4ed | https://github.com/rlister/slackbotsy/blob/198b9e3316630f4ae76f6c3e7da71ffae89ec4ed/lib/slackbotsy/api.rb#L37-L41 |
24,054 | rlister/slackbotsy | lib/slackbotsy/api.rb | Slackbotsy.Api.post_message | def post_message(params)
self.class.post('/chat.postMessage', body: params.merge({token: @token})).tap do |response|
raise "error posting message: #{response.fetch('error', 'unknown error')}" unless response['ok']
end
end | ruby | def post_message(params)
self.class.post('/chat.postMessage', body: params.merge({token: @token})).tap do |response|
raise "error posting message: #{response.fetch('error', 'unknown error')}" unless response['ok']
end
end | [
"def",
"post_message",
"(",
"params",
")",
"self",
".",
"class",
".",
"post",
"(",
"'/chat.postMessage'",
",",
"body",
":",
"params",
".",
"merge",
"(",
"{",
"token",
":",
"@token",
"}",
")",
")",
".",
"tap",
"do",
"|",
"response",
"|",
"raise",
"\"e... | send message to one channel as a single post with params text, channel, as_user | [
"send",
"message",
"to",
"one",
"channel",
"as",
"a",
"single",
"post",
"with",
"params",
"text",
"channel",
"as_user"
] | 198b9e3316630f4ae76f6c3e7da71ffae89ec4ed | https://github.com/rlister/slackbotsy/blob/198b9e3316630f4ae76f6c3e7da71ffae89ec4ed/lib/slackbotsy/api.rb#L44-L48 |
24,055 | cloudfoundry-attic/cfoundry | lib/cfoundry/upload_helpers.rb | CFoundry.UploadHelpers.prune_empty_directories | def prune_empty_directories(path)
all_files = all_files(path)
directories = all_files.select { |x| File.directory?(x) }
directories.sort! { |a, b| b.size <=> a.size }
directories.each do |directory|
entries = all_files(directory)
FileUtils.rmdir(directory) if entries.empty?
... | ruby | def prune_empty_directories(path)
all_files = all_files(path)
directories = all_files.select { |x| File.directory?(x) }
directories.sort! { |a, b| b.size <=> a.size }
directories.each do |directory|
entries = all_files(directory)
FileUtils.rmdir(directory) if entries.empty?
... | [
"def",
"prune_empty_directories",
"(",
"path",
")",
"all_files",
"=",
"all_files",
"(",
"path",
")",
"directories",
"=",
"all_files",
".",
"select",
"{",
"|",
"x",
"|",
"File",
".",
"directory?",
"(",
"x",
")",
"}",
"directories",
".",
"sort!",
"{",
"|",... | OK, HERES THE PLAN...
1. Get all the directories in the entire file tree.
2. Sort them by the length of their absolute path.
3. Go through the list, longest paths first, and remove
the directories that are empty.
This ensures that directories containing empty directories
are also pruned. | [
"OK",
"HERES",
"THE",
"PLAN",
"..."
] | 028576968a054e2524be0b6e00b1400a831db9f4 | https://github.com/cloudfoundry-attic/cfoundry/blob/028576968a054e2524be0b6e00b1400a831db9f4/lib/cfoundry/upload_helpers.rb#L188-L198 |
24,056 | rlister/slackbotsy | lib/slackbotsy/bot.rb | Slackbotsy.Bot.setup_incoming_webhook | def setup_incoming_webhook
## incoming_webhook will be used if provided, otherwise fallback to old-style url with team and token
url = @options.fetch('incoming_webhook', false) || "https://#{@options['team']}.slack.com/services/hooks/incoming-webhook?token=#{@options['incoming_token']}"
@uri = URI.pa... | ruby | def setup_incoming_webhook
## incoming_webhook will be used if provided, otherwise fallback to old-style url with team and token
url = @options.fetch('incoming_webhook', false) || "https://#{@options['team']}.slack.com/services/hooks/incoming-webhook?token=#{@options['incoming_token']}"
@uri = URI.pa... | [
"def",
"setup_incoming_webhook",
"## incoming_webhook will be used if provided, otherwise fallback to old-style url with team and token",
"url",
"=",
"@options",
".",
"fetch",
"(",
"'incoming_webhook'",
",",
"false",
")",
"||",
"\"https://#{@options['team']}.slack.com/services/hooks/inco... | setup http connection for sending async incoming webhook messages to slack | [
"setup",
"http",
"connection",
"for",
"sending",
"async",
"incoming",
"webhook",
"messages",
"to",
"slack"
] | 198b9e3316630f4ae76f6c3e7da71ffae89ec4ed | https://github.com/rlister/slackbotsy/blob/198b9e3316630f4ae76f6c3e7da71ffae89ec4ed/lib/slackbotsy/bot.rb#L34-L41 |
24,057 | rlister/slackbotsy | lib/slackbotsy/bot.rb | Slackbotsy.Bot.post | def post(options)
payload = {
username: @options['name'],
channel: @options['channel']
}.merge(options)
payload[:channel] = payload[:channel].gsub(/^#?/, '#') #slack api needs leading # on channel
request = Net::HTTP::Post.new(@uri.request_uri)
request.set_form_data(payloa... | ruby | def post(options)
payload = {
username: @options['name'],
channel: @options['channel']
}.merge(options)
payload[:channel] = payload[:channel].gsub(/^#?/, '#') #slack api needs leading # on channel
request = Net::HTTP::Post.new(@uri.request_uri)
request.set_form_data(payloa... | [
"def",
"post",
"(",
"options",
")",
"payload",
"=",
"{",
"username",
":",
"@options",
"[",
"'name'",
"]",
",",
"channel",
":",
"@options",
"[",
"'channel'",
"]",
"}",
".",
"merge",
"(",
"options",
")",
"payload",
"[",
":channel",
"]",
"=",
"payload",
... | raw post of hash to slack webhook | [
"raw",
"post",
"of",
"hash",
"to",
"slack",
"webhook"
] | 198b9e3316630f4ae76f6c3e7da71ffae89ec4ed | https://github.com/rlister/slackbotsy/blob/198b9e3316630f4ae76f6c3e7da71ffae89ec4ed/lib/slackbotsy/bot.rb#L51-L61 |
24,058 | rlister/slackbotsy | lib/slackbotsy/bot.rb | Slackbotsy.Bot.hear | def hear(regex, &block)
@listeners << OpenStruct.new(regex: regex, desc: @last_desc, proc: block)
@last_desc = nil
end | ruby | def hear(regex, &block)
@listeners << OpenStruct.new(regex: regex, desc: @last_desc, proc: block)
@last_desc = nil
end | [
"def",
"hear",
"(",
"regex",
",",
"&",
"block",
")",
"@listeners",
"<<",
"OpenStruct",
".",
"new",
"(",
"regex",
":",
"regex",
",",
"desc",
":",
"@last_desc",
",",
"proc",
":",
"block",
")",
"@last_desc",
"=",
"nil",
"end"
] | add regex to things to hear | [
"add",
"regex",
"to",
"things",
"to",
"hear"
] | 198b9e3316630f4ae76f6c3e7da71ffae89ec4ed | https://github.com/rlister/slackbotsy/blob/198b9e3316630f4ae76f6c3e7da71ffae89ec4ed/lib/slackbotsy/bot.rb#L115-L118 |
24,059 | rlister/slackbotsy | lib/slackbotsy/bot.rb | Slackbotsy.Bot.eval_scripts | def eval_scripts(*files)
files.flatten.each do |file|
self.instance_eval(File.open(file).read)
end
end | ruby | def eval_scripts(*files)
files.flatten.each do |file|
self.instance_eval(File.open(file).read)
end
end | [
"def",
"eval_scripts",
"(",
"*",
"files",
")",
"files",
".",
"flatten",
".",
"each",
"do",
"|",
"file",
"|",
"self",
".",
"instance_eval",
"(",
"File",
".",
"open",
"(",
"file",
")",
".",
"read",
")",
"end",
"end"
] | pass list of files containing hear statements, to be opened and evaled | [
"pass",
"list",
"of",
"files",
"containing",
"hear",
"statements",
"to",
"be",
"opened",
"and",
"evaled"
] | 198b9e3316630f4ae76f6c3e7da71ffae89ec4ed | https://github.com/rlister/slackbotsy/blob/198b9e3316630f4ae76f6c3e7da71ffae89ec4ed/lib/slackbotsy/bot.rb#L121-L125 |
24,060 | rlister/slackbotsy | lib/slackbotsy/bot.rb | Slackbotsy.Bot.handle_outgoing_webhook | def handle_outgoing_webhook(msg)
return nil unless @options['outgoing_token'].include?(msg[:token]) # ensure messages are for us from slack
return nil if msg[:user_name] == 'slackbot' # do not reply to self
return nil unless msg[:text].is_a?(String) # skip empty messages
responses = get_respon... | ruby | def handle_outgoing_webhook(msg)
return nil unless @options['outgoing_token'].include?(msg[:token]) # ensure messages are for us from slack
return nil if msg[:user_name] == 'slackbot' # do not reply to self
return nil unless msg[:text].is_a?(String) # skip empty messages
responses = get_respon... | [
"def",
"handle_outgoing_webhook",
"(",
"msg",
")",
"return",
"nil",
"unless",
"@options",
"[",
"'outgoing_token'",
"]",
".",
"include?",
"(",
"msg",
"[",
":token",
"]",
")",
"# ensure messages are for us from slack",
"return",
"nil",
"if",
"msg",
"[",
":user_name"... | check message and run blocks for any matches | [
"check",
"message",
"and",
"run",
"blocks",
"for",
"any",
"matches"
] | 198b9e3316630f4ae76f6c3e7da71ffae89ec4ed | https://github.com/rlister/slackbotsy/blob/198b9e3316630f4ae76f6c3e7da71ffae89ec4ed/lib/slackbotsy/bot.rb#L128-L138 |
24,061 | rlister/slackbotsy | lib/slackbotsy/bot.rb | Slackbotsy.Bot.get_responses | def get_responses(msg, text)
message = Slackbotsy::Message.new(self, msg)
@listeners.map do |listener|
text.match(listener.regex) do |mdata|
begin
message.instance_exec(mdata, *mdata[1..-1], &listener.proc)
rescue => err # keep running even with a broken script, but re... | ruby | def get_responses(msg, text)
message = Slackbotsy::Message.new(self, msg)
@listeners.map do |listener|
text.match(listener.regex) do |mdata|
begin
message.instance_exec(mdata, *mdata[1..-1], &listener.proc)
rescue => err # keep running even with a broken script, but re... | [
"def",
"get_responses",
"(",
"msg",
",",
"text",
")",
"message",
"=",
"Slackbotsy",
"::",
"Message",
".",
"new",
"(",
"self",
",",
"msg",
")",
"@listeners",
".",
"map",
"do",
"|",
"listener",
"|",
"text",
".",
"match",
"(",
"listener",
".",
"regex",
... | run on msg all hear blocks matching text | [
"run",
"on",
"msg",
"all",
"hear",
"blocks",
"matching",
"text"
] | 198b9e3316630f4ae76f6c3e7da71ffae89ec4ed | https://github.com/rlister/slackbotsy/blob/198b9e3316630f4ae76f6c3e7da71ffae89ec4ed/lib/slackbotsy/bot.rb#L156-L167 |
24,062 | cloudfoundry-attic/cfoundry | lib/cfoundry/v2/client.rb | CFoundry::V2.Client.current_user | def current_user
return unless token
token_data = @base.token.token_data
if guid = token_data[:user_id]
user = user(guid)
user.emails = [{ :value => token_data[:email] }]
user
end
end | ruby | def current_user
return unless token
token_data = @base.token.token_data
if guid = token_data[:user_id]
user = user(guid)
user.emails = [{ :value => token_data[:email] }]
user
end
end | [
"def",
"current_user",
"return",
"unless",
"token",
"token_data",
"=",
"@base",
".",
"token",
".",
"token_data",
"if",
"guid",
"=",
"token_data",
"[",
":user_id",
"]",
"user",
"=",
"user",
"(",
"guid",
")",
"user",
".",
"emails",
"=",
"[",
"{",
":value",... | The currently authenticated user. | [
"The",
"currently",
"authenticated",
"user",
"."
] | 028576968a054e2524be0b6e00b1400a831db9f4 | https://github.com/cloudfoundry-attic/cfoundry/blob/028576968a054e2524be0b6e00b1400a831db9f4/lib/cfoundry/v2/client.rb#L36-L45 |
24,063 | nilsding/twittbot | lib/twittbot/bot.rb | Twittbot.Bot.auth | def auth
require 'oauth'
say "This will reset your current access tokens.", :red if already_authed?
# get the request token URL
callback = OAuth::OUT_OF_BAND
consumer = OAuth::Consumer.new $bot[:config][:consumer_key],
$bot[:config][:consumer_secret],
... | ruby | def auth
require 'oauth'
say "This will reset your current access tokens.", :red if already_authed?
# get the request token URL
callback = OAuth::OUT_OF_BAND
consumer = OAuth::Consumer.new $bot[:config][:consumer_key],
$bot[:config][:consumer_secret],
... | [
"def",
"auth",
"require",
"'oauth'",
"say",
"\"This will reset your current access tokens.\"",
",",
":red",
"if",
"already_authed?",
"# get the request token URL",
"callback",
"=",
"OAuth",
"::",
"OUT_OF_BAND",
"consumer",
"=",
"OAuth",
"::",
"Consumer",
".",
"new",
"$b... | Authenticates an account with Twitter. | [
"Authenticates",
"an",
"account",
"with",
"Twitter",
"."
] | acddc9514453b17461255c1201f6309b3fc42b17 | https://github.com/nilsding/twittbot/blob/acddc9514453b17461255c1201f6309b3fc42b17/lib/twittbot/bot.rb#L42-L69 |
24,064 | nilsding/twittbot | lib/twittbot/bot.rb | Twittbot.Bot.start | def start
check_config
init_clients
if $bot[:stream]
puts "connecting to streaming APIs"
@userstream_thread ||= Thread.new do
loop do
begin
puts "connected to user stream"
@streamer.user do |obj|
handle_stream_object o... | ruby | def start
check_config
init_clients
if $bot[:stream]
puts "connecting to streaming APIs"
@userstream_thread ||= Thread.new do
loop do
begin
puts "connected to user stream"
@streamer.user do |obj|
handle_stream_object o... | [
"def",
"start",
"check_config",
"init_clients",
"if",
"$bot",
"[",
":stream",
"]",
"puts",
"\"connecting to streaming APIs\"",
"@userstream_thread",
"||=",
"Thread",
".",
"new",
"do",
"loop",
"do",
"begin",
"puts",
"\"connected to user stream\"",
"@streamer",
".",
"us... | Starts the bot. | [
"Starts",
"the",
"bot",
"."
] | acddc9514453b17461255c1201f6309b3fc42b17 | https://github.com/nilsding/twittbot/blob/acddc9514453b17461255c1201f6309b3fc42b17/lib/twittbot/bot.rb#L72-L127 |
24,065 | nilsding/twittbot | lib/twittbot/bot.rb | Twittbot.Bot.load_bot_code | def load_bot_code
load_special_tasks
files = Dir["#{File.expand_path('./lib', @options[:current_dir])}/**/*"]
files.each do |file|
require_relative file.sub(/\.rb$/, '') if file.end_with? '.rb'
end
end | ruby | def load_bot_code
load_special_tasks
files = Dir["#{File.expand_path('./lib', @options[:current_dir])}/**/*"]
files.each do |file|
require_relative file.sub(/\.rb$/, '') if file.end_with? '.rb'
end
end | [
"def",
"load_bot_code",
"load_special_tasks",
"files",
"=",
"Dir",
"[",
"\"#{File.expand_path('./lib', @options[:current_dir])}/**/*\"",
"]",
"files",
".",
"each",
"do",
"|",
"file",
"|",
"require_relative",
"file",
".",
"sub",
"(",
"/",
"\\.",
"/",
",",
"''",
")"... | Loads the bot's actual code which is stored in the bot's +lib+
subdirectory. | [
"Loads",
"the",
"bot",
"s",
"actual",
"code",
"which",
"is",
"stored",
"in",
"the",
"bot",
"s",
"+",
"lib",
"+",
"subdirectory",
"."
] | acddc9514453b17461255c1201f6309b3fc42b17 | https://github.com/nilsding/twittbot/blob/acddc9514453b17461255c1201f6309b3fc42b17/lib/twittbot/bot.rb#L162-L168 |
24,066 | nilsding/twittbot | lib/twittbot/bot.rb | Twittbot.Bot.do_callbacks | def do_callbacks(callback_type, object, options = {})
return if $bot[:callbacks][callback_type].nil?
$bot[:callbacks][callback_type].each do |c|
c[:block].call object, options
end
end | ruby | def do_callbacks(callback_type, object, options = {})
return if $bot[:callbacks][callback_type].nil?
$bot[:callbacks][callback_type].each do |c|
c[:block].call object, options
end
end | [
"def",
"do_callbacks",
"(",
"callback_type",
",",
"object",
",",
"options",
"=",
"{",
"}",
")",
"return",
"if",
"$bot",
"[",
":callbacks",
"]",
"[",
"callback_type",
"]",
".",
"nil?",
"$bot",
"[",
":callbacks",
"]",
"[",
"callback_type",
"]",
".",
"each"... | Runs callbacks.
@param callback_type [:Symbol] The callback type.
@param object [Object] The object | [
"Runs",
"callbacks",
"."
] | acddc9514453b17461255c1201f6309b3fc42b17 | https://github.com/nilsding/twittbot/blob/acddc9514453b17461255c1201f6309b3fc42b17/lib/twittbot/bot.rb#L230-L235 |
24,067 | nilsding/twittbot | lib/twittbot/bot.rb | Twittbot.Bot.do_direct_message | def do_direct_message(dm, opts = {})
return if dm.sender.screen_name == $bot[:config][:screen_name]
return do_callbacks(:direct_message, dm, opts) unless dm.text.start_with? $bot[:config][:dm_command_prefix]
dm_text = dm.text.sub($bot[:config][:dm_command_prefix], '').strip
return if dm_text.emp... | ruby | def do_direct_message(dm, opts = {})
return if dm.sender.screen_name == $bot[:config][:screen_name]
return do_callbacks(:direct_message, dm, opts) unless dm.text.start_with? $bot[:config][:dm_command_prefix]
dm_text = dm.text.sub($bot[:config][:dm_command_prefix], '').strip
return if dm_text.emp... | [
"def",
"do_direct_message",
"(",
"dm",
",",
"opts",
"=",
"{",
"}",
")",
"return",
"if",
"dm",
".",
"sender",
".",
"screen_name",
"==",
"$bot",
"[",
":config",
"]",
"[",
":screen_name",
"]",
"return",
"do_callbacks",
"(",
":direct_message",
",",
"dm",
","... | Processes a direct message.
@param dm [Twitter::DirectMessage] received direct message | [
"Processes",
"a",
"direct",
"message",
"."
] | acddc9514453b17461255c1201f6309b3fc42b17 | https://github.com/nilsding/twittbot/blob/acddc9514453b17461255c1201f6309b3fc42b17/lib/twittbot/bot.rb#L251-L267 |
24,068 | nilsding/twittbot | lib/twittbot/bot.rb | Twittbot.Bot.list_tasks | def list_tasks
tasks = $bot[:tasks].map do |name, value|
[name, value[:desc]]
end.to_h
longest_name = tasks.keys.map(&:to_s).max { |a, b| a.length <=> b.length }.length
tasks = tasks.map do |name, desc|
"twittbot cron %-*s # %s" % [longest_name + 2, name, desc]
end.sort
... | ruby | def list_tasks
tasks = $bot[:tasks].map do |name, value|
[name, value[:desc]]
end.to_h
longest_name = tasks.keys.map(&:to_s).max { |a, b| a.length <=> b.length }.length
tasks = tasks.map do |name, desc|
"twittbot cron %-*s # %s" % [longest_name + 2, name, desc]
end.sort
... | [
"def",
"list_tasks",
"tasks",
"=",
"$bot",
"[",
":tasks",
"]",
".",
"map",
"do",
"|",
"name",
",",
"value",
"|",
"[",
"name",
",",
"value",
"[",
":desc",
"]",
"]",
"end",
".",
"to_h",
"longest_name",
"=",
"tasks",
".",
"keys",
".",
"map",
"(",
":... | Lists all tasks | [
"Lists",
"all",
"tasks"
] | acddc9514453b17461255c1201f6309b3fc42b17 | https://github.com/nilsding/twittbot/blob/acddc9514453b17461255c1201f6309b3fc42b17/lib/twittbot/bot.rb#L308-L318 |
24,069 | masa16/phys-units | lib/phys/units/quantity.rb | Phys.Quantity.want | def want(unit=nil)
case unit
when Unit
expr = unit.expr
when Quantity
expr = unit.expr
unit = unit.unit
when String,Symbol
expr = unit
unit = Unit.parse(expr)
when Numeric
unit = Unit.cast(unit)
when NilClass
unit = Unit.cast(1)... | ruby | def want(unit=nil)
case unit
when Unit
expr = unit.expr
when Quantity
expr = unit.expr
unit = unit.unit
when String,Symbol
expr = unit
unit = Unit.parse(expr)
when Numeric
unit = Unit.cast(unit)
when NilClass
unit = Unit.cast(1)... | [
"def",
"want",
"(",
"unit",
"=",
"nil",
")",
"case",
"unit",
"when",
"Unit",
"expr",
"=",
"unit",
".",
"expr",
"when",
"Quantity",
"expr",
"=",
"unit",
".",
"expr",
"unit",
"=",
"unit",
".",
"unit",
"when",
"String",
",",
"Symbol",
"expr",
"=",
"un... | Conversion to a quantity in another unit.
@param [String,Symbol,Unit,Quantity] unit unit expression.
@return [Phys::Quantity] quantity in the unit of +unit+.
@raise [Phys::UnitError] if unit conversion is failed. | [
"Conversion",
"to",
"a",
"quantity",
"in",
"another",
"unit",
"."
] | f781f0a031f5476940c4acc175ff5a9cfd197d84 | https://github.com/masa16/phys-units/blob/f781f0a031f5476940c4acc175ff5a9cfd197d84/lib/phys/units/quantity.rb#L126-L145 |
24,070 | masa16/phys-units | lib/phys/units/quantity.rb | Phys.Quantity.close_to | def close_to(other,epsilon=Float::EPSILON)
other_value = @unit.convert(other)
abs_sum = @value.abs+other_value.abs
(@value-other_value).abs <= abs_sum*epsilon
end | ruby | def close_to(other,epsilon=Float::EPSILON)
other_value = @unit.convert(other)
abs_sum = @value.abs+other_value.abs
(@value-other_value).abs <= abs_sum*epsilon
end | [
"def",
"close_to",
"(",
"other",
",",
"epsilon",
"=",
"Float",
"::",
"EPSILON",
")",
"other_value",
"=",
"@unit",
".",
"convert",
"(",
"other",
")",
"abs_sum",
"=",
"@value",
".",
"abs",
"+",
"other_value",
".",
"abs",
"(",
"@value",
"-",
"other_value",
... | Comparison of quantities.
Before the comparison, it converts +other+ to the unit of +self+.
@param [Phys::Quantity] other
@return [Integer]
@raise [Phys::UnitError] if unit conversion is failed.
Equality. Returns +true+ if +self+ has the same value as +other+.
Before the comparison, it converts +other+ to the u... | [
"Comparison",
"of",
"quantities",
".",
"Before",
"the",
"comparison",
"it",
"converts",
"+",
"other",
"+",
"to",
"the",
"unit",
"of",
"+",
"self",
"+",
"."
] | f781f0a031f5476940c4acc175ff5a9cfd197d84 | https://github.com/masa16/phys-units/blob/f781f0a031f5476940c4acc175ff5a9cfd197d84/lib/phys/units/quantity.rb#L301-L305 |
24,071 | masa16/phys-units | lib/phys/units/quantity.rb | Phys.Quantity.to_base_unit | def to_base_unit
unit = @unit.base_unit
val = unit.convert(self)
expr = unit.unit_string
self.class.new( val, expr, unit )
end | ruby | def to_base_unit
unit = @unit.base_unit
val = unit.convert(self)
expr = unit.unit_string
self.class.new( val, expr, unit )
end | [
"def",
"to_base_unit",
"unit",
"=",
"@unit",
".",
"base_unit",
"val",
"=",
"unit",
".",
"convert",
"(",
"self",
")",
"expr",
"=",
"unit",
".",
"unit_string",
"self",
".",
"class",
".",
"new",
"(",
"val",
",",
"expr",
",",
"unit",
")",
"end"
] | Conversion to base unit.
Returns the quantity converted to a base unit.
@return [Phys::Quantity] a quantity in the base unit.
@raise [Phys::UnitError] if unit conversion is failed. | [
"Conversion",
"to",
"base",
"unit",
".",
"Returns",
"the",
"quantity",
"converted",
"to",
"a",
"base",
"unit",
"."
] | f781f0a031f5476940c4acc175ff5a9cfd197d84 | https://github.com/masa16/phys-units/blob/f781f0a031f5476940c4acc175ff5a9cfd197d84/lib/phys/units/quantity.rb#L492-L497 |
24,072 | masa16/phys-units | lib/phys/units/quantity.rb | Phys.Quantity.inspect | def inspect
expr = @expr || @unit.expr
expr = (expr) ? ","+expr.inspect : ""
sufx = (@@verbose_inspect) ? " "+@unit.inspect : ""
self.class.to_s+"["+Unit::Utils.num_inspect(@value)+expr+"]"+sufx
end | ruby | def inspect
expr = @expr || @unit.expr
expr = (expr) ? ","+expr.inspect : ""
sufx = (@@verbose_inspect) ? " "+@unit.inspect : ""
self.class.to_s+"["+Unit::Utils.num_inspect(@value)+expr+"]"+sufx
end | [
"def",
"inspect",
"expr",
"=",
"@expr",
"||",
"@unit",
".",
"expr",
"expr",
"=",
"(",
"expr",
")",
"?",
"\",\"",
"+",
"expr",
".",
"inspect",
":",
"\"\"",
"sufx",
"=",
"(",
"@@verbose_inspect",
")",
"?",
"\" \"",
"+",
"@unit",
".",
"inspect",
":",
... | Inspect String.
@return [String] | [
"Inspect",
"String",
"."
] | f781f0a031f5476940c4acc175ff5a9cfd197d84 | https://github.com/masa16/phys-units/blob/f781f0a031f5476940c4acc175ff5a9cfd197d84/lib/phys/units/quantity.rb#L547-L552 |
24,073 | levinalex/lis | lib/lis/messages.rb | LIS::Message.Base.to_message | def to_message
@fields ||= {}
arr = Array.new(self.class.default_fields)
type_id + @fields.inject(arr) { |a,(k,v)| a[k-1] = v; a }.join("|")
end | ruby | def to_message
@fields ||= {}
arr = Array.new(self.class.default_fields)
type_id + @fields.inject(arr) { |a,(k,v)| a[k-1] = v; a }.join("|")
end | [
"def",
"to_message",
"@fields",
"||=",
"{",
"}",
"arr",
"=",
"Array",
".",
"new",
"(",
"self",
".",
"class",
".",
"default_fields",
")",
"type_id",
"+",
"@fields",
".",
"inject",
"(",
"arr",
")",
"{",
"|",
"a",
",",
"(",
"k",
",",
"v",
")",
"|",
... | serialize a Message object into a String
message = Message.from_string("5L|1|N") #=> <LIS::Message>
message.to_message #=> "5L|1|N" | [
"serialize",
"a",
"Message",
"object",
"into",
"a",
"String"
] | 405f97d8ea2e8bbd33ac45fcbdc1bc39a0852d3f | https://github.com/levinalex/lis/blob/405f97d8ea2e8bbd33ac45fcbdc1bc39a0852d3f/lib/lis/messages.rb#L121-L125 |
24,074 | longhotsummer/slaw | lib/slaw/generator.rb | Slaw.ActGenerator.guess_section_number_after_title | def guess_section_number_after_title(text)
before = text.scan(/^\w{4,}[^\n]+\n\d+\. /).length
after = text.scan(/^\s*\n\d+\. \w{4,}/).length
before > after * 1.25
end | ruby | def guess_section_number_after_title(text)
before = text.scan(/^\w{4,}[^\n]+\n\d+\. /).length
after = text.scan(/^\s*\n\d+\. \w{4,}/).length
before > after * 1.25
end | [
"def",
"guess_section_number_after_title",
"(",
"text",
")",
"before",
"=",
"text",
".",
"scan",
"(",
"/",
"\\w",
"\\n",
"\\n",
"\\d",
"\\.",
"/",
")",
".",
"length",
"after",
"=",
"text",
".",
"scan",
"(",
"/",
"\\s",
"\\n",
"\\d",
"\\.",
"\\w",
"/"... | Try to determine if section numbers come after titles,
rather than before.
eg:
Section title
1. Section content
versus
1. Section title
Section content | [
"Try",
"to",
"determine",
"if",
"section",
"numbers",
"come",
"after",
"titles",
"rather",
"than",
"before",
"."
] | cab2a7c74f9d820e64324aaf10328ff9a5c91dbb | https://github.com/longhotsummer/slaw/blob/cab2a7c74f9d820e64324aaf10328ff9a5c91dbb/lib/slaw/generator.rb#L75-L80 |
24,075 | longhotsummer/slaw | lib/slaw/generator.rb | Slaw.ActGenerator.text_from_act | def text_from_act(doc)
# look on the load path for an XSL file for this grammar
filename = "/slaw/grammars/#{@grammar}/act_text.xsl"
if dir = $LOAD_PATH.find { |p| File.exist?(p + filename) }
xslt = Nokogiri::XSLT(File.read(dir + filename))
xslt.transform(doc).child.to_xml
else
... | ruby | def text_from_act(doc)
# look on the load path for an XSL file for this grammar
filename = "/slaw/grammars/#{@grammar}/act_text.xsl"
if dir = $LOAD_PATH.find { |p| File.exist?(p + filename) }
xslt = Nokogiri::XSLT(File.read(dir + filename))
xslt.transform(doc).child.to_xml
else
... | [
"def",
"text_from_act",
"(",
"doc",
")",
"# look on the load path for an XSL file for this grammar",
"filename",
"=",
"\"/slaw/grammars/#{@grammar}/act_text.xsl\"",
"if",
"dir",
"=",
"$LOAD_PATH",
".",
"find",
"{",
"|",
"p",
"|",
"File",
".",
"exist?",
"(",
"p",
"+",
... | Transform an Akoma Ntoso XML document back into a plain-text version
suitable for re-parsing back into XML with no loss of structure. | [
"Transform",
"an",
"Akoma",
"Ntoso",
"XML",
"document",
"back",
"into",
"a",
"plain",
"-",
"text",
"version",
"suitable",
"for",
"re",
"-",
"parsing",
"back",
"into",
"XML",
"with",
"no",
"loss",
"of",
"structure",
"."
] | cab2a7c74f9d820e64324aaf10328ff9a5c91dbb | https://github.com/longhotsummer/slaw/blob/cab2a7c74f9d820e64324aaf10328ff9a5c91dbb/lib/slaw/generator.rb#L84-L94 |
24,076 | 3scale/3scale_ws_api_for_ruby | lib/3scale/client.rb | ThreeScale.Client.authorize | def authorize(options)
extensions = options.delete :extensions
creds = creds_params(options)
path = "/transactions/authorize.xml" + options_to_params(options, ALL_PARAMS) + '&' + creds
headers = extensions_to_header extensions if extensions
http_response = @http.get(path, headers: headers... | ruby | def authorize(options)
extensions = options.delete :extensions
creds = creds_params(options)
path = "/transactions/authorize.xml" + options_to_params(options, ALL_PARAMS) + '&' + creds
headers = extensions_to_header extensions if extensions
http_response = @http.get(path, headers: headers... | [
"def",
"authorize",
"(",
"options",
")",
"extensions",
"=",
"options",
".",
"delete",
":extensions",
"creds",
"=",
"creds_params",
"(",
"options",
")",
"path",
"=",
"\"/transactions/authorize.xml\"",
"+",
"options_to_params",
"(",
"options",
",",
"ALL_PARAMS",
")"... | Authorize an application.
== Parameters
Hash with options:
service_token:: token granting access to the specified service_id.
app_id:: id of the application to authorize. This is required.
app_key:: secret key assigned to the application. Required only if application has
a ... | [
"Authorize",
"an",
"application",
"."
] | c4952601a3ad3b6c3e5fda6dffc003bbcaaca3aa | https://github.com/3scale/3scale_ws_api_for_ruby/blob/c4952601a3ad3b6c3e5fda6dffc003bbcaaca3aa/lib/3scale/client.rb#L237-L253 |
24,077 | 3scale/3scale_ws_api_for_ruby | lib/3scale/client.rb | ThreeScale.Client.usage_report | def usage_report(node)
period_start = node.at('period_start')
period_end = node.at('period_end')
{ :metric => node['metric'].to_s.strip,
:period => node['period'].to_s.strip.to_sym,
:period_start => period_start ? period_start.content : '',
:period_end => per... | ruby | def usage_report(node)
period_start = node.at('period_start')
period_end = node.at('period_end')
{ :metric => node['metric'].to_s.strip,
:period => node['period'].to_s.strip.to_sym,
:period_start => period_start ? period_start.content : '',
:period_end => per... | [
"def",
"usage_report",
"(",
"node",
")",
"period_start",
"=",
"node",
".",
"at",
"(",
"'period_start'",
")",
"period_end",
"=",
"node",
".",
"at",
"(",
"'period_end'",
")",
"{",
":metric",
"=>",
"node",
"[",
"'metric'",
"]",
".",
"to_s",
".",
"strip",
... | It can be a user usage report or an app usage report | [
"It",
"can",
"be",
"a",
"user",
"usage",
"report",
"or",
"an",
"app",
"usage",
"report"
] | c4952601a3ad3b6c3e5fda6dffc003bbcaaca3aa | https://github.com/3scale/3scale_ws_api_for_ruby/blob/c4952601a3ad3b6c3e5fda6dffc003bbcaaca3aa/lib/3scale/client.rb#L409-L419 |
24,078 | 3scale/3scale_ws_api_for_ruby | lib/3scale/client.rb | ThreeScale.Client.generate_creds_params | def generate_creds_params
define_singleton_method :creds_params,
if @service_tokens
lambda do |options|
token = options.delete(:service_token)
service_id = options[:service_id]
raise ArgumentError, "need to specify a service_token and a service_id" unless toke... | ruby | def generate_creds_params
define_singleton_method :creds_params,
if @service_tokens
lambda do |options|
token = options.delete(:service_token)
service_id = options[:service_id]
raise ArgumentError, "need to specify a service_token and a service_id" unless toke... | [
"def",
"generate_creds_params",
"define_singleton_method",
":creds_params",
",",
"if",
"@service_tokens",
"lambda",
"do",
"|",
"options",
"|",
"token",
"=",
"options",
".",
"delete",
"(",
":service_token",
")",
"service_id",
"=",
"options",
"[",
":service_id",
"]",
... | helper to generate the creds_params method | [
"helper",
"to",
"generate",
"the",
"creds_params",
"method"
] | c4952601a3ad3b6c3e5fda6dffc003bbcaaca3aa | https://github.com/3scale/3scale_ws_api_for_ruby/blob/c4952601a3ad3b6c3e5fda6dffc003bbcaaca3aa/lib/3scale/client.rb#L436-L453 |
24,079 | nilsding/twittbot | lib/twittbot/gem_ext/twitter/tweet.rb | Twitter.Tweet.reply | def reply(tweet_text, options = {})
return if $bot.nil? or $bot[:client].nil?
opts = {
reply_all: false
}.merge(options)
mentions = self.mentioned_users(opts[:reply_all])
result = "@#{mentions.join(" @")} #{tweet_text}"[(0...140)]
$bot[:client].update result, in_reply_to_s... | ruby | def reply(tweet_text, options = {})
return if $bot.nil? or $bot[:client].nil?
opts = {
reply_all: false
}.merge(options)
mentions = self.mentioned_users(opts[:reply_all])
result = "@#{mentions.join(" @")} #{tweet_text}"[(0...140)]
$bot[:client].update result, in_reply_to_s... | [
"def",
"reply",
"(",
"tweet_text",
",",
"options",
"=",
"{",
"}",
")",
"return",
"if",
"$bot",
".",
"nil?",
"or",
"$bot",
"[",
":client",
"]",
".",
"nil?",
"opts",
"=",
"{",
"reply_all",
":",
"false",
"}",
".",
"merge",
"(",
"options",
")",
"mentio... | Creates a reply to this tweet.
@param tweet_text [:String] tweet text
@param options [Hash] A customizable set of options.
@option options [Boolean] :reply_all (false) Add all users mentioned in the tweet text to the reply. | [
"Creates",
"a",
"reply",
"to",
"this",
"tweet",
"."
] | acddc9514453b17461255c1201f6309b3fc42b17 | https://github.com/nilsding/twittbot/blob/acddc9514453b17461255c1201f6309b3fc42b17/lib/twittbot/gem_ext/twitter/tweet.rb#L7-L20 |
24,080 | nilsding/twittbot | lib/twittbot/gem_ext/twitter/tweet.rb | Twitter.Tweet.mentioned_users | def mentioned_users(reply_all = true, screen_name = $bot[:config][:screen_name])
userlist = [ self.user.screen_name ]
if reply_all
self.text.scan /@([A-Za-z0-9_]{1,16})/ do |user_name|
user_name = user_name[0]
userlist << user_name unless userlist.include?(user_name) or screen_na... | ruby | def mentioned_users(reply_all = true, screen_name = $bot[:config][:screen_name])
userlist = [ self.user.screen_name ]
if reply_all
self.text.scan /@([A-Za-z0-9_]{1,16})/ do |user_name|
user_name = user_name[0]
userlist << user_name unless userlist.include?(user_name) or screen_na... | [
"def",
"mentioned_users",
"(",
"reply_all",
"=",
"true",
",",
"screen_name",
"=",
"$bot",
"[",
":config",
"]",
"[",
":screen_name",
"]",
")",
"userlist",
"=",
"[",
"self",
".",
"user",
".",
"screen_name",
"]",
"if",
"reply_all",
"self",
".",
"text",
".",... | Scans the tweet text for screen names.
@param reply_all [Boolean] Include all users in the reply.
@param screen_name [String] The user's screen name (i.e. that one who clicked "Reply")
@return [Array] An array of user names. | [
"Scans",
"the",
"tweet",
"text",
"for",
"screen",
"names",
"."
] | acddc9514453b17461255c1201f6309b3fc42b17 | https://github.com/nilsding/twittbot/blob/acddc9514453b17461255c1201f6309b3fc42b17/lib/twittbot/gem_ext/twitter/tweet.rb#L47-L56 |
24,081 | nilsding/twittbot | lib/twittbot/gem_ext/twitter/direct_message.rb | Twitter.DirectMessage.reply | def reply(direct_message_text)
return if $bot.nil? or $bot[:client].nil?
$bot[:client].create_direct_message self.sender.id, direct_message_text
rescue Twitter::Error => e
puts "caught Twitter error while replying via DM: #{e.message}"
end | ruby | def reply(direct_message_text)
return if $bot.nil? or $bot[:client].nil?
$bot[:client].create_direct_message self.sender.id, direct_message_text
rescue Twitter::Error => e
puts "caught Twitter error while replying via DM: #{e.message}"
end | [
"def",
"reply",
"(",
"direct_message_text",
")",
"return",
"if",
"$bot",
".",
"nil?",
"or",
"$bot",
"[",
":client",
"]",
".",
"nil?",
"$bot",
"[",
":client",
"]",
".",
"create_direct_message",
"self",
".",
"sender",
".",
"id",
",",
"direct_message_text",
"... | Replies to this direct message.
@param direct_message_text [:String] direct message text | [
"Replies",
"to",
"this",
"direct",
"message",
"."
] | acddc9514453b17461255c1201f6309b3fc42b17 | https://github.com/nilsding/twittbot/blob/acddc9514453b17461255c1201f6309b3fc42b17/lib/twittbot/gem_ext/twitter/direct_message.rb#L5-L11 |
24,082 | gurgeous/sinew | lib/sinew/request.rb | Sinew.Request.perform | def perform
validate!
party_options = options.dup
# merge proxy
if proxy = self.proxy
addr, port = proxy.split(':')
party_options[:http_proxyaddr] = addr
party_options[:http_proxyport] = port || 80
end
# now merge runtime_options
party_options = party... | ruby | def perform
validate!
party_options = options.dup
# merge proxy
if proxy = self.proxy
addr, port = proxy.split(':')
party_options[:http_proxyaddr] = addr
party_options[:http_proxyport] = port || 80
end
# now merge runtime_options
party_options = party... | [
"def",
"perform",
"validate!",
"party_options",
"=",
"options",
".",
"dup",
"# merge proxy",
"if",
"proxy",
"=",
"self",
".",
"proxy",
"addr",
",",
"port",
"=",
"proxy",
".",
"split",
"(",
"':'",
")",
"party_options",
"[",
":http_proxyaddr",
"]",
"=",
"add... | run the request, return the result | [
"run",
"the",
"request",
"return",
"the",
"result"
] | c5a0f027939fedb597c28a8553f63f514584724a | https://github.com/gurgeous/sinew/blob/c5a0f027939fedb597c28a8553f63f514584724a/lib/sinew/request.rb#L36-L58 |
24,083 | gurgeous/sinew | lib/sinew/request.rb | Sinew.Request.parse_url | def parse_url(url)
s = url
# remove entities
s = HTML_ENTITIES.decode(s)
# fix a couple of common encoding bugs
s = s.gsub(' ', '%20')
s = s.gsub("'", '%27')
# append query manually (instead of letting HTTParty handle it) so we can
# include it in cache_key
query... | ruby | def parse_url(url)
s = url
# remove entities
s = HTML_ENTITIES.decode(s)
# fix a couple of common encoding bugs
s = s.gsub(' ', '%20')
s = s.gsub("'", '%27')
# append query manually (instead of letting HTTParty handle it) so we can
# include it in cache_key
query... | [
"def",
"parse_url",
"(",
"url",
")",
"s",
"=",
"url",
"# remove entities",
"s",
"=",
"HTML_ENTITIES",
".",
"decode",
"(",
"s",
")",
"# fix a couple of common encoding bugs",
"s",
"=",
"s",
".",
"gsub",
"(",
"' '",
",",
"'%20'",
")",
"s",
"=",
"s",
".",
... | We accept sloppy urls and attempt to clean them up | [
"We",
"accept",
"sloppy",
"urls",
"and",
"attempt",
"to",
"clean",
"them",
"up"
] | c5a0f027939fedb597c28a8553f63f514584724a | https://github.com/gurgeous/sinew/blob/c5a0f027939fedb597c28a8553f63f514584724a/lib/sinew/request.rb#L61-L81 |
24,084 | nilsding/twittbot | lib/twittbot/botpart.rb | Twittbot.BotPart.cmd | def cmd(name, options = {}, &block)
raise "Command already exists: #{name}" if $bot[:commands].include? name
raise "Command name does not contain only alphanumerical characters" unless name.to_s.match /\A[A-Za-z0-9]+\z/
opts = {
admin: true
}.merge(options)
$bot[:commands][name... | ruby | def cmd(name, options = {}, &block)
raise "Command already exists: #{name}" if $bot[:commands].include? name
raise "Command name does not contain only alphanumerical characters" unless name.to_s.match /\A[A-Za-z0-9]+\z/
opts = {
admin: true
}.merge(options)
$bot[:commands][name... | [
"def",
"cmd",
"(",
"name",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"raise",
"\"Command already exists: #{name}\"",
"if",
"$bot",
"[",
":commands",
"]",
".",
"include?",
"name",
"raise",
"\"Command name does not contain only alphanumerical characters\"",... | Defines a new direct message command.
@param name [Symbol] The name of the command. Can only contain alphanumerical characters.
The recommended maximum length is 4 characters.
@param options [Hash] A customizable set of options.
@option options [Boolean] :admin (true) Require admin status for this command. | [
"Defines",
"a",
"new",
"direct",
"message",
"command",
"."
] | acddc9514453b17461255c1201f6309b3fc42b17 | https://github.com/nilsding/twittbot/blob/acddc9514453b17461255c1201f6309b3fc42b17/lib/twittbot/botpart.rb#L80-L92 |
24,085 | nilsding/twittbot | lib/twittbot/botpart.rb | Twittbot.BotPart.task | def task(name, options = {}, &block)
name = name.to_s.downcase.to_sym
task_re = /\A[a-z0-9.:-_]+\z/
raise "Task already exists: #{name}" if $bot[:tasks].include?(name)
raise "Task name does not match regexp #{task_re.to_s}" unless name.to_s.match(task_re)
opts = {
desc: ''
}... | ruby | def task(name, options = {}, &block)
name = name.to_s.downcase.to_sym
task_re = /\A[a-z0-9.:-_]+\z/
raise "Task already exists: #{name}" if $bot[:tasks].include?(name)
raise "Task name does not match regexp #{task_re.to_s}" unless name.to_s.match(task_re)
opts = {
desc: ''
}... | [
"def",
"task",
"(",
"name",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"name",
"=",
"name",
".",
"to_s",
".",
"downcase",
".",
"to_sym",
"task_re",
"=",
"/",
"\\A",
"\\z",
"/",
"raise",
"\"Task already exists: #{name}\"",
"if",
"$bot",
"[",... | Defines a new task to be run outside of a running Twittbot process.
@param name [Symbol] The name of the task.
@param options [Hash] A customizable set of options.
@option options [String] :desc ("") Description of this task | [
"Defines",
"a",
"new",
"task",
"to",
"be",
"run",
"outside",
"of",
"a",
"running",
"Twittbot",
"process",
"."
] | acddc9514453b17461255c1201f6309b3fc42b17 | https://github.com/nilsding/twittbot/blob/acddc9514453b17461255c1201f6309b3fc42b17/lib/twittbot/botpart.rb#L98-L112 |
24,086 | nilsding/twittbot | lib/twittbot/botpart.rb | Twittbot.BotPart.save_config | def save_config
botpart_config = Hash[@config.to_a - $bot[:config].to_a]
unless botpart_config.empty?
File.open @botpart_config_path, 'w' do |f|
f.write botpart_config.to_yaml
end
end
end | ruby | def save_config
botpart_config = Hash[@config.to_a - $bot[:config].to_a]
unless botpart_config.empty?
File.open @botpart_config_path, 'w' do |f|
f.write botpart_config.to_yaml
end
end
end | [
"def",
"save_config",
"botpart_config",
"=",
"Hash",
"[",
"@config",
".",
"to_a",
"-",
"$bot",
"[",
":config",
"]",
".",
"to_a",
"]",
"unless",
"botpart_config",
".",
"empty?",
"File",
".",
"open",
"@botpart_config_path",
",",
"'w'",
"do",
"|",
"f",
"|",
... | Saves the botpart's configuration. This is automatically called when
Twittbot exits. | [
"Saves",
"the",
"botpart",
"s",
"configuration",
".",
"This",
"is",
"automatically",
"called",
"when",
"Twittbot",
"exits",
"."
] | acddc9514453b17461255c1201f6309b3fc42b17 | https://github.com/nilsding/twittbot/blob/acddc9514453b17461255c1201f6309b3fc42b17/lib/twittbot/botpart.rb#L116-L124 |
24,087 | cloudfoundry-attic/cfoundry | lib/cfoundry/v2/app.rb | CFoundry::V2.App.health | def health
if state == "STARTED"
healthy_count = running_instances
expected = total_instances
if expected > 0
ratio = healthy_count / expected.to_f
if ratio == 1.0
"RUNNING"
else
"#{(ratio * 100).to_i}%"
end
else
... | ruby | def health
if state == "STARTED"
healthy_count = running_instances
expected = total_instances
if expected > 0
ratio = healthy_count / expected.to_f
if ratio == 1.0
"RUNNING"
else
"#{(ratio * 100).to_i}%"
end
else
... | [
"def",
"health",
"if",
"state",
"==",
"\"STARTED\"",
"healthy_count",
"=",
"running_instances",
"expected",
"=",
"total_instances",
"if",
"expected",
">",
"0",
"ratio",
"=",
"healthy_count",
"/",
"expected",
".",
"to_f",
"if",
"ratio",
"==",
"1.0",
"\"RUNNING\""... | Determine application health.
If all instances are running, returns "RUNNING". If only some are
started, returns the percentage of them that are healthy.
Otherwise, returns application's status. | [
"Determine",
"application",
"health",
"."
] | 028576968a054e2524be0b6e00b1400a831db9f4 | https://github.com/cloudfoundry-attic/cfoundry/blob/028576968a054e2524be0b6e00b1400a831db9f4/lib/cfoundry/v2/app.rb#L182-L202 |
24,088 | cloudfoundry-attic/cfoundry | lib/cfoundry/v2/app.rb | CFoundry::V2.App.bind | def bind(*instances)
instances.each do |i|
binding = @client.service_binding
binding.app = self
binding.service_instance = i
binding.create!
end
self
end | ruby | def bind(*instances)
instances.each do |i|
binding = @client.service_binding
binding.app = self
binding.service_instance = i
binding.create!
end
self
end | [
"def",
"bind",
"(",
"*",
"instances",
")",
"instances",
".",
"each",
"do",
"|",
"i",
"|",
"binding",
"=",
"@client",
".",
"service_binding",
"binding",
".",
"app",
"=",
"self",
"binding",
".",
"service_instance",
"=",
"i",
"binding",
".",
"create!",
"end... | Bind services to application. | [
"Bind",
"services",
"to",
"application",
"."
] | 028576968a054e2524be0b6e00b1400a831db9f4 | https://github.com/cloudfoundry-attic/cfoundry/blob/028576968a054e2524be0b6e00b1400a831db9f4/lib/cfoundry/v2/app.rb#L251-L260 |
24,089 | cloudfoundry-attic/cfoundry | lib/cfoundry/v2/app.rb | CFoundry::V2.App.unbind | def unbind(*instances)
service_bindings.each do |b|
if instances.include? b.service_instance
b.delete!
end
end
self
end | ruby | def unbind(*instances)
service_bindings.each do |b|
if instances.include? b.service_instance
b.delete!
end
end
self
end | [
"def",
"unbind",
"(",
"*",
"instances",
")",
"service_bindings",
".",
"each",
"do",
"|",
"b",
"|",
"if",
"instances",
".",
"include?",
"b",
".",
"service_instance",
"b",
".",
"delete!",
"end",
"end",
"self",
"end"
] | Unbind services from application. | [
"Unbind",
"services",
"from",
"application",
"."
] | 028576968a054e2524be0b6e00b1400a831db9f4 | https://github.com/cloudfoundry-attic/cfoundry/blob/028576968a054e2524be0b6e00b1400a831db9f4/lib/cfoundry/v2/app.rb#L263-L271 |
24,090 | joeyates/metar-parser | lib/metar/station.rb | Metar.Station.parser | def parser
raw = Metar::Raw::Noaa.new(@cccc)
Metar::Parser.new(raw)
end | ruby | def parser
raw = Metar::Raw::Noaa.new(@cccc)
Metar::Parser.new(raw)
end | [
"def",
"parser",
"raw",
"=",
"Metar",
"::",
"Raw",
"::",
"Noaa",
".",
"new",
"(",
"@cccc",
")",
"Metar",
"::",
"Parser",
".",
"new",
"(",
"raw",
")",
"end"
] | No check is made on the existence of the station | [
"No",
"check",
"is",
"made",
"on",
"the",
"existence",
"of",
"the",
"station"
] | 8a771e046d62bd15d87b24a86d21891202ecccaf | https://github.com/joeyates/metar-parser/blob/8a771e046d62bd15d87b24a86d21891202ecccaf/lib/metar/station.rb#L64-L67 |
24,091 | openfoodfacts/openfoodfacts-ruby | lib/openfoodfacts/product.rb | Openfoodfacts.Product.weburl | def weburl(locale: nil, domain: DEFAULT_DOMAIN)
locale ||= self.lc || DEFAULT_LOCALE
if self.code && prefix = LOCALE_WEBURL_PREFIXES[locale]
path = "#{prefix}/#{self.code}"
"https://#{locale}.#{domain}/#{path}"
end
end | ruby | def weburl(locale: nil, domain: DEFAULT_DOMAIN)
locale ||= self.lc || DEFAULT_LOCALE
if self.code && prefix = LOCALE_WEBURL_PREFIXES[locale]
path = "#{prefix}/#{self.code}"
"https://#{locale}.#{domain}/#{path}"
end
end | [
"def",
"weburl",
"(",
"locale",
":",
"nil",
",",
"domain",
":",
"DEFAULT_DOMAIN",
")",
"locale",
"||=",
"self",
".",
"lc",
"||",
"DEFAULT_LOCALE",
"if",
"self",
".",
"code",
"&&",
"prefix",
"=",
"LOCALE_WEBURL_PREFIXES",
"[",
"locale",
"]",
"path",
"=",
... | Return Product web URL according to locale | [
"Return",
"Product",
"web",
"URL",
"according",
"to",
"locale"
] | 34bfbcb090ec8fc355b2da76ca73421a68aeb84c | https://github.com/openfoodfacts/openfoodfacts-ruby/blob/34bfbcb090ec8fc355b2da76ca73421a68aeb84c/lib/openfoodfacts/product.rb#L175-L182 |
24,092 | joeyates/metar-parser | lib/metar/parser.rb | Metar.Parser.seek_visibility | def seek_visibility
if observer.value == :auto # WMO 15.4
if @chunks[0] == '////'
@chunks.shift # Simply dispose of it
return
end
end
if @chunks[0] == '1' or @chunks[0] == '2'
@visibility = Metar::Data::Visibility.parse(@chunks[0] + ' ' + @chunks[1])
... | ruby | def seek_visibility
if observer.value == :auto # WMO 15.4
if @chunks[0] == '////'
@chunks.shift # Simply dispose of it
return
end
end
if @chunks[0] == '1' or @chunks[0] == '2'
@visibility = Metar::Data::Visibility.parse(@chunks[0] + ' ' + @chunks[1])
... | [
"def",
"seek_visibility",
"if",
"observer",
".",
"value",
"==",
":auto",
"# WMO 15.4",
"if",
"@chunks",
"[",
"0",
"]",
"==",
"'////'",
"@chunks",
".",
"shift",
"# Simply dispose of it",
"return",
"end",
"end",
"if",
"@chunks",
"[",
"0",
"]",
"==",
"'1'",
"... | 15.10, 15.6.1 | [
"15",
".",
"10",
"15",
".",
"6",
".",
"1"
] | 8a771e046d62bd15d87b24a86d21891202ecccaf | https://github.com/joeyates/metar-parser/blob/8a771e046d62bd15d87b24a86d21891202ecccaf/lib/metar/parser.rb#L223-L244 |
24,093 | masa16/phys-units | lib/phys/units/unit.rb | Phys.Unit.inspect | def inspect
use_dimension
a = [Utils.num_inspect(@factor), @dim.inspect]
a << "@name="+@name.inspect if @name
a << "@expr="+@expr.inspect if @expr
a << "@offset="+@offset.inspect if @offset
a << "@dimensionless=true" if @dimensionless
if @dimension_value && @dimension_value!=1
... | ruby | def inspect
use_dimension
a = [Utils.num_inspect(@factor), @dim.inspect]
a << "@name="+@name.inspect if @name
a << "@expr="+@expr.inspect if @expr
a << "@offset="+@offset.inspect if @offset
a << "@dimensionless=true" if @dimensionless
if @dimension_value && @dimension_value!=1
... | [
"def",
"inspect",
"use_dimension",
"a",
"=",
"[",
"Utils",
".",
"num_inspect",
"(",
"@factor",
")",
",",
"@dim",
".",
"inspect",
"]",
"a",
"<<",
"\"@name=\"",
"+",
"@name",
".",
"inspect",
"if",
"@name",
"a",
"<<",
"\"@expr=\"",
"+",
"@expr",
".",
"ins... | Inspect string.
@return [String]
@example
Phys::Unit["N"].inspect #=> '#<Phys::Unit 1,{"kg"=>1, "m"=>1, "s"=>-2},@expr="newton">' | [
"Inspect",
"string",
"."
] | f781f0a031f5476940c4acc175ff5a9cfd197d84 | https://github.com/masa16/phys-units/blob/f781f0a031f5476940c4acc175ff5a9cfd197d84/lib/phys/units/unit.rb#L173-L185 |
24,094 | masa16/phys-units | lib/phys/units/unit.rb | Phys.Unit.unit_string | def unit_string
use_dimension
a = []
a << Utils.num_inspect(@factor) if @factor!=1
a += @dim.map do |k,d|
if d==1
k
else
"#{k}^#{d}"
end
end
a.join(" ")
end | ruby | def unit_string
use_dimension
a = []
a << Utils.num_inspect(@factor) if @factor!=1
a += @dim.map do |k,d|
if d==1
k
else
"#{k}^#{d}"
end
end
a.join(" ")
end | [
"def",
"unit_string",
"use_dimension",
"a",
"=",
"[",
"]",
"a",
"<<",
"Utils",
".",
"num_inspect",
"(",
"@factor",
")",
"if",
"@factor",
"!=",
"1",
"a",
"+=",
"@dim",
".",
"map",
"do",
"|",
"k",
",",
"d",
"|",
"if",
"d",
"==",
"1",
"k",
"else",
... | Make a string of this unit expressed in base units.
@return [String]
@example
Phys::Unit["psi"].string_form #=> "(8896443230521/129032)*1e-04 kg m^-1 s^-2" | [
"Make",
"a",
"string",
"of",
"this",
"unit",
"expressed",
"in",
"base",
"units",
"."
] | f781f0a031f5476940c4acc175ff5a9cfd197d84 | https://github.com/masa16/phys-units/blob/f781f0a031f5476940c4acc175ff5a9cfd197d84/lib/phys/units/unit.rb#L191-L203 |
24,095 | masa16/phys-units | lib/phys/units/unit.rb | Phys.Unit.conversion_factor | def conversion_factor
use_dimension
f = @factor
@dim.each do |k,d|
if d != 0
u = LIST[k]
if u.dimensionless?
f *= u.dimension_value**d
end
end
end
f
end | ruby | def conversion_factor
use_dimension
f = @factor
@dim.each do |k,d|
if d != 0
u = LIST[k]
if u.dimensionless?
f *= u.dimension_value**d
end
end
end
f
end | [
"def",
"conversion_factor",
"use_dimension",
"f",
"=",
"@factor",
"@dim",
".",
"each",
"do",
"|",
"k",
",",
"d",
"|",
"if",
"d",
"!=",
"0",
"u",
"=",
"LIST",
"[",
"k",
"]",
"if",
"u",
".",
"dimensionless?",
"f",
"*=",
"u",
".",
"dimension_value",
"... | Conversion Factor to base unit, including dimension-value.
@return [Numeric]
@example
Phys::Unit["deg"].dimension #=> {"pi"=>1, "radian"=>1}
Phys::Unit["deg"].factor #=> (1/180)
Phys::Unit["deg"].conversion_factor #=> 0.017453292519943295
@see #factor | [
"Conversion",
"Factor",
"to",
"base",
"unit",
"including",
"dimension",
"-",
"value",
"."
] | f781f0a031f5476940c4acc175ff5a9cfd197d84 | https://github.com/masa16/phys-units/blob/f781f0a031f5476940c4acc175ff5a9cfd197d84/lib/phys/units/unit.rb#L219-L231 |
24,096 | masa16/phys-units | lib/phys/units/unit.rb | Phys.Unit.convert | def convert(quantity)
if Quantity===quantity
assert_same_dimension(quantity.unit)
v = quantity.unit.convert_value_to_base_unit(quantity.value)
convert_value_from_base_unit(v)
else
quantity / to_numeric
end
end | ruby | def convert(quantity)
if Quantity===quantity
assert_same_dimension(quantity.unit)
v = quantity.unit.convert_value_to_base_unit(quantity.value)
convert_value_from_base_unit(v)
else
quantity / to_numeric
end
end | [
"def",
"convert",
"(",
"quantity",
")",
"if",
"Quantity",
"===",
"quantity",
"assert_same_dimension",
"(",
"quantity",
".",
"unit",
")",
"v",
"=",
"quantity",
".",
"unit",
".",
"convert_value_to_base_unit",
"(",
"quantity",
".",
"value",
")",
"convert_value_from... | Convert a quantity to this unit.
@param [Phys::Quantity] quantity to be converted.
@return [Phys::Quantity]
@raise [UnitError] if unit conversion is failed. | [
"Convert",
"a",
"quantity",
"to",
"this",
"unit",
"."
] | f781f0a031f5476940c4acc175ff5a9cfd197d84 | https://github.com/masa16/phys-units/blob/f781f0a031f5476940c4acc175ff5a9cfd197d84/lib/phys/units/unit.rb#L304-L312 |
24,097 | masa16/phys-units | lib/phys/units/unit.rb | Phys.Unit.convert_scale | def convert_scale(quantity)
if Quantity===quantity
assert_same_dimension(quantity.unit)
v = quantity.value * quantity.unit.conversion_factor
v = v / self.conversion_factor
else
quantity / to_numeric
end
end | ruby | def convert_scale(quantity)
if Quantity===quantity
assert_same_dimension(quantity.unit)
v = quantity.value * quantity.unit.conversion_factor
v = v / self.conversion_factor
else
quantity / to_numeric
end
end | [
"def",
"convert_scale",
"(",
"quantity",
")",
"if",
"Quantity",
"===",
"quantity",
"assert_same_dimension",
"(",
"quantity",
".",
"unit",
")",
"v",
"=",
"quantity",
".",
"value",
"*",
"quantity",
".",
"unit",
".",
"conversion_factor",
"v",
"=",
"v",
"/",
"... | Convert a quantity to this unit only in scale.
@param [Phys::Quantity] quantity to be converted.
@return [Phys::Quantity]
@raise [UnitError] if unit conversion is failed. | [
"Convert",
"a",
"quantity",
"to",
"this",
"unit",
"only",
"in",
"scale",
"."
] | f781f0a031f5476940c4acc175ff5a9cfd197d84 | https://github.com/masa16/phys-units/blob/f781f0a031f5476940c4acc175ff5a9cfd197d84/lib/phys/units/unit.rb#L318-L326 |
24,098 | masa16/phys-units | lib/phys/units/unit.rb | Phys.Unit.+ | def +(x)
x = Unit.cast(x)
check_operable2(x)
assert_same_dimension(x)
Unit.new(@factor+x.factor,@dim.dup)
end | ruby | def +(x)
x = Unit.cast(x)
check_operable2(x)
assert_same_dimension(x)
Unit.new(@factor+x.factor,@dim.dup)
end | [
"def",
"+",
"(",
"x",
")",
"x",
"=",
"Unit",
".",
"cast",
"(",
"x",
")",
"check_operable2",
"(",
"x",
")",
"assert_same_dimension",
"(",
"x",
")",
"Unit",
".",
"new",
"(",
"@factor",
"+",
"x",
".",
"factor",
",",
"@dim",
".",
"dup",
")",
"end"
] | Addition of units.
Both units must be operable and conversion-allowed.
@param [Phys::Unit, Numeric] x other unit
@return [Phys::Unit]
@raise [Phys::UnitError] if unit conversion is failed. | [
"Addition",
"of",
"units",
".",
"Both",
"units",
"must",
"be",
"operable",
"and",
"conversion",
"-",
"allowed",
"."
] | f781f0a031f5476940c4acc175ff5a9cfd197d84 | https://github.com/masa16/phys-units/blob/f781f0a031f5476940c4acc175ff5a9cfd197d84/lib/phys/units/unit.rb#L432-L437 |
24,099 | masa16/phys-units | lib/phys/units/unit.rb | Phys.Unit.* | def *(x)
x = Unit.cast(x)
if scalar?
return x
elsif x.scalar?
return self.dup
end
check_operable2(x)
dims = dimension_binop(x){|a,b| a+b}
factor = self.factor * x.factor
Unit.new(factor,dims)
end | ruby | def *(x)
x = Unit.cast(x)
if scalar?
return x
elsif x.scalar?
return self.dup
end
check_operable2(x)
dims = dimension_binop(x){|a,b| a+b}
factor = self.factor * x.factor
Unit.new(factor,dims)
end | [
"def",
"*",
"(",
"x",
")",
"x",
"=",
"Unit",
".",
"cast",
"(",
"x",
")",
"if",
"scalar?",
"return",
"x",
"elsif",
"x",
".",
"scalar?",
"return",
"self",
".",
"dup",
"end",
"check_operable2",
"(",
"x",
")",
"dims",
"=",
"dimension_binop",
"(",
"x",
... | Multiplication of units.
Both units must be operable.
@param [Phys::Unit, Numeric] x other unit
@return [Phys::Unit]
@raise [Phys::UnitError] if not operable. | [
"Multiplication",
"of",
"units",
".",
"Both",
"units",
"must",
"be",
"operable",
"."
] | f781f0a031f5476940c4acc175ff5a9cfd197d84 | https://github.com/masa16/phys-units/blob/f781f0a031f5476940c4acc175ff5a9cfd197d84/lib/phys/units/unit.rb#L473-L484 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.