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
15,600
codeplant/simple-navigation
lib/simple_navigation/item_container.rb
SimpleNavigation.ItemContainer.level_for_item
def level_for_item(navi_key) return level if self[navi_key] items.each do |item| next unless item.sub_navigation level = item.sub_navigation.level_for_item(navi_key) return level if level end return nil end
ruby
def level_for_item(navi_key) return level if self[navi_key] items.each do |item| next unless item.sub_navigation level = item.sub_navigation.level_for_item(navi_key) return level if level end return nil end
[ "def", "level_for_item", "(", "navi_key", ")", "return", "level", "if", "self", "[", "navi_key", "]", "items", ".", "each", "do", "|", "item", "|", "next", "unless", "item", ".", "sub_navigation", "level", "=", "item", ".", "sub_navigation", ".", "level_for_item", "(", "navi_key", ")", "return", "level", "if", "level", "end", "return", "nil", "end" ]
Returns the level of the item specified by navi_key. Recursively works its way down the item's sub_navigations if the desired item is not found directly in this container's items. Returns nil if item cannot be found.
[ "Returns", "the", "level", "of", "the", "item", "specified", "by", "navi_key", ".", "Recursively", "works", "its", "way", "down", "the", "item", "s", "sub_navigations", "if", "the", "desired", "item", "is", "not", "found", "directly", "in", "this", "container", "s", "items", ".", "Returns", "nil", "if", "item", "cannot", "be", "found", "." ]
ed5b99744754b8f3dfca44c885df5aa938730b64
https://github.com/codeplant/simple-navigation/blob/ed5b99744754b8f3dfca44c885df5aa938730b64/lib/simple_navigation/item_container.rb#L89-L98
15,601
ueno/ruby-gpgme
lib/gpgme/key_common.rb
GPGME.KeyCommon.usable_for?
def usable_for?(purposes) unless purposes.kind_of? Array purposes = [purposes] end return false if [:revoked, :expired, :disabled, :invalid].include? trust return (purposes - capability).empty? end
ruby
def usable_for?(purposes) unless purposes.kind_of? Array purposes = [purposes] end return false if [:revoked, :expired, :disabled, :invalid].include? trust return (purposes - capability).empty? end
[ "def", "usable_for?", "(", "purposes", ")", "unless", "purposes", ".", "kind_of?", "Array", "purposes", "=", "[", "purposes", "]", "end", "return", "false", "if", "[", ":revoked", ",", ":expired", ",", ":disabled", ",", ":invalid", "]", ".", "include?", "trust", "return", "(", "purposes", "-", "capability", ")", ".", "empty?", "end" ]
Checks if the key is capable of all of these actions. If empty array is passed then will return true. Returns false if the keys trust has been invalidated.
[ "Checks", "if", "the", "key", "is", "capable", "of", "all", "of", "these", "actions", ".", "If", "empty", "array", "is", "passed", "then", "will", "return", "true", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/key_common.rb#L31-L37
15,602
ueno/ruby-gpgme
lib/gpgme/data.rb
GPGME.Data.read
def read(length = nil) if length GPGME::gpgme_data_read(self, length) else buf = String.new loop do s = GPGME::gpgme_data_read(self, BLOCK_SIZE) break unless s buf << s end buf end end
ruby
def read(length = nil) if length GPGME::gpgme_data_read(self, length) else buf = String.new loop do s = GPGME::gpgme_data_read(self, BLOCK_SIZE) break unless s buf << s end buf end end
[ "def", "read", "(", "length", "=", "nil", ")", "if", "length", "GPGME", "::", "gpgme_data_read", "(", "self", ",", "length", ")", "else", "buf", "=", "String", ".", "new", "loop", "do", "s", "=", "GPGME", "::", "gpgme_data_read", "(", "self", ",", "BLOCK_SIZE", ")", "break", "unless", "s", "buf", "<<", "s", "end", "buf", "end", "end" ]
class << self Read at most +length+ bytes from the data object, or to the end of file if +length+ is omitted or is +nil+. @example data = GPGME::Data.new("From a string") data.read # => "From a string" @example data = GPGME::Data.new("From a string") data.read(4) # => "From"
[ "class", "<<", "self", "Read", "at", "most", "+", "length", "+", "bytes", "from", "the", "data", "object", "or", "to", "the", "end", "of", "file", "if", "+", "length", "+", "is", "omitted", "or", "is", "+", "nil", "+", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/data.rb#L112-L124
15,603
ueno/ruby-gpgme
lib/gpgme/data.rb
GPGME.Data.seek
def seek(offset, whence = IO::SEEK_SET) GPGME::gpgme_data_seek(self, offset, IO::SEEK_SET) end
ruby
def seek(offset, whence = IO::SEEK_SET) GPGME::gpgme_data_seek(self, offset, IO::SEEK_SET) end
[ "def", "seek", "(", "offset", ",", "whence", "=", "IO", "::", "SEEK_SET", ")", "GPGME", "::", "gpgme_data_seek", "(", "self", ",", "offset", ",", "IO", "::", "SEEK_SET", ")", "end" ]
Seek to a given +offset+ in the data object according to the value of +whence+. @example going to the beginning of the buffer after writing something data = GPGME::Data.new("Some data") data.read # => "Some data" data.read # => "" data.seek 0 data.read # => "Some data"
[ "Seek", "to", "a", "given", "+", "offset", "+", "in", "the", "data", "object", "according", "to", "the", "value", "of", "+", "whence", "+", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/data.rb#L137-L139
15,604
ueno/ruby-gpgme
lib/gpgme/data.rb
GPGME.Data.file_name=
def file_name=(file_name) err = GPGME::gpgme_data_set_file_name(self, file_name) exc = GPGME::error_to_exception(err) raise exc if exc file_name end
ruby
def file_name=(file_name) err = GPGME::gpgme_data_set_file_name(self, file_name) exc = GPGME::error_to_exception(err) raise exc if exc file_name end
[ "def", "file_name", "=", "(", "file_name", ")", "err", "=", "GPGME", "::", "gpgme_data_set_file_name", "(", "self", ",", "file_name", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "file_name", "end" ]
Sets the file name for this buffer. @raise [GPGME::Error::InvalidValue] if the value isn't accepted.
[ "Sets", "the", "file", "name", "for", "this", "buffer", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/data.rb#L197-L202
15,605
ueno/ruby-gpgme
lib/gpgme/key.rb
GPGME.Key.delete!
def delete!(allow_secret = false) GPGME::Ctx.new do |ctx| ctx.delete_key self, allow_secret end end
ruby
def delete!(allow_secret = false) GPGME::Ctx.new do |ctx| ctx.delete_key self, allow_secret end end
[ "def", "delete!", "(", "allow_secret", "=", "false", ")", "GPGME", "::", "Ctx", ".", "new", "do", "|", "ctx", "|", "ctx", ".", "delete_key", "self", ",", "allow_secret", "end", "end" ]
Delete this key. If it's public, and has a secret one it will fail unless +allow_secret+ is specified as true.
[ "Delete", "this", "key", ".", "If", "it", "s", "public", "and", "has", "a", "secret", "one", "it", "will", "fail", "unless", "+", "allow_secret", "+", "is", "specified", "as", "true", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/key.rb#L148-L152
15,606
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.protocol=
def protocol=(proto) err = GPGME::gpgme_set_protocol(self, proto) exc = GPGME::error_to_exception(err) raise exc if exc proto end
ruby
def protocol=(proto) err = GPGME::gpgme_set_protocol(self, proto) exc = GPGME::error_to_exception(err) raise exc if exc proto end
[ "def", "protocol", "=", "(", "proto", ")", "err", "=", "GPGME", "::", "gpgme_set_protocol", "(", "self", ",", "proto", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "proto", "end" ]
Getters and setters Set the +protocol+ used within this context. See {GPGME::Ctx.new} for possible values.
[ "Getters", "and", "setters" ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L108-L113
15,607
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.keylist_next
def keylist_next rkey = [] err = GPGME::gpgme_op_keylist_next(self, rkey) exc = GPGME::error_to_exception(err) raise exc if exc rkey[0] end
ruby
def keylist_next rkey = [] err = GPGME::gpgme_op_keylist_next(self, rkey) exc = GPGME::error_to_exception(err) raise exc if exc rkey[0] end
[ "def", "keylist_next", "rkey", "=", "[", "]", "err", "=", "GPGME", "::", "gpgme_op_keylist_next", "(", "self", ",", "rkey", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "rkey", "[", "0", "]", "end" ]
Advance to the next key in the key listing operation. Used by {GPGME::Ctx#each_key}
[ "Advance", "to", "the", "next", "key", "in", "the", "key", "listing", "operation", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L281-L287
15,608
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.keylist_end
def keylist_end err = GPGME::gpgme_op_keylist_end(self) exc = GPGME::error_to_exception(err) raise exc if exc end
ruby
def keylist_end err = GPGME::gpgme_op_keylist_end(self) exc = GPGME::error_to_exception(err) raise exc if exc end
[ "def", "keylist_end", "err", "=", "GPGME", "::", "gpgme_op_keylist_end", "(", "self", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "end" ]
End a pending key list operation. Used by {GPGME::Ctx#each_key}
[ "End", "a", "pending", "key", "list", "operation", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L292-L296
15,609
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.each_key
def each_key(pattern = nil, secret_only = false, &block) keylist_start(pattern, secret_only) begin loop { yield keylist_next } rescue EOFError # The last key in the list has already been returned. ensure keylist_end end end
ruby
def each_key(pattern = nil, secret_only = false, &block) keylist_start(pattern, secret_only) begin loop { yield keylist_next } rescue EOFError # The last key in the list has already been returned. ensure keylist_end end end
[ "def", "each_key", "(", "pattern", "=", "nil", ",", "secret_only", "=", "false", ",", "&", "block", ")", "keylist_start", "(", "pattern", ",", "secret_only", ")", "begin", "loop", "{", "yield", "keylist_next", "}", "rescue", "EOFError", "# The last key in the list has already been returned.", "ensure", "keylist_end", "end", "end" ]
Convenient method to iterate over keys. If +pattern+ is +nil+, all available keys are returned. If +secret_only+ is +true+, only secret keys are returned. See {GPGME::Key.find} for an example of how to use, or for an easier way to use.
[ "Convenient", "method", "to", "iterate", "over", "keys", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L305-L314
15,610
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.keys
def keys(pattern = nil, secret_only = nil) keys = [] each_key(pattern, secret_only) do |key| keys << key end keys end
ruby
def keys(pattern = nil, secret_only = nil) keys = [] each_key(pattern, secret_only) do |key| keys << key end keys end
[ "def", "keys", "(", "pattern", "=", "nil", ",", "secret_only", "=", "nil", ")", "keys", "=", "[", "]", "each_key", "(", "pattern", ",", "secret_only", ")", "do", "|", "key", "|", "keys", "<<", "key", "end", "keys", "end" ]
Returns the keys that match the +pattern+, or all if +pattern+ is nil. Returns only secret keys if +secret_only+ is true.
[ "Returns", "the", "keys", "that", "match", "the", "+", "pattern", "+", "or", "all", "if", "+", "pattern", "+", "is", "nil", ".", "Returns", "only", "secret", "keys", "if", "+", "secret_only", "+", "is", "true", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L319-L325
15,611
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.get_key
def get_key(fingerprint, secret = false) rkey = [] err = GPGME::gpgme_get_key(self, fingerprint, rkey, secret ? 1 : 0) exc = GPGME::error_to_exception(err) raise exc if exc rkey[0] end
ruby
def get_key(fingerprint, secret = false) rkey = [] err = GPGME::gpgme_get_key(self, fingerprint, rkey, secret ? 1 : 0) exc = GPGME::error_to_exception(err) raise exc if exc rkey[0] end
[ "def", "get_key", "(", "fingerprint", ",", "secret", "=", "false", ")", "rkey", "=", "[", "]", "err", "=", "GPGME", "::", "gpgme_get_key", "(", "self", ",", "fingerprint", ",", "rkey", ",", "secret", "?", "1", ":", "0", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "rkey", "[", "0", "]", "end" ]
Get the key with the +fingerprint+. If +secret+ is +true+, secret key is returned.
[ "Get", "the", "key", "with", "the", "+", "fingerprint", "+", ".", "If", "+", "secret", "+", "is", "+", "true", "+", "secret", "key", "is", "returned", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L329-L335
15,612
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.import_keys
def import_keys(keydata) err = GPGME::gpgme_op_import(self, keydata) exc = GPGME::error_to_exception(err) raise exc if exc end
ruby
def import_keys(keydata) err = GPGME::gpgme_op_import(self, keydata) exc = GPGME::error_to_exception(err) raise exc if exc end
[ "def", "import_keys", "(", "keydata", ")", "err", "=", "GPGME", "::", "gpgme_op_import", "(", "self", ",", "keydata", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "end" ]
Add the keys in the data buffer to the key ring.
[ "Add", "the", "keys", "in", "the", "data", "buffer", "to", "the", "key", "ring", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L382-L386
15,613
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.delete_key
def delete_key(key, allow_secret = false) err = GPGME::gpgme_op_delete(self, key, allow_secret ? 1 : 0) exc = GPGME::error_to_exception(err) raise exc if exc end
ruby
def delete_key(key, allow_secret = false) err = GPGME::gpgme_op_delete(self, key, allow_secret ? 1 : 0) exc = GPGME::error_to_exception(err) raise exc if exc end
[ "def", "delete_key", "(", "key", ",", "allow_secret", "=", "false", ")", "err", "=", "GPGME", "::", "gpgme_op_delete", "(", "self", ",", "key", ",", "allow_secret", "?", "1", ":", "0", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "end" ]
Delete the key from the key ring. If allow_secret is false, only public keys are deleted, otherwise secret keys are deleted as well.
[ "Delete", "the", "key", "from", "the", "key", "ring", ".", "If", "allow_secret", "is", "false", "only", "public", "keys", "are", "deleted", "otherwise", "secret", "keys", "are", "deleted", "as", "well", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L396-L400
15,614
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.edit_key
def edit_key(key, editfunc, hook_value = nil, out = Data.new) err = GPGME::gpgme_op_edit(self, key, editfunc, hook_value, out) exc = GPGME::error_to_exception(err) raise exc if exc end
ruby
def edit_key(key, editfunc, hook_value = nil, out = Data.new) err = GPGME::gpgme_op_edit(self, key, editfunc, hook_value, out) exc = GPGME::error_to_exception(err) raise exc if exc end
[ "def", "edit_key", "(", "key", ",", "editfunc", ",", "hook_value", "=", "nil", ",", "out", "=", "Data", ".", "new", ")", "err", "=", "GPGME", "::", "gpgme_op_edit", "(", "self", ",", "key", ",", "editfunc", ",", "hook_value", ",", "out", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "end" ]
Edit attributes of the key in the local key ring.
[ "Edit", "attributes", "of", "the", "key", "in", "the", "local", "key", "ring", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L404-L408
15,615
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.edit_card_key
def edit_card_key(key, editfunc, hook_value = nil, out = Data.new) err = GPGME::gpgme_op_card_edit(self, key, editfunc, hook_value, out) exc = GPGME::error_to_exception(err) raise exc if exc end
ruby
def edit_card_key(key, editfunc, hook_value = nil, out = Data.new) err = GPGME::gpgme_op_card_edit(self, key, editfunc, hook_value, out) exc = GPGME::error_to_exception(err) raise exc if exc end
[ "def", "edit_card_key", "(", "key", ",", "editfunc", ",", "hook_value", "=", "nil", ",", "out", "=", "Data", ".", "new", ")", "err", "=", "GPGME", "::", "gpgme_op_card_edit", "(", "self", ",", "key", ",", "editfunc", ",", "hook_value", ",", "out", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "end" ]
Edit attributes of the key on the card.
[ "Edit", "attributes", "of", "the", "key", "on", "the", "card", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L412-L416
15,616
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.verify
def verify(sig, signed_text = nil, plain = Data.new) err = GPGME::gpgme_op_verify(self, sig, signed_text, plain) exc = GPGME::error_to_exception(err) raise exc if exc plain end
ruby
def verify(sig, signed_text = nil, plain = Data.new) err = GPGME::gpgme_op_verify(self, sig, signed_text, plain) exc = GPGME::error_to_exception(err) raise exc if exc plain end
[ "def", "verify", "(", "sig", ",", "signed_text", "=", "nil", ",", "plain", "=", "Data", ".", "new", ")", "err", "=", "GPGME", "::", "gpgme_op_verify", "(", "self", ",", "sig", ",", "signed_text", ",", "plain", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "plain", "end" ]
Verify that the signature in the data object is a valid signature.
[ "Verify", "that", "the", "signature", "in", "the", "data", "object", "is", "a", "valid", "signature", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L444-L449
15,617
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.add_signer
def add_signer(*keys) keys.each do |key| err = GPGME::gpgme_signers_add(self, key) exc = GPGME::error_to_exception(err) raise exc if exc end end
ruby
def add_signer(*keys) keys.each do |key| err = GPGME::gpgme_signers_add(self, key) exc = GPGME::error_to_exception(err) raise exc if exc end end
[ "def", "add_signer", "(", "*", "keys", ")", "keys", ".", "each", "do", "|", "key", "|", "err", "=", "GPGME", "::", "gpgme_signers_add", "(", "self", ",", "key", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "end", "end" ]
Add _keys_ to the list of signers.
[ "Add", "_keys_", "to", "the", "list", "of", "signers", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L461-L467
15,618
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.sign
def sign(plain, sig = Data.new, mode = GPGME::SIG_MODE_NORMAL) err = GPGME::gpgme_op_sign(self, plain, sig, mode) exc = GPGME::error_to_exception(err) raise exc if exc sig end
ruby
def sign(plain, sig = Data.new, mode = GPGME::SIG_MODE_NORMAL) err = GPGME::gpgme_op_sign(self, plain, sig, mode) exc = GPGME::error_to_exception(err) raise exc if exc sig end
[ "def", "sign", "(", "plain", ",", "sig", "=", "Data", ".", "new", ",", "mode", "=", "GPGME", "::", "SIG_MODE_NORMAL", ")", "err", "=", "GPGME", "::", "gpgme_op_sign", "(", "self", ",", "plain", ",", "sig", ",", "mode", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "sig", "end" ]
Create a signature for the text. +plain+ is a data object which contains the text. +sig+ is a data object where the generated signature is stored.
[ "Create", "a", "signature", "for", "the", "text", ".", "+", "plain", "+", "is", "a", "data", "object", "which", "contains", "the", "text", ".", "+", "sig", "+", "is", "a", "data", "object", "where", "the", "generated", "signature", "is", "stored", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L472-L477
15,619
ueno/ruby-gpgme
lib/gpgme/ctx.rb
GPGME.Ctx.encrypt
def encrypt(recp, plain, cipher = Data.new, flags = 0) err = GPGME::gpgme_op_encrypt(self, recp, flags, plain, cipher) exc = GPGME::error_to_exception(err) raise exc if exc cipher end
ruby
def encrypt(recp, plain, cipher = Data.new, flags = 0) err = GPGME::gpgme_op_encrypt(self, recp, flags, plain, cipher) exc = GPGME::error_to_exception(err) raise exc if exc cipher end
[ "def", "encrypt", "(", "recp", ",", "plain", ",", "cipher", "=", "Data", ".", "new", ",", "flags", "=", "0", ")", "err", "=", "GPGME", "::", "gpgme_op_encrypt", "(", "self", ",", "recp", ",", "flags", ",", "plain", ",", "cipher", ")", "exc", "=", "GPGME", "::", "error_to_exception", "(", "err", ")", "raise", "exc", "if", "exc", "cipher", "end" ]
Encrypt the plaintext in the data object for the recipients and return the ciphertext.
[ "Encrypt", "the", "plaintext", "in", "the", "data", "object", "for", "the", "recipients", "and", "return", "the", "ciphertext", "." ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/ctx.rb#L485-L490
15,620
ueno/ruby-gpgme
lib/gpgme/crypto.rb
GPGME.Crypto.encrypt
def encrypt(plain, options = {}) options = @default_options.merge options plain_data = Data.new(plain) cipher_data = Data.new(options[:output]) keys = Key.find(:public, options[:recipients]) keys = nil if options[:symmetric] flags = 0 flags |= GPGME::ENCRYPT_ALWAYS_TRUST if options[:always_trust] GPGME::Ctx.new(options) do |ctx| begin if options[:sign] if options[:signers] signers = Key.find(:public, options[:signers], :sign) ctx.add_signer(*signers) end ctx.encrypt_sign(keys, plain_data, cipher_data, flags) else ctx.encrypt(keys, plain_data, cipher_data, flags) end rescue GPGME::Error::UnusablePublicKey => exc exc.keys = ctx.encrypt_result.invalid_recipients raise exc rescue GPGME::Error::UnusableSecretKey => exc exc.keys = ctx.sign_result.invalid_signers raise exc end end cipher_data.seek(0) cipher_data end
ruby
def encrypt(plain, options = {}) options = @default_options.merge options plain_data = Data.new(plain) cipher_data = Data.new(options[:output]) keys = Key.find(:public, options[:recipients]) keys = nil if options[:symmetric] flags = 0 flags |= GPGME::ENCRYPT_ALWAYS_TRUST if options[:always_trust] GPGME::Ctx.new(options) do |ctx| begin if options[:sign] if options[:signers] signers = Key.find(:public, options[:signers], :sign) ctx.add_signer(*signers) end ctx.encrypt_sign(keys, plain_data, cipher_data, flags) else ctx.encrypt(keys, plain_data, cipher_data, flags) end rescue GPGME::Error::UnusablePublicKey => exc exc.keys = ctx.encrypt_result.invalid_recipients raise exc rescue GPGME::Error::UnusableSecretKey => exc exc.keys = ctx.sign_result.invalid_signers raise exc end end cipher_data.seek(0) cipher_data end
[ "def", "encrypt", "(", "plain", ",", "options", "=", "{", "}", ")", "options", "=", "@default_options", ".", "merge", "options", "plain_data", "=", "Data", ".", "new", "(", "plain", ")", "cipher_data", "=", "Data", ".", "new", "(", "options", "[", ":output", "]", ")", "keys", "=", "Key", ".", "find", "(", ":public", ",", "options", "[", ":recipients", "]", ")", "keys", "=", "nil", "if", "options", "[", ":symmetric", "]", "flags", "=", "0", "flags", "|=", "GPGME", "::", "ENCRYPT_ALWAYS_TRUST", "if", "options", "[", ":always_trust", "]", "GPGME", "::", "Ctx", ".", "new", "(", "options", ")", "do", "|", "ctx", "|", "begin", "if", "options", "[", ":sign", "]", "if", "options", "[", ":signers", "]", "signers", "=", "Key", ".", "find", "(", ":public", ",", "options", "[", ":signers", "]", ",", ":sign", ")", "ctx", ".", "add_signer", "(", "signers", ")", "end", "ctx", ".", "encrypt_sign", "(", "keys", ",", "plain_data", ",", "cipher_data", ",", "flags", ")", "else", "ctx", ".", "encrypt", "(", "keys", ",", "plain_data", ",", "cipher_data", ",", "flags", ")", "end", "rescue", "GPGME", "::", "Error", "::", "UnusablePublicKey", "=>", "exc", "exc", ".", "keys", "=", "ctx", ".", "encrypt_result", ".", "invalid_recipients", "raise", "exc", "rescue", "GPGME", "::", "Error", "::", "UnusableSecretKey", "=>", "exc", "exc", ".", "keys", "=", "ctx", ".", "sign_result", ".", "invalid_signers", "raise", "exc", "end", "end", "cipher_data", ".", "seek", "(", "0", ")", "cipher_data", "end" ]
Encrypts an element crypto.encrypt something, options Will return a {GPGME::Data} element which can then be read. Must have some key imported, look for {GPGME::Key.import} to know how to import one, or the gpg documentation to know how to create one @param plain Must be something that can be converted into a {GPGME::Data} object, or a {GPGME::Data} object itself. @param [Hash] options The optional parameters are as follows: * +:recipients+ for which recipient do you want to encrypt this file. It will pick the first one available if none specified. Can be an array of identifiers or just one (a string). * +:symmetric+ if set to true, will ignore +:recipients+, and will perform a symmetric encryption. Must provide a password via the +:password+ option. * +:always_trust+ if set to true specifies all the recipients to be trusted, thus not requiring confirmation. * +:sign+ if set to true, performs a combined sign and encrypt operation. * +:signers+ if +:sign+ specified to true, a list of additional possible signers. Must be an array of sign identifiers. * +:output+ if specified, it will write the output into it. It will be converted to a {GPGME::Data} object, so it could be a file for example. * Any other option accepted by {GPGME::Ctx.new} @return [GPGME::Data] a {GPGME::Data} object that can be read. @example returns a {GPGME::Data} that can be later encrypted encrypted = crypto.encrypt "Hello world!" encrypted.read # => Encrypted stuff @example to be decrypted by someone@example.com. crypto.encrypt "Hello", :recipients => "someone@example.com" @example If I didn't trust any of my keys by default crypto.encrypt "Hello" # => GPGME::Error::General crypto.encrypt "Hello", :always_trust => true # => Will work fine @example encrypted string that can be decrypted and/or *verified* crypto.encrypt "Hello", :sign => true @example multiple signers crypto.encrypt "Hello", :sign => true, :signers => "extra@example.com" @example writing to a file instead file = File.open("signed.sec","w+") crypto.encrypt "Hello", :output => file # output written to signed.sec @raise [GPGME::Error::General] when trying to encrypt with a key that is not trusted, and +:always_trust+ wasn't specified
[ "Encrypts", "an", "element" ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/crypto.rb#L79-L112
15,621
ueno/ruby-gpgme
lib/gpgme/crypto.rb
GPGME.Crypto.decrypt
def decrypt(cipher, options = {}) options = @default_options.merge options plain_data = Data.new(options[:output]) cipher_data = Data.new(cipher) GPGME::Ctx.new(options) do |ctx| begin ctx.decrypt_verify(cipher_data, plain_data) rescue GPGME::Error::UnsupportedAlgorithm => exc exc.algorithm = ctx.decrypt_result.unsupported_algorithm raise exc rescue GPGME::Error::WrongKeyUsage => exc exc.key_usage = ctx.decrypt_result.wrong_key_usage raise exc end verify_result = ctx.verify_result if verify_result && block_given? verify_result.signatures.each do |signature| yield signature end end end plain_data.seek(0) plain_data end
ruby
def decrypt(cipher, options = {}) options = @default_options.merge options plain_data = Data.new(options[:output]) cipher_data = Data.new(cipher) GPGME::Ctx.new(options) do |ctx| begin ctx.decrypt_verify(cipher_data, plain_data) rescue GPGME::Error::UnsupportedAlgorithm => exc exc.algorithm = ctx.decrypt_result.unsupported_algorithm raise exc rescue GPGME::Error::WrongKeyUsage => exc exc.key_usage = ctx.decrypt_result.wrong_key_usage raise exc end verify_result = ctx.verify_result if verify_result && block_given? verify_result.signatures.each do |signature| yield signature end end end plain_data.seek(0) plain_data end
[ "def", "decrypt", "(", "cipher", ",", "options", "=", "{", "}", ")", "options", "=", "@default_options", ".", "merge", "options", "plain_data", "=", "Data", ".", "new", "(", "options", "[", ":output", "]", ")", "cipher_data", "=", "Data", ".", "new", "(", "cipher", ")", "GPGME", "::", "Ctx", ".", "new", "(", "options", ")", "do", "|", "ctx", "|", "begin", "ctx", ".", "decrypt_verify", "(", "cipher_data", ",", "plain_data", ")", "rescue", "GPGME", "::", "Error", "::", "UnsupportedAlgorithm", "=>", "exc", "exc", ".", "algorithm", "=", "ctx", ".", "decrypt_result", ".", "unsupported_algorithm", "raise", "exc", "rescue", "GPGME", "::", "Error", "::", "WrongKeyUsage", "=>", "exc", "exc", ".", "key_usage", "=", "ctx", ".", "decrypt_result", ".", "wrong_key_usage", "raise", "exc", "end", "verify_result", "=", "ctx", ".", "verify_result", "if", "verify_result", "&&", "block_given?", "verify_result", ".", "signatures", ".", "each", "do", "|", "signature", "|", "yield", "signature", "end", "end", "end", "plain_data", ".", "seek", "(", "0", ")", "plain_data", "end" ]
Decrypts a previously encrypted element crypto.decrypt cipher, options, &block Must have the appropiate key to be able to decrypt, of course. Returns a {GPGME::Data} object which can then be read. @param cipher Must be something that can be converted into a {GPGME::Data} object, or a {GPGME::Data} object itself. It is the element that will be decrypted. @param [Hash] options The optional parameters: * +:output+ if specified, it will write the output into it. It will me converted to a {GPGME::Data} object, so it can also be a file, for example. * If the file was encrypted with symmentric encryption, must provide a :password option. * Any other option accepted by {GPGME::Ctx.new} @param &block In the block all the signatures are yielded, so one could verify them. See examples. @return [GPGME::Data] a {GPGME::Data} that can be read. @example Simple decrypt crypto.decrypt encrypted_data @example symmetric encryption, or passwored key crypto.decrypt encrypted_data, :password => "gpgme" @example Output to file file = File.open("decrypted.txt", "w+") crypto.decrypt encrypted_data, :output => file @example Verifying signatures crypto.decrypt encrypted_data do |signature| raise "Signature could not be verified" unless signature.valid? end @raise [GPGME::Error::UnsupportedAlgorithm] when the cipher was encrypted using an algorithm that's not supported currently. @raise [GPGME::Error::WrongKeyUsage] TODO Don't know when @raise [GPGME::Error::DecryptFailed] when the cipher was encrypted for a key that's not available currently.
[ "Decrypts", "a", "previously", "encrypted", "element" ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/crypto.rb#L164-L192
15,622
ueno/ruby-gpgme
lib/gpgme/crypto.rb
GPGME.Crypto.sign
def sign(text, options = {}) options = @default_options.merge options plain = Data.new(text) output = Data.new(options[:output]) mode = options[:mode] || GPGME::SIG_MODE_NORMAL GPGME::Ctx.new(options) do |ctx| if options[:signer] signers = Key.find(:secret, options[:signer], :sign) ctx.add_signer(*signers) end begin ctx.sign(plain, output, mode) rescue GPGME::Error::UnusableSecretKey => exc exc.keys = ctx.sign_result.invalid_signers raise exc end end output.seek(0) output end
ruby
def sign(text, options = {}) options = @default_options.merge options plain = Data.new(text) output = Data.new(options[:output]) mode = options[:mode] || GPGME::SIG_MODE_NORMAL GPGME::Ctx.new(options) do |ctx| if options[:signer] signers = Key.find(:secret, options[:signer], :sign) ctx.add_signer(*signers) end begin ctx.sign(plain, output, mode) rescue GPGME::Error::UnusableSecretKey => exc exc.keys = ctx.sign_result.invalid_signers raise exc end end output.seek(0) output end
[ "def", "sign", "(", "text", ",", "options", "=", "{", "}", ")", "options", "=", "@default_options", ".", "merge", "options", "plain", "=", "Data", ".", "new", "(", "text", ")", "output", "=", "Data", ".", "new", "(", "options", "[", ":output", "]", ")", "mode", "=", "options", "[", ":mode", "]", "||", "GPGME", "::", "SIG_MODE_NORMAL", "GPGME", "::", "Ctx", ".", "new", "(", "options", ")", "do", "|", "ctx", "|", "if", "options", "[", ":signer", "]", "signers", "=", "Key", ".", "find", "(", ":secret", ",", "options", "[", ":signer", "]", ",", ":sign", ")", "ctx", ".", "add_signer", "(", "signers", ")", "end", "begin", "ctx", ".", "sign", "(", "plain", ",", "output", ",", "mode", ")", "rescue", "GPGME", "::", "Error", "::", "UnusableSecretKey", "=>", "exc", "exc", ".", "keys", "=", "ctx", ".", "sign_result", ".", "invalid_signers", "raise", "exc", "end", "end", "output", ".", "seek", "(", "0", ")", "output", "end" ]
Creates a signature of a text crypto.sign text, options Must have the appropiate key to be able to decrypt, of course. Returns a {GPGME::Data} object which can then be read. @param text The object that will be signed. Must be something that can be converted to {GPGME::Data}. @param [Hash] options Optional parameters. * +:signer+ sign identifier to sign the text with. Will use the first key it finds if none specified. * +:output+ if specified, it will write the output into it. It will be converted to a {GPGME::Data} object, so it could be a file for example. * +:mode+ Desired type of signature. Options are: - +GPGME::SIG_MODE_NORMAL+ for a normal signature. The default one if not specified. - +GPGME::SIG_MODE_DETACH+ for a detached signature - +GPGME::SIG_MODE_CLEAR+ for a cleartext signature * Any other option accepted by {GPGME::Ctx.new} @return [GPGME::Data] a {GPGME::Data} that can be read. @example normal sign crypto.sign "Hi there" @example outputing to a file file = File.open("text.sign", "w+") crypto.sign "Hi there", :options => file @example doing a detached signature crypto.sign "Hi there", :mode => GPGME::SIG_MODE_DETACH @example specifying the signer crypto.sign "Hi there", :signer => "mrsimo@example.com" @raise [GPGME::Error::UnusableSecretKey] TODO don't know when
[ "Creates", "a", "signature", "of", "a", "text" ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/crypto.rb#L235-L258
15,623
ueno/ruby-gpgme
lib/gpgme/crypto.rb
GPGME.Crypto.verify
def verify(sig, options = {}) options = @default_options.merge options sig = Data.new(sig) signed_text = Data.new(options[:signed_text]) output = Data.new(options[:output]) unless options[:signed_text] GPGME::Ctx.new(options) do |ctx| ctx.verify(sig, signed_text, output) ctx.verify_result.signatures.each do |signature| yield signature end end if output output.seek(0) output end end
ruby
def verify(sig, options = {}) options = @default_options.merge options sig = Data.new(sig) signed_text = Data.new(options[:signed_text]) output = Data.new(options[:output]) unless options[:signed_text] GPGME::Ctx.new(options) do |ctx| ctx.verify(sig, signed_text, output) ctx.verify_result.signatures.each do |signature| yield signature end end if output output.seek(0) output end end
[ "def", "verify", "(", "sig", ",", "options", "=", "{", "}", ")", "options", "=", "@default_options", ".", "merge", "options", "sig", "=", "Data", ".", "new", "(", "sig", ")", "signed_text", "=", "Data", ".", "new", "(", "options", "[", ":signed_text", "]", ")", "output", "=", "Data", ".", "new", "(", "options", "[", ":output", "]", ")", "unless", "options", "[", ":signed_text", "]", "GPGME", "::", "Ctx", ".", "new", "(", "options", ")", "do", "|", "ctx", "|", "ctx", ".", "verify", "(", "sig", ",", "signed_text", ",", "output", ")", "ctx", ".", "verify_result", ".", "signatures", ".", "each", "do", "|", "signature", "|", "yield", "signature", "end", "end", "if", "output", "output", ".", "seek", "(", "0", ")", "output", "end", "end" ]
Verifies a previously signed element crypto.verify sig, options, &block Must have the proper keys available. @param sig The signature itself. Must be possible to convert into a {GPGME::Data} object, so can be a file. @param [Hash] options * +:signed_text+ if the sign is detached, then must be the plain text for which the signature was created. * +:output+ where to store the result of the signature. Will be converted to a {GPGME::Data} object. * Any other option accepted by {GPGME::Ctx.new} @param &block In the block all the signatures are yielded, so one could verify them. See examples. @return [GPGME::Data] unless the sign is detached, the {GPGME::Data} object with the plain text. If the sign is detached, will return nil. @example simple verification sign = crypto.sign("Hi there") data = crypto.verify(sign) { |signature| signature.valid? } data.read # => "Hi there" @example saving output to file sign = crypto.sign("Hi there") out = File.open("test.asc", "w+") crypto.verify(sign, :output => out) {|signature| signature.valid?} out.read # => "Hi there" @example verifying a detached signature sign = crypto.detach_sign("Hi there") # Will fail crypto.verify(sign) { |signature| signature.valid? } # Will succeed crypto.verify(sign, :signed_text => "hi there") do |signature| signature.valid? end
[ "Verifies", "a", "previously", "signed", "element" ]
e84f42e2e8d956940c2430e5ccfbba9e989e3370
https://github.com/ueno/ruby-gpgme/blob/e84f42e2e8d956940c2430e5ccfbba9e989e3370/lib/gpgme/crypto.rb#L304-L322
15,624
mojombo/grit
lib/grit/index.rb
Grit.Index.add
def add(path, data) path = path.split('/') filename = path.pop current = self.tree path.each do |dir| current[dir] ||= {} node = current[dir] current = node end current[filename] = data end
ruby
def add(path, data) path = path.split('/') filename = path.pop current = self.tree path.each do |dir| current[dir] ||= {} node = current[dir] current = node end current[filename] = data end
[ "def", "add", "(", "path", ",", "data", ")", "path", "=", "path", ".", "split", "(", "'/'", ")", "filename", "=", "path", ".", "pop", "current", "=", "self", ".", "tree", "path", ".", "each", "do", "|", "dir", "|", "current", "[", "dir", "]", "||=", "{", "}", "node", "=", "current", "[", "dir", "]", "current", "=", "node", "end", "current", "[", "filename", "]", "=", "data", "end" ]
Initialize a new Index object. repo - The Grit::Repo to which the index belongs. Returns the newly initialized Grit::Index. Public: Add a file to the index. path - The String file path including filename (no slash prefix). data - The String binary contents of the file. Returns nothing.
[ "Initialize", "a", "new", "Index", "object", "." ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/index.rb#L36-L49
15,625
mojombo/grit
lib/grit/index.rb
Grit.Index.write_tree
def write_tree(tree = nil, now_tree = nil) tree = self.tree if !tree tree_contents = {} # fill in original tree now_tree = read_tree(now_tree) if(now_tree && now_tree.is_a?(String)) now_tree.contents.each do |obj| sha = [obj.id].pack("H*") k = obj.name k += '/' if (obj.class == Grit::Tree) tmode = obj.mode.to_i.to_s ## remove zero-padding tree_contents[k] = "%s %s\0%s" % [tmode, obj.name, sha] end if now_tree # overwrite with new tree contents tree.each do |k, v| case v when Array sha, mode = v if sha.size == 40 # must be a sha sha = [sha].pack("H*") mode = mode.to_i.to_s # leading 0s not allowed k = k.split('/').last # slashes not allowed str = "%s %s\0%s" % [mode, k, sha] tree_contents[k] = str end when String sha = write_blob(v) sha = [sha].pack("H*") str = "%s %s\0%s" % ['100644', k, sha] tree_contents[k] = str when Hash ctree = now_tree/k if now_tree sha = write_tree(v, ctree) sha = [sha].pack("H*") str = "%s %s\0%s" % ['40000', k, sha] tree_contents[k + '/'] = str when false tree_contents.delete(k) end end tr = tree_contents.sort.map { |k, v| v }.join('') @last_tree_size = tr.size self.repo.git.put_raw_object(tr, 'tree') end
ruby
def write_tree(tree = nil, now_tree = nil) tree = self.tree if !tree tree_contents = {} # fill in original tree now_tree = read_tree(now_tree) if(now_tree && now_tree.is_a?(String)) now_tree.contents.each do |obj| sha = [obj.id].pack("H*") k = obj.name k += '/' if (obj.class == Grit::Tree) tmode = obj.mode.to_i.to_s ## remove zero-padding tree_contents[k] = "%s %s\0%s" % [tmode, obj.name, sha] end if now_tree # overwrite with new tree contents tree.each do |k, v| case v when Array sha, mode = v if sha.size == 40 # must be a sha sha = [sha].pack("H*") mode = mode.to_i.to_s # leading 0s not allowed k = k.split('/').last # slashes not allowed str = "%s %s\0%s" % [mode, k, sha] tree_contents[k] = str end when String sha = write_blob(v) sha = [sha].pack("H*") str = "%s %s\0%s" % ['100644', k, sha] tree_contents[k] = str when Hash ctree = now_tree/k if now_tree sha = write_tree(v, ctree) sha = [sha].pack("H*") str = "%s %s\0%s" % ['40000', k, sha] tree_contents[k + '/'] = str when false tree_contents.delete(k) end end tr = tree_contents.sort.map { |k, v| v }.join('') @last_tree_size = tr.size self.repo.git.put_raw_object(tr, 'tree') end
[ "def", "write_tree", "(", "tree", "=", "nil", ",", "now_tree", "=", "nil", ")", "tree", "=", "self", ".", "tree", "if", "!", "tree", "tree_contents", "=", "{", "}", "# fill in original tree", "now_tree", "=", "read_tree", "(", "now_tree", ")", "if", "(", "now_tree", "&&", "now_tree", ".", "is_a?", "(", "String", ")", ")", "now_tree", ".", "contents", ".", "each", "do", "|", "obj", "|", "sha", "=", "[", "obj", ".", "id", "]", ".", "pack", "(", "\"H*\"", ")", "k", "=", "obj", ".", "name", "k", "+=", "'/'", "if", "(", "obj", ".", "class", "==", "Grit", "::", "Tree", ")", "tmode", "=", "obj", ".", "mode", ".", "to_i", ".", "to_s", "## remove zero-padding", "tree_contents", "[", "k", "]", "=", "\"%s %s\\0%s\"", "%", "[", "tmode", ",", "obj", ".", "name", ",", "sha", "]", "end", "if", "now_tree", "# overwrite with new tree contents", "tree", ".", "each", "do", "|", "k", ",", "v", "|", "case", "v", "when", "Array", "sha", ",", "mode", "=", "v", "if", "sha", ".", "size", "==", "40", "# must be a sha", "sha", "=", "[", "sha", "]", ".", "pack", "(", "\"H*\"", ")", "mode", "=", "mode", ".", "to_i", ".", "to_s", "# leading 0s not allowed", "k", "=", "k", ".", "split", "(", "'/'", ")", ".", "last", "# slashes not allowed", "str", "=", "\"%s %s\\0%s\"", "%", "[", "mode", ",", "k", ",", "sha", "]", "tree_contents", "[", "k", "]", "=", "str", "end", "when", "String", "sha", "=", "write_blob", "(", "v", ")", "sha", "=", "[", "sha", "]", ".", "pack", "(", "\"H*\"", ")", "str", "=", "\"%s %s\\0%s\"", "%", "[", "'100644'", ",", "k", ",", "sha", "]", "tree_contents", "[", "k", "]", "=", "str", "when", "Hash", "ctree", "=", "now_tree", "/", "k", "if", "now_tree", "sha", "=", "write_tree", "(", "v", ",", "ctree", ")", "sha", "=", "[", "sha", "]", ".", "pack", "(", "\"H*\"", ")", "str", "=", "\"%s %s\\0%s\"", "%", "[", "'40000'", ",", "k", ",", "sha", "]", "tree_contents", "[", "k", "+", "'/'", "]", "=", "str", "when", "false", "tree_contents", ".", "delete", "(", "k", ")", "end", "end", "tr", "=", "tree_contents", ".", "sort", ".", "map", "{", "|", "k", ",", "v", "|", "v", "}", ".", "join", "(", "''", ")", "@last_tree_size", "=", "tr", ".", "size", "self", ".", "repo", ".", "git", ".", "put_raw_object", "(", "tr", ",", "'tree'", ")", "end" ]
Recursively write a tree to the index. tree - The Hash tree map: key - The String directory or filename. val - The Hash submap or the String contents of the file. now_tree - The Grit::Tree representing the a previous tree upon which this tree will be based (default: nil). Returns the String SHA1 String of the tree.
[ "Recursively", "write", "a", "tree", "to", "the", "index", "." ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/index.rb#L165-L210
15,626
mojombo/grit
lib/grit/tree.rb
Grit.Tree.content_from_string
def content_from_string(repo, text) mode, type, id, name = text.split(/ |\t/, 4) case type when "tree" Tree.create(repo, :id => id, :mode => mode, :name => name) when "blob" Blob.create(repo, :id => id, :mode => mode, :name => name) when "link" Blob.create(repo, :id => id, :mode => mode, :name => name) when "commit" Submodule.create(repo, :id => id, :mode => mode, :name => name) else raise Grit::InvalidObjectType, type end end
ruby
def content_from_string(repo, text) mode, type, id, name = text.split(/ |\t/, 4) case type when "tree" Tree.create(repo, :id => id, :mode => mode, :name => name) when "blob" Blob.create(repo, :id => id, :mode => mode, :name => name) when "link" Blob.create(repo, :id => id, :mode => mode, :name => name) when "commit" Submodule.create(repo, :id => id, :mode => mode, :name => name) else raise Grit::InvalidObjectType, type end end
[ "def", "content_from_string", "(", "repo", ",", "text", ")", "mode", ",", "type", ",", "id", ",", "name", "=", "text", ".", "split", "(", "/", "\\t", "/", ",", "4", ")", "case", "type", "when", "\"tree\"", "Tree", ".", "create", "(", "repo", ",", ":id", "=>", "id", ",", ":mode", "=>", "mode", ",", ":name", "=>", "name", ")", "when", "\"blob\"", "Blob", ".", "create", "(", "repo", ",", ":id", "=>", "id", ",", ":mode", "=>", "mode", ",", ":name", "=>", "name", ")", "when", "\"link\"", "Blob", ".", "create", "(", "repo", ",", ":id", "=>", "id", ",", ":mode", "=>", "mode", ",", ":name", "=>", "name", ")", "when", "\"commit\"", "Submodule", ".", "create", "(", "repo", ",", ":id", "=>", "id", ",", ":mode", "=>", "mode", ",", ":name", "=>", "name", ")", "else", "raise", "Grit", "::", "InvalidObjectType", ",", "type", "end", "end" ]
Parse a content item and create the appropriate object +repo+ is the Repo +text+ is the single line containing the items data in `git ls-tree` format Returns Grit::Blob or Grit::Tree
[ "Parse", "a", "content", "item", "and", "create", "the", "appropriate", "object", "+", "repo", "+", "is", "the", "Repo", "+", "text", "+", "is", "the", "single", "line", "containing", "the", "items", "data", "in", "git", "ls", "-", "tree", "format" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/tree.rb#L67-L81
15,627
mojombo/grit
lib/grit/tree.rb
Grit.Tree./
def /(file) if file =~ /\// file.split("/").inject(self) { |acc, x| acc/x } rescue nil else self.contents.find { |c| c.name == file } end end
ruby
def /(file) if file =~ /\// file.split("/").inject(self) { |acc, x| acc/x } rescue nil else self.contents.find { |c| c.name == file } end end
[ "def", "/", "(", "file", ")", "if", "file", "=~", "/", "\\/", "/", "file", ".", "split", "(", "\"/\"", ")", ".", "inject", "(", "self", ")", "{", "|", "acc", ",", "x", "|", "acc", "/", "x", "}", "rescue", "nil", "else", "self", ".", "contents", ".", "find", "{", "|", "c", "|", "c", ".", "name", "==", "file", "}", "end", "end" ]
Find the named object in this tree's contents Examples Repo.new('/path/to/grit').tree/'lib' # => #<Grit::Tree "6cc23ee138be09ff8c28b07162720018b244e95e"> Repo.new('/path/to/grit').tree/'README.txt' # => #<Grit::Blob "8b1e02c0fb554eed2ce2ef737a68bb369d7527df"> Returns Grit::Blob or Grit::Tree or nil if not found
[ "Find", "the", "named", "object", "in", "this", "tree", "s", "contents" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/tree.rb#L92-L98
15,628
mojombo/grit
lib/grit/submodule.rb
Grit.Submodule.create_initialize
def create_initialize(repo, atts) @repo = repo atts.each do |k, v| instance_variable_set("@#{k}".to_sym, v) end self end
ruby
def create_initialize(repo, atts) @repo = repo atts.each do |k, v| instance_variable_set("@#{k}".to_sym, v) end self end
[ "def", "create_initialize", "(", "repo", ",", "atts", ")", "@repo", "=", "repo", "atts", ".", "each", "do", "|", "k", ",", "v", "|", "instance_variable_set", "(", "\"@#{k}\"", ".", "to_sym", ",", "v", ")", "end", "self", "end" ]
Initializer for Submodule.create +repo+ is the Repo +atts+ is a Hash of instance variable data Returns Grit::Submodule
[ "Initializer", "for", "Submodule", ".", "create", "+", "repo", "+", "is", "the", "Repo", "+", "atts", "+", "is", "a", "Hash", "of", "instance", "variable", "data" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/submodule.rb#L22-L28
15,629
mojombo/grit
lib/grit/submodule.rb
Grit.Submodule.url
def url(ref) config = self.class.config(@repo, ref) lookup = config.keys.inject({}) do |acc, key| id = config[key]['id'] acc[id] = config[key]['url'] acc end lookup[@id] end
ruby
def url(ref) config = self.class.config(@repo, ref) lookup = config.keys.inject({}) do |acc, key| id = config[key]['id'] acc[id] = config[key]['url'] acc end lookup[@id] end
[ "def", "url", "(", "ref", ")", "config", "=", "self", ".", "class", ".", "config", "(", "@repo", ",", "ref", ")", "lookup", "=", "config", ".", "keys", ".", "inject", "(", "{", "}", ")", "do", "|", "acc", ",", "key", "|", "id", "=", "config", "[", "key", "]", "[", "'id'", "]", "acc", "[", "id", "]", "=", "config", "[", "key", "]", "[", "'url'", "]", "acc", "end", "lookup", "[", "@id", "]", "end" ]
The url of this submodule +ref+ is the committish that should be used to look up the url Returns String
[ "The", "url", "of", "this", "submodule", "+", "ref", "+", "is", "the", "committish", "that", "should", "be", "used", "to", "look", "up", "the", "url" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/submodule.rb#L34-L44
15,630
mojombo/grit
lib/grit/status.rb
Grit.Status.diff_files
def diff_files hsh = {} @base.git.diff_files.split("\n").each do |line| (info, file) = line.split("\t") (mode_src, mode_dest, sha_src, sha_dest, type) = info.split hsh[file] = {:path => file, :mode_file => mode_src.to_s[1, 7], :mode_index => mode_dest, :sha_file => sha_src, :sha_index => sha_dest, :type => type} end hsh end
ruby
def diff_files hsh = {} @base.git.diff_files.split("\n").each do |line| (info, file) = line.split("\t") (mode_src, mode_dest, sha_src, sha_dest, type) = info.split hsh[file] = {:path => file, :mode_file => mode_src.to_s[1, 7], :mode_index => mode_dest, :sha_file => sha_src, :sha_index => sha_dest, :type => type} end hsh end
[ "def", "diff_files", "hsh", "=", "{", "}", "@base", ".", "git", ".", "diff_files", ".", "split", "(", "\"\\n\"", ")", ".", "each", "do", "|", "line", "|", "(", "info", ",", "file", ")", "=", "line", ".", "split", "(", "\"\\t\"", ")", "(", "mode_src", ",", "mode_dest", ",", "sha_src", ",", "sha_dest", ",", "type", ")", "=", "info", ".", "split", "hsh", "[", "file", "]", "=", "{", ":path", "=>", "file", ",", ":mode_file", "=>", "mode_src", ".", "to_s", "[", "1", ",", "7", "]", ",", ":mode_index", "=>", "mode_dest", ",", ":sha_file", "=>", "sha_src", ",", ":sha_index", "=>", "sha_dest", ",", ":type", "=>", "type", "}", "end", "hsh", "end" ]
compares the index and the working directory
[ "compares", "the", "index", "and", "the", "working", "directory" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/status.rb#L118-L127
15,631
mojombo/grit
lib/grit/actor.rb
Grit.Actor.output
def output(time) offset = time.utc_offset / 60 "%s <%s> %d %+.2d%.2d" % [ @name, @email || "null", time.to_i, offset / 60, offset.abs % 60] end
ruby
def output(time) offset = time.utc_offset / 60 "%s <%s> %d %+.2d%.2d" % [ @name, @email || "null", time.to_i, offset / 60, offset.abs % 60] end
[ "def", "output", "(", "time", ")", "offset", "=", "time", ".", "utc_offset", "/", "60", "\"%s <%s> %d %+.2d%.2d\"", "%", "[", "@name", ",", "@email", "||", "\"null\"", ",", "time", ".", "to_i", ",", "offset", "/", "60", ",", "offset", ".", "abs", "%", "60", "]", "end" ]
Outputs an actor string for Git commits. actor = Actor.new('bob', 'bob@email.com') actor.output(time) # => "bob <bob@email.com> UNIX_TIME +0700" time - The Time the commit was authored or committed. Returns a String.
[ "Outputs", "an", "actor", "string", "for", "Git", "commits", "." ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/actor.rb#L36-L44
15,632
mojombo/grit
lib/grit/repo.rb
Grit.Repo.recent_tag_name
def recent_tag_name(committish = nil, options = {}) value = git.describe({:always => true}.update(options), committish.to_s).to_s.strip value.size.zero? ? nil : value end
ruby
def recent_tag_name(committish = nil, options = {}) value = git.describe({:always => true}.update(options), committish.to_s).to_s.strip value.size.zero? ? nil : value end
[ "def", "recent_tag_name", "(", "committish", "=", "nil", ",", "options", "=", "{", "}", ")", "value", "=", "git", ".", "describe", "(", "{", ":always", "=>", "true", "}", ".", "update", "(", "options", ")", ",", "committish", ".", "to_s", ")", ".", "to_s", ".", "strip", "value", ".", "size", ".", "zero?", "?", "nil", ":", "value", "end" ]
Finds the most recent annotated tag name that is reachable from a commit. @repo.recent_tag_name('master') # => "v1.0-0-abcdef" committish - optional commit SHA, branch, or tag name. options - optional hash of options to pass to git. Default: {:always => true} :tags => true # use lightweight tags too. :abbrev => Integer # number of hex digits to form the unique name. Defaults to 7. :long => true # always output tag + commit sha # see `git describe` docs for more options. Returns the String tag name, or just the commit if no tag is found. If there have been updates since the tag was made, a suffix is added with the number of commits since the tag, and the abbreviated object name of the most recent commit. Returns nil if the committish value is not found.
[ "Finds", "the", "most", "recent", "annotated", "tag", "name", "that", "is", "reachable", "from", "a", "commit", "." ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/repo.rb#L300-L303
15,633
mojombo/grit
lib/grit/repo.rb
Grit.Repo.refs_list
def refs_list refs = self.git.for_each_ref refarr = refs.split("\n").map do |line| shatype, ref = line.split("\t") sha, type = shatype.split(' ') [ref, sha, type] end refarr end
ruby
def refs_list refs = self.git.for_each_ref refarr = refs.split("\n").map do |line| shatype, ref = line.split("\t") sha, type = shatype.split(' ') [ref, sha, type] end refarr end
[ "def", "refs_list", "refs", "=", "self", ".", "git", ".", "for_each_ref", "refarr", "=", "refs", ".", "split", "(", "\"\\n\"", ")", ".", "map", "do", "|", "line", "|", "shatype", ",", "ref", "=", "line", ".", "split", "(", "\"\\t\"", ")", "sha", ",", "type", "=", "shatype", ".", "split", "(", "' '", ")", "[", "ref", ",", "sha", ",", "type", "]", "end", "refarr", "end" ]
returns an array of hashes representing all references
[ "returns", "an", "array", "of", "hashes", "representing", "all", "references" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/repo.rb#L350-L358
15,634
mojombo/grit
lib/grit/repo.rb
Grit.Repo.commit_deltas_from
def commit_deltas_from(other_repo, ref = "master", other_ref = "master") # TODO: we should be able to figure out the branch point, rather than # rev-list'ing the whole thing repo_refs = self.git.rev_list({}, ref).strip.split("\n") other_repo_refs = other_repo.git.rev_list({}, other_ref).strip.split("\n") (other_repo_refs - repo_refs).map do |refn| Commit.find_all(other_repo, refn, {:max_count => 1}).first end end
ruby
def commit_deltas_from(other_repo, ref = "master", other_ref = "master") # TODO: we should be able to figure out the branch point, rather than # rev-list'ing the whole thing repo_refs = self.git.rev_list({}, ref).strip.split("\n") other_repo_refs = other_repo.git.rev_list({}, other_ref).strip.split("\n") (other_repo_refs - repo_refs).map do |refn| Commit.find_all(other_repo, refn, {:max_count => 1}).first end end
[ "def", "commit_deltas_from", "(", "other_repo", ",", "ref", "=", "\"master\"", ",", "other_ref", "=", "\"master\"", ")", "# TODO: we should be able to figure out the branch point, rather than", "# rev-list'ing the whole thing", "repo_refs", "=", "self", ".", "git", ".", "rev_list", "(", "{", "}", ",", "ref", ")", ".", "strip", ".", "split", "(", "\"\\n\"", ")", "other_repo_refs", "=", "other_repo", ".", "git", ".", "rev_list", "(", "{", "}", ",", "other_ref", ")", ".", "strip", ".", "split", "(", "\"\\n\"", ")", "(", "other_repo_refs", "-", "repo_refs", ")", ".", "map", "do", "|", "refn", "|", "Commit", ".", "find_all", "(", "other_repo", ",", "refn", ",", "{", ":max_count", "=>", "1", "}", ")", ".", "first", "end", "end" ]
Returns a list of commits that is in +other_repo+ but not in self Returns Grit::Commit[]
[ "Returns", "a", "list", "of", "commits", "that", "is", "in", "+", "other_repo", "+", "but", "not", "in", "self" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/repo.rb#L433-L442
15,635
mojombo/grit
lib/grit/repo.rb
Grit.Repo.log
def log(commit = 'master', path = nil, options = {}) default_options = {:pretty => "raw"} actual_options = default_options.merge(options) arg = path ? [commit, '--', path] : [commit] commits = self.git.log(actual_options, *arg) Commit.list_from_string(self, commits) end
ruby
def log(commit = 'master', path = nil, options = {}) default_options = {:pretty => "raw"} actual_options = default_options.merge(options) arg = path ? [commit, '--', path] : [commit] commits = self.git.log(actual_options, *arg) Commit.list_from_string(self, commits) end
[ "def", "log", "(", "commit", "=", "'master'", ",", "path", "=", "nil", ",", "options", "=", "{", "}", ")", "default_options", "=", "{", ":pretty", "=>", "\"raw\"", "}", "actual_options", "=", "default_options", ".", "merge", "(", "options", ")", "arg", "=", "path", "?", "[", "commit", ",", "'--'", ",", "path", "]", ":", "[", "commit", "]", "commits", "=", "self", ".", "git", ".", "log", "(", "actual_options", ",", "arg", ")", "Commit", ".", "list_from_string", "(", "self", ",", "commits", ")", "end" ]
The commit log for a treeish Returns Grit::Commit[]
[ "The", "commit", "log", "for", "a", "treeish" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/repo.rb#L541-L547
15,636
mojombo/grit
lib/grit/repo.rb
Grit.Repo.alternates=
def alternates=(alts) alts.each do |alt| unless File.exist?(alt) raise "Could not set alternates. Alternate path #{alt} must exist" end end if alts.empty? self.git.fs_write('objects/info/alternates', '') else self.git.fs_write('objects/info/alternates', alts.join("\n")) end end
ruby
def alternates=(alts) alts.each do |alt| unless File.exist?(alt) raise "Could not set alternates. Alternate path #{alt} must exist" end end if alts.empty? self.git.fs_write('objects/info/alternates', '') else self.git.fs_write('objects/info/alternates', alts.join("\n")) end end
[ "def", "alternates", "=", "(", "alts", ")", "alts", ".", "each", "do", "|", "alt", "|", "unless", "File", ".", "exist?", "(", "alt", ")", "raise", "\"Could not set alternates. Alternate path #{alt} must exist\"", "end", "end", "if", "alts", ".", "empty?", "self", ".", "git", ".", "fs_write", "(", "'objects/info/alternates'", ",", "''", ")", "else", "self", ".", "git", ".", "fs_write", "(", "'objects/info/alternates'", ",", "alts", ".", "join", "(", "\"\\n\"", ")", ")", "end", "end" ]
Sets the alternates +alts+ is the Array of String paths representing the alternates Returns nothing
[ "Sets", "the", "alternates", "+", "alts", "+", "is", "the", "Array", "of", "String", "paths", "representing", "the", "alternates" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/repo.rb#L663-L675
15,637
mojombo/grit
lib/grit/commit.rb
Grit.Commit.diffs
def diffs(options = {}) if parents.empty? show else self.class.diff(@repo, parents.first.id, @id, [], options) end end
ruby
def diffs(options = {}) if parents.empty? show else self.class.diff(@repo, parents.first.id, @id, [], options) end end
[ "def", "diffs", "(", "options", "=", "{", "}", ")", "if", "parents", ".", "empty?", "show", "else", "self", ".", "class", ".", "diff", "(", "@repo", ",", "parents", ".", "first", ".", "id", ",", "@id", ",", "[", "]", ",", "options", ")", "end", "end" ]
Shows diffs between the commit's parent and the commit. options - An optional Hash of options, passed to Grit::Commit.diff. Returns Grit::Diff[] (baked)
[ "Shows", "diffs", "between", "the", "commit", "s", "parent", "and", "the", "commit", "." ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/commit.rb#L219-L225
15,638
mojombo/grit
lib/grit/git.rb
Grit.Git.fs_write
def fs_write(file, contents) path = File.join(self.git_dir, file) FileUtils.mkdir_p(File.dirname(path)) File.open(path, 'w') do |f| f.write(contents) end end
ruby
def fs_write(file, contents) path = File.join(self.git_dir, file) FileUtils.mkdir_p(File.dirname(path)) File.open(path, 'w') do |f| f.write(contents) end end
[ "def", "fs_write", "(", "file", ",", "contents", ")", "path", "=", "File", ".", "join", "(", "self", ".", "git_dir", ",", "file", ")", "FileUtils", ".", "mkdir_p", "(", "File", ".", "dirname", "(", "path", ")", ")", "File", ".", "open", "(", "path", ",", "'w'", ")", "do", "|", "f", "|", "f", ".", "write", "(", "contents", ")", "end", "end" ]
Write a normal file to the filesystem. +file+ is the relative path from the Git dir +contents+ is the String content to be written Returns nothing
[ "Write", "a", "normal", "file", "to", "the", "filesystem", ".", "+", "file", "+", "is", "the", "relative", "path", "from", "the", "Git", "dir", "+", "contents", "+", "is", "the", "String", "content", "to", "be", "written" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L128-L134
15,639
mojombo/grit
lib/grit/git.rb
Grit.Git.fs_move
def fs_move(from, to) FileUtils.mv(File.join(self.git_dir, from), File.join(self.git_dir, to)) end
ruby
def fs_move(from, to) FileUtils.mv(File.join(self.git_dir, from), File.join(self.git_dir, to)) end
[ "def", "fs_move", "(", "from", ",", "to", ")", "FileUtils", ".", "mv", "(", "File", ".", "join", "(", "self", ".", "git_dir", ",", "from", ")", ",", "File", ".", "join", "(", "self", ".", "git_dir", ",", "to", ")", ")", "end" ]
Move a normal file +from+ is the relative path to the current file +to+ is the relative path to the destination file Returns nothing
[ "Move", "a", "normal", "file", "+", "from", "+", "is", "the", "relative", "path", "to", "the", "current", "file", "+", "to", "+", "is", "the", "relative", "path", "to", "the", "destination", "file" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L149-L151
15,640
mojombo/grit
lib/grit/git.rb
Grit.Git.fs_chmod
def fs_chmod(mode, file = '/') FileUtils.chmod_R(mode, File.join(self.git_dir, file)) end
ruby
def fs_chmod(mode, file = '/') FileUtils.chmod_R(mode, File.join(self.git_dir, file)) end
[ "def", "fs_chmod", "(", "mode", ",", "file", "=", "'/'", ")", "FileUtils", ".", "chmod_R", "(", "mode", ",", "File", ".", "join", "(", "self", ".", "git_dir", ",", "file", ")", ")", "end" ]
Chmod the the file or dir and everything beneath +file+ is the relative path from the Git dir Returns nothing
[ "Chmod", "the", "the", "file", "or", "dir", "and", "everything", "beneath", "+", "file", "+", "is", "the", "relative", "path", "from", "the", "Git", "dir" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L165-L167
15,641
mojombo/grit
lib/grit/git.rb
Grit.Git.check_applies
def check_applies(options={}, head_sha=nil, applies_sha=nil) options, head_sha, applies_sha = {}, options, head_sha if !options.is_a?(Hash) options = options.dup options[:env] &&= options[:env].dup git_index = create_tempfile('index', true) (options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index) options[:raise] = true status = 0 begin native(:read_tree, options.dup, head_sha) stdin = native(:diff, options.dup, "#{applies_sha}^", applies_sha) native(:apply, options.merge(:check => true, :cached => true, :input => stdin)) rescue CommandFailed => fail status += fail.exitstatus end status end
ruby
def check_applies(options={}, head_sha=nil, applies_sha=nil) options, head_sha, applies_sha = {}, options, head_sha if !options.is_a?(Hash) options = options.dup options[:env] &&= options[:env].dup git_index = create_tempfile('index', true) (options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index) options[:raise] = true status = 0 begin native(:read_tree, options.dup, head_sha) stdin = native(:diff, options.dup, "#{applies_sha}^", applies_sha) native(:apply, options.merge(:check => true, :cached => true, :input => stdin)) rescue CommandFailed => fail status += fail.exitstatus end status end
[ "def", "check_applies", "(", "options", "=", "{", "}", ",", "head_sha", "=", "nil", ",", "applies_sha", "=", "nil", ")", "options", ",", "head_sha", ",", "applies_sha", "=", "{", "}", ",", "options", ",", "head_sha", "if", "!", "options", ".", "is_a?", "(", "Hash", ")", "options", "=", "options", ".", "dup", "options", "[", ":env", "]", "&&=", "options", "[", ":env", "]", ".", "dup", "git_index", "=", "create_tempfile", "(", "'index'", ",", "true", ")", "(", "options", "[", ":env", "]", "||=", "{", "}", ")", ".", "merge!", "(", "'GIT_INDEX_FILE'", "=>", "git_index", ")", "options", "[", ":raise", "]", "=", "true", "status", "=", "0", "begin", "native", "(", ":read_tree", ",", "options", ".", "dup", ",", "head_sha", ")", "stdin", "=", "native", "(", ":diff", ",", "options", ".", "dup", ",", "\"#{applies_sha}^\"", ",", "applies_sha", ")", "native", "(", ":apply", ",", "options", ".", "merge", "(", ":check", "=>", "true", ",", ":cached", "=>", "true", ",", ":input", "=>", "stdin", ")", ")", "rescue", "CommandFailed", "=>", "fail", "status", "+=", "fail", ".", "exitstatus", "end", "status", "end" ]
Checks if the patch of a commit can be applied to the given head. options - grit command options hash head_sha - String SHA or ref to check the patch against. applies_sha - String SHA of the patch. The patch itself is retrieved with #get_patch. Returns 0 if the patch applies cleanly (according to `git apply`), or an Integer that is the sum of the failed exit statuses.
[ "Checks", "if", "the", "patch", "of", "a", "commit", "can", "be", "applied", "to", "the", "given", "head", "." ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L207-L225
15,642
mojombo/grit
lib/grit/git.rb
Grit.Git.get_patch
def get_patch(options={}, applies_sha=nil) options, applies_sha = {}, options if !options.is_a?(Hash) options = options.dup options[:env] &&= options[:env].dup git_index = create_tempfile('index', true) (options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index) native(:diff, options, "#{applies_sha}^", applies_sha) end
ruby
def get_patch(options={}, applies_sha=nil) options, applies_sha = {}, options if !options.is_a?(Hash) options = options.dup options[:env] &&= options[:env].dup git_index = create_tempfile('index', true) (options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index) native(:diff, options, "#{applies_sha}^", applies_sha) end
[ "def", "get_patch", "(", "options", "=", "{", "}", ",", "applies_sha", "=", "nil", ")", "options", ",", "applies_sha", "=", "{", "}", ",", "options", "if", "!", "options", ".", "is_a?", "(", "Hash", ")", "options", "=", "options", ".", "dup", "options", "[", ":env", "]", "&&=", "options", "[", ":env", "]", ".", "dup", "git_index", "=", "create_tempfile", "(", "'index'", ",", "true", ")", "(", "options", "[", ":env", "]", "||=", "{", "}", ")", ".", "merge!", "(", "'GIT_INDEX_FILE'", "=>", "git_index", ")", "native", "(", ":diff", ",", "options", ",", "\"#{applies_sha}^\"", ",", "applies_sha", ")", "end" ]
Gets a patch for a given SHA using `git diff`. options - grit command options hash applies_sha - String SHA to get the patch from, using this command: `git diff #{applies_sha}^ #{applies_sha}` Returns the String patch from `git diff`.
[ "Gets", "a", "patch", "for", "a", "given", "SHA", "using", "git", "diff", "." ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L234-L243
15,643
mojombo/grit
lib/grit/git.rb
Grit.Git.apply_patch
def apply_patch(options={}, head_sha=nil, patch=nil) options, head_sha, patch = {}, options, head_sha if !options.is_a?(Hash) options = options.dup options[:env] &&= options[:env].dup options[:raise] = true git_index = create_tempfile('index', true) (options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index) begin native(:read_tree, options.dup, head_sha) native(:apply, options.merge(:cached => true, :input => patch)) rescue CommandFailed return false end native(:write_tree, :env => options[:env]).to_s.chomp! end
ruby
def apply_patch(options={}, head_sha=nil, patch=nil) options, head_sha, patch = {}, options, head_sha if !options.is_a?(Hash) options = options.dup options[:env] &&= options[:env].dup options[:raise] = true git_index = create_tempfile('index', true) (options[:env] ||= {}).merge!('GIT_INDEX_FILE' => git_index) begin native(:read_tree, options.dup, head_sha) native(:apply, options.merge(:cached => true, :input => patch)) rescue CommandFailed return false end native(:write_tree, :env => options[:env]).to_s.chomp! end
[ "def", "apply_patch", "(", "options", "=", "{", "}", ",", "head_sha", "=", "nil", ",", "patch", "=", "nil", ")", "options", ",", "head_sha", ",", "patch", "=", "{", "}", ",", "options", ",", "head_sha", "if", "!", "options", ".", "is_a?", "(", "Hash", ")", "options", "=", "options", ".", "dup", "options", "[", ":env", "]", "&&=", "options", "[", ":env", "]", ".", "dup", "options", "[", ":raise", "]", "=", "true", "git_index", "=", "create_tempfile", "(", "'index'", ",", "true", ")", "(", "options", "[", ":env", "]", "||=", "{", "}", ")", ".", "merge!", "(", "'GIT_INDEX_FILE'", "=>", "git_index", ")", "begin", "native", "(", ":read_tree", ",", "options", ".", "dup", ",", "head_sha", ")", "native", "(", ":apply", ",", "options", ".", "merge", "(", ":cached", "=>", "true", ",", ":input", "=>", "patch", ")", ")", "rescue", "CommandFailed", "return", "false", "end", "native", "(", ":write_tree", ",", ":env", "=>", "options", "[", ":env", "]", ")", ".", "to_s", ".", "chomp!", "end" ]
Applies the given patch against the given SHA of the current repo. options - grit command hash head_sha - String SHA or ref to apply the patch to. patch - The String patch to apply. Get this from #get_patch. Returns the String Tree SHA on a successful patch application, or false.
[ "Applies", "the", "given", "patch", "against", "the", "given", "SHA", "of", "the", "current", "repo", "." ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L252-L268
15,644
mojombo/grit
lib/grit/git.rb
Grit.Git.native
def native(cmd, options = {}, *args, &block) args = args.first if args.size == 1 && args[0].is_a?(Array) args.map! { |a| a.to_s } args.reject! { |a| a.empty? } # special option arguments env = options.delete(:env) || {} raise_errors = options.delete(:raise) process_info = options.delete(:process_info) # fall back to using a shell when the last argument looks like it wants to # start a pipeline for compatibility with previous versions of grit. return run(prefix, cmd, '', options, args) if args[-1].to_s[0] == ?| # more options input = options.delete(:input) timeout = options.delete(:timeout); timeout = true if timeout.nil? base = options.delete(:base); base = true if base.nil? chdir = options.delete(:chdir) # build up the git process argv argv = [] argv << Git.git_binary argv << "--git-dir=#{git_dir}" if base argv << cmd.to_s.tr('_', '-') argv.concat(options_to_argv(options)) argv.concat(args) # run it and deal with fallout Grit.log(argv.join(' ')) if Grit.debug process = Child.new(env, *(argv + [{ :input => input, :chdir => chdir, :timeout => (Grit::Git.git_timeout if timeout == true), :max => (Grit::Git.git_max_size if timeout == true) }])) Grit.log(process.out) if Grit.debug Grit.log(process.err) if Grit.debug status = process.status if raise_errors && !status.success? raise CommandFailed.new(argv.join(' '), status.exitstatus, process.err) elsif process_info [status.exitstatus, process.out, process.err] else process.out end rescue TimeoutExceeded, MaximumOutputExceeded raise GitTimeout, argv.join(' ') end
ruby
def native(cmd, options = {}, *args, &block) args = args.first if args.size == 1 && args[0].is_a?(Array) args.map! { |a| a.to_s } args.reject! { |a| a.empty? } # special option arguments env = options.delete(:env) || {} raise_errors = options.delete(:raise) process_info = options.delete(:process_info) # fall back to using a shell when the last argument looks like it wants to # start a pipeline for compatibility with previous versions of grit. return run(prefix, cmd, '', options, args) if args[-1].to_s[0] == ?| # more options input = options.delete(:input) timeout = options.delete(:timeout); timeout = true if timeout.nil? base = options.delete(:base); base = true if base.nil? chdir = options.delete(:chdir) # build up the git process argv argv = [] argv << Git.git_binary argv << "--git-dir=#{git_dir}" if base argv << cmd.to_s.tr('_', '-') argv.concat(options_to_argv(options)) argv.concat(args) # run it and deal with fallout Grit.log(argv.join(' ')) if Grit.debug process = Child.new(env, *(argv + [{ :input => input, :chdir => chdir, :timeout => (Grit::Git.git_timeout if timeout == true), :max => (Grit::Git.git_max_size if timeout == true) }])) Grit.log(process.out) if Grit.debug Grit.log(process.err) if Grit.debug status = process.status if raise_errors && !status.success? raise CommandFailed.new(argv.join(' '), status.exitstatus, process.err) elsif process_info [status.exitstatus, process.out, process.err] else process.out end rescue TimeoutExceeded, MaximumOutputExceeded raise GitTimeout, argv.join(' ') end
[ "def", "native", "(", "cmd", ",", "options", "=", "{", "}", ",", "*", "args", ",", "&", "block", ")", "args", "=", "args", ".", "first", "if", "args", ".", "size", "==", "1", "&&", "args", "[", "0", "]", ".", "is_a?", "(", "Array", ")", "args", ".", "map!", "{", "|", "a", "|", "a", ".", "to_s", "}", "args", ".", "reject!", "{", "|", "a", "|", "a", ".", "empty?", "}", "# special option arguments", "env", "=", "options", ".", "delete", "(", ":env", ")", "||", "{", "}", "raise_errors", "=", "options", ".", "delete", "(", ":raise", ")", "process_info", "=", "options", ".", "delete", "(", ":process_info", ")", "# fall back to using a shell when the last argument looks like it wants to", "# start a pipeline for compatibility with previous versions of grit.", "return", "run", "(", "prefix", ",", "cmd", ",", "''", ",", "options", ",", "args", ")", "if", "args", "[", "-", "1", "]", ".", "to_s", "[", "0", "]", "==", "?|", "# more options", "input", "=", "options", ".", "delete", "(", ":input", ")", "timeout", "=", "options", ".", "delete", "(", ":timeout", ")", ";", "timeout", "=", "true", "if", "timeout", ".", "nil?", "base", "=", "options", ".", "delete", "(", ":base", ")", ";", "base", "=", "true", "if", "base", ".", "nil?", "chdir", "=", "options", ".", "delete", "(", ":chdir", ")", "# build up the git process argv", "argv", "=", "[", "]", "argv", "<<", "Git", ".", "git_binary", "argv", "<<", "\"--git-dir=#{git_dir}\"", "if", "base", "argv", "<<", "cmd", ".", "to_s", ".", "tr", "(", "'_'", ",", "'-'", ")", "argv", ".", "concat", "(", "options_to_argv", "(", "options", ")", ")", "argv", ".", "concat", "(", "args", ")", "# run it and deal with fallout", "Grit", ".", "log", "(", "argv", ".", "join", "(", "' '", ")", ")", "if", "Grit", ".", "debug", "process", "=", "Child", ".", "new", "(", "env", ",", "(", "argv", "+", "[", "{", ":input", "=>", "input", ",", ":chdir", "=>", "chdir", ",", ":timeout", "=>", "(", "Grit", "::", "Git", ".", "git_timeout", "if", "timeout", "==", "true", ")", ",", ":max", "=>", "(", "Grit", "::", "Git", ".", "git_max_size", "if", "timeout", "==", "true", ")", "}", "]", ")", ")", "Grit", ".", "log", "(", "process", ".", "out", ")", "if", "Grit", ".", "debug", "Grit", ".", "log", "(", "process", ".", "err", ")", "if", "Grit", ".", "debug", "status", "=", "process", ".", "status", "if", "raise_errors", "&&", "!", "status", ".", "success?", "raise", "CommandFailed", ".", "new", "(", "argv", ".", "join", "(", "' '", ")", ",", "status", ".", "exitstatus", ",", "process", ".", "err", ")", "elsif", "process_info", "[", "status", ".", "exitstatus", ",", "process", ".", "out", ",", "process", ".", "err", "]", "else", "process", ".", "out", "end", "rescue", "TimeoutExceeded", ",", "MaximumOutputExceeded", "raise", "GitTimeout", ",", "argv", ".", "join", "(", "' '", ")", "end" ]
Execute a git command, bypassing any library implementation. cmd - The name of the git command as a Symbol. Underscores are converted to dashes as in :rev_parse => 'rev-parse'. options - Command line option arguments passed to the git command. Single char keys are converted to short options (:a => -a). Multi-char keys are converted to long options (:arg => '--arg'). Underscores in keys are converted to dashes. These special options are used to control command execution and are not passed in command invocation: :timeout - Maximum amount of time the command can run for before being aborted. When true, use Grit::Git.git_timeout; when numeric, use that number of seconds; when false or 0, disable timeout. :base - Set false to avoid passing the --git-dir argument when invoking the git command. :env - Hash of environment variable key/values that are set on the child process. :raise - When set true, commands that exit with a non-zero status raise a CommandFailed exception. This option is available only on platforms that support fork(2). :process_info - By default, a single string with output written to the process's stdout is returned. Setting this option to true results in a [exitstatus, out, err] tuple being returned instead. args - Non-option arguments passed on the command line. Optionally yields to the block an IO object attached to the child process's STDIN. Examples git.native(:rev_list, {:max_count => 10, :header => true}, "master") Returns a String with all output written to the child process's stdout when the :process_info option is not set. Returns a [exitstatus, out, err] tuple when the :process_info option is set. The exitstatus is an small integer that was the process's exit status. The out and err elements are the data written to stdout and stderr as Strings. Raises Grit::Git::GitTimeout when the timeout is exceeded or when more than Grit::Git.git_max_size bytes are output. Raises Grit::Git::CommandFailed when the :raise option is set true and the git command exits with a non-zero exit status. The CommandFailed's #command, #exitstatus, and #err attributes can be used to retrieve additional detail about the error.
[ "Execute", "a", "git", "command", "bypassing", "any", "library", "implementation", "." ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L313-L364
15,645
mojombo/grit
lib/grit/git.rb
Grit.Git.run
def run(prefix, cmd, postfix, options, args, &block) timeout = options.delete(:timeout) rescue nil timeout = true if timeout.nil? base = options.delete(:base) rescue nil base = true if base.nil? if input = options.delete(:input) block = lambda { |stdin| stdin.write(input) } end opt_args = transform_options(options) if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/ ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|' || Grit.no_quote) ? a : "\"#{e(a)}\"" } gitdir = base ? "--git-dir=\"#{self.git_dir}\"" : "" call = "#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}" else ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|' || Grit.no_quote) ? a : "'#{e(a)}'" } gitdir = base ? "--git-dir='#{self.git_dir}'" : "" call = "#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}" end Grit.log(call) if Grit.debug response, err = timeout ? sh(call, &block) : wild_sh(call, &block) Grit.log(response) if Grit.debug Grit.log(err) if Grit.debug response end
ruby
def run(prefix, cmd, postfix, options, args, &block) timeout = options.delete(:timeout) rescue nil timeout = true if timeout.nil? base = options.delete(:base) rescue nil base = true if base.nil? if input = options.delete(:input) block = lambda { |stdin| stdin.write(input) } end opt_args = transform_options(options) if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/ ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|' || Grit.no_quote) ? a : "\"#{e(a)}\"" } gitdir = base ? "--git-dir=\"#{self.git_dir}\"" : "" call = "#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}" else ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|' || Grit.no_quote) ? a : "'#{e(a)}'" } gitdir = base ? "--git-dir='#{self.git_dir}'" : "" call = "#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}" end Grit.log(call) if Grit.debug response, err = timeout ? sh(call, &block) : wild_sh(call, &block) Grit.log(response) if Grit.debug Grit.log(err) if Grit.debug response end
[ "def", "run", "(", "prefix", ",", "cmd", ",", "postfix", ",", "options", ",", "args", ",", "&", "block", ")", "timeout", "=", "options", ".", "delete", "(", ":timeout", ")", "rescue", "nil", "timeout", "=", "true", "if", "timeout", ".", "nil?", "base", "=", "options", ".", "delete", "(", ":base", ")", "rescue", "nil", "base", "=", "true", "if", "base", ".", "nil?", "if", "input", "=", "options", ".", "delete", "(", ":input", ")", "block", "=", "lambda", "{", "|", "stdin", "|", "stdin", ".", "write", "(", "input", ")", "}", "end", "opt_args", "=", "transform_options", "(", "options", ")", "if", "RUBY_PLATFORM", ".", "downcase", "=~", "/", "/", "ext_args", "=", "args", ".", "reject", "{", "|", "a", "|", "a", ".", "empty?", "}", ".", "map", "{", "|", "a", "|", "(", "a", "==", "'--'", "||", "a", "[", "0", "]", ".", "chr", "==", "'|'", "||", "Grit", ".", "no_quote", ")", "?", "a", ":", "\"\\\"#{e(a)}\\\"\"", "}", "gitdir", "=", "base", "?", "\"--git-dir=\\\"#{self.git_dir}\\\"\"", ":", "\"\"", "call", "=", "\"#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}\"", "else", "ext_args", "=", "args", ".", "reject", "{", "|", "a", "|", "a", ".", "empty?", "}", ".", "map", "{", "|", "a", "|", "(", "a", "==", "'--'", "||", "a", "[", "0", "]", ".", "chr", "==", "'|'", "||", "Grit", ".", "no_quote", ")", "?", "a", ":", "\"'#{e(a)}'\"", "}", "gitdir", "=", "base", "?", "\"--git-dir='#{self.git_dir}'\"", ":", "\"\"", "call", "=", "\"#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}\"", "end", "Grit", ".", "log", "(", "call", ")", "if", "Grit", ".", "debug", "response", ",", "err", "=", "timeout", "?", "sh", "(", "call", ",", "block", ")", ":", "wild_sh", "(", "call", ",", "block", ")", "Grit", ".", "log", "(", "response", ")", "if", "Grit", ".", "debug", "Grit", ".", "log", "(", "err", ")", "if", "Grit", ".", "debug", "response", "end" ]
DEPRECATED OPEN3-BASED COMMAND EXECUTION
[ "DEPRECATED", "OPEN3", "-", "BASED", "COMMAND", "EXECUTION" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L422-L450
15,646
mojombo/grit
lib/grit/git.rb
Grit.Git.transform_options
def transform_options(options) args = [] options.keys.each do |opt| if opt.to_s.size == 1 if options[opt] == true args << "-#{opt}" elsif options[opt] == false # ignore else val = options.delete(opt) args << "-#{opt.to_s} '#{e(val)}'" end else if options[opt] == true args << "--#{opt.to_s.gsub(/_/, '-')}" elsif options[opt] == false # ignore else val = options.delete(opt) args << "--#{opt.to_s.gsub(/_/, '-')}='#{e(val)}'" end end end args end
ruby
def transform_options(options) args = [] options.keys.each do |opt| if opt.to_s.size == 1 if options[opt] == true args << "-#{opt}" elsif options[opt] == false # ignore else val = options.delete(opt) args << "-#{opt.to_s} '#{e(val)}'" end else if options[opt] == true args << "--#{opt.to_s.gsub(/_/, '-')}" elsif options[opt] == false # ignore else val = options.delete(opt) args << "--#{opt.to_s.gsub(/_/, '-')}='#{e(val)}'" end end end args end
[ "def", "transform_options", "(", "options", ")", "args", "=", "[", "]", "options", ".", "keys", ".", "each", "do", "|", "opt", "|", "if", "opt", ".", "to_s", ".", "size", "==", "1", "if", "options", "[", "opt", "]", "==", "true", "args", "<<", "\"-#{opt}\"", "elsif", "options", "[", "opt", "]", "==", "false", "# ignore", "else", "val", "=", "options", ".", "delete", "(", "opt", ")", "args", "<<", "\"-#{opt.to_s} '#{e(val)}'\"", "end", "else", "if", "options", "[", "opt", "]", "==", "true", "args", "<<", "\"--#{opt.to_s.gsub(/_/, '-')}\"", "elsif", "options", "[", "opt", "]", "==", "false", "# ignore", "else", "val", "=", "options", ".", "delete", "(", "opt", ")", "args", "<<", "\"--#{opt.to_s.gsub(/_/, '-')}='#{e(val)}'\"", "end", "end", "end", "args", "end" ]
Transform Ruby style options into git command line options +options+ is a hash of Ruby style options Returns String[] e.g. ["--max-count=10", "--header"]
[ "Transform", "Ruby", "style", "options", "into", "git", "command", "line", "options", "+", "options", "+", "is", "a", "hash", "of", "Ruby", "style", "options" ]
5608567286e64a1c55c5e7fcd415364e04f8986e
https://github.com/mojombo/grit/blob/5608567286e64a1c55c5e7fcd415364e04f8986e/lib/grit/git.rb#L474-L498
15,647
pact-foundation/pact-mock_service
lib/pact/consumer_contract/request_decorator.rb
Pact.RequestDecorator.body
def body if content_type_is_form && request.body.is_a?(Hash) URI.encode_www_form convert_hash_body_to_array_of_arrays else Pact::Reification.from_term(request.body) end end
ruby
def body if content_type_is_form && request.body.is_a?(Hash) URI.encode_www_form convert_hash_body_to_array_of_arrays else Pact::Reification.from_term(request.body) end end
[ "def", "body", "if", "content_type_is_form", "&&", "request", ".", "body", ".", "is_a?", "(", "Hash", ")", "URI", ".", "encode_www_form", "convert_hash_body_to_array_of_arrays", "else", "Pact", "::", "Reification", ".", "from_term", "(", "request", ".", "body", ")", "end", "end" ]
This feels wrong to be checking the class type of the body Do this better somehow.
[ "This", "feels", "wrong", "to", "be", "checking", "the", "class", "type", "of", "the", "body", "Do", "this", "better", "somehow", "." ]
3c26b469cbb796fa0045bb617b64c41c6b13b547
https://github.com/pact-foundation/pact-mock_service/blob/3c26b469cbb796fa0045bb617b64c41c6b13b547/lib/pact/consumer_contract/request_decorator.rb#L49-L55
15,648
pact-foundation/pact-mock_service
lib/pact/consumer_contract/request_decorator.rb
Pact.RequestDecorator.convert_hash_body_to_array_of_arrays
def convert_hash_body_to_array_of_arrays arrays = [] request.body.keys.each do | key | [*request.body[key]].each do | value | arrays << [key, value] end end Pact::Reification.from_term(arrays) end
ruby
def convert_hash_body_to_array_of_arrays arrays = [] request.body.keys.each do | key | [*request.body[key]].each do | value | arrays << [key, value] end end Pact::Reification.from_term(arrays) end
[ "def", "convert_hash_body_to_array_of_arrays", "arrays", "=", "[", "]", "request", ".", "body", ".", "keys", ".", "each", "do", "|", "key", "|", "[", "request", ".", "body", "[", "key", "]", "]", ".", "each", "do", "|", "value", "|", "arrays", "<<", "[", "key", ",", "value", "]", "end", "end", "Pact", "::", "Reification", ".", "from_term", "(", "arrays", ")", "end" ]
This probably belongs somewhere else.
[ "This", "probably", "belongs", "somewhere", "else", "." ]
3c26b469cbb796fa0045bb617b64c41c6b13b547
https://github.com/pact-foundation/pact-mock_service/blob/3c26b469cbb796fa0045bb617b64c41c6b13b547/lib/pact/consumer_contract/request_decorator.rb#L62-L71
15,649
theforeman/foreman-tasks
app/services/foreman_tasks/proxy_selector.rb
ForemanTasks.ProxySelector.select_by_jobs_count
def select_by_jobs_count(proxies) exclude = @tasks.keys + @offline @tasks.merge!(get_counts(proxies - exclude)) next_proxy = @tasks.select { |proxy, _| proxies.include?(proxy) } .min_by { |_, job_count| job_count }.try(:first) @tasks[next_proxy] += 1 if next_proxy.present? next_proxy end
ruby
def select_by_jobs_count(proxies) exclude = @tasks.keys + @offline @tasks.merge!(get_counts(proxies - exclude)) next_proxy = @tasks.select { |proxy, _| proxies.include?(proxy) } .min_by { |_, job_count| job_count }.try(:first) @tasks[next_proxy] += 1 if next_proxy.present? next_proxy end
[ "def", "select_by_jobs_count", "(", "proxies", ")", "exclude", "=", "@tasks", ".", "keys", "+", "@offline", "@tasks", ".", "merge!", "(", "get_counts", "(", "proxies", "-", "exclude", ")", ")", "next_proxy", "=", "@tasks", ".", "select", "{", "|", "proxy", ",", "_", "|", "proxies", ".", "include?", "(", "proxy", ")", "}", ".", "min_by", "{", "|", "_", ",", "job_count", "|", "job_count", "}", ".", "try", "(", ":first", ")", "@tasks", "[", "next_proxy", "]", "+=", "1", "if", "next_proxy", ".", "present?", "next_proxy", "end" ]
Get the least loaded proxy from the given list of proxies
[ "Get", "the", "least", "loaded", "proxy", "from", "the", "given", "list", "of", "proxies" ]
d99094fa99d6b34324e6c8d10da4d012675c6e36
https://github.com/theforeman/foreman-tasks/blob/d99094fa99d6b34324e6c8d10da4d012675c6e36/app/services/foreman_tasks/proxy_selector.rb#L33-L40
15,650
theforeman/foreman-tasks
app/models/foreman_tasks/lock.rb
ForemanTasks.Lock.colliding_locks
def colliding_locks task_ids = task.self_and_parents.map(&:id) colliding_locks_scope = Lock.active.where(Lock.arel_table[:task_id].not_in(task_ids)) colliding_locks_scope = colliding_locks_scope.where(name: name, resource_id: resource_id, resource_type: resource_type) unless exclusive? colliding_locks_scope = colliding_locks_scope.where(:exclusive => true) end colliding_locks_scope end
ruby
def colliding_locks task_ids = task.self_and_parents.map(&:id) colliding_locks_scope = Lock.active.where(Lock.arel_table[:task_id].not_in(task_ids)) colliding_locks_scope = colliding_locks_scope.where(name: name, resource_id: resource_id, resource_type: resource_type) unless exclusive? colliding_locks_scope = colliding_locks_scope.where(:exclusive => true) end colliding_locks_scope end
[ "def", "colliding_locks", "task_ids", "=", "task", ".", "self_and_parents", ".", "map", "(", ":id", ")", "colliding_locks_scope", "=", "Lock", ".", "active", ".", "where", "(", "Lock", ".", "arel_table", "[", ":task_id", "]", ".", "not_in", "(", "task_ids", ")", ")", "colliding_locks_scope", "=", "colliding_locks_scope", ".", "where", "(", "name", ":", "name", ",", "resource_id", ":", "resource_id", ",", "resource_type", ":", "resource_type", ")", "unless", "exclusive?", "colliding_locks_scope", "=", "colliding_locks_scope", ".", "where", "(", ":exclusive", "=>", "true", ")", "end", "colliding_locks_scope", "end" ]
returns a scope of the locks colliding with this one
[ "returns", "a", "scope", "of", "the", "locks", "colliding", "with", "this", "one" ]
d99094fa99d6b34324e6c8d10da4d012675c6e36
https://github.com/theforeman/foreman-tasks/blob/d99094fa99d6b34324e6c8d10da4d012675c6e36/app/models/foreman_tasks/lock.rb#L53-L63
15,651
theforeman/foreman-tasks
app/models/foreman_tasks/remote_task.rb
ForemanTasks.RemoteTask.trigger
def trigger(proxy_action_name, input) response = begin proxy.trigger_task(proxy_action_name, input).merge('result' => 'success') rescue RestClient::Exception => e logger.warn "Could not trigger task on the smart proxy: #{e.message}" {} end update_from_batch_trigger(response) save! end
ruby
def trigger(proxy_action_name, input) response = begin proxy.trigger_task(proxy_action_name, input).merge('result' => 'success') rescue RestClient::Exception => e logger.warn "Could not trigger task on the smart proxy: #{e.message}" {} end update_from_batch_trigger(response) save! end
[ "def", "trigger", "(", "proxy_action_name", ",", "input", ")", "response", "=", "begin", "proxy", ".", "trigger_task", "(", "proxy_action_name", ",", "input", ")", ".", "merge", "(", "'result'", "=>", "'success'", ")", "rescue", "RestClient", "::", "Exception", "=>", "e", "logger", ".", "warn", "\"Could not trigger task on the smart proxy: #{e.message}\"", "{", "}", "end", "update_from_batch_trigger", "(", "response", ")", "save!", "end" ]
Triggers a task on the proxy "the old way"
[ "Triggers", "a", "task", "on", "the", "proxy", "the", "old", "way" ]
d99094fa99d6b34324e6c8d10da4d012675c6e36
https://github.com/theforeman/foreman-tasks/blob/d99094fa99d6b34324e6c8d10da4d012675c6e36/app/models/foreman_tasks/remote_task.rb#L16-L25
15,652
theforeman/foreman-tasks
app/lib/actions/proxy_action.rb
Actions.ProxyAction.fill_continuous_output
def fill_continuous_output(continuous_output) failed_proxy_tasks.each do |failure_data| message = _('Initialization error: %s') % "#{failure_data[:exception_class]} - #{failure_data[:exception_message]}" continuous_output.add_output(message, 'debug', failure_data[:timestamp]) end end
ruby
def fill_continuous_output(continuous_output) failed_proxy_tasks.each do |failure_data| message = _('Initialization error: %s') % "#{failure_data[:exception_class]} - #{failure_data[:exception_message]}" continuous_output.add_output(message, 'debug', failure_data[:timestamp]) end end
[ "def", "fill_continuous_output", "(", "continuous_output", ")", "failed_proxy_tasks", ".", "each", "do", "|", "failure_data", "|", "message", "=", "_", "(", "'Initialization error: %s'", ")", "%", "\"#{failure_data[:exception_class]} - #{failure_data[:exception_message]}\"", "continuous_output", ".", "add_output", "(", "message", ",", "'debug'", ",", "failure_data", "[", ":timestamp", "]", ")", "end", "end" ]
The proxy action is able to contribute to continuous output
[ "The", "proxy", "action", "is", "able", "to", "contribute", "to", "continuous", "output" ]
d99094fa99d6b34324e6c8d10da4d012675c6e36
https://github.com/theforeman/foreman-tasks/blob/d99094fa99d6b34324e6c8d10da4d012675c6e36/app/lib/actions/proxy_action.rb#L167-L173
15,653
theforeman/foreman-tasks
app/lib/actions/recurring_action.rb
Actions.RecurringAction.trigger_repeat
def trigger_repeat(execution_plan) request_id = ::Logging.mdc['request'] ::Logging.mdc['request'] = SecureRandom.uuid if execution_plan.delay_record && recurring_logic_task_group args = execution_plan.delay_record.args logic = recurring_logic_task_group.recurring_logic logic.trigger_repeat_after(task.start_at, self.class, *args) end ensure ::Logging.mdc['request'] = request_id end
ruby
def trigger_repeat(execution_plan) request_id = ::Logging.mdc['request'] ::Logging.mdc['request'] = SecureRandom.uuid if execution_plan.delay_record && recurring_logic_task_group args = execution_plan.delay_record.args logic = recurring_logic_task_group.recurring_logic logic.trigger_repeat_after(task.start_at, self.class, *args) end ensure ::Logging.mdc['request'] = request_id end
[ "def", "trigger_repeat", "(", "execution_plan", ")", "request_id", "=", "::", "Logging", ".", "mdc", "[", "'request'", "]", "::", "Logging", ".", "mdc", "[", "'request'", "]", "=", "SecureRandom", ".", "uuid", "if", "execution_plan", ".", "delay_record", "&&", "recurring_logic_task_group", "args", "=", "execution_plan", ".", "delay_record", ".", "args", "logic", "=", "recurring_logic_task_group", ".", "recurring_logic", "logic", ".", "trigger_repeat_after", "(", "task", ".", "start_at", ",", "self", ".", "class", ",", "args", ")", "end", "ensure", "::", "Logging", ".", "mdc", "[", "'request'", "]", "=", "request_id", "end" ]
Hook to be called when a repetition needs to be triggered. This either happens when the plan goes into planned state or when it fails.
[ "Hook", "to", "be", "called", "when", "a", "repetition", "needs", "to", "be", "triggered", ".", "This", "either", "happens", "when", "the", "plan", "goes", "into", "planned", "state", "or", "when", "it", "fails", "." ]
d99094fa99d6b34324e6c8d10da4d012675c6e36
https://github.com/theforeman/foreman-tasks/blob/d99094fa99d6b34324e6c8d10da4d012675c6e36/app/lib/actions/recurring_action.rb#L14-L24
15,654
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/repos/following.rb
BitBucket.Repos::Following.followers
def followers(user_name, repo_name, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? normalize! params response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/followers/", params) return response unless block_given? response.each { |el| yield el } end
ruby
def followers(user_name, repo_name, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? normalize! params response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/followers/", params) return response unless block_given? response.each { |el| yield el } end
[ "def", "followers", "(", "user_name", ",", "repo_name", ",", "params", "=", "{", "}", ")", "_update_user_repo_params", "(", "user_name", ",", "repo_name", ")", "_validate_user_repo_params", "(", "user", ",", "repo", ")", "unless", "user?", "&&", "repo?", "normalize!", "params", "response", "=", "get_request", "(", "\"/1.0/repositories/#{user}/#{repo.downcase}/followers/\"", ",", "params", ")", "return", "response", "unless", "block_given?", "response", ".", "each", "{", "|", "el", "|", "yield", "el", "}", "end" ]
List repo followers = Examples bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name' bitbucket.repos.following.followers bitbucket.repos.following.followers { |watcher| ... }
[ "List", "repo", "followers" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/following.rb#L13-L21
15,655
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/repos/following.rb
BitBucket.Repos::Following.followed
def followed(*args) params = args.extract_options! normalize! params response = get_request("/1.0/user/follows", params) return response unless block_given? response.each { |el| yield el } end
ruby
def followed(*args) params = args.extract_options! normalize! params response = get_request("/1.0/user/follows", params) return response unless block_given? response.each { |el| yield el } end
[ "def", "followed", "(", "*", "args", ")", "params", "=", "args", ".", "extract_options!", "normalize!", "params", "response", "=", "get_request", "(", "\"/1.0/user/follows\"", ",", "params", ")", "return", "response", "unless", "block_given?", "response", ".", "each", "{", "|", "el", "|", "yield", "el", "}", "end" ]
List repos being followed by the authenticated user = Examples bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...' bitbucket.repos.following.followed
[ "List", "repos", "being", "followed", "by", "the", "authenticated", "user" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/following.rb#L29-L36
15,656
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/repos/components.rb
BitBucket.Repos::Components.get
def get(user_name, repo_name, component_id, params={}) update_and_validate_user_repo_params(user_name, repo_name) normalize! params get_request("/2.0/repositories/#{user}/#{repo.downcase}/components/#{component_id}", params) end
ruby
def get(user_name, repo_name, component_id, params={}) update_and_validate_user_repo_params(user_name, repo_name) normalize! params get_request("/2.0/repositories/#{user}/#{repo.downcase}/components/#{component_id}", params) end
[ "def", "get", "(", "user_name", ",", "repo_name", ",", "component_id", ",", "params", "=", "{", "}", ")", "update_and_validate_user_repo_params", "(", "user_name", ",", "repo_name", ")", "normalize!", "params", "get_request", "(", "\"/2.0/repositories/#{user}/#{repo.downcase}/components/#{component_id}\"", ",", "params", ")", "end" ]
Get a component by it's ID = Examples bitbucket = BitBucket.new bitbucket.repos.components.get 'user-name', 'repo-name', 1
[ "Get", "a", "component", "by", "it", "s", "ID" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/components.rb#L29-L34
15,657
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/repos/services.rb
BitBucket.Repos::Services.create
def create(user_name, repo_name, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? normalize! params assert_required_keys(REQUIRED_KEY_PARAM_NAMES, params) post_request("/1.0/repositories/#{user}/#{repo.downcase}/services", params) end
ruby
def create(user_name, repo_name, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? normalize! params assert_required_keys(REQUIRED_KEY_PARAM_NAMES, params) post_request("/1.0/repositories/#{user}/#{repo.downcase}/services", params) end
[ "def", "create", "(", "user_name", ",", "repo_name", ",", "params", "=", "{", "}", ")", "_update_user_repo_params", "(", "user_name", ",", "repo_name", ")", "_validate_user_repo_params", "(", "user", ",", "repo", ")", "unless", "user?", "&&", "repo?", "normalize!", "params", "assert_required_keys", "(", "REQUIRED_KEY_PARAM_NAMES", ",", "params", ")", "post_request", "(", "\"/1.0/repositories/#{user}/#{repo.downcase}/services\"", ",", "params", ")", "end" ]
Create a service = Inputs * <tt>:type</tt> - One of the supported services. The type is a case-insensitive value. = Examples bitbucket = BitBucket.new bitbucket.repos.services.create 'user-name', 'repo-name', "type" => "Basecamp", "Password" => "...", "Username" => "...", "Discussion URL" => "..."
[ "Create", "a", "service" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/services.rb#L55-L62
15,658
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/repos/services.rb
BitBucket.Repos::Services.edit
def edit(user_name, repo_name, service_id, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? _validate_presence_of(service_id) normalize! params put_request("/1.0/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params) end
ruby
def edit(user_name, repo_name, service_id, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? _validate_presence_of(service_id) normalize! params put_request("/1.0/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params) end
[ "def", "edit", "(", "user_name", ",", "repo_name", ",", "service_id", ",", "params", "=", "{", "}", ")", "_update_user_repo_params", "(", "user_name", ",", "repo_name", ")", "_validate_user_repo_params", "(", "user", ",", "repo", ")", "unless", "user?", "&&", "repo?", "_validate_presence_of", "(", "service_id", ")", "normalize!", "params", "put_request", "(", "\"/1.0/repositories/#{user}/#{repo.downcase}/services/#{service_id}\"", ",", "params", ")", "end" ]
Edit a service = Inputs * <tt>:type</tt> - One of the supported services. The type is a case-insensitive value. = Examples bitbucket = BitBucket.new bitbucket.repos.services.edit 'user-name', 'repo-name', 109172378, "type" => "Basecamp", "Password" => "...", "Username" => "...", "Discussion URL" => "..."
[ "Edit", "a", "service" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/services.rb#L77-L85
15,659
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/repos/default_reviewers.rb
BitBucket.Repos::DefaultReviewers.get
def get(user_name, repo_name, reviewer_username, params={}) update_and_validate_user_repo_params(user_name, repo_name) normalize! params get_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params) end
ruby
def get(user_name, repo_name, reviewer_username, params={}) update_and_validate_user_repo_params(user_name, repo_name) normalize! params get_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params) end
[ "def", "get", "(", "user_name", ",", "repo_name", ",", "reviewer_username", ",", "params", "=", "{", "}", ")", "update_and_validate_user_repo_params", "(", "user_name", ",", "repo_name", ")", "normalize!", "params", "get_request", "(", "\"/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}\"", ",", "params", ")", "end" ]
Get a default reviewer's info = Examples bitbucket = BitBucket.new bitbucket.repos.default_reviewers.get 'user-name', 'repo-name', 'reviewer-username'
[ "Get", "a", "default", "reviewer", "s", "info" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/default_reviewers.rb#L27-L32
15,660
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/repos/default_reviewers.rb
BitBucket.Repos::DefaultReviewers.add
def add(user_name, repo_name, reviewer_username, params={}) update_and_validate_user_repo_params(user_name, repo_name) normalize! params put_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params) end
ruby
def add(user_name, repo_name, reviewer_username, params={}) update_and_validate_user_repo_params(user_name, repo_name) normalize! params put_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params) end
[ "def", "add", "(", "user_name", ",", "repo_name", ",", "reviewer_username", ",", "params", "=", "{", "}", ")", "update_and_validate_user_repo_params", "(", "user_name", ",", "repo_name", ")", "normalize!", "params", "put_request", "(", "\"/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}\"", ",", "params", ")", "end" ]
Add a user to the default-reviewers list for the repo = Examples bitbucket = BitBucket.new bitbucket.repos.default_reviewers.add 'user-name', 'repo-name', 'reviewer-username'
[ "Add", "a", "user", "to", "the", "default", "-", "reviewers", "list", "for", "the", "repo" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/default_reviewers.rb#L40-L45
15,661
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/repos/default_reviewers.rb
BitBucket.Repos::DefaultReviewers.remove
def remove(user_name, repo_name, reviewer_username, params={}) update_and_validate_user_repo_params(user_name, repo_name) normalize! params delete_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params) end
ruby
def remove(user_name, repo_name, reviewer_username, params={}) update_and_validate_user_repo_params(user_name, repo_name) normalize! params delete_request("/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}", params) end
[ "def", "remove", "(", "user_name", ",", "repo_name", ",", "reviewer_username", ",", "params", "=", "{", "}", ")", "update_and_validate_user_repo_params", "(", "user_name", ",", "repo_name", ")", "normalize!", "params", "delete_request", "(", "\"/2.0/repositories/#{user_name}/#{repo_name}/default-reviewers/#{reviewer_username}\"", ",", "params", ")", "end" ]
Remove a user from the default-reviewers list for the repo = Examples bitbucket = BitBucket.new bitbucket.repos.default_reviewers.remove 'user-name', 'repo-name', 'reviewer-username'
[ "Remove", "a", "user", "from", "the", "default", "-", "reviewers", "list", "for", "the", "repo" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/default_reviewers.rb#L53-L57
15,662
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/issues/components.rb
BitBucket.Issues::Components.get
def get(user_name, repo_name, component_id, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? _validate_presence_of component_id normalize! params get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params) end
ruby
def get(user_name, repo_name, component_id, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? _validate_presence_of component_id normalize! params get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params) end
[ "def", "get", "(", "user_name", ",", "repo_name", ",", "component_id", ",", "params", "=", "{", "}", ")", "_update_user_repo_params", "(", "user_name", ",", "repo_name", ")", "_validate_user_repo_params", "(", "user", ",", "repo", ")", "unless", "user?", "&&", "repo?", "_validate_presence_of", "component_id", "normalize!", "params", "get_request", "(", "\"/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}\"", ",", "params", ")", "end" ]
Get a single component = Examples bitbucket = BitBucket.new bitbucket.issues.components.find 'user-name', 'repo-name', 'component-id'
[ "Get", "a", "single", "component" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/issues/components.rb#L36-L43
15,663
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/issues/components.rb
BitBucket.Issues::Components.update
def update(user_name, repo_name, component_id, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? _validate_presence_of component_id normalize! params filter! VALID_COMPONENT_INPUTS, params assert_required_keys(VALID_COMPONENT_INPUTS, params) put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params) end
ruby
def update(user_name, repo_name, component_id, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? _validate_presence_of component_id normalize! params filter! VALID_COMPONENT_INPUTS, params assert_required_keys(VALID_COMPONENT_INPUTS, params) put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params) end
[ "def", "update", "(", "user_name", ",", "repo_name", ",", "component_id", ",", "params", "=", "{", "}", ")", "_update_user_repo_params", "(", "user_name", ",", "repo_name", ")", "_validate_user_repo_params", "(", "user", ",", "repo", ")", "unless", "user?", "&&", "repo?", "_validate_presence_of", "component_id", "normalize!", "params", "filter!", "VALID_COMPONENT_INPUTS", ",", "params", "assert_required_keys", "(", "VALID_COMPONENT_INPUTS", ",", "params", ")", "put_request", "(", "\"/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}\"", ",", "params", ")", "end" ]
Update a component = Inputs <tt>:name</tt> - Required string = Examples @bitbucket = BitBucket.new @bitbucket.issues.components.update 'user-name', 'repo-name', 'component-id', :name => 'API'
[ "Update", "a", "component" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/issues/components.rb#L76-L86
15,664
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/issues/components.rb
BitBucket.Issues::Components.delete
def delete(user_name, repo_name, component_id, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? _validate_presence_of component_id normalize! params delete_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params) end
ruby
def delete(user_name, repo_name, component_id, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? _validate_presence_of component_id normalize! params delete_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params) end
[ "def", "delete", "(", "user_name", ",", "repo_name", ",", "component_id", ",", "params", "=", "{", "}", ")", "_update_user_repo_params", "(", "user_name", ",", "repo_name", ")", "_validate_user_repo_params", "(", "user", ",", "repo", ")", "unless", "user?", "&&", "repo?", "_validate_presence_of", "component_id", "normalize!", "params", "delete_request", "(", "\"/1.0/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}\"", ",", "params", ")", "end" ]
Delete a component = Examples bitbucket = BitBucket.new bitbucket.issues.components.delete 'user-name', 'repo-name', 'component-id'
[ "Delete", "a", "component" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/issues/components.rb#L95-L103
15,665
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/repos/keys.rb
BitBucket.Repos::Keys.create
def create(user_name, repo_name, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? normalize! params filter! VALID_KEY_PARAM_NAMES, params assert_required_keys(VALID_KEY_PARAM_NAMES, params) options = { headers: { "Content-Type" => "application/json" } } post_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/", params, options) end
ruby
def create(user_name, repo_name, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? normalize! params filter! VALID_KEY_PARAM_NAMES, params assert_required_keys(VALID_KEY_PARAM_NAMES, params) options = { headers: { "Content-Type" => "application/json" } } post_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/", params, options) end
[ "def", "create", "(", "user_name", ",", "repo_name", ",", "params", "=", "{", "}", ")", "_update_user_repo_params", "(", "user_name", ",", "repo_name", ")", "_validate_user_repo_params", "(", "user", ",", "repo", ")", "unless", "user?", "&&", "repo?", "normalize!", "params", "filter!", "VALID_KEY_PARAM_NAMES", ",", "params", "assert_required_keys", "(", "VALID_KEY_PARAM_NAMES", ",", "params", ")", "options", "=", "{", "headers", ":", "{", "\"Content-Type\"", "=>", "\"application/json\"", "}", "}", "post_request", "(", "\"/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/\"", ",", "params", ",", "options", ")", "end" ]
Create a key = Inputs * <tt>:title</tt> - Required string. * <tt>:key</tt> - Required string. = Examples bitbucket = BitBucket.new bitbucket.repos.keys.create 'user-name', 'repo-name', "label" => "octocat@octomac", "key" => "ssh-rsa AAA..."
[ "Create", "a", "key" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/keys.rb#L38-L47
15,666
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/repos/keys.rb
BitBucket.Repos::Keys.edit
def edit(user_name, repo_name, key_id, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? _validate_presence_of key_id normalize! params filter! VALID_KEY_PARAM_NAMES, params put_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/#{key_id}", params) end
ruby
def edit(user_name, repo_name, key_id, params={}) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? _validate_presence_of key_id normalize! params filter! VALID_KEY_PARAM_NAMES, params put_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/#{key_id}", params) end
[ "def", "edit", "(", "user_name", ",", "repo_name", ",", "key_id", ",", "params", "=", "{", "}", ")", "_update_user_repo_params", "(", "user_name", ",", "repo_name", ")", "_validate_user_repo_params", "(", "user", ",", "repo", ")", "unless", "user?", "&&", "repo?", "_validate_presence_of", "key_id", "normalize!", "params", "filter!", "VALID_KEY_PARAM_NAMES", ",", "params", "put_request", "(", "\"/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/#{key_id}\"", ",", "params", ")", "end" ]
Edit a key = Inputs * <tt>:title</tt> - Required string. * <tt>:key</tt> - Required string. = Examples bitbucket = BitBucket.new bitbucket.repos.keys.edit 'user-name', 'repo-name', "label" => "octocat@octomac", "key" => "ssh-rsa AAA..."
[ "Edit", "a", "key" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/repos/keys.rb#L61-L70
15,667
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/teams.rb
BitBucket.Teams.members
def members(team_name) response = get_request("/2.0/teams/#{team_name.to_s}/members") return response["values"] unless block_given? response["values"].each { |el| yield el } end
ruby
def members(team_name) response = get_request("/2.0/teams/#{team_name.to_s}/members") return response["values"] unless block_given? response["values"].each { |el| yield el } end
[ "def", "members", "(", "team_name", ")", "response", "=", "get_request", "(", "\"/2.0/teams/#{team_name.to_s}/members\"", ")", "return", "response", "[", "\"values\"", "]", "unless", "block_given?", "response", "[", "\"values\"", "]", ".", "each", "{", "|", "el", "|", "yield", "el", "}", "end" ]
List members of the provided team = Examples bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...' bitbucket.teams.members(:team_name_here) bitbucket.teams.members(:team_name_here) { |member| ... }
[ "List", "members", "of", "the", "provided", "team" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/teams.rb#L42-L46
15,668
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/teams.rb
BitBucket.Teams.followers
def followers(team_name) response = get_request("/2.0/teams/#{team_name.to_s}/followers") return response["values"] unless block_given? response["values"].each { |el| yield el } end
ruby
def followers(team_name) response = get_request("/2.0/teams/#{team_name.to_s}/followers") return response["values"] unless block_given? response["values"].each { |el| yield el } end
[ "def", "followers", "(", "team_name", ")", "response", "=", "get_request", "(", "\"/2.0/teams/#{team_name.to_s}/followers\"", ")", "return", "response", "[", "\"values\"", "]", "unless", "block_given?", "response", "[", "\"values\"", "]", ".", "each", "{", "|", "el", "|", "yield", "el", "}", "end" ]
List followers of the provided team = Examples bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...' bitbucket.teams.followers(:team_name_here) bitbucket.teams.followers(:team_name_here) { |follower| ... }
[ "List", "followers", "of", "the", "provided", "team" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/teams.rb#L54-L58
15,669
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/teams.rb
BitBucket.Teams.following
def following(team_name) response = get_request("/2.0/teams/#{team_name.to_s}/following") return response["values"] unless block_given? response["values"].each { |el| yield el } end
ruby
def following(team_name) response = get_request("/2.0/teams/#{team_name.to_s}/following") return response["values"] unless block_given? response["values"].each { |el| yield el } end
[ "def", "following", "(", "team_name", ")", "response", "=", "get_request", "(", "\"/2.0/teams/#{team_name.to_s}/following\"", ")", "return", "response", "[", "\"values\"", "]", "unless", "block_given?", "response", "[", "\"values\"", "]", ".", "each", "{", "|", "el", "|", "yield", "el", "}", "end" ]
List accounts following the provided team = Examples bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...' bitbucket.teams.following(:team_name_here) bitbucket.teams.following(:team_name_here) { |followee| ... }
[ "List", "accounts", "following", "the", "provided", "team" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/teams.rb#L66-L70
15,670
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/teams.rb
BitBucket.Teams.repos
def repos(team_name) response = get_request("/2.0/repositories/#{team_name.to_s}") return response["values"] unless block_given? response["values"].each { |el| yield el } end
ruby
def repos(team_name) response = get_request("/2.0/repositories/#{team_name.to_s}") return response["values"] unless block_given? response["values"].each { |el| yield el } end
[ "def", "repos", "(", "team_name", ")", "response", "=", "get_request", "(", "\"/2.0/repositories/#{team_name.to_s}\"", ")", "return", "response", "[", "\"values\"", "]", "unless", "block_given?", "response", "[", "\"values\"", "]", ".", "each", "{", "|", "el", "|", "yield", "el", "}", "end" ]
List repos for provided team Private repos will only be returned if the user is authorized to view them = Examples bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...' bitbucket.teams.repos(:team_name_here) bitbucket.teams.repos(:team_name_here) { |repo| ... }
[ "List", "repos", "for", "provided", "team", "Private", "repos", "will", "only", "be", "returned", "if", "the", "user", "is", "authorized", "to", "view", "them" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/teams.rb#L79-L83
15,671
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/issues.rb
BitBucket.Issues.list_repo
def list_repo(user_name, repo_name, params={ }) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? normalize! params filter! VALID_ISSUE_PARAM_NAMES, params # _merge_mime_type(:issue, params) assert_valid_values(VALID_ISSUE_PARAM_VALUES, params) response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues", params) return response.issues unless block_given? response.issues.each { |el| yield el } end
ruby
def list_repo(user_name, repo_name, params={ }) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? normalize! params filter! VALID_ISSUE_PARAM_NAMES, params # _merge_mime_type(:issue, params) assert_valid_values(VALID_ISSUE_PARAM_VALUES, params) response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues", params) return response.issues unless block_given? response.issues.each { |el| yield el } end
[ "def", "list_repo", "(", "user_name", ",", "repo_name", ",", "params", "=", "{", "}", ")", "_update_user_repo_params", "(", "user_name", ",", "repo_name", ")", "_validate_user_repo_params", "(", "user", ",", "repo", ")", "unless", "user?", "&&", "repo?", "normalize!", "params", "filter!", "VALID_ISSUE_PARAM_NAMES", ",", "params", "# _merge_mime_type(:issue, params)", "assert_valid_values", "(", "VALID_ISSUE_PARAM_VALUES", ",", "params", ")", "response", "=", "get_request", "(", "\"/1.0/repositories/#{user}/#{repo.downcase}/issues\"", ",", "params", ")", "return", "response", ".", "issues", "unless", "block_given?", "response", ".", "issues", ".", "each", "{", "|", "el", "|", "yield", "el", "}", "end" ]
List issues for a repository = Inputs <tt>:limit</tt> - Optional - Number of issues to retrieve, default 15 <tt>:start</tt> - Optional - Issue offset, default 0 <tt>:search</tt> - Optional - A string to search for <tt>:sort</tt> - Optional - Sorts the output by any of the metadata fields <tt>:title</tt> - Optional - Contains a filter operation to restrict the list of issues by the issue title <tt>:content</tt> - Optional - Contains a filter operation to restrict the list of issues by the issue content <tt>:version</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the version <tt>:milestone</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the milestone <tt>:component</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the component <tt>:kind</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the issue kind <tt>:status</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the issue status <tt>:responsible</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the user responsible <tt>:reported_by</tt> - Optional - Contains a filter operation to restrict the list of issues by the user that reported the issue = Examples bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name' bitbucket.issues.list_repo :filter => 'kind=bug&kind=enhancement'
[ "List", "issues", "for", "a", "repository" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/issues.rb#L76-L88
15,672
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/issues.rb
BitBucket.Issues.create
def create(user_name, repo_name, params={ }) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? normalize! params _merge_user_into_params!(params) unless params.has_key?('user') # _merge_mime_type(:issue, params) filter! VALID_ISSUE_PARAM_NAMES, params assert_required_keys(%w[ title ], params) post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/", params) end
ruby
def create(user_name, repo_name, params={ }) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? normalize! params _merge_user_into_params!(params) unless params.has_key?('user') # _merge_mime_type(:issue, params) filter! VALID_ISSUE_PARAM_NAMES, params assert_required_keys(%w[ title ], params) post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/", params) end
[ "def", "create", "(", "user_name", ",", "repo_name", ",", "params", "=", "{", "}", ")", "_update_user_repo_params", "(", "user_name", ",", "repo_name", ")", "_validate_user_repo_params", "(", "user", ",", "repo", ")", "unless", "user?", "&&", "repo?", "normalize!", "params", "_merge_user_into_params!", "(", "params", ")", "unless", "params", ".", "has_key?", "(", "'user'", ")", "# _merge_mime_type(:issue, params)", "filter!", "VALID_ISSUE_PARAM_NAMES", ",", "params", "assert_required_keys", "(", "%w[", "title", "]", ",", "params", ")", "post_request", "(", "\"/1.0/repositories/#{user}/#{repo.downcase}/issues/\"", ",", "params", ")", "end" ]
Create an issue = Inputs <tt>:title</tt> - Required string <tt>:content</tt> - Optional string <tt>:responsible</tt> - Optional string - Login for the user that this issue should be assigned to. <tt>:milestone</tt> - Optional number - Milestone to associate this issue with <tt>:version</tt> - Optional number - Version to associate this issue with <tt>:component</tt> - Optional number - Component to associate this issue with <tt>:priority</tt> - Optional string - The priority of this issue * <tt>trivial</tt> * <tt>minor</tt> * <tt>major</tt> * <tt>critical</tt> * <tt>blocker</tt> <tt>:status</tt> - Optional string - The status of this issue * <tt>new</tt> * <tt>open</tt> * <tt>resolved</tt> * <tt>on hold</tt> * <tt>invalid</tt> * <tt>duplicate</tt> * <tt>wontfix</tt> <tt>:kind</tt> - Optional string - The kind of issue * <tt>bug</tt> * <tt>enhancement</tt> * <tt>proposal</tt> * <tt>task</tt> = Examples bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name' bitbucket.issues.create "title" => "Found a bug", "content" => "I'm having a problem with this.", "responsible" => "octocat", "milestone" => 1, "priority" => "blocker"
[ "Create", "an", "issue" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/issues.rb#L166-L177
15,673
bitbucket-rest-api/bitbucket
lib/bitbucket_rest_api/api.rb
BitBucket.API.method_missing
def method_missing(method, *args, &block) # :nodoc: case method.to_s when /^(.*)\?$/ return !self.send($1.to_s).nil? when /^clear_(.*)$/ self.send("#{$1.to_s}=", nil) else super end end
ruby
def method_missing(method, *args, &block) # :nodoc: case method.to_s when /^(.*)\?$/ return !self.send($1.to_s).nil? when /^clear_(.*)$/ self.send("#{$1.to_s}=", nil) else super end end
[ "def", "method_missing", "(", "method", ",", "*", "args", ",", "&", "block", ")", "# :nodoc:", "case", "method", ".", "to_s", "when", "/", "\\?", "/", "return", "!", "self", ".", "send", "(", "$1", ".", "to_s", ")", ".", "nil?", "when", "/", "/", "self", ".", "send", "(", "\"#{$1.to_s}=\"", ",", "nil", ")", "else", "super", "end", "end" ]
Responds to attribute query or attribute clear
[ "Responds", "to", "attribute", "query", "or", "attribute", "clear" ]
e03b6935104d59b3d9a922474c3dc210a5ef76d2
https://github.com/bitbucket-rest-api/bitbucket/blob/e03b6935104d59b3d9a922474c3dc210a5ef76d2/lib/bitbucket_rest_api/api.rb#L71-L80
15,674
janko/down
lib/down/utils.rb
Down.Utils.filename_from_content_disposition
def filename_from_content_disposition(content_disposition) content_disposition = content_disposition.to_s escaped_filename = content_disposition[/filename\*=UTF-8''(\S+)/, 1] || content_disposition[/filename="([^"]*)"/, 1] || content_disposition[/filename=(\S+)/, 1] filename = CGI.unescape(escaped_filename.to_s) filename unless filename.empty? end
ruby
def filename_from_content_disposition(content_disposition) content_disposition = content_disposition.to_s escaped_filename = content_disposition[/filename\*=UTF-8''(\S+)/, 1] || content_disposition[/filename="([^"]*)"/, 1] || content_disposition[/filename=(\S+)/, 1] filename = CGI.unescape(escaped_filename.to_s) filename unless filename.empty? end
[ "def", "filename_from_content_disposition", "(", "content_disposition", ")", "content_disposition", "=", "content_disposition", ".", "to_s", "escaped_filename", "=", "content_disposition", "[", "/", "\\*", "\\S", "/", ",", "1", "]", "||", "content_disposition", "[", "/", "/", ",", "1", "]", "||", "content_disposition", "[", "/", "\\S", "/", ",", "1", "]", "filename", "=", "CGI", ".", "unescape", "(", "escaped_filename", ".", "to_s", ")", "filename", "unless", "filename", ".", "empty?", "end" ]
Retrieves potential filename from the "Content-Disposition" header.
[ "Retrieves", "potential", "filename", "from", "the", "Content", "-", "Disposition", "header", "." ]
300ed69edd4de2ea8298f1b43e99de091976fe93
https://github.com/janko/down/blob/300ed69edd4de2ea8298f1b43e99de091976fe93/lib/down/utils.rb#L8-L19
15,675
janko/down
lib/down/wget.rb
Down.Wget.download
def download(url, *args, max_size: nil, content_length_proc: nil, progress_proc: nil, destination: nil, **options) io = open(url, *args, **options, rewindable: false) content_length_proc.call(io.size) if content_length_proc && io.size if max_size && io.size && io.size > max_size raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)" end extname = File.extname(URI(url).path) tempfile = Tempfile.new(["down-wget", extname], binmode: true) until io.eof? chunk = io.readpartial(nil, buffer ||= String.new) tempfile.write(chunk) progress_proc.call(tempfile.size) if progress_proc if max_size && tempfile.size > max_size raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)" end end tempfile.open # flush written content tempfile.extend Down::Wget::DownloadedFile tempfile.url = url tempfile.headers = io.data[:headers] download_result(tempfile, destination) rescue tempfile.close! if tempfile raise ensure io.close if io end
ruby
def download(url, *args, max_size: nil, content_length_proc: nil, progress_proc: nil, destination: nil, **options) io = open(url, *args, **options, rewindable: false) content_length_proc.call(io.size) if content_length_proc && io.size if max_size && io.size && io.size > max_size raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)" end extname = File.extname(URI(url).path) tempfile = Tempfile.new(["down-wget", extname], binmode: true) until io.eof? chunk = io.readpartial(nil, buffer ||= String.new) tempfile.write(chunk) progress_proc.call(tempfile.size) if progress_proc if max_size && tempfile.size > max_size raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)" end end tempfile.open # flush written content tempfile.extend Down::Wget::DownloadedFile tempfile.url = url tempfile.headers = io.data[:headers] download_result(tempfile, destination) rescue tempfile.close! if tempfile raise ensure io.close if io end
[ "def", "download", "(", "url", ",", "*", "args", ",", "max_size", ":", "nil", ",", "content_length_proc", ":", "nil", ",", "progress_proc", ":", "nil", ",", "destination", ":", "nil", ",", "**", "options", ")", "io", "=", "open", "(", "url", ",", "args", ",", "**", "options", ",", "rewindable", ":", "false", ")", "content_length_proc", ".", "call", "(", "io", ".", "size", ")", "if", "content_length_proc", "&&", "io", ".", "size", "if", "max_size", "&&", "io", ".", "size", "&&", "io", ".", "size", ">", "max_size", "raise", "Down", "::", "TooLarge", ",", "\"file is too large (max is #{max_size/1024/1024}MB)\"", "end", "extname", "=", "File", ".", "extname", "(", "URI", "(", "url", ")", ".", "path", ")", "tempfile", "=", "Tempfile", ".", "new", "(", "[", "\"down-wget\"", ",", "extname", "]", ",", "binmode", ":", "true", ")", "until", "io", ".", "eof?", "chunk", "=", "io", ".", "readpartial", "(", "nil", ",", "buffer", "||=", "String", ".", "new", ")", "tempfile", ".", "write", "(", "chunk", ")", "progress_proc", ".", "call", "(", "tempfile", ".", "size", ")", "if", "progress_proc", "if", "max_size", "&&", "tempfile", ".", "size", ">", "max_size", "raise", "Down", "::", "TooLarge", ",", "\"file is too large (max is #{max_size/1024/1024}MB)\"", "end", "end", "tempfile", ".", "open", "# flush written content", "tempfile", ".", "extend", "Down", "::", "Wget", "::", "DownloadedFile", "tempfile", ".", "url", "=", "url", "tempfile", ".", "headers", "=", "io", ".", "data", "[", ":headers", "]", "download_result", "(", "tempfile", ",", "destination", ")", "rescue", "tempfile", ".", "close!", "if", "tempfile", "raise", "ensure", "io", ".", "close", "if", "io", "end" ]
Initializes the backend with common defaults. Downlods the remote file to disk. Accepts wget command-line options and some additional options as well.
[ "Initializes", "the", "backend", "with", "common", "defaults", ".", "Downlods", "the", "remote", "file", "to", "disk", ".", "Accepts", "wget", "command", "-", "line", "options", "and", "some", "additional", "options", "as", "well", "." ]
300ed69edd4de2ea8298f1b43e99de091976fe93
https://github.com/janko/down/blob/300ed69edd4de2ea8298f1b43e99de091976fe93/lib/down/wget.rb#L32-L68
15,676
janko/down
lib/down/wget.rb
Down.Wget.open
def open(url, *args, rewindable: true, **options) arguments = generate_command(url, *args, **options) command = Down::Wget::Command.execute(arguments) # Wrap the wget command output in an IO-like object. output = Down::ChunkedIO.new( chunks: command.enum_for(:output), on_close: command.method(:terminate), rewindable: false, ) # https://github.com/tmm1/http_parser.rb/issues/29#issuecomment-309976363 header_string = output.readpartial header_string << output.readpartial until header_string.include?("\r\n\r\n") header_string, first_chunk = header_string.split("\r\n\r\n", 2) # Use an HTTP parser to parse out the response headers. parser = HTTP::Parser.new parser << header_string if parser.headers.nil? output.close raise Down::Error, "failed to parse response headers" end headers = parser.headers status = parser.status_code content_length = headers["Content-Length"].to_i if headers["Content-Length"] charset = headers["Content-Type"][/;\s*charset=([^;]+)/i, 1] if headers["Content-Type"] # Create an Enumerator which will lazily retrieve chunks of response body. chunks = Enumerator.new do |yielder| yielder << first_chunk if first_chunk yielder << output.readpartial until output.eof? end Down::ChunkedIO.new( chunks: chunks, size: content_length, encoding: charset, rewindable: rewindable, on_close: output.method(:close), data: { status: status, headers: headers }, ) end
ruby
def open(url, *args, rewindable: true, **options) arguments = generate_command(url, *args, **options) command = Down::Wget::Command.execute(arguments) # Wrap the wget command output in an IO-like object. output = Down::ChunkedIO.new( chunks: command.enum_for(:output), on_close: command.method(:terminate), rewindable: false, ) # https://github.com/tmm1/http_parser.rb/issues/29#issuecomment-309976363 header_string = output.readpartial header_string << output.readpartial until header_string.include?("\r\n\r\n") header_string, first_chunk = header_string.split("\r\n\r\n", 2) # Use an HTTP parser to parse out the response headers. parser = HTTP::Parser.new parser << header_string if parser.headers.nil? output.close raise Down::Error, "failed to parse response headers" end headers = parser.headers status = parser.status_code content_length = headers["Content-Length"].to_i if headers["Content-Length"] charset = headers["Content-Type"][/;\s*charset=([^;]+)/i, 1] if headers["Content-Type"] # Create an Enumerator which will lazily retrieve chunks of response body. chunks = Enumerator.new do |yielder| yielder << first_chunk if first_chunk yielder << output.readpartial until output.eof? end Down::ChunkedIO.new( chunks: chunks, size: content_length, encoding: charset, rewindable: rewindable, on_close: output.method(:close), data: { status: status, headers: headers }, ) end
[ "def", "open", "(", "url", ",", "*", "args", ",", "rewindable", ":", "true", ",", "**", "options", ")", "arguments", "=", "generate_command", "(", "url", ",", "args", ",", "**", "options", ")", "command", "=", "Down", "::", "Wget", "::", "Command", ".", "execute", "(", "arguments", ")", "# Wrap the wget command output in an IO-like object.", "output", "=", "Down", "::", "ChunkedIO", ".", "new", "(", "chunks", ":", "command", ".", "enum_for", "(", ":output", ")", ",", "on_close", ":", "command", ".", "method", "(", ":terminate", ")", ",", "rewindable", ":", "false", ",", ")", "# https://github.com/tmm1/http_parser.rb/issues/29#issuecomment-309976363", "header_string", "=", "output", ".", "readpartial", "header_string", "<<", "output", ".", "readpartial", "until", "header_string", ".", "include?", "(", "\"\\r\\n\\r\\n\"", ")", "header_string", ",", "first_chunk", "=", "header_string", ".", "split", "(", "\"\\r\\n\\r\\n\"", ",", "2", ")", "# Use an HTTP parser to parse out the response headers.", "parser", "=", "HTTP", "::", "Parser", ".", "new", "parser", "<<", "header_string", "if", "parser", ".", "headers", ".", "nil?", "output", ".", "close", "raise", "Down", "::", "Error", ",", "\"failed to parse response headers\"", "end", "headers", "=", "parser", ".", "headers", "status", "=", "parser", ".", "status_code", "content_length", "=", "headers", "[", "\"Content-Length\"", "]", ".", "to_i", "if", "headers", "[", "\"Content-Length\"", "]", "charset", "=", "headers", "[", "\"Content-Type\"", "]", "[", "/", "\\s", "/i", ",", "1", "]", "if", "headers", "[", "\"Content-Type\"", "]", "# Create an Enumerator which will lazily retrieve chunks of response body.", "chunks", "=", "Enumerator", ".", "new", "do", "|", "yielder", "|", "yielder", "<<", "first_chunk", "if", "first_chunk", "yielder", "<<", "output", ".", "readpartial", "until", "output", ".", "eof?", "end", "Down", "::", "ChunkedIO", ".", "new", "(", "chunks", ":", "chunks", ",", "size", ":", "content_length", ",", "encoding", ":", "charset", ",", "rewindable", ":", "rewindable", ",", "on_close", ":", "output", ".", "method", "(", ":close", ")", ",", "data", ":", "{", "status", ":", "status", ",", "headers", ":", "headers", "}", ",", ")", "end" ]
Starts retrieving the remote file and returns an IO-like object which downloads the response body on-demand. Accepts wget command-line options.
[ "Starts", "retrieving", "the", "remote", "file", "and", "returns", "an", "IO", "-", "like", "object", "which", "downloads", "the", "response", "body", "on", "-", "demand", ".", "Accepts", "wget", "command", "-", "line", "options", "." ]
300ed69edd4de2ea8298f1b43e99de091976fe93
https://github.com/janko/down/blob/300ed69edd4de2ea8298f1b43e99de091976fe93/lib/down/wget.rb#L72-L117
15,677
janko/down
lib/down/wget.rb
Down.Wget.generate_command
def generate_command(url, *args, **options) command = %W[wget --no-verbose --save-headers -O -] options = @arguments.grep(Hash).inject({}, :merge).merge(options) args = @arguments.grep(->(o){!o.is_a?(Hash)}) + args (args + options.to_a).each do |option, value| if option.is_a?(String) command << option elsif option.length == 1 command << "-#{option}" else command << "--#{option.to_s.gsub("_", "-")}" end command << value.to_s unless value.nil? end command << url command end
ruby
def generate_command(url, *args, **options) command = %W[wget --no-verbose --save-headers -O -] options = @arguments.grep(Hash).inject({}, :merge).merge(options) args = @arguments.grep(->(o){!o.is_a?(Hash)}) + args (args + options.to_a).each do |option, value| if option.is_a?(String) command << option elsif option.length == 1 command << "-#{option}" else command << "--#{option.to_s.gsub("_", "-")}" end command << value.to_s unless value.nil? end command << url command end
[ "def", "generate_command", "(", "url", ",", "*", "args", ",", "**", "options", ")", "command", "=", "%W[", "wget", "--no-verbose", "--save-headers", "-O", "-", "]", "options", "=", "@arguments", ".", "grep", "(", "Hash", ")", ".", "inject", "(", "{", "}", ",", ":merge", ")", ".", "merge", "(", "options", ")", "args", "=", "@arguments", ".", "grep", "(", "->", "(", "o", ")", "{", "!", "o", ".", "is_a?", "(", "Hash", ")", "}", ")", "+", "args", "(", "args", "+", "options", ".", "to_a", ")", ".", "each", "do", "|", "option", ",", "value", "|", "if", "option", ".", "is_a?", "(", "String", ")", "command", "<<", "option", "elsif", "option", ".", "length", "==", "1", "command", "<<", "\"-#{option}\"", "else", "command", "<<", "\"--#{option.to_s.gsub(\"_\", \"-\")}\"", "end", "command", "<<", "value", ".", "to_s", "unless", "value", ".", "nil?", "end", "command", "<<", "url", "command", "end" ]
Generates the wget command.
[ "Generates", "the", "wget", "command", "." ]
300ed69edd4de2ea8298f1b43e99de091976fe93
https://github.com/janko/down/blob/300ed69edd4de2ea8298f1b43e99de091976fe93/lib/down/wget.rb#L122-L142
15,678
janko/down
lib/down/http.rb
Down.Http.download
def download(url, max_size: nil, progress_proc: nil, content_length_proc: nil, destination: nil, **options, &block) response = request(url, **options, &block) content_length_proc.call(response.content_length) if content_length_proc && response.content_length if max_size && response.content_length && response.content_length > max_size raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)" end extname = File.extname(response.uri.path) tempfile = Tempfile.new(["down-http", extname], binmode: true) stream_body(response) do |chunk| tempfile.write(chunk) chunk.clear # deallocate string progress_proc.call(tempfile.size) if progress_proc if max_size && tempfile.size > max_size raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)" end end tempfile.open # flush written content tempfile.extend Down::Http::DownloadedFile tempfile.url = response.uri.to_s tempfile.headers = response.headers.to_h download_result(tempfile, destination) rescue tempfile.close! if tempfile raise end
ruby
def download(url, max_size: nil, progress_proc: nil, content_length_proc: nil, destination: nil, **options, &block) response = request(url, **options, &block) content_length_proc.call(response.content_length) if content_length_proc && response.content_length if max_size && response.content_length && response.content_length > max_size raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)" end extname = File.extname(response.uri.path) tempfile = Tempfile.new(["down-http", extname], binmode: true) stream_body(response) do |chunk| tempfile.write(chunk) chunk.clear # deallocate string progress_proc.call(tempfile.size) if progress_proc if max_size && tempfile.size > max_size raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)" end end tempfile.open # flush written content tempfile.extend Down::Http::DownloadedFile tempfile.url = response.uri.to_s tempfile.headers = response.headers.to_h download_result(tempfile, destination) rescue tempfile.close! if tempfile raise end
[ "def", "download", "(", "url", ",", "max_size", ":", "nil", ",", "progress_proc", ":", "nil", ",", "content_length_proc", ":", "nil", ",", "destination", ":", "nil", ",", "**", "options", ",", "&", "block", ")", "response", "=", "request", "(", "url", ",", "**", "options", ",", "block", ")", "content_length_proc", ".", "call", "(", "response", ".", "content_length", ")", "if", "content_length_proc", "&&", "response", ".", "content_length", "if", "max_size", "&&", "response", ".", "content_length", "&&", "response", ".", "content_length", ">", "max_size", "raise", "Down", "::", "TooLarge", ",", "\"file is too large (max is #{max_size/1024/1024}MB)\"", "end", "extname", "=", "File", ".", "extname", "(", "response", ".", "uri", ".", "path", ")", "tempfile", "=", "Tempfile", ".", "new", "(", "[", "\"down-http\"", ",", "extname", "]", ",", "binmode", ":", "true", ")", "stream_body", "(", "response", ")", "do", "|", "chunk", "|", "tempfile", ".", "write", "(", "chunk", ")", "chunk", ".", "clear", "# deallocate string", "progress_proc", ".", "call", "(", "tempfile", ".", "size", ")", "if", "progress_proc", "if", "max_size", "&&", "tempfile", ".", "size", ">", "max_size", "raise", "Down", "::", "TooLarge", ",", "\"file is too large (max is #{max_size/1024/1024}MB)\"", "end", "end", "tempfile", ".", "open", "# flush written content", "tempfile", ".", "extend", "Down", "::", "Http", "::", "DownloadedFile", "tempfile", ".", "url", "=", "response", ".", "uri", ".", "to_s", "tempfile", ".", "headers", "=", "response", ".", "headers", ".", "to_h", "download_result", "(", "tempfile", ",", "destination", ")", "rescue", "tempfile", ".", "close!", "if", "tempfile", "raise", "end" ]
Initializes the backend with common defaults. Downlods the remote file to disk. Accepts HTTP.rb options via a hash or a block, and some additional options as well.
[ "Initializes", "the", "backend", "with", "common", "defaults", ".", "Downlods", "the", "remote", "file", "to", "disk", ".", "Accepts", "HTTP", ".", "rb", "options", "via", "a", "hash", "or", "a", "block", "and", "some", "additional", "options", "as", "well", "." ]
300ed69edd4de2ea8298f1b43e99de091976fe93
https://github.com/janko/down/blob/300ed69edd4de2ea8298f1b43e99de091976fe93/lib/down/http.rb#L33-L66
15,679
janko/down
lib/down/http.rb
Down.Http.open
def open(url, rewindable: true, **options, &block) response = request(url, **options, &block) Down::ChunkedIO.new( chunks: enum_for(:stream_body, response), size: response.content_length, encoding: response.content_type.charset, rewindable: rewindable, data: { status: response.code, headers: response.headers.to_h, response: response }, ) end
ruby
def open(url, rewindable: true, **options, &block) response = request(url, **options, &block) Down::ChunkedIO.new( chunks: enum_for(:stream_body, response), size: response.content_length, encoding: response.content_type.charset, rewindable: rewindable, data: { status: response.code, headers: response.headers.to_h, response: response }, ) end
[ "def", "open", "(", "url", ",", "rewindable", ":", "true", ",", "**", "options", ",", "&", "block", ")", "response", "=", "request", "(", "url", ",", "**", "options", ",", "block", ")", "Down", "::", "ChunkedIO", ".", "new", "(", "chunks", ":", "enum_for", "(", ":stream_body", ",", "response", ")", ",", "size", ":", "response", ".", "content_length", ",", "encoding", ":", "response", ".", "content_type", ".", "charset", ",", "rewindable", ":", "rewindable", ",", "data", ":", "{", "status", ":", "response", ".", "code", ",", "headers", ":", "response", ".", "headers", ".", "to_h", ",", "response", ":", "response", "}", ",", ")", "end" ]
Starts retrieving the remote file and returns an IO-like object which downloads the response body on-demand. Accepts HTTP.rb options via a hash or a block.
[ "Starts", "retrieving", "the", "remote", "file", "and", "returns", "an", "IO", "-", "like", "object", "which", "downloads", "the", "response", "body", "on", "-", "demand", ".", "Accepts", "HTTP", ".", "rb", "options", "via", "a", "hash", "or", "a", "block", "." ]
300ed69edd4de2ea8298f1b43e99de091976fe93
https://github.com/janko/down/blob/300ed69edd4de2ea8298f1b43e99de091976fe93/lib/down/http.rb#L71-L81
15,680
janko/down
lib/down/http.rb
Down.Http.stream_body
def stream_body(response, &block) response.body.each(&block) rescue => exception request_error!(exception) ensure response.connection.close unless @client.persistent? end
ruby
def stream_body(response, &block) response.body.each(&block) rescue => exception request_error!(exception) ensure response.connection.close unless @client.persistent? end
[ "def", "stream_body", "(", "response", ",", "&", "block", ")", "response", ".", "body", ".", "each", "(", "block", ")", "rescue", "=>", "exception", "request_error!", "(", "exception", ")", "ensure", "response", ".", "connection", ".", "close", "unless", "@client", ".", "persistent?", "end" ]
Yields chunks of the response body to the block.
[ "Yields", "chunks", "of", "the", "response", "body", "to", "the", "block", "." ]
300ed69edd4de2ea8298f1b43e99de091976fe93
https://github.com/janko/down/blob/300ed69edd4de2ea8298f1b43e99de091976fe93/lib/down/http.rb#L104-L110
15,681
janko/down
lib/down/net_http.rb
Down.NetHttp.download
def download(url, options = {}) options = @options.merge(options) max_size = options.delete(:max_size) max_redirects = options.delete(:max_redirects) progress_proc = options.delete(:progress_proc) content_length_proc = options.delete(:content_length_proc) destination = options.delete(:destination) headers = options.delete(:headers) || {} # Use open-uri's :content_lenth_proc or :progress_proc to raise an # exception early if the file is too large. # # Also disable following redirects, as we'll provide our own # implementation that has the ability to limit the number of redirects. open_uri_options = { content_length_proc: proc { |size| if size && max_size && size > max_size raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)" end content_length_proc.call(size) if content_length_proc }, progress_proc: proc { |current_size| if max_size && current_size > max_size raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)" end progress_proc.call(current_size) if progress_proc }, redirect: false, } # Handle basic authentication in the :proxy option. if options[:proxy] proxy = URI(options.delete(:proxy)) user = proxy.user password = proxy.password if user || password proxy.user = nil proxy.password = nil open_uri_options[:proxy_http_basic_authentication] = [proxy.to_s, user, password] else open_uri_options[:proxy] = proxy.to_s end end open_uri_options.merge!(options) open_uri_options.merge!(headers) uri = ensure_uri(addressable_normalize(url)) # Handle basic authentication in the remote URL. if uri.user || uri.password open_uri_options[:http_basic_authentication] ||= [uri.user, uri.password] uri.user = nil uri.password = nil end open_uri_file = open_uri(uri, open_uri_options, follows_remaining: max_redirects) # Handle the fact that open-uri returns StringIOs for small files. tempfile = ensure_tempfile(open_uri_file, File.extname(open_uri_file.base_uri.path)) OpenURI::Meta.init tempfile, open_uri_file # add back open-uri methods tempfile.extend Down::NetHttp::DownloadedFile download_result(tempfile, destination) end
ruby
def download(url, options = {}) options = @options.merge(options) max_size = options.delete(:max_size) max_redirects = options.delete(:max_redirects) progress_proc = options.delete(:progress_proc) content_length_proc = options.delete(:content_length_proc) destination = options.delete(:destination) headers = options.delete(:headers) || {} # Use open-uri's :content_lenth_proc or :progress_proc to raise an # exception early if the file is too large. # # Also disable following redirects, as we'll provide our own # implementation that has the ability to limit the number of redirects. open_uri_options = { content_length_proc: proc { |size| if size && max_size && size > max_size raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)" end content_length_proc.call(size) if content_length_proc }, progress_proc: proc { |current_size| if max_size && current_size > max_size raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)" end progress_proc.call(current_size) if progress_proc }, redirect: false, } # Handle basic authentication in the :proxy option. if options[:proxy] proxy = URI(options.delete(:proxy)) user = proxy.user password = proxy.password if user || password proxy.user = nil proxy.password = nil open_uri_options[:proxy_http_basic_authentication] = [proxy.to_s, user, password] else open_uri_options[:proxy] = proxy.to_s end end open_uri_options.merge!(options) open_uri_options.merge!(headers) uri = ensure_uri(addressable_normalize(url)) # Handle basic authentication in the remote URL. if uri.user || uri.password open_uri_options[:http_basic_authentication] ||= [uri.user, uri.password] uri.user = nil uri.password = nil end open_uri_file = open_uri(uri, open_uri_options, follows_remaining: max_redirects) # Handle the fact that open-uri returns StringIOs for small files. tempfile = ensure_tempfile(open_uri_file, File.extname(open_uri_file.base_uri.path)) OpenURI::Meta.init tempfile, open_uri_file # add back open-uri methods tempfile.extend Down::NetHttp::DownloadedFile download_result(tempfile, destination) end
[ "def", "download", "(", "url", ",", "options", "=", "{", "}", ")", "options", "=", "@options", ".", "merge", "(", "options", ")", "max_size", "=", "options", ".", "delete", "(", ":max_size", ")", "max_redirects", "=", "options", ".", "delete", "(", ":max_redirects", ")", "progress_proc", "=", "options", ".", "delete", "(", ":progress_proc", ")", "content_length_proc", "=", "options", ".", "delete", "(", ":content_length_proc", ")", "destination", "=", "options", ".", "delete", "(", ":destination", ")", "headers", "=", "options", ".", "delete", "(", ":headers", ")", "||", "{", "}", "# Use open-uri's :content_lenth_proc or :progress_proc to raise an", "# exception early if the file is too large.", "#", "# Also disable following redirects, as we'll provide our own", "# implementation that has the ability to limit the number of redirects.", "open_uri_options", "=", "{", "content_length_proc", ":", "proc", "{", "|", "size", "|", "if", "size", "&&", "max_size", "&&", "size", ">", "max_size", "raise", "Down", "::", "TooLarge", ",", "\"file is too large (max is #{max_size/1024/1024}MB)\"", "end", "content_length_proc", ".", "call", "(", "size", ")", "if", "content_length_proc", "}", ",", "progress_proc", ":", "proc", "{", "|", "current_size", "|", "if", "max_size", "&&", "current_size", ">", "max_size", "raise", "Down", "::", "TooLarge", ",", "\"file is too large (max is #{max_size/1024/1024}MB)\"", "end", "progress_proc", ".", "call", "(", "current_size", ")", "if", "progress_proc", "}", ",", "redirect", ":", "false", ",", "}", "# Handle basic authentication in the :proxy option.", "if", "options", "[", ":proxy", "]", "proxy", "=", "URI", "(", "options", ".", "delete", "(", ":proxy", ")", ")", "user", "=", "proxy", ".", "user", "password", "=", "proxy", ".", "password", "if", "user", "||", "password", "proxy", ".", "user", "=", "nil", "proxy", ".", "password", "=", "nil", "open_uri_options", "[", ":proxy_http_basic_authentication", "]", "=", "[", "proxy", ".", "to_s", ",", "user", ",", "password", "]", "else", "open_uri_options", "[", ":proxy", "]", "=", "proxy", ".", "to_s", "end", "end", "open_uri_options", ".", "merge!", "(", "options", ")", "open_uri_options", ".", "merge!", "(", "headers", ")", "uri", "=", "ensure_uri", "(", "addressable_normalize", "(", "url", ")", ")", "# Handle basic authentication in the remote URL.", "if", "uri", ".", "user", "||", "uri", ".", "password", "open_uri_options", "[", ":http_basic_authentication", "]", "||=", "[", "uri", ".", "user", ",", "uri", ".", "password", "]", "uri", ".", "user", "=", "nil", "uri", ".", "password", "=", "nil", "end", "open_uri_file", "=", "open_uri", "(", "uri", ",", "open_uri_options", ",", "follows_remaining", ":", "max_redirects", ")", "# Handle the fact that open-uri returns StringIOs for small files.", "tempfile", "=", "ensure_tempfile", "(", "open_uri_file", ",", "File", ".", "extname", "(", "open_uri_file", ".", "base_uri", ".", "path", ")", ")", "OpenURI", "::", "Meta", ".", "init", "tempfile", ",", "open_uri_file", "# add back open-uri methods", "tempfile", ".", "extend", "Down", "::", "NetHttp", "::", "DownloadedFile", "download_result", "(", "tempfile", ",", "destination", ")", "end" ]
Initializes the backend with common defaults. Downloads a remote file to disk using open-uri. Accepts any open-uri options, and a few more.
[ "Initializes", "the", "backend", "with", "common", "defaults", ".", "Downloads", "a", "remote", "file", "to", "disk", "using", "open", "-", "uri", ".", "Accepts", "any", "open", "-", "uri", "options", "and", "a", "few", "more", "." ]
300ed69edd4de2ea8298f1b43e99de091976fe93
https://github.com/janko/down/blob/300ed69edd4de2ea8298f1b43e99de091976fe93/lib/down/net_http.rb#L27-L94
15,682
janko/down
lib/down/net_http.rb
Down.NetHttp.ensure_uri
def ensure_uri(url, allow_relative: false) begin uri = URI(url) rescue URI::InvalidURIError => exception raise Down::InvalidUrl, exception.message end unless allow_relative && uri.relative? raise Down::InvalidUrl, "URL scheme needs to be http or https: #{uri}" unless uri.is_a?(URI::HTTP) end uri end
ruby
def ensure_uri(url, allow_relative: false) begin uri = URI(url) rescue URI::InvalidURIError => exception raise Down::InvalidUrl, exception.message end unless allow_relative && uri.relative? raise Down::InvalidUrl, "URL scheme needs to be http or https: #{uri}" unless uri.is_a?(URI::HTTP) end uri end
[ "def", "ensure_uri", "(", "url", ",", "allow_relative", ":", "false", ")", "begin", "uri", "=", "URI", "(", "url", ")", "rescue", "URI", "::", "InvalidURIError", "=>", "exception", "raise", "Down", "::", "InvalidUrl", ",", "exception", ".", "message", "end", "unless", "allow_relative", "&&", "uri", ".", "relative?", "raise", "Down", "::", "InvalidUrl", ",", "\"URL scheme needs to be http or https: #{uri}\"", "unless", "uri", ".", "is_a?", "(", "URI", "::", "HTTP", ")", "end", "uri", "end" ]
Checks that the url is a valid URI and that its scheme is http or https.
[ "Checks", "that", "the", "url", "is", "a", "valid", "URI", "and", "that", "its", "scheme", "is", "http", "or", "https", "." ]
300ed69edd4de2ea8298f1b43e99de091976fe93
https://github.com/janko/down/blob/300ed69edd4de2ea8298f1b43e99de091976fe93/lib/down/net_http.rb#L272-L284
15,683
janko/down
lib/down/net_http.rb
Down.NetHttp.addressable_normalize
def addressable_normalize(url) addressable_uri = Addressable::URI.parse(url) addressable_uri.normalize.to_s end
ruby
def addressable_normalize(url) addressable_uri = Addressable::URI.parse(url) addressable_uri.normalize.to_s end
[ "def", "addressable_normalize", "(", "url", ")", "addressable_uri", "=", "Addressable", "::", "URI", ".", "parse", "(", "url", ")", "addressable_uri", ".", "normalize", ".", "to_s", "end" ]
Makes sure that the URL is properly encoded.
[ "Makes", "sure", "that", "the", "URL", "is", "properly", "encoded", "." ]
300ed69edd4de2ea8298f1b43e99de091976fe93
https://github.com/janko/down/blob/300ed69edd4de2ea8298f1b43e99de091976fe93/lib/down/net_http.rb#L287-L290
15,684
janko/down
lib/down/backend.rb
Down.Backend.download_result
def download_result(tempfile, destination) return tempfile unless destination tempfile.close # required for Windows FileUtils.mv tempfile.path, destination nil end
ruby
def download_result(tempfile, destination) return tempfile unless destination tempfile.close # required for Windows FileUtils.mv tempfile.path, destination nil end
[ "def", "download_result", "(", "tempfile", ",", "destination", ")", "return", "tempfile", "unless", "destination", "tempfile", ".", "close", "# required for Windows", "FileUtils", ".", "mv", "tempfile", ".", "path", ",", "destination", "nil", "end" ]
If destination path is defined, move tempfile to the destination, otherwise return the tempfile unchanged.
[ "If", "destination", "path", "is", "defined", "move", "tempfile", "to", "the", "destination", "otherwise", "return", "the", "tempfile", "unchanged", "." ]
300ed69edd4de2ea8298f1b43e99de091976fe93
https://github.com/janko/down/blob/300ed69edd4de2ea8298f1b43e99de091976fe93/lib/down/backend.rb#L24-L31
15,685
tubedude/xirr
lib/xirr/newton_method.rb
Xirr.NewtonMethod.xirr
def xirr guess, options func = Function.new(self, :xnpv) rate = [guess || cf.irr_guess] begin nlsolve(func, rate) (rate[0] <= -1 || rate[0].nan?) ? nil : rate[0].round(Xirr::PRECISION) # rate[0].round(Xirr::PRECISION) rescue nil end end
ruby
def xirr guess, options func = Function.new(self, :xnpv) rate = [guess || cf.irr_guess] begin nlsolve(func, rate) (rate[0] <= -1 || rate[0].nan?) ? nil : rate[0].round(Xirr::PRECISION) # rate[0].round(Xirr::PRECISION) rescue nil end end
[ "def", "xirr", "guess", ",", "options", "func", "=", "Function", ".", "new", "(", "self", ",", ":xnpv", ")", "rate", "=", "[", "guess", "||", "cf", ".", "irr_guess", "]", "begin", "nlsolve", "(", "func", ",", "rate", ")", "(", "rate", "[", "0", "]", "<=", "-", "1", "||", "rate", "[", "0", "]", ".", "nan?", ")", "?", "nil", ":", "rate", "[", "0", "]", ".", "round", "(", "Xirr", "::", "PRECISION", ")", "# rate[0].round(Xirr::PRECISION)", "rescue", "nil", "end", "end" ]
Calculates XIRR using Newton method @return [BigDecimal] @param guess [Float]
[ "Calculates", "XIRR", "using", "Newton", "method" ]
e8488a95b217c463d54a5d311ce02a9474f22f7e
https://github.com/tubedude/xirr/blob/e8488a95b217c463d54a5d311ce02a9474f22f7e/lib/xirr/newton_method.rb#L47-L58
15,686
tubedude/xirr
lib/xirr/bisection.rb
Xirr.Bisection.xirr
def xirr(midpoint, options) # Initial values left = [BigDecimal.new(-0.99999999, Xirr::PRECISION), cf.irr_guess].min right = [BigDecimal.new(9.99999999, Xirr::PRECISION), cf.irr_guess + 1].max @original_right = right midpoint ||= cf.irr_guess midpoint, runs = loop_rates(left, midpoint, right, options[:iteration_limit]) get_answer(midpoint, options, runs) end
ruby
def xirr(midpoint, options) # Initial values left = [BigDecimal.new(-0.99999999, Xirr::PRECISION), cf.irr_guess].min right = [BigDecimal.new(9.99999999, Xirr::PRECISION), cf.irr_guess + 1].max @original_right = right midpoint ||= cf.irr_guess midpoint, runs = loop_rates(left, midpoint, right, options[:iteration_limit]) get_answer(midpoint, options, runs) end
[ "def", "xirr", "(", "midpoint", ",", "options", ")", "# Initial values", "left", "=", "[", "BigDecimal", ".", "new", "(", "-", "0.99999999", ",", "Xirr", "::", "PRECISION", ")", ",", "cf", ".", "irr_guess", "]", ".", "min", "right", "=", "[", "BigDecimal", ".", "new", "(", "9.99999999", ",", "Xirr", "::", "PRECISION", ")", ",", "cf", ".", "irr_guess", "+", "1", "]", ".", "max", "@original_right", "=", "right", "midpoint", "||=", "cf", ".", "irr_guess", "midpoint", ",", "runs", "=", "loop_rates", "(", "left", ",", "midpoint", ",", "right", ",", "options", "[", ":iteration_limit", "]", ")", "get_answer", "(", "midpoint", ",", "options", ",", "runs", ")", "end" ]
Calculates yearly Internal Rate of Return @return [BigDecimal] @param midpoint [Float] An initial guess rate will override the {Cashflow#irr_guess}
[ "Calculates", "yearly", "Internal", "Rate", "of", "Return" ]
e8488a95b217c463d54a5d311ce02a9474f22f7e
https://github.com/tubedude/xirr/blob/e8488a95b217c463d54a5d311ce02a9474f22f7e/lib/xirr/bisection.rb#L11-L23
15,687
tubedude/xirr
lib/xirr/base.rb
Xirr.Base.xnpv
def xnpv(rate) cf.inject(0) do |sum, t| sum + (xnpv_c rate, t.amount, periods_from_start(t.date)) end end
ruby
def xnpv(rate) cf.inject(0) do |sum, t| sum + (xnpv_c rate, t.amount, periods_from_start(t.date)) end end
[ "def", "xnpv", "(", "rate", ")", "cf", ".", "inject", "(", "0", ")", "do", "|", "sum", ",", "t", "|", "sum", "+", "(", "xnpv_c", "rate", ",", "t", ".", "amount", ",", "periods_from_start", "(", "t", ".", "date", ")", ")", "end", "end" ]
Net Present Value function that will be used to reduce the cashflow @param rate [BigDecimal] @return [BigDecimal]
[ "Net", "Present", "Value", "function", "that", "will", "be", "used", "to", "reduce", "the", "cashflow" ]
e8488a95b217c463d54a5d311ce02a9474f22f7e
https://github.com/tubedude/xirr/blob/e8488a95b217c463d54a5d311ce02a9474f22f7e/lib/xirr/base.rb#L25-L29
15,688
rake-compiler/rake-compiler
lib/rake/extensiontask.rb
Rake.ExtensionTask.define_staging_file_tasks
def define_staging_file_tasks(files, lib_path, stage_path, platf, ruby_ver) files.each do |gem_file| # ignore directories and the binary extension next if File.directory?(gem_file) || gem_file == "#{lib_path}/#{binary(platf)}" stage_file = "#{stage_path}/#{gem_file}" # copy each file from base to stage directory unless Rake::Task.task_defined?(stage_file) then directory File.dirname(stage_file) file stage_file => [File.dirname(stage_file), gem_file] do cp gem_file, stage_file end end # append each file to the copy task task "copy:#{@name}:#{platf}:#{ruby_ver}" => [stage_file] end end
ruby
def define_staging_file_tasks(files, lib_path, stage_path, platf, ruby_ver) files.each do |gem_file| # ignore directories and the binary extension next if File.directory?(gem_file) || gem_file == "#{lib_path}/#{binary(platf)}" stage_file = "#{stage_path}/#{gem_file}" # copy each file from base to stage directory unless Rake::Task.task_defined?(stage_file) then directory File.dirname(stage_file) file stage_file => [File.dirname(stage_file), gem_file] do cp gem_file, stage_file end end # append each file to the copy task task "copy:#{@name}:#{platf}:#{ruby_ver}" => [stage_file] end end
[ "def", "define_staging_file_tasks", "(", "files", ",", "lib_path", ",", "stage_path", ",", "platf", ",", "ruby_ver", ")", "files", ".", "each", "do", "|", "gem_file", "|", "# ignore directories and the binary extension", "next", "if", "File", ".", "directory?", "(", "gem_file", ")", "||", "gem_file", "==", "\"#{lib_path}/#{binary(platf)}\"", "stage_file", "=", "\"#{stage_path}/#{gem_file}\"", "# copy each file from base to stage directory", "unless", "Rake", "::", "Task", ".", "task_defined?", "(", "stage_file", ")", "then", "directory", "File", ".", "dirname", "(", "stage_file", ")", "file", "stage_file", "=>", "[", "File", ".", "dirname", "(", "stage_file", ")", ",", "gem_file", "]", "do", "cp", "gem_file", ",", "stage_file", "end", "end", "# append each file to the copy task", "task", "\"copy:#{@name}:#{platf}:#{ruby_ver}\"", "=>", "[", "stage_file", "]", "end", "end" ]
copy other gem files to staging directory
[ "copy", "other", "gem", "files", "to", "staging", "directory" ]
18b335a87000efe91db8997f586772150528f342
https://github.com/rake-compiler/rake-compiler/blob/18b335a87000efe91db8997f586772150528f342/lib/rake/extensiontask.rb#L91-L108
15,689
rake-compiler/rake-compiler
lib/rake/javaextensiontask.rb
Rake.JavaExtensionTask.java_extdirs_arg
def java_extdirs_arg extdirs = Java::java.lang.System.getProperty('java.ext.dirs') rescue nil extdirs = ENV['JAVA_EXT_DIR'] unless extdirs java_extdir = extdirs.nil? ? "" : "-extdirs \"#{extdirs}\"" end
ruby
def java_extdirs_arg extdirs = Java::java.lang.System.getProperty('java.ext.dirs') rescue nil extdirs = ENV['JAVA_EXT_DIR'] unless extdirs java_extdir = extdirs.nil? ? "" : "-extdirs \"#{extdirs}\"" end
[ "def", "java_extdirs_arg", "extdirs", "=", "Java", "::", "java", ".", "lang", ".", "System", ".", "getProperty", "(", "'java.ext.dirs'", ")", "rescue", "nil", "extdirs", "=", "ENV", "[", "'JAVA_EXT_DIR'", "]", "unless", "extdirs", "java_extdir", "=", "extdirs", ".", "nil?", "?", "\"\"", ":", "\"-extdirs \\\"#{extdirs}\\\"\"", "end" ]
Discover Java Extension Directories and build an extdirs argument
[ "Discover", "Java", "Extension", "Directories", "and", "build", "an", "extdirs", "argument" ]
18b335a87000efe91db8997f586772150528f342
https://github.com/rake-compiler/rake-compiler/blob/18b335a87000efe91db8997f586772150528f342/lib/rake/javaextensiontask.rb#L190-L194
15,690
WinRb/WinRM
lib/winrm/connection.rb
WinRM.Connection.shell
def shell(shell_type, shell_opts = {}) shell = shell_factory.create_shell(shell_type, shell_opts) if block_given? begin yield shell ensure shell.close end else shell end end
ruby
def shell(shell_type, shell_opts = {}) shell = shell_factory.create_shell(shell_type, shell_opts) if block_given? begin yield shell ensure shell.close end else shell end end
[ "def", "shell", "(", "shell_type", ",", "shell_opts", "=", "{", "}", ")", "shell", "=", "shell_factory", ".", "create_shell", "(", "shell_type", ",", "shell_opts", ")", "if", "block_given?", "begin", "yield", "shell", "ensure", "shell", ".", "close", "end", "else", "shell", "end", "end" ]
Creates a new shell on the remote Windows server associated with this connection. @param shell_type [Symbol] The shell type :cmd or :powershell @param shell_opts [Hash] Options targeted for the created shell @return [Shell] PowerShell or Cmd shell instance.
[ "Creates", "a", "new", "shell", "on", "the", "remote", "Windows", "server", "associated", "with", "this", "connection", "." ]
a5afd4755bd5a3e0672f6a6014448476f0631909
https://github.com/WinRb/WinRM/blob/a5afd4755bd5a3e0672f6a6014448476f0631909/lib/winrm/connection.rb#L38-L49
15,691
WinRb/WinRM
lib/winrm/connection.rb
WinRM.Connection.run_wql
def run_wql(wql, namespace = 'root/cimv2/*', &block) query = WinRM::WSMV::WqlQuery.new(transport, @connection_opts, wql, namespace) query.process_response(transport.send_request(query.build), &block) end
ruby
def run_wql(wql, namespace = 'root/cimv2/*', &block) query = WinRM::WSMV::WqlQuery.new(transport, @connection_opts, wql, namespace) query.process_response(transport.send_request(query.build), &block) end
[ "def", "run_wql", "(", "wql", ",", "namespace", "=", "'root/cimv2/*'", ",", "&", "block", ")", "query", "=", "WinRM", "::", "WSMV", "::", "WqlQuery", ".", "new", "(", "transport", ",", "@connection_opts", ",", "wql", ",", "namespace", ")", "query", ".", "process_response", "(", "transport", ".", "send_request", "(", "query", ".", "build", ")", ",", "block", ")", "end" ]
Executes a WQL query against the WinRM connection @param wql [String] The wql query @param namespace [String] namespace for query - default is root/cimv2/* @return [Hash] Hash representation of wql query response (Hash is empty if a block is given) @yeild [type, item] Yields the time name and item for every item
[ "Executes", "a", "WQL", "query", "against", "the", "WinRM", "connection" ]
a5afd4755bd5a3e0672f6a6014448476f0631909
https://github.com/WinRb/WinRM/blob/a5afd4755bd5a3e0672f6a6014448476f0631909/lib/winrm/connection.rb#L56-L59
15,692
honeybadger-io/honeybadger-ruby
lib/honeybadger/config.rb
Honeybadger.Config.includes_token?
def includes_token?(obj, value) return false unless obj.kind_of?(Array) obj.map(&:to_sym).include?(value.to_sym) end
ruby
def includes_token?(obj, value) return false unless obj.kind_of?(Array) obj.map(&:to_sym).include?(value.to_sym) end
[ "def", "includes_token?", "(", "obj", ",", "value", ")", "return", "false", "unless", "obj", ".", "kind_of?", "(", "Array", ")", "obj", ".", "map", "(", ":to_sym", ")", ".", "include?", "(", "value", ".", "to_sym", ")", "end" ]
Takes an Array and a value and returns true if the value exists in the array in String or Symbol form, otherwise false.
[ "Takes", "an", "Array", "and", "a", "value", "and", "returns", "true", "if", "the", "value", "exists", "in", "the", "array", "in", "String", "or", "Symbol", "form", "otherwise", "false", "." ]
dc4af07c347814c2c8a71778c5bcd4d6979b4638
https://github.com/honeybadger-io/honeybadger-ruby/blob/dc4af07c347814c2c8a71778c5bcd4d6979b4638/lib/honeybadger/config.rb#L378-L381
15,693
honeybadger-io/honeybadger-ruby
lib/honeybadger/notice.rb
Honeybadger.Notice.ignore_by_class?
def ignore_by_class?(ignored_class = nil) @ignore_by_class ||= Proc.new do |ignored_class| case error_class when (ignored_class.respond_to?(:name) ? ignored_class.name : ignored_class) true else exception && ignored_class.is_a?(Class) && exception.class < ignored_class end end ignored_class ? @ignore_by_class.call(ignored_class) : config.ignored_classes.any?(&@ignore_by_class) end
ruby
def ignore_by_class?(ignored_class = nil) @ignore_by_class ||= Proc.new do |ignored_class| case error_class when (ignored_class.respond_to?(:name) ? ignored_class.name : ignored_class) true else exception && ignored_class.is_a?(Class) && exception.class < ignored_class end end ignored_class ? @ignore_by_class.call(ignored_class) : config.ignored_classes.any?(&@ignore_by_class) end
[ "def", "ignore_by_class?", "(", "ignored_class", "=", "nil", ")", "@ignore_by_class", "||=", "Proc", ".", "new", "do", "|", "ignored_class", "|", "case", "error_class", "when", "(", "ignored_class", ".", "respond_to?", "(", ":name", ")", "?", "ignored_class", ".", "name", ":", "ignored_class", ")", "true", "else", "exception", "&&", "ignored_class", ".", "is_a?", "(", "Class", ")", "&&", "exception", ".", "class", "<", "ignored_class", "end", "end", "ignored_class", "?", "@ignore_by_class", ".", "call", "(", "ignored_class", ")", ":", "config", ".", "ignored_classes", ".", "any?", "(", "@ignore_by_class", ")", "end" ]
Determines if error class should be ignored. ignored_class_name - The name of the ignored class. May be a string or regexp (optional). Returns true or false.
[ "Determines", "if", "error", "class", "should", "be", "ignored", "." ]
dc4af07c347814c2c8a71778c5bcd4d6979b4638
https://github.com/honeybadger-io/honeybadger-ruby/blob/dc4af07c347814c2c8a71778c5bcd4d6979b4638/lib/honeybadger/notice.rb#L305-L316
15,694
honeybadger-io/honeybadger-ruby
lib/honeybadger/notice.rb
Honeybadger.Notice.construct_request_hash
def construct_request_hash request = { url: url, component: component, action: action, params: params, session: session, cgi_data: cgi_data, sanitizer: request_sanitizer } request.delete_if {|k,v| config.excluded_request_keys.include?(k) } Util::RequestPayload.build(request) end
ruby
def construct_request_hash request = { url: url, component: component, action: action, params: params, session: session, cgi_data: cgi_data, sanitizer: request_sanitizer } request.delete_if {|k,v| config.excluded_request_keys.include?(k) } Util::RequestPayload.build(request) end
[ "def", "construct_request_hash", "request", "=", "{", "url", ":", "url", ",", "component", ":", "component", ",", "action", ":", "action", ",", "params", ":", "params", ",", "session", ":", "session", ",", "cgi_data", ":", "cgi_data", ",", "sanitizer", ":", "request_sanitizer", "}", "request", ".", "delete_if", "{", "|", "k", ",", "v", "|", "config", ".", "excluded_request_keys", ".", "include?", "(", "k", ")", "}", "Util", "::", "RequestPayload", ".", "build", "(", "request", ")", "end" ]
Construct the request data. Returns Hash request data.
[ "Construct", "the", "request", "data", "." ]
dc4af07c347814c2c8a71778c5bcd4d6979b4638
https://github.com/honeybadger-io/honeybadger-ruby/blob/dc4af07c347814c2c8a71778c5bcd4d6979b4638/lib/honeybadger/notice.rb#L331-L343
15,695
honeybadger-io/honeybadger-ruby
lib/honeybadger/notice.rb
Honeybadger.Notice.exception_context
def exception_context(exception) # This extra check exists because the exception itself is not expected to # convert to a hash. object = exception if exception.respond_to?(:to_honeybadger_context) object ||= {}.freeze Context(object) end
ruby
def exception_context(exception) # This extra check exists because the exception itself is not expected to # convert to a hash. object = exception if exception.respond_to?(:to_honeybadger_context) object ||= {}.freeze Context(object) end
[ "def", "exception_context", "(", "exception", ")", "# This extra check exists because the exception itself is not expected to", "# convert to a hash.", "object", "=", "exception", "if", "exception", ".", "respond_to?", "(", ":to_honeybadger_context", ")", "object", "||=", "{", "}", ".", "freeze", "Context", "(", "object", ")", "end" ]
Get optional context from exception. Returns the Hash context.
[ "Get", "optional", "context", "from", "exception", "." ]
dc4af07c347814c2c8a71778c5bcd4d6979b4638
https://github.com/honeybadger-io/honeybadger-ruby/blob/dc4af07c347814c2c8a71778c5bcd4d6979b4638/lib/honeybadger/notice.rb#L348-L355
15,696
honeybadger-io/honeybadger-ruby
lib/honeybadger/notice.rb
Honeybadger.Notice.parse_backtrace
def parse_backtrace(backtrace) Backtrace.parse( backtrace, filters: construct_backtrace_filters(opts), config: config, source_radius: config[:'exceptions.source_radius'] ).to_a end
ruby
def parse_backtrace(backtrace) Backtrace.parse( backtrace, filters: construct_backtrace_filters(opts), config: config, source_radius: config[:'exceptions.source_radius'] ).to_a end
[ "def", "parse_backtrace", "(", "backtrace", ")", "Backtrace", ".", "parse", "(", "backtrace", ",", "filters", ":", "construct_backtrace_filters", "(", "opts", ")", ",", "config", ":", "config", ",", "source_radius", ":", "config", "[", ":'", "'", "]", ")", ".", "to_a", "end" ]
Parse Backtrace from exception backtrace. backtrace - The Array backtrace from exception. Returns the Backtrace.
[ "Parse", "Backtrace", "from", "exception", "backtrace", "." ]
dc4af07c347814c2c8a71778c5bcd4d6979b4638
https://github.com/honeybadger-io/honeybadger-ruby/blob/dc4af07c347814c2c8a71778c5bcd4d6979b4638/lib/honeybadger/notice.rb#L443-L450
15,697
honeybadger-io/honeybadger-ruby
lib/honeybadger/notice.rb
Honeybadger.Notice.exception_cause
def exception_cause(exception) e = exception if e.respond_to?(:cause) && e.cause && e.cause.is_a?(Exception) e.cause elsif e.respond_to?(:original_exception) && e.original_exception && e.original_exception.is_a?(Exception) e.original_exception elsif e.respond_to?(:continued_exception) && e.continued_exception && e.continued_exception.is_a?(Exception) e.continued_exception end end
ruby
def exception_cause(exception) e = exception if e.respond_to?(:cause) && e.cause && e.cause.is_a?(Exception) e.cause elsif e.respond_to?(:original_exception) && e.original_exception && e.original_exception.is_a?(Exception) e.original_exception elsif e.respond_to?(:continued_exception) && e.continued_exception && e.continued_exception.is_a?(Exception) e.continued_exception end end
[ "def", "exception_cause", "(", "exception", ")", "e", "=", "exception", "if", "e", ".", "respond_to?", "(", ":cause", ")", "&&", "e", ".", "cause", "&&", "e", ".", "cause", ".", "is_a?", "(", "Exception", ")", "e", ".", "cause", "elsif", "e", ".", "respond_to?", "(", ":original_exception", ")", "&&", "e", ".", "original_exception", "&&", "e", ".", "original_exception", ".", "is_a?", "(", "Exception", ")", "e", ".", "original_exception", "elsif", "e", ".", "respond_to?", "(", ":continued_exception", ")", "&&", "e", ".", "continued_exception", "&&", "e", ".", "continued_exception", ".", "is_a?", "(", "Exception", ")", "e", ".", "continued_exception", "end", "end" ]
Fetch cause from exception. exception - Exception to fetch cause from. Returns the Exception cause.
[ "Fetch", "cause", "from", "exception", "." ]
dc4af07c347814c2c8a71778c5bcd4d6979b4638
https://github.com/honeybadger-io/honeybadger-ruby/blob/dc4af07c347814c2c8a71778c5bcd4d6979b4638/lib/honeybadger/notice.rb#L468-L477
15,698
honeybadger-io/honeybadger-ruby
lib/honeybadger/notice.rb
Honeybadger.Notice.unwrap_causes
def unwrap_causes(cause) causes, c, i = [], cause, 0 while c && i < MAX_EXCEPTION_CAUSES causes << { class: c.class.name, message: c.message, backtrace: parse_backtrace(c.backtrace || caller) } i += 1 c = exception_cause(c) end causes end
ruby
def unwrap_causes(cause) causes, c, i = [], cause, 0 while c && i < MAX_EXCEPTION_CAUSES causes << { class: c.class.name, message: c.message, backtrace: parse_backtrace(c.backtrace || caller) } i += 1 c = exception_cause(c) end causes end
[ "def", "unwrap_causes", "(", "cause", ")", "causes", ",", "c", ",", "i", "=", "[", "]", ",", "cause", ",", "0", "while", "c", "&&", "i", "<", "MAX_EXCEPTION_CAUSES", "causes", "<<", "{", "class", ":", "c", ".", "class", ".", "name", ",", "message", ":", "c", ".", "message", ",", "backtrace", ":", "parse_backtrace", "(", "c", ".", "backtrace", "||", "caller", ")", "}", "i", "+=", "1", "c", "=", "exception_cause", "(", "c", ")", "end", "causes", "end" ]
Create a list of causes. cause - The first cause to unwrap. Returns Array causes (in Hash payload format).
[ "Create", "a", "list", "of", "causes", "." ]
dc4af07c347814c2c8a71778c5bcd4d6979b4638
https://github.com/honeybadger-io/honeybadger-ruby/blob/dc4af07c347814c2c8a71778c5bcd4d6979b4638/lib/honeybadger/notice.rb#L484-L498
15,699
honeybadger-io/honeybadger-ruby
lib/honeybadger/worker.rb
Honeybadger.Worker.flush
def flush mutex.synchronize do if thread && thread.alive? queue.push(marker) marker.wait(mutex) end end end
ruby
def flush mutex.synchronize do if thread && thread.alive? queue.push(marker) marker.wait(mutex) end end end
[ "def", "flush", "mutex", ".", "synchronize", "do", "if", "thread", "&&", "thread", ".", "alive?", "queue", ".", "push", "(", "marker", ")", "marker", ".", "wait", "(", "mutex", ")", "end", "end", "end" ]
Blocks until queue is processed up to this point in time.
[ "Blocks", "until", "queue", "is", "processed", "up", "to", "this", "point", "in", "time", "." ]
dc4af07c347814c2c8a71778c5bcd4d6979b4638
https://github.com/honeybadger-io/honeybadger-ruby/blob/dc4af07c347814c2c8a71778c5bcd4d6979b4638/lib/honeybadger/worker.rb#L96-L103