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
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.update_factory | def update_factory(id, update_factory_body, opts = {})
data, _status_code, _headers = update_factory_with_http_info(id, update_factory_body, opts)
return data
end | ruby | def update_factory(id, update_factory_body, opts = {})
data, _status_code, _headers = update_factory_with_http_info(id, update_factory_body, opts)
return data
end | [
"def",
"update_factory",
"(",
"id",
",",
"update_factory_body",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"update_factory_with_http_info",
"(",
"id",
",",
"update_factory_body",
",",
"opts",
")",
"return",
"data",
"end"
] | Updates a Factory's settings. Returns a Factory object.
@param id id of the factory
@param update_factory_body
@param [Hash] opts the optional parameters
@option opts [BOOLEAN] :with_storage_provider if set to `true`, results will include a storage provider's id
@return [Factory] | [
"Updates",
"a",
"Factory",
"s",
"settings",
".",
"Returns",
"a",
"Factory",
"object",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1808-L1811 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.update_notifications | def update_notifications(factory_id, cloud_notification_settings_body, opts = {})
data, _status_code, _headers = update_notifications_with_http_info(factory_id, cloud_notification_settings_body, opts)
return data
end | ruby | def update_notifications(factory_id, cloud_notification_settings_body, opts = {})
data, _status_code, _headers = update_notifications_with_http_info(factory_id, cloud_notification_settings_body, opts)
return data
end | [
"def",
"update_notifications",
"(",
"factory_id",
",",
"cloud_notification_settings_body",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"update_notifications_with_http_info",
"(",
"factory_id",
",",
"cloud_notification_settings_body",
",",
"opts",
")",
"return",
"data",
"end"
] | Updates a Factory's notification settings.
@param factory_id Id of a Factory.
@param cloud_notification_settings_body
@param [Hash] opts the optional parameters
@return [CloudNotificationSettings] | [
"Updates",
"a",
"Factory",
"s",
"notification",
"settings",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1871-L1874 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.update_profile | def update_profile(id, factory_id, update_profile_body, opts = {})
data, _status_code, _headers = update_profile_with_http_info(id, factory_id, update_profile_body, opts)
return data
end | ruby | def update_profile(id, factory_id, update_profile_body, opts = {})
data, _status_code, _headers = update_profile_with_http_info(id, factory_id, update_profile_body, opts)
return data
end | [
"def",
"update_profile",
"(",
"id",
",",
"factory_id",
",",
"update_profile_body",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"update_profile_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"update_profile_body",
",",
"opts",
")",
"return",
"data",
"end"
] | Updates a given Profile
@param id
@param factory_id Id of a Factory.
@param update_profile_body
@param [Hash] opts the optional parameters
@option opts [BOOLEAN] :exclude_advanced_services
@option opts [BOOLEAN] :expand If expand option is set Profile objects will contain all command parameters, even if their value is default. By default this is not set.
@return [Profile] | [
"Updates",
"a",
"given",
"Profile"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1936-L1939 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.upload_video | def upload_video(factory_id, video_upload_body, opts = {})
data, _status_code, _headers = upload_video_with_http_info(factory_id, video_upload_body, opts)
return data
end | ruby | def upload_video(factory_id, video_upload_body, opts = {})
data, _status_code, _headers = upload_video_with_http_info(factory_id, video_upload_body, opts)
return data
end | [
"def",
"upload_video",
"(",
"factory_id",
",",
"video_upload_body",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"upload_video_with_http_info",
"(",
"factory_id",
",",
"video_upload_body",
",",
"opts",
")",
"return",
"data",
"end"
] | Creates an upload session.
@param factory_id Id of a Factory.
@param video_upload_body
@param [Hash] opts the optional parameters
@return [UploadSession] | [
"Creates",
"an",
"upload",
"session",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L2007-L2010 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.video_encodings | def video_encodings(id, factory_id, opts = {})
data, _status_code, _headers = video_encodings_with_http_info(id, factory_id, opts)
return data
end | ruby | def video_encodings(id, factory_id, opts = {})
data, _status_code, _headers = video_encodings_with_http_info(id, factory_id, opts)
return data
end | [
"def",
"video_encodings",
"(",
"id",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"video_encodings_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a list of Encodings that belong to a Video.
@param id Id of a Video.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@option opts [Integer] :page A page to be fetched. Default is `1`.
@option opts [Integer] :per_page A number of results per page. Default is `100`.
@option opts [BOOLEAN] :screenshots Determines whether the response will include screenshots. By default this is not set.
@option opts [BOOLEAN] :precise_status Determines whether the response will include a precise status. By default this is not set.
@return [PaginatedEncodingsCollection] | [
"Returns",
"a",
"list",
"of",
"Encodings",
"that",
"belong",
"to",
"a",
"Video",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L2135-L2138 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.video_metadata | def video_metadata(id, factory_id, opts = {})
data, _status_code, _headers = video_metadata_with_http_info(id, factory_id, opts)
return data
end | ruby | def video_metadata(id, factory_id, opts = {})
data, _status_code, _headers = video_metadata_with_http_info(id, factory_id, opts)
return data
end | [
"def",
"video_metadata",
"(",
"id",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"video_metadata_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a Video's metadata
@param id Id of a Video.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [VideoMetadata] | [
"Returns",
"a",
"Video",
"s",
"metadata"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L2205-L2208 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.videos | def videos(factory_id, opts = {})
data, _status_code, _headers = videos_with_http_info(factory_id, opts)
return data
end | ruby | def videos(factory_id, opts = {})
data, _status_code, _headers = videos_with_http_info(factory_id, opts)
return data
end | [
"def",
"videos",
"(",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"videos_with_http_info",
"(",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a collection of Video objects.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@option opts [Integer] :page A page to be fetched. Default is `1`.
@option opts [Integer] :per_page A number of results per page. Default is `100`.
@return [PaginatedVideoCollection] | [
"Returns",
"a",
"collection",
"of",
"Video",
"objects",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L2268-L2271 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.workflows | def workflows(factory_id, opts = {})
data, _status_code, _headers = workflows_with_http_info(factory_id, opts)
return data
end | ruby | def workflows(factory_id, opts = {})
data, _status_code, _headers = workflows_with_http_info(factory_id, opts)
return data
end | [
"def",
"workflows",
"(",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"workflows_with_http_info",
"(",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a collection of Workflows that belong to a Factory.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@option opts [Integer] :page A page to be fetched. Default is `1`.
@option opts [Integer] :per_page A number of results per page. Default is `100`.
@return [PaginatedWorkflowsCollection] | [
"Returns",
"a",
"collection",
"of",
"Workflows",
"that",
"belong",
"to",
"a",
"Factory",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L2330-L2333 | train |
appirits/comable | core/app/helpers/comable/application_helper.rb | Comable.ApplicationHelper.liquid_assigns | def liquid_assigns
view_context.assigns.merge(
current_store: current_store,
current_comable_user: current_comable_user,
current_order: current_order,
current_trackers: current_trackers,
form_authenticity_token: form_authenticity_token
).stringify_keys
end | ruby | def liquid_assigns
view_context.assigns.merge(
current_store: current_store,
current_comable_user: current_comable_user,
current_order: current_order,
current_trackers: current_trackers,
form_authenticity_token: form_authenticity_token
).stringify_keys
end | [
"def",
"liquid_assigns",
"view_context",
".",
"assigns",
".",
"merge",
"(",
"current_store",
":",
"current_store",
",",
"current_comable_user",
":",
"current_comable_user",
",",
"current_order",
":",
"current_order",
",",
"current_trackers",
":",
"current_trackers",
",",
"form_authenticity_token",
":",
"form_authenticity_token",
")",
".",
"stringify_keys",
"end"
] | To use the functionality of liquid-rails | [
"To",
"use",
"the",
"functionality",
"of",
"liquid",
"-",
"rails"
] | b0cf028da35ea9def1c675680e5e5293a969bebc | https://github.com/appirits/comable/blob/b0cf028da35ea9def1c675680e5e5293a969bebc/core/app/helpers/comable/application_helper.rb#L58-L66 | train |
shadowbq/snort-thresholds | lib/threshold/thresholds.rb | Threshold.Thresholds.flush | def flush
begin
valid_existing_file?(@file)
raise ReadOnlyThresholdsFile if @readonly
hash = current_hash
file = File.open(@file, 'w+')
raise ThresholdAtomicLockFailure, 'The @file state/hash changed before we could flush the file' unless stored_hash == hash
file.write self.sort.to_s
file.close
rescue NonExistantThresholdFile
raise ReadOnlyThresholdsFile if @readonly
file = File.open(@file, 'w')
file.write self.sort.to_s
file.close
end
stored_hash=current_hash
return true
end | ruby | def flush
begin
valid_existing_file?(@file)
raise ReadOnlyThresholdsFile if @readonly
hash = current_hash
file = File.open(@file, 'w+')
raise ThresholdAtomicLockFailure, 'The @file state/hash changed before we could flush the file' unless stored_hash == hash
file.write self.sort.to_s
file.close
rescue NonExistantThresholdFile
raise ReadOnlyThresholdsFile if @readonly
file = File.open(@file, 'w')
file.write self.sort.to_s
file.close
end
stored_hash=current_hash
return true
end | [
"def",
"flush",
"begin",
"valid_existing_file?",
"(",
"@file",
")",
"raise",
"ReadOnlyThresholdsFile",
"if",
"@readonly",
"hash",
"=",
"current_hash",
"file",
"=",
"File",
".",
"open",
"(",
"@file",
",",
"'w+'",
")",
"raise",
"ThresholdAtomicLockFailure",
",",
"'The @file state/hash changed before we could flush the file'",
"unless",
"stored_hash",
"==",
"hash",
"file",
".",
"write",
"self",
".",
"sort",
".",
"to_s",
"file",
".",
"close",
"rescue",
"NonExistantThresholdFile",
"raise",
"ReadOnlyThresholdsFile",
"if",
"@readonly",
"file",
"=",
"File",
".",
"open",
"(",
"@file",
",",
"'w'",
")",
"file",
".",
"write",
"self",
".",
"sort",
".",
"to_s",
"file",
".",
"close",
"end",
"stored_hash",
"=",
"current_hash",
"return",
"true",
"end"
] | Write changes to the file | [
"Write",
"changes",
"to",
"the",
"file"
] | e3e9d1b10c2460846e1779fda67e8bec0422f53e | https://github.com/shadowbq/snort-thresholds/blob/e3e9d1b10c2460846e1779fda67e8bec0422f53e/lib/threshold/thresholds.rb#L22-L41 | train |
shadowbq/snort-thresholds | lib/threshold/thresholds.rb | Threshold.Thresholds.loadfile | def loadfile
valid_existing_file?(@file)
results = Threshold::Parser.new(@file)
@stored_hash= results.filehash
#puts stored_hash
results.caps.each do |result|
builder = Threshold::Builder.new(result)
self << builder.build
end
end | ruby | def loadfile
valid_existing_file?(@file)
results = Threshold::Parser.new(@file)
@stored_hash= results.filehash
#puts stored_hash
results.caps.each do |result|
builder = Threshold::Builder.new(result)
self << builder.build
end
end | [
"def",
"loadfile",
"valid_existing_file?",
"(",
"@file",
")",
"results",
"=",
"Threshold",
"::",
"Parser",
".",
"new",
"(",
"@file",
")",
"@stored_hash",
"=",
"results",
".",
"filehash",
"results",
".",
"caps",
".",
"each",
"do",
"|",
"result",
"|",
"builder",
"=",
"Threshold",
"::",
"Builder",
".",
"new",
"(",
"result",
")",
"self",
"<<",
"builder",
".",
"build",
"end",
"end"
] | Append in the thresholds.conf file to current collection | [
"Append",
"in",
"the",
"thresholds",
".",
"conf",
"file",
"to",
"current",
"collection"
] | e3e9d1b10c2460846e1779fda67e8bec0422f53e | https://github.com/shadowbq/snort-thresholds/blob/e3e9d1b10c2460846e1779fda67e8bec0422f53e/lib/threshold/thresholds.rb#L50-L61 | train |
shadowbq/snort-thresholds | lib/threshold/thresholds.rb | Threshold.Thresholds.valid? | def valid?
begin
self.each do |threshold|
if threshold.respond_to?(:valid?)
return false unless threshold.valid?
else
raise InvalidThresholdsObject, "Container object has unknown objects"
end
end
return true
rescue InvalidThresholdsObject
return false
end
end | ruby | def valid?
begin
self.each do |threshold|
if threshold.respond_to?(:valid?)
return false unless threshold.valid?
else
raise InvalidThresholdsObject, "Container object has unknown objects"
end
end
return true
rescue InvalidThresholdsObject
return false
end
end | [
"def",
"valid?",
"begin",
"self",
".",
"each",
"do",
"|",
"threshold",
"|",
"if",
"threshold",
".",
"respond_to?",
"(",
":valid?",
")",
"return",
"false",
"unless",
"threshold",
".",
"valid?",
"else",
"raise",
"InvalidThresholdsObject",
",",
"\"Container object has unknown objects\"",
"end",
"end",
"return",
"true",
"rescue",
"InvalidThresholdsObject",
"return",
"false",
"end",
"end"
] | Check if all objects in the Threshold Instance report .valid? | [
"Check",
"if",
"all",
"objects",
"in",
"the",
"Threshold",
"Instance",
"report",
".",
"valid?"
] | e3e9d1b10c2460846e1779fda67e8bec0422f53e | https://github.com/shadowbq/snort-thresholds/blob/e3e9d1b10c2460846e1779fda67e8bec0422f53e/lib/threshold/thresholds.rb#L64-L77 | train |
shadowbq/snort-thresholds | lib/threshold/thresholds.rb | Threshold.Thresholds.uniq | def uniq(&blk)
if block_given?
Thresholds.new(@thresholds.uniq(&blk))
else
Thresholds.new(@thresholds.uniq{ |lineitem| lineitem.to_s(true) })
end
end | ruby | def uniq(&blk)
if block_given?
Thresholds.new(@thresholds.uniq(&blk))
else
Thresholds.new(@thresholds.uniq{ |lineitem| lineitem.to_s(true) })
end
end | [
"def",
"uniq",
"(",
"&",
"blk",
")",
"if",
"block_given?",
"Thresholds",
".",
"new",
"(",
"@thresholds",
".",
"uniq",
"(",
"&",
"blk",
")",
")",
"else",
"Thresholds",
".",
"new",
"(",
"@thresholds",
".",
"uniq",
"{",
"|",
"lineitem",
"|",
"lineitem",
".",
"to_s",
"(",
"true",
")",
"}",
")",
"end",
"end"
] | Uniques by default to printable output
Returns a new Threshold Object | [
"Uniques",
"by",
"default",
"to",
"printable",
"output",
"Returns",
"a",
"new",
"Threshold",
"Object"
] | e3e9d1b10c2460846e1779fda67e8bec0422f53e | https://github.com/shadowbq/snort-thresholds/blob/e3e9d1b10c2460846e1779fda67e8bec0422f53e/lib/threshold/thresholds.rb#L138-L144 | train |
shadowbq/snort-thresholds | lib/threshold/thresholds.rb | Threshold.Thresholds.suppressions | def suppressions(&blk)
if block_given?
self.suppressions.select(&blk)
else
Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::Suppression"})
end
end | ruby | def suppressions(&blk)
if block_given?
self.suppressions.select(&blk)
else
Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::Suppression"})
end
end | [
"def",
"suppressions",
"(",
"&",
"blk",
")",
"if",
"block_given?",
"self",
".",
"suppressions",
".",
"select",
"(",
"&",
"blk",
")",
"else",
"Thresholds",
".",
"new",
"(",
"@thresholds",
".",
"select",
"{",
"|",
"t",
"|",
"t",
".",
"class",
".",
"to_s",
"==",
"\"Threshold::Suppression\"",
"}",
")",
"end",
"end"
] | Returns a new Threshold Object with just suppressions | [
"Returns",
"a",
"new",
"Threshold",
"Object",
"with",
"just",
"suppressions"
] | e3e9d1b10c2460846e1779fda67e8bec0422f53e | https://github.com/shadowbq/snort-thresholds/blob/e3e9d1b10c2460846e1779fda67e8bec0422f53e/lib/threshold/thresholds.rb#L173-L179 | train |
shadowbq/snort-thresholds | lib/threshold/thresholds.rb | Threshold.Thresholds.event_filters | def event_filters(&blk)
if block_given?
self.event_filters.select(&blk)
else
Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::EventFilter"})
end
end | ruby | def event_filters(&blk)
if block_given?
self.event_filters.select(&blk)
else
Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::EventFilter"})
end
end | [
"def",
"event_filters",
"(",
"&",
"blk",
")",
"if",
"block_given?",
"self",
".",
"event_filters",
".",
"select",
"(",
"&",
"blk",
")",
"else",
"Thresholds",
".",
"new",
"(",
"@thresholds",
".",
"select",
"{",
"|",
"t",
"|",
"t",
".",
"class",
".",
"to_s",
"==",
"\"Threshold::EventFilter\"",
"}",
")",
"end",
"end"
] | Returns a new Threshold Object with just event_filters | [
"Returns",
"a",
"new",
"Threshold",
"Object",
"with",
"just",
"event_filters"
] | e3e9d1b10c2460846e1779fda67e8bec0422f53e | https://github.com/shadowbq/snort-thresholds/blob/e3e9d1b10c2460846e1779fda67e8bec0422f53e/lib/threshold/thresholds.rb#L182-L188 | train |
shadowbq/snort-thresholds | lib/threshold/thresholds.rb | Threshold.Thresholds.rate_filters | def rate_filters(&blk)
if block_given?
self.rate_filters.select(&blk)
else
Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::RateFilter"})
end
end | ruby | def rate_filters(&blk)
if block_given?
self.rate_filters.select(&blk)
else
Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::RateFilter"})
end
end | [
"def",
"rate_filters",
"(",
"&",
"blk",
")",
"if",
"block_given?",
"self",
".",
"rate_filters",
".",
"select",
"(",
"&",
"blk",
")",
"else",
"Thresholds",
".",
"new",
"(",
"@thresholds",
".",
"select",
"{",
"|",
"t",
"|",
"t",
".",
"class",
".",
"to_s",
"==",
"\"Threshold::RateFilter\"",
"}",
")",
"end",
"end"
] | Returns a new Threshold Object with just rate_filters | [
"Returns",
"a",
"new",
"Threshold",
"Object",
"with",
"just",
"rate_filters"
] | e3e9d1b10c2460846e1779fda67e8bec0422f53e | https://github.com/shadowbq/snort-thresholds/blob/e3e9d1b10c2460846e1779fda67e8bec0422f53e/lib/threshold/thresholds.rb#L191-L197 | train |
yoppi/backlog-api | lib/backlog/api.rb | Backlog.API.count_issue | def count_issue(condition)
raise Backlog::API::ArgumentError, "must specify 'projectId'" unless condition.has_key? "projectId"
condition = Backlog::Object::FindCondition.new(condition)
self.call("backlog.countIssue", condition.to_h)
end | ruby | def count_issue(condition)
raise Backlog::API::ArgumentError, "must specify 'projectId'" unless condition.has_key? "projectId"
condition = Backlog::Object::FindCondition.new(condition)
self.call("backlog.countIssue", condition.to_h)
end | [
"def",
"count_issue",
"(",
"condition",
")",
"raise",
"Backlog",
"::",
"API",
"::",
"ArgumentError",
",",
"\"must specify 'projectId'\"",
"unless",
"condition",
".",
"has_key?",
"\"projectId\"",
"condition",
"=",
"Backlog",
"::",
"Object",
"::",
"FindCondition",
".",
"new",
"(",
"condition",
")",
"self",
".",
"call",
"(",
"\"backlog.countIssue\"",
",",
"condition",
".",
"to_h",
")",
"end"
] | Hash -> Integer | [
"Hash",
"-",
">",
"Integer"
] | e11c045a2bb9d578160b6bf4b7cd01745c086d76 | https://github.com/yoppi/backlog-api/blob/e11c045a2bb9d578160b6bf4b7cd01745c086d76/lib/backlog/api.rb#L115-L119 | train |
brainmap/nifti | lib/nifti/n_object.rb | NIFTI.NObject.write | def write(file_name, options={})
if file_name.is_a?(String)
w = NWrite.new(self, file_name, options)
w.write
# Write process succesful?
@write_success = w.success
# If any messages has been recorded, send these to the message handling method:
add_msg(w.msg) if w.msg.length > 0
else
raise ArgumentError, "Invalid file_name. Expected String, got #{file_name.class}."
end
end | ruby | def write(file_name, options={})
if file_name.is_a?(String)
w = NWrite.new(self, file_name, options)
w.write
# Write process succesful?
@write_success = w.success
# If any messages has been recorded, send these to the message handling method:
add_msg(w.msg) if w.msg.length > 0
else
raise ArgumentError, "Invalid file_name. Expected String, got #{file_name.class}."
end
end | [
"def",
"write",
"(",
"file_name",
",",
"options",
"=",
"{",
"}",
")",
"if",
"file_name",
".",
"is_a?",
"(",
"String",
")",
"w",
"=",
"NWrite",
".",
"new",
"(",
"self",
",",
"file_name",
",",
"options",
")",
"w",
".",
"write",
"@write_success",
"=",
"w",
".",
"success",
"add_msg",
"(",
"w",
".",
"msg",
")",
"if",
"w",
".",
"msg",
".",
"length",
">",
"0",
"else",
"raise",
"ArgumentError",
",",
"\"Invalid file_name. Expected String, got #{file_name.class}.\"",
"end",
"end"
] | Passes the NObject to the DWrite class, which writes out the header and image to the specified file.
=== Parameters
* <tt>file_name</tt> -- A string which identifies the path & name of the NIfTI file which is to be written to disk.
* <tt>options</tt> -- A hash of parameters.
=== Options
=== Examples
obj.write(path + "test.dcm") | [
"Passes",
"the",
"NObject",
"to",
"the",
"DWrite",
"class",
"which",
"writes",
"out",
"the",
"header",
"and",
"image",
"to",
"the",
"specified",
"file",
"."
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_object.rb#L99-L110 | train |
brainmap/nifti | lib/nifti/n_object.rb | NIFTI.NObject.read | def read(string, options={})
if string.is_a?(String)
@string = string
r = NRead.new(string, options)
# Store the data to the instance variables if the readout was a success:
if r.success
@read_success = true
# Update instance variables based on the properties of the NRead object:
@header = r.hdr
@extended_header = r.extended_header
if r.image_narray
@image = r.image_narray
elsif r.image_rubyarray
@image = r.image_rubyarray
end
else
@read_success = false
end
# If any messages have been recorded, send these to the message handling method:
add_msg(r.msg) if r.msg.length > 0
else
raise ArgumentError, "Invalid argument. Expected String, got #{string.class}."
end
end | ruby | def read(string, options={})
if string.is_a?(String)
@string = string
r = NRead.new(string, options)
# Store the data to the instance variables if the readout was a success:
if r.success
@read_success = true
# Update instance variables based on the properties of the NRead object:
@header = r.hdr
@extended_header = r.extended_header
if r.image_narray
@image = r.image_narray
elsif r.image_rubyarray
@image = r.image_rubyarray
end
else
@read_success = false
end
# If any messages have been recorded, send these to the message handling method:
add_msg(r.msg) if r.msg.length > 0
else
raise ArgumentError, "Invalid argument. Expected String, got #{string.class}."
end
end | [
"def",
"read",
"(",
"string",
",",
"options",
"=",
"{",
"}",
")",
"if",
"string",
".",
"is_a?",
"(",
"String",
")",
"@string",
"=",
"string",
"r",
"=",
"NRead",
".",
"new",
"(",
"string",
",",
"options",
")",
"if",
"r",
".",
"success",
"@read_success",
"=",
"true",
"@header",
"=",
"r",
".",
"hdr",
"@extended_header",
"=",
"r",
".",
"extended_header",
"if",
"r",
".",
"image_narray",
"@image",
"=",
"r",
".",
"image_narray",
"elsif",
"r",
".",
"image_rubyarray",
"@image",
"=",
"r",
".",
"image_rubyarray",
"end",
"else",
"@read_success",
"=",
"false",
"end",
"add_msg",
"(",
"r",
".",
"msg",
")",
"if",
"r",
".",
"msg",
".",
"length",
">",
"0",
"else",
"raise",
"ArgumentError",
",",
"\"Invalid argument. Expected String, got #{string.class}.\"",
"end",
"end"
] | Returns a NIFTI object by reading and parsing the specified file.
This is accomplished by initializing the NRead class, which loads NIFTI information.
=== Notes
This method is called automatically when initializing the NObject class with a file parameter,
and in practice should not be called by users. | [
"Returns",
"a",
"NIFTI",
"object",
"by",
"reading",
"and",
"parsing",
"the",
"specified",
"file",
".",
"This",
"is",
"accomplished",
"by",
"initializing",
"the",
"NRead",
"class",
"which",
"loads",
"NIFTI",
"information",
"."
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_object.rb#L123-L146 | train |
thelabtech/questionnaire | app/models/qe/question_sheet.rb | Qe.QuestionSheet.duplicate | def duplicate
new_sheet = QuestionSheet.new(self.attributes)
new_sheet.label = self.label + ' - COPY'
new_sheet.save(:validate => false)
self.pages.each do |page|
page.copy_to(new_sheet)
end
new_sheet
end | ruby | def duplicate
new_sheet = QuestionSheet.new(self.attributes)
new_sheet.label = self.label + ' - COPY'
new_sheet.save(:validate => false)
self.pages.each do |page|
page.copy_to(new_sheet)
end
new_sheet
end | [
"def",
"duplicate",
"new_sheet",
"=",
"QuestionSheet",
".",
"new",
"(",
"self",
".",
"attributes",
")",
"new_sheet",
".",
"label",
"=",
"self",
".",
"label",
"+",
"' - COPY'",
"new_sheet",
".",
"save",
"(",
":validate",
"=>",
"false",
")",
"self",
".",
"pages",
".",
"each",
"do",
"|",
"page",
"|",
"page",
".",
"copy_to",
"(",
"new_sheet",
")",
"end",
"new_sheet",
"end"
] | Pages get duplicated
Question elements get associated
non-question elements get cloned | [
"Pages",
"get",
"duplicated",
"Question",
"elements",
"get",
"associated",
"non",
"-",
"question",
"elements",
"get",
"cloned"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/models/qe/question_sheet.rb#L50-L58 | train |
cie/rubylog | lib/rubylog/variable.rb | Rubylog.Variable.rubylog_unify | def rubylog_unify other
# check if we are bound
if @bound
# if we are bound
# proceed to our dereferenced value
rubylog_dereference.rubylog_unify(other) do yield end
else
# if we are unbound
# dereference the other
other = other.rubylog_dereference
# if the other is a variable
if other.is_a? Rubylog::Variable
# succeed if same object
(yield; return) if self.equal? other
# we union our guards with the other's
other.append_guards guards do
# and bind to the other
bind_to other do
yield
end
end
else
# if the other is a value
# bind to it and
bind_to other do
# check our guards
if guards.all? {|g|g.rubylog_matches_as_guard? other}
yield
end
end
end
end
end | ruby | def rubylog_unify other
# check if we are bound
if @bound
# if we are bound
# proceed to our dereferenced value
rubylog_dereference.rubylog_unify(other) do yield end
else
# if we are unbound
# dereference the other
other = other.rubylog_dereference
# if the other is a variable
if other.is_a? Rubylog::Variable
# succeed if same object
(yield; return) if self.equal? other
# we union our guards with the other's
other.append_guards guards do
# and bind to the other
bind_to other do
yield
end
end
else
# if the other is a value
# bind to it and
bind_to other do
# check our guards
if guards.all? {|g|g.rubylog_matches_as_guard? other}
yield
end
end
end
end
end | [
"def",
"rubylog_unify",
"other",
"if",
"@bound",
"rubylog_dereference",
".",
"rubylog_unify",
"(",
"other",
")",
"do",
"yield",
"end",
"else",
"other",
"=",
"other",
".",
"rubylog_dereference",
"if",
"other",
".",
"is_a?",
"Rubylog",
"::",
"Variable",
"(",
"yield",
";",
"return",
")",
"if",
"self",
".",
"equal?",
"other",
"other",
".",
"append_guards",
"guards",
"do",
"bind_to",
"other",
"do",
"yield",
"end",
"end",
"else",
"bind_to",
"other",
"do",
"if",
"guards",
".",
"all?",
"{",
"|",
"g",
"|",
"g",
".",
"rubylog_matches_as_guard?",
"other",
"}",
"yield",
"end",
"end",
"end",
"end",
"end"
] | Unifies the receiver with another value.
First dereferences both the receiver and the other. If both dereferenced
values are variables, unifies them with the other being bound to the
receiver. If one of them is a variable, it gets bound to the other value.
If none of them is a variable, they are checked for equality with eql?.
Succeeds if other is the same object as the receiver. | [
"Unifies",
"the",
"receiver",
"with",
"another",
"value",
"."
] | bd53971b6bc6a9459b79257c925bdc795bf8c04b | https://github.com/cie/rubylog/blob/bd53971b6bc6a9459b79257c925bdc795bf8c04b/lib/rubylog/variable.rb#L63-L98 | train |
thelabtech/questionnaire | app/models/qe/reference_sheet.rb | Qe.ReferenceSheet.send_invite | def send_invite
return if self.email.blank?
application = self.applicant_answer_sheet
Notifier.deliver_notification(self.email,
application.email,
"Reference Invite",
{'reference_full_name' => self.name,
'applicant_full_name' => application.name,
'applicant_email' => application.email,
'applicant_home_phone' => application.phone,
'reference_url' => edit_reference_sheet_url(self, :a => self.access_key, :host => ActionMailer::Base.default_url_options[:host])})
# Send notification to applicant
Notifier.deliver_notification(applicant_answer_sheet.email, # RECIPIENTS
Questionnaire.from_email, # FROM
"Reference Notification to Applicant", # LIQUID TEMPLATE NAME
{'applicant_full_name' => applicant_answer_sheet.name,
'reference_full_name' => self.name,
'reference_email' => self.email,
'application_url' => edit_answer_sheet_url(applicant_answer_sheet, :host => ActionMailer::Base.default_url_options[:host])})
self.email_sent_at = Time.now
self.save(:validate => false)
true
end | ruby | def send_invite
return if self.email.blank?
application = self.applicant_answer_sheet
Notifier.deliver_notification(self.email,
application.email,
"Reference Invite",
{'reference_full_name' => self.name,
'applicant_full_name' => application.name,
'applicant_email' => application.email,
'applicant_home_phone' => application.phone,
'reference_url' => edit_reference_sheet_url(self, :a => self.access_key, :host => ActionMailer::Base.default_url_options[:host])})
# Send notification to applicant
Notifier.deliver_notification(applicant_answer_sheet.email, # RECIPIENTS
Questionnaire.from_email, # FROM
"Reference Notification to Applicant", # LIQUID TEMPLATE NAME
{'applicant_full_name' => applicant_answer_sheet.name,
'reference_full_name' => self.name,
'reference_email' => self.email,
'application_url' => edit_answer_sheet_url(applicant_answer_sheet, :host => ActionMailer::Base.default_url_options[:host])})
self.email_sent_at = Time.now
self.save(:validate => false)
true
end | [
"def",
"send_invite",
"return",
"if",
"self",
".",
"email",
".",
"blank?",
"application",
"=",
"self",
".",
"applicant_answer_sheet",
"Notifier",
".",
"deliver_notification",
"(",
"self",
".",
"email",
",",
"application",
".",
"email",
",",
"\"Reference Invite\"",
",",
"{",
"'reference_full_name'",
"=>",
"self",
".",
"name",
",",
"'applicant_full_name'",
"=>",
"application",
".",
"name",
",",
"'applicant_email'",
"=>",
"application",
".",
"email",
",",
"'applicant_home_phone'",
"=>",
"application",
".",
"phone",
",",
"'reference_url'",
"=>",
"edit_reference_sheet_url",
"(",
"self",
",",
":a",
"=>",
"self",
".",
"access_key",
",",
":host",
"=>",
"ActionMailer",
"::",
"Base",
".",
"default_url_options",
"[",
":host",
"]",
")",
"}",
")",
"Notifier",
".",
"deliver_notification",
"(",
"applicant_answer_sheet",
".",
"email",
",",
"Questionnaire",
".",
"from_email",
",",
"\"Reference Notification to Applicant\"",
",",
"{",
"'applicant_full_name'",
"=>",
"applicant_answer_sheet",
".",
"name",
",",
"'reference_full_name'",
"=>",
"self",
".",
"name",
",",
"'reference_email'",
"=>",
"self",
".",
"email",
",",
"'application_url'",
"=>",
"edit_answer_sheet_url",
"(",
"applicant_answer_sheet",
",",
":host",
"=>",
"ActionMailer",
"::",
"Base",
".",
"default_url_options",
"[",
":host",
"]",
")",
"}",
")",
"self",
".",
"email_sent_at",
"=",
"Time",
".",
"now",
"self",
".",
"save",
"(",
":validate",
"=>",
"false",
")",
"true",
"end"
] | send email invite | [
"send",
"email",
"invite"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/models/qe/reference_sheet.rb#L77-L103 | train |
flydata/elastic-mapreduce | lib/uuidtools.rb | UUIDTools.UUID.generate_i | def generate_i
return (begin
bytes = (time_low << 96) + (time_mid << 80) +
(time_hi_and_version << 64) + (clock_seq_hi_and_reserved << 56) +
(clock_seq_low << 48)
for i in 0..5
bytes += (nodes[i] << (40 - (i * 8)))
end
bytes
end)
end | ruby | def generate_i
return (begin
bytes = (time_low << 96) + (time_mid << 80) +
(time_hi_and_version << 64) + (clock_seq_hi_and_reserved << 56) +
(clock_seq_low << 48)
for i in 0..5
bytes += (nodes[i] << (40 - (i * 8)))
end
bytes
end)
end | [
"def",
"generate_i",
"return",
"(",
"begin",
"bytes",
"=",
"(",
"time_low",
"<<",
"96",
")",
"+",
"(",
"time_mid",
"<<",
"80",
")",
"+",
"(",
"time_hi_and_version",
"<<",
"64",
")",
"+",
"(",
"clock_seq_hi_and_reserved",
"<<",
"56",
")",
"+",
"(",
"clock_seq_low",
"<<",
"48",
")",
"for",
"i",
"in",
"0",
"..",
"5",
"bytes",
"+=",
"(",
"nodes",
"[",
"i",
"]",
"<<",
"(",
"40",
"-",
"(",
"i",
"*",
"8",
")",
")",
")",
"end",
"bytes",
"end",
")",
"end"
] | Generates an integer representation for this UUID. | [
"Generates",
"an",
"integer",
"representation",
"for",
"this",
"UUID",
"."
] | fc96593d27c7e4797aef67ff4f8c76ee35609d57 | https://github.com/flydata/elastic-mapreduce/blob/fc96593d27c7e4797aef67ff4f8c76ee35609d57/lib/uuidtools.rb#L447-L457 | train |
lanrion/baidu | lib/baidu/client.rb | Baidu.Client.authorize_url | def authorize_url(opts = {})
opts[:redirect_uri] ||= DEFAULT_REDIRECT_URI
# scope:非必须参数,以空格分隔的权限列表,若不传递此参数,代表请求用户的默认权限。关于权限的具体信息请参考“权限列表”。
opts[:scope] ||= "basic netdisk super_msg"
oauth_client.auth_code.authorize_url(scope: opts[:scope], redirect_uri: opts[:redirect_uri])
end | ruby | def authorize_url(opts = {})
opts[:redirect_uri] ||= DEFAULT_REDIRECT_URI
# scope:非必须参数,以空格分隔的权限列表,若不传递此参数,代表请求用户的默认权限。关于权限的具体信息请参考“权限列表”。
opts[:scope] ||= "basic netdisk super_msg"
oauth_client.auth_code.authorize_url(scope: opts[:scope], redirect_uri: opts[:redirect_uri])
end | [
"def",
"authorize_url",
"(",
"opts",
"=",
"{",
"}",
")",
"opts",
"[",
":redirect_uri",
"]",
"||=",
"DEFAULT_REDIRECT_URI",
"opts",
"[",
":scope",
"]",
"||=",
"\"basic netdisk super_msg\"",
"oauth_client",
".",
"auth_code",
".",
"authorize_url",
"(",
"scope",
":",
"opts",
"[",
":scope",
"]",
",",
"redirect_uri",
":",
"opts",
"[",
":redirect_uri",
"]",
")",
"end"
] | =begin rdoc
OAuth2 +authorize_url+
redirect or open this URL for login in Baidu website
=== Params:
* +opts+ Hash
* +redirect_uri+ String - default Baidu::DEFAULT_REDIRECT_URI,URL with logined redirect back
=== Rails example:
class SessionController
def oauth
redirect_to $baidu.authorize_url(redirect_uri: callback_session_url)
end
def callback
auth_code = params[:code]
$baidu.token!(auth_code)
end
end
=end | [
"=",
"begin",
"rdoc",
"OAuth2",
"+",
"authorize_url",
"+"
] | 5eeecec67e402f9ea890049f5abf42f1ce3866f4 | https://github.com/lanrion/baidu/blob/5eeecec67e402f9ea890049f5abf42f1ce3866f4/lib/baidu/client.rb#L61-L66 | train |
lanrion/baidu | lib/baidu/client.rb | Baidu.Client.token! | def token!(authorization_code,opts = {})
opts[:redirect_uri] ||= DEFAULT_REDIRECT_URI
self.access_token = oauth_client.auth_code.get_token(authorization_code, redirect_uri: opts[:redirect_uri])
end | ruby | def token!(authorization_code,opts = {})
opts[:redirect_uri] ||= DEFAULT_REDIRECT_URI
self.access_token = oauth_client.auth_code.get_token(authorization_code, redirect_uri: opts[:redirect_uri])
end | [
"def",
"token!",
"(",
"authorization_code",
",",
"opts",
"=",
"{",
"}",
")",
"opts",
"[",
":redirect_uri",
"]",
"||=",
"DEFAULT_REDIRECT_URI",
"self",
".",
"access_token",
"=",
"oauth_client",
".",
"auth_code",
".",
"get_token",
"(",
"authorization_code",
",",
"redirect_uri",
":",
"opts",
"[",
":redirect_uri",
"]",
")",
"end"
] | =begin rdoc
OAuth get_token method
This method will get #access_token (OAuth2::AccessToken) ... and save in Baidu instance
== Params:
* authorization_code - Authorization Code in callback URL
* opts
* +redirect_uri+ String - default Baidu::DEFAULT_REDIRECT_URI,URL with logined redirect back
=end | [
"=",
"begin",
"rdoc",
"OAuth",
"get_token",
"method"
] | 5eeecec67e402f9ea890049f5abf42f1ce3866f4 | https://github.com/lanrion/baidu/blob/5eeecec67e402f9ea890049f5abf42f1ce3866f4/lib/baidu/client.rb#L80-L83 | train |
lanrion/baidu | lib/baidu/client.rb | Baidu.Client.refresh_token! | def refresh_token!(refresh_token)
old_token = OAuth2::AccessToken.new(oauth_client,'', refresh_token: refresh_token)
self.access_token = old_token.refresh!
end | ruby | def refresh_token!(refresh_token)
old_token = OAuth2::AccessToken.new(oauth_client,'', refresh_token: refresh_token)
self.access_token = old_token.refresh!
end | [
"def",
"refresh_token!",
"(",
"refresh_token",
")",
"old_token",
"=",
"OAuth2",
"::",
"AccessToken",
".",
"new",
"(",
"oauth_client",
",",
"''",
",",
"refresh_token",
":",
"refresh_token",
")",
"self",
".",
"access_token",
"=",
"old_token",
".",
"refresh!",
"end"
] | =begin rdoc
OAuth refresh_token method
Refresh tokens when token was expired
== Params:
* refresh_token - refresh_token in last got #access_token
=end | [
"=",
"begin",
"rdoc",
"OAuth",
"refresh_token",
"method"
] | 5eeecec67e402f9ea890049f5abf42f1ce3866f4 | https://github.com/lanrion/baidu/blob/5eeecec67e402f9ea890049f5abf42f1ce3866f4/lib/baidu/client.rb#L98-L101 | train |
sleewoo/minispec | lib/minispec/api/instance/mocks/stubs.rb | MiniSpec.InstanceAPI.stub | def stub object, stub, visibility = nil, &proc
[Symbol, String, Hash].include?(stub.class) ||
raise(ArgumentError, 'a Symbol, String or Hash expected')
if stub.is_a?(Hash)
return hash_stub(object, stub, visibility, &proc)
elsif stub =~ /\./
return chained_stub(object, stub, visibility, &proc)
end
visibility ||= MiniSpec::Utils.method_visibility(object, stub) || :public
stubs = (@__ms__stubs[object.__id__] ||= {})
stubs[stub] ||= MiniSpec::Mocks::Stub.new(object, @__ms__messages, @__ms__stubs__originals)
stubs[stub].stubify(stub, visibility, &proc)
stubs[stub]
end | ruby | def stub object, stub, visibility = nil, &proc
[Symbol, String, Hash].include?(stub.class) ||
raise(ArgumentError, 'a Symbol, String or Hash expected')
if stub.is_a?(Hash)
return hash_stub(object, stub, visibility, &proc)
elsif stub =~ /\./
return chained_stub(object, stub, visibility, &proc)
end
visibility ||= MiniSpec::Utils.method_visibility(object, stub) || :public
stubs = (@__ms__stubs[object.__id__] ||= {})
stubs[stub] ||= MiniSpec::Mocks::Stub.new(object, @__ms__messages, @__ms__stubs__originals)
stubs[stub].stubify(stub, visibility, &proc)
stubs[stub]
end | [
"def",
"stub",
"object",
",",
"stub",
",",
"visibility",
"=",
"nil",
",",
"&",
"proc",
"[",
"Symbol",
",",
"String",
",",
"Hash",
"]",
".",
"include?",
"(",
"stub",
".",
"class",
")",
"||",
"raise",
"(",
"ArgumentError",
",",
"'a Symbol, String or Hash expected'",
")",
"if",
"stub",
".",
"is_a?",
"(",
"Hash",
")",
"return",
"hash_stub",
"(",
"object",
",",
"stub",
",",
"visibility",
",",
"&",
"proc",
")",
"elsif",
"stub",
"=~",
"/",
"\\.",
"/",
"return",
"chained_stub",
"(",
"object",
",",
"stub",
",",
"visibility",
",",
"&",
"proc",
")",
"end",
"visibility",
"||=",
"MiniSpec",
"::",
"Utils",
".",
"method_visibility",
"(",
"object",
",",
"stub",
")",
"||",
":public",
"stubs",
"=",
"(",
"@__ms__stubs",
"[",
"object",
".",
"__id__",
"]",
"||=",
"{",
"}",
")",
"stubs",
"[",
"stub",
"]",
"||=",
"MiniSpec",
"::",
"Mocks",
"::",
"Stub",
".",
"new",
"(",
"object",
",",
"@__ms__messages",
",",
"@__ms__stubs__originals",
")",
"stubs",
"[",
"stub",
"]",
".",
"stubify",
"(",
"stub",
",",
"visibility",
",",
"&",
"proc",
")",
"stubs",
"[",
"stub",
"]",
"end"
] | stubbing given method and keeps original visibility
if a block given, it will receive original method as first argument
and any passed parameters as rest arguments.
@example make Some::Remote::API.call to return success
stub(Some::Remote::API, :call) { :success }
@example call original
stub(obj, :a) {|orig| orig.call}
@param object object to define stub on
@param stub method to be stubbed.
if a Hash given, keys will be stubbed methods and values return values
@param [Proc] &proc block to be yielded when stub called
@return MiniSpec::Mocks::Stub instance | [
"stubbing",
"given",
"method",
"and",
"keeps",
"original",
"visibility"
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/api/instance/mocks/stubs.rb#L21-L36 | train |
sleewoo/minispec | lib/minispec/api/instance/mocks/stubs.rb | MiniSpec.InstanceAPI.stubs | def stubs object, *stubs, &proc
MiniSpec::Mocks::MultipleStubsProxy.new(stubs.map {|s| stub(object, s, &proc)})
end | ruby | def stubs object, *stubs, &proc
MiniSpec::Mocks::MultipleStubsProxy.new(stubs.map {|s| stub(object, s, &proc)})
end | [
"def",
"stubs",
"object",
",",
"*",
"stubs",
",",
"&",
"proc",
"MiniSpec",
"::",
"Mocks",
"::",
"MultipleStubsProxy",
".",
"new",
"(",
"stubs",
".",
"map",
"{",
"|",
"s",
"|",
"stub",
"(",
"object",
",",
"s",
",",
"&",
"proc",
")",
"}",
")",
"end"
] | same as `stub` except it defines multiple stubs at once
@param object
@param *stubs
@param &proc
@return MiniSpec::Mocks::MultipleStubsProxy instance | [
"same",
"as",
"stub",
"except",
"it",
"defines",
"multiple",
"stubs",
"at",
"once"
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/api/instance/mocks/stubs.rb#L70-L72 | train |
qw3/getnet_api | lib/getnet_api/card.rb | GetnetApi.Card.to_request | def to_request
card = {
number_token: self.number_token,
cardholder_name: self.cardholder_name,
security_code: self.security_code,
brand: self.brand,
expiration_month: self.expiration_month,
expiration_year: self.expiration_year
}
return card
end | ruby | def to_request
card = {
number_token: self.number_token,
cardholder_name: self.cardholder_name,
security_code: self.security_code,
brand: self.brand,
expiration_month: self.expiration_month,
expiration_year: self.expiration_year
}
return card
end | [
"def",
"to_request",
"card",
"=",
"{",
"number_token",
":",
"self",
".",
"number_token",
",",
"cardholder_name",
":",
"self",
".",
"cardholder_name",
",",
"security_code",
":",
"self",
".",
"security_code",
",",
"brand",
":",
"self",
".",
"brand",
",",
"expiration_month",
":",
"self",
".",
"expiration_month",
",",
"expiration_year",
":",
"self",
".",
"expiration_year",
"}",
"return",
"card",
"end"
] | Nova instancia da classe Card
@param [Hash] campos
Montar o Hash de dados do pagamento no padrão utilizado pela Getnet | [
"Nova",
"instancia",
"da",
"classe",
"Card"
] | 94cbda66aab03d83ea38bc5325ea2a02a639e922 | https://github.com/qw3/getnet_api/blob/94cbda66aab03d83ea38bc5325ea2a02a639e922/lib/getnet_api/card.rb#L55-L66 | train |
zerowidth/camper_van | lib/camper_van/server.rb | CamperVan.Server.post_init | def post_init(*args)
logger.info "got connection from #{remote_ip}"
# initialize the line-based protocol: IRC is \r\n
@lt2_delimiter = "\r\n"
# start up the IRCD for this connection
@ircd = IRCD.new(self, options)
if options[:ssl]
logger.info "starting TLS for #{remote_ip}"
start_tls(:cert_chain_file => options[:ssl_cert], :private_key_file => options[:ssl_private_key], :verify_peer => options[:ssl_verify_peer])
end
end | ruby | def post_init(*args)
logger.info "got connection from #{remote_ip}"
# initialize the line-based protocol: IRC is \r\n
@lt2_delimiter = "\r\n"
# start up the IRCD for this connection
@ircd = IRCD.new(self, options)
if options[:ssl]
logger.info "starting TLS for #{remote_ip}"
start_tls(:cert_chain_file => options[:ssl_cert], :private_key_file => options[:ssl_private_key], :verify_peer => options[:ssl_verify_peer])
end
end | [
"def",
"post_init",
"(",
"*",
"args",
")",
"logger",
".",
"info",
"\"got connection from #{remote_ip}\"",
"@lt2_delimiter",
"=",
"\"\\r\\n\"",
"@ircd",
"=",
"IRCD",
".",
"new",
"(",
"self",
",",
"options",
")",
"if",
"options",
"[",
":ssl",
"]",
"logger",
".",
"info",
"\"starting TLS for #{remote_ip}\"",
"start_tls",
"(",
":cert_chain_file",
"=>",
"options",
"[",
":ssl_cert",
"]",
",",
":private_key_file",
"=>",
"options",
"[",
":ssl_private_key",
"]",
",",
":verify_peer",
"=>",
"options",
"[",
":ssl_verify_peer",
"]",
")",
"end",
"end"
] | Public callback once a server connection is established.
Initializes an IRCD instance for this connection. | [
"Public",
"callback",
"once",
"a",
"server",
"connection",
"is",
"established",
"."
] | 984351a3b472e936a451f1d1cd987ca27d981d23 | https://github.com/zerowidth/camper_van/blob/984351a3b472e936a451f1d1cd987ca27d981d23/lib/camper_van/server.rb#L105-L118 | train |
jamesotron/IPAddrExtensions | lib/ipaddr_extensions.rb | IPAddrExtensions.ClassMethods.generate_ULA | def generate_ULA(mac, subnet_id = 0, locally_assigned=true)
now = Time.now.utc
ntp_time = ((now.to_i + 2208988800) << 32) + now.nsec # Convert time to an NTP timstamp.
system_id = '::/64'.to_ip.eui_64(mac).to_i # Generate an EUI64 from the provided MAC address.
key = [ ntp_time, system_id ].pack('QQ') # Pack the ntp timestamp and the system_id into a binary string
global_id = Digest::SHA1.digest( key ).unpack('QQ').last & 0xffffffffff # Use only the last 40 bytes of the SHA1 digest.
prefix =
(126 << 121) + # 0xfc (bytes 0..6)
((locally_assigned ? 1 : 0) << 120) + # locally assigned? (byte 7)
(global_id << 80) + # 40 bit global idenfitier (bytes 8..48)
((subnet_id & 0xffff) << 64) # 16 bit subnet_id (bytes 48..64)
prefix.to_ip(Socket::AF_INET6).tap { |p| p.length = 64 }
end | ruby | def generate_ULA(mac, subnet_id = 0, locally_assigned=true)
now = Time.now.utc
ntp_time = ((now.to_i + 2208988800) << 32) + now.nsec # Convert time to an NTP timstamp.
system_id = '::/64'.to_ip.eui_64(mac).to_i # Generate an EUI64 from the provided MAC address.
key = [ ntp_time, system_id ].pack('QQ') # Pack the ntp timestamp and the system_id into a binary string
global_id = Digest::SHA1.digest( key ).unpack('QQ').last & 0xffffffffff # Use only the last 40 bytes of the SHA1 digest.
prefix =
(126 << 121) + # 0xfc (bytes 0..6)
((locally_assigned ? 1 : 0) << 120) + # locally assigned? (byte 7)
(global_id << 80) + # 40 bit global idenfitier (bytes 8..48)
((subnet_id & 0xffff) << 64) # 16 bit subnet_id (bytes 48..64)
prefix.to_ip(Socket::AF_INET6).tap { |p| p.length = 64 }
end | [
"def",
"generate_ULA",
"(",
"mac",
",",
"subnet_id",
"=",
"0",
",",
"locally_assigned",
"=",
"true",
")",
"now",
"=",
"Time",
".",
"now",
".",
"utc",
"ntp_time",
"=",
"(",
"(",
"now",
".",
"to_i",
"+",
"2208988800",
")",
"<<",
"32",
")",
"+",
"now",
".",
"nsec",
"system_id",
"=",
"'::/64'",
".",
"to_ip",
".",
"eui_64",
"(",
"mac",
")",
".",
"to_i",
"key",
"=",
"[",
"ntp_time",
",",
"system_id",
"]",
".",
"pack",
"(",
"'QQ'",
")",
"global_id",
"=",
"Digest",
"::",
"SHA1",
".",
"digest",
"(",
"key",
")",
".",
"unpack",
"(",
"'QQ'",
")",
".",
"last",
"&",
"0xffffffffff",
"prefix",
"=",
"(",
"126",
"<<",
"121",
")",
"+",
"(",
"(",
"locally_assigned",
"?",
"1",
":",
"0",
")",
"<<",
"120",
")",
"+",
"(",
"global_id",
"<<",
"80",
")",
"+",
"(",
"(",
"subnet_id",
"&",
"0xffff",
")",
"<<",
"64",
")",
"prefix",
".",
"to_ip",
"(",
"Socket",
"::",
"AF_INET6",
")",
".",
"tap",
"{",
"|",
"p",
"|",
"p",
".",
"length",
"=",
"64",
"}",
"end"
] | Generate an IPv6 Unique Local Address using the supplied system MAC address.
Note that the MAC address is just used as a source of randomness, so where you
get it from is not important and doesn't restrict this ULA to just that system.
See RFC4193 | [
"Generate",
"an",
"IPv6",
"Unique",
"Local",
"Address",
"using",
"the",
"supplied",
"system",
"MAC",
"address",
".",
"Note",
"that",
"the",
"MAC",
"address",
"is",
"just",
"used",
"as",
"a",
"source",
"of",
"randomness",
"so",
"where",
"you",
"get",
"it",
"from",
"is",
"not",
"important",
"and",
"doesn",
"t",
"restrict",
"this",
"ULA",
"to",
"just",
"that",
"system",
".",
"See",
"RFC4193"
] | 0426dbad801cf305129370fb991cd9785cdfeb71 | https://github.com/jamesotron/IPAddrExtensions/blob/0426dbad801cf305129370fb991cd9785cdfeb71/lib/ipaddr_extensions.rb#L495-L509 | train |
thelabtech/questionnaire | app/controllers/qe/admin/question_pages_controller.rb | Qe.Admin::QuestionPagesController.show_panel | def show_panel
@tab_name = params[:panel_name]
@panel_name = params[:panel_name] == "properties" ? "prop_sheet" : params[:panel_name]
@all_pages = @question_sheet.pages.find(:all) # for pages_list
@page = @question_sheet.pages.find(params[:id])
respond_to do |format|
format.js # load panel
end
end | ruby | def show_panel
@tab_name = params[:panel_name]
@panel_name = params[:panel_name] == "properties" ? "prop_sheet" : params[:panel_name]
@all_pages = @question_sheet.pages.find(:all) # for pages_list
@page = @question_sheet.pages.find(params[:id])
respond_to do |format|
format.js # load panel
end
end | [
"def",
"show_panel",
"@tab_name",
"=",
"params",
"[",
":panel_name",
"]",
"@panel_name",
"=",
"params",
"[",
":panel_name",
"]",
"==",
"\"properties\"",
"?",
"\"prop_sheet\"",
":",
"params",
"[",
":panel_name",
"]",
"@all_pages",
"=",
"@question_sheet",
".",
"pages",
".",
"find",
"(",
":all",
")",
"@page",
"=",
"@question_sheet",
".",
"pages",
".",
"find",
"(",
"params",
"[",
":id",
"]",
")",
"respond_to",
"do",
"|",
"format",
"|",
"format",
".",
"js",
"end",
"end"
] | load panel all AJAX-like
GET | [
"load",
"panel",
"all",
"AJAX",
"-",
"like",
"GET"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/controllers/qe/admin/question_pages_controller.rb#L74-L83 | train |
codefoundry/svn | lib/svn/utils.rb | Svn.Utils.wrap | def wrap( obj )
ptr = FFI::MemoryPointer.new( :uint64 )
ptr.write_uint64( obj.object_id )
ptr
end | ruby | def wrap( obj )
ptr = FFI::MemoryPointer.new( :uint64 )
ptr.write_uint64( obj.object_id )
ptr
end | [
"def",
"wrap",
"(",
"obj",
")",
"ptr",
"=",
"FFI",
"::",
"MemoryPointer",
".",
"new",
"(",
":uint64",
")",
"ptr",
".",
"write_uint64",
"(",
"obj",
".",
"object_id",
")",
"ptr",
"end"
] | Returns a pointer to the object_id of +obj+ | [
"Returns",
"a",
"pointer",
"to",
"the",
"object_id",
"of",
"+",
"obj",
"+"
] | 930a8da65fbecf3ffed50655e1cb10fcbc484be4 | https://github.com/codefoundry/svn/blob/930a8da65fbecf3ffed50655e1cb10fcbc484be4/lib/svn/utils.rb#L12-L16 | train |
sleewoo/minispec | lib/minispec/utils.rb | MiniSpec.Utils.method_visibility | def method_visibility object, method
{
public: :public_methods,
protected: :protected_methods,
private: :private_methods
}.each_pair do |v,m|
if v == :public
# in case public_methods overridden to include method
# but method in fact does not exists,
# most notable ActiveRecord::Base#find which rely on method_missing
return v if object.respond_to?(method)
else
return v if object.send(m).include?(method)
end
end
nil
end | ruby | def method_visibility object, method
{
public: :public_methods,
protected: :protected_methods,
private: :private_methods
}.each_pair do |v,m|
if v == :public
# in case public_methods overridden to include method
# but method in fact does not exists,
# most notable ActiveRecord::Base#find which rely on method_missing
return v if object.respond_to?(method)
else
return v if object.send(m).include?(method)
end
end
nil
end | [
"def",
"method_visibility",
"object",
",",
"method",
"{",
"public",
":",
":public_methods",
",",
"protected",
":",
":protected_methods",
",",
"private",
":",
":private_methods",
"}",
".",
"each_pair",
"do",
"|",
"v",
",",
"m",
"|",
"if",
"v",
"==",
":public",
"return",
"v",
"if",
"object",
".",
"respond_to?",
"(",
"method",
")",
"else",
"return",
"v",
"if",
"object",
".",
"send",
"(",
"m",
")",
".",
"include?",
"(",
"method",
")",
"end",
"end",
"nil",
"end"
] | determines method's visibility
@param object
@param method
@return [Symbol] or nil | [
"determines",
"method",
"s",
"visibility"
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/utils.rb#L59-L75 | train |
sleewoo/minispec | lib/minispec/utils.rb | MiniSpec.Utils.any_match? | def any_match? label, matchers
reject, select = matchers.partition {|m| m.is_a?(Hash)}
rejected = rejected?(label, reject)
if select.any?
return select.find {|x| (x == :*) || match?(label, x)} && !rejected
end
!rejected
end | ruby | def any_match? label, matchers
reject, select = matchers.partition {|m| m.is_a?(Hash)}
rejected = rejected?(label, reject)
if select.any?
return select.find {|x| (x == :*) || match?(label, x)} && !rejected
end
!rejected
end | [
"def",
"any_match?",
"label",
",",
"matchers",
"reject",
",",
"select",
"=",
"matchers",
".",
"partition",
"{",
"|",
"m",
"|",
"m",
".",
"is_a?",
"(",
"Hash",
")",
"}",
"rejected",
"=",
"rejected?",
"(",
"label",
",",
"reject",
")",
"if",
"select",
".",
"any?",
"return",
"select",
".",
"find",
"{",
"|",
"x",
"|",
"(",
"x",
"==",
":*",
")",
"||",
"match?",
"(",
"label",
",",
"x",
")",
"}",
"&&",
"!",
"rejected",
"end",
"!",
"rejected",
"end"
] | checks whether given label matches any matcher.
even if label matched, it will return `false` if label matches some rejector.
@param label
@param matchers an `Array` of matchers and rejectors.
matchers contained as hashes, rejectors as arrays.
@return `true` or `false` | [
"checks",
"whether",
"given",
"label",
"matches",
"any",
"matcher",
".",
"even",
"if",
"label",
"matched",
"it",
"will",
"return",
"false",
"if",
"label",
"matches",
"some",
"rejector",
"."
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/utils.rb#L100-L108 | train |
sleewoo/minispec | lib/minispec/utils.rb | MiniSpec.Utils.rejected? | def rejected? label, reject
if reject.any? && (x = reject.first[:except])
if x.is_a?(Array)
return true if x.find {|m| match?(label, m)}
else
return true if match?(label, x)
end
end
false
end | ruby | def rejected? label, reject
if reject.any? && (x = reject.first[:except])
if x.is_a?(Array)
return true if x.find {|m| match?(label, m)}
else
return true if match?(label, x)
end
end
false
end | [
"def",
"rejected?",
"label",
",",
"reject",
"if",
"reject",
".",
"any?",
"&&",
"(",
"x",
"=",
"reject",
".",
"first",
"[",
":except",
"]",
")",
"if",
"x",
".",
"is_a?",
"(",
"Array",
")",
"return",
"true",
"if",
"x",
".",
"find",
"{",
"|",
"m",
"|",
"match?",
"(",
"label",
",",
"m",
")",
"}",
"else",
"return",
"true",
"if",
"match?",
"(",
"label",
",",
"x",
")",
"end",
"end",
"false",
"end"
] | checks whether given label matches any rejector.
@param label
@param reject an `Array` of rejectors, each being a `Hash` containing `:except` key
@return `true` or `false` | [
"checks",
"whether",
"given",
"label",
"matches",
"any",
"rejector",
"."
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/utils.rb#L116-L125 | train |
sleewoo/minispec | lib/minispec/utils.rb | MiniSpec.Utils.match? | def match? label, x
x.is_a?(Regexp) ? label.to_s =~ x : label == x
end | ruby | def match? label, x
x.is_a?(Regexp) ? label.to_s =~ x : label == x
end | [
"def",
"match?",
"label",
",",
"x",
"x",
".",
"is_a?",
"(",
"Regexp",
")",
"?",
"label",
".",
"to_s",
"=~",
"x",
":",
"label",
"==",
"x",
"end"
] | compare given label to given expression.
if expression is a `Regexp` comparing using `=~`.
otherwise `==` are used
@param label
@param x
@return `true` or `false` | [
"compare",
"given",
"label",
"to",
"given",
"expression",
".",
"if",
"expression",
"is",
"a",
"Regexp",
"comparing",
"using",
"=",
"~",
".",
"otherwise",
"==",
"are",
"used"
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/utils.rb#L135-L137 | train |
kissmetrics/uri_signer | lib/uri_signer/signer.rb | UriSigner.Signer.uri_with_signature | def uri_with_signature
separator = if request_parser.query_params? then '&' else '?' end
encoded_signature = signature.extend(UriSigner::Helpers::String).escaped
"%s%s_signature=%s" % [self.uri, separator, encoded_signature]
end | ruby | def uri_with_signature
separator = if request_parser.query_params? then '&' else '?' end
encoded_signature = signature.extend(UriSigner::Helpers::String).escaped
"%s%s_signature=%s" % [self.uri, separator, encoded_signature]
end | [
"def",
"uri_with_signature",
"separator",
"=",
"if",
"request_parser",
".",
"query_params?",
"then",
"'&'",
"else",
"'?'",
"end",
"encoded_signature",
"=",
"signature",
".",
"extend",
"(",
"UriSigner",
"::",
"Helpers",
"::",
"String",
")",
".",
"escaped",
"\"%s%s_signature=%s\"",
"%",
"[",
"self",
".",
"uri",
",",
"separator",
",",
"encoded_signature",
"]",
"end"
] | Returns the URI with the signature appended to the query string
return [String] | [
"Returns",
"the",
"URI",
"with",
"the",
"signature",
"appended",
"to",
"the",
"query",
"string"
] | 3169df476c7f8ed88c5af6ade2c826ad3e5fa2a3 | https://github.com/kissmetrics/uri_signer/blob/3169df476c7f8ed88c5af6ade2c826ad3e5fa2a3/lib/uri_signer/signer.rb#L57-L61 | train |
grk/polish | lib/polish/proxies.rb | Polish.Proxies.pluralize | def pluralize(n, *variants)
raise ArgumentError, "Must have a Numeric as a first parameter" unless n.is_a?(Numeric)
raise ArgumentError, "Must have 3 variants for pluralization" if variants.size < 3
variants_hash = pluralization_variants_to_hash(*variants)
I18n.backend.send(:pluralize, LOCALE, variants_hash, n)
end | ruby | def pluralize(n, *variants)
raise ArgumentError, "Must have a Numeric as a first parameter" unless n.is_a?(Numeric)
raise ArgumentError, "Must have 3 variants for pluralization" if variants.size < 3
variants_hash = pluralization_variants_to_hash(*variants)
I18n.backend.send(:pluralize, LOCALE, variants_hash, n)
end | [
"def",
"pluralize",
"(",
"n",
",",
"*",
"variants",
")",
"raise",
"ArgumentError",
",",
"\"Must have a Numeric as a first parameter\"",
"unless",
"n",
".",
"is_a?",
"(",
"Numeric",
")",
"raise",
"ArgumentError",
",",
"\"Must have 3 variants for pluralization\"",
"if",
"variants",
".",
"size",
"<",
"3",
"variants_hash",
"=",
"pluralization_variants_to_hash",
"(",
"*",
"variants",
")",
"I18n",
".",
"backend",
".",
"send",
"(",
":pluralize",
",",
"LOCALE",
",",
"variants_hash",
",",
"n",
")",
"end"
] | Simple pluralization proxy
Usage:
Polish.pluralize(1, "dom", "domy", "domów") | [
"Simple",
"pluralization",
"proxy"
] | d1488048e53f93eabe7219eb7d5760eef55a362b | https://github.com/grk/polish/blob/d1488048e53f93eabe7219eb7d5760eef55a362b/lib/polish/proxies.rb#L24-L29 | train |
thelabtech/questionnaire | app/models/qe/question.rb | Qe.Question.set_response | def set_response(values, app)
values = Array.wrap(values)
if !object_name.blank? and !attribute_name.blank?
# if eval("app." + object_name).present?
object = object_name == 'application' ? app : eval("app." + object_name)
unless object.present?
if object_name.include?('.')
objects = object_name.split('.')
object = eval("app." + objects[0..-2].join('.') + ".create_" + objects.last)
eval("app." + objects[0..-2].join('.')).reload
end
end
unless responses(app) == values
value = ActiveRecord::Base.connection.quote_string(values.first)
if self.is_a?(DateField) && value.present?
begin
value = Date.strptime(value, (I18n.t 'date.formats.default'))
rescue
raise "invalid date - " + value.inspect
end
end
object.update_attribute(attribute_name, value)
end
# else
# raise object_name.inspect + ' == ' + attribute_name.inspect
# end
else
@answers ||= []
@mark_for_destroy ||= []
# go through existing answers (in reverse order, as we delete)
(@answers.length - 1).downto(0) do |index|
# reject: skip over responses that are unchanged
unless values.reject! {|value| value == @answers[index]}
# remove any answers that don't match the posted values
@mark_for_destroy << @answers[index] # destroy from database later
@answers.delete_at(index)
end
end
# insert any new answers
for value in values
if @mark_for_destroy.empty?
answer = Answer.new(:question_id => self.id)
else
# re-use marked answers (an update vs. a delete+insert)
answer = @mark_for_destroy.pop
end
answer.set(value)
@answers << answer
end
end
end | ruby | def set_response(values, app)
values = Array.wrap(values)
if !object_name.blank? and !attribute_name.blank?
# if eval("app." + object_name).present?
object = object_name == 'application' ? app : eval("app." + object_name)
unless object.present?
if object_name.include?('.')
objects = object_name.split('.')
object = eval("app." + objects[0..-2].join('.') + ".create_" + objects.last)
eval("app." + objects[0..-2].join('.')).reload
end
end
unless responses(app) == values
value = ActiveRecord::Base.connection.quote_string(values.first)
if self.is_a?(DateField) && value.present?
begin
value = Date.strptime(value, (I18n.t 'date.formats.default'))
rescue
raise "invalid date - " + value.inspect
end
end
object.update_attribute(attribute_name, value)
end
# else
# raise object_name.inspect + ' == ' + attribute_name.inspect
# end
else
@answers ||= []
@mark_for_destroy ||= []
# go through existing answers (in reverse order, as we delete)
(@answers.length - 1).downto(0) do |index|
# reject: skip over responses that are unchanged
unless values.reject! {|value| value == @answers[index]}
# remove any answers that don't match the posted values
@mark_for_destroy << @answers[index] # destroy from database later
@answers.delete_at(index)
end
end
# insert any new answers
for value in values
if @mark_for_destroy.empty?
answer = Answer.new(:question_id => self.id)
else
# re-use marked answers (an update vs. a delete+insert)
answer = @mark_for_destroy.pop
end
answer.set(value)
@answers << answer
end
end
end | [
"def",
"set_response",
"(",
"values",
",",
"app",
")",
"values",
"=",
"Array",
".",
"wrap",
"(",
"values",
")",
"if",
"!",
"object_name",
".",
"blank?",
"and",
"!",
"attribute_name",
".",
"blank?",
"object",
"=",
"object_name",
"==",
"'application'",
"?",
"app",
":",
"eval",
"(",
"\"app.\"",
"+",
"object_name",
")",
"unless",
"object",
".",
"present?",
"if",
"object_name",
".",
"include?",
"(",
"'.'",
")",
"objects",
"=",
"object_name",
".",
"split",
"(",
"'.'",
")",
"object",
"=",
"eval",
"(",
"\"app.\"",
"+",
"objects",
"[",
"0",
"..",
"-",
"2",
"]",
".",
"join",
"(",
"'.'",
")",
"+",
"\".create_\"",
"+",
"objects",
".",
"last",
")",
"eval",
"(",
"\"app.\"",
"+",
"objects",
"[",
"0",
"..",
"-",
"2",
"]",
".",
"join",
"(",
"'.'",
")",
")",
".",
"reload",
"end",
"end",
"unless",
"responses",
"(",
"app",
")",
"==",
"values",
"value",
"=",
"ActiveRecord",
"::",
"Base",
".",
"connection",
".",
"quote_string",
"(",
"values",
".",
"first",
")",
"if",
"self",
".",
"is_a?",
"(",
"DateField",
")",
"&&",
"value",
".",
"present?",
"begin",
"value",
"=",
"Date",
".",
"strptime",
"(",
"value",
",",
"(",
"I18n",
".",
"t",
"'date.formats.default'",
")",
")",
"rescue",
"raise",
"\"invalid date - \"",
"+",
"value",
".",
"inspect",
"end",
"end",
"object",
".",
"update_attribute",
"(",
"attribute_name",
",",
"value",
")",
"end",
"else",
"@answers",
"||=",
"[",
"]",
"@mark_for_destroy",
"||=",
"[",
"]",
"(",
"@answers",
".",
"length",
"-",
"1",
")",
".",
"downto",
"(",
"0",
")",
"do",
"|",
"index",
"|",
"unless",
"values",
".",
"reject!",
"{",
"|",
"value",
"|",
"value",
"==",
"@answers",
"[",
"index",
"]",
"}",
"@mark_for_destroy",
"<<",
"@answers",
"[",
"index",
"]",
"@answers",
".",
"delete_at",
"(",
"index",
")",
"end",
"end",
"for",
"value",
"in",
"values",
"if",
"@mark_for_destroy",
".",
"empty?",
"answer",
"=",
"Answer",
".",
"new",
"(",
":question_id",
"=>",
"self",
".",
"id",
")",
"else",
"answer",
"=",
"@mark_for_destroy",
".",
"pop",
"end",
"answer",
".",
"set",
"(",
"value",
")",
"@answers",
"<<",
"answer",
"end",
"end",
"end"
] | set answers from posted response | [
"set",
"answers",
"from",
"posted",
"response"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/models/qe/question.rb#L126-L177 | train |
thelabtech/questionnaire | app/models/qe/question.rb | Qe.Question.save_response | def save_response(answer_sheet)
unless @answers.nil?
for answer in @answers
if answer.is_a?(Answer)
answer.answer_sheet_id = answer_sheet.id
answer.save!
end
end
end
# remove others
unless @mark_for_destroy.nil?
for answer in @mark_for_destroy
answer.destroy
end
@mark_for_destroy.clear
end
rescue TypeError
raise answer.inspect
end | ruby | def save_response(answer_sheet)
unless @answers.nil?
for answer in @answers
if answer.is_a?(Answer)
answer.answer_sheet_id = answer_sheet.id
answer.save!
end
end
end
# remove others
unless @mark_for_destroy.nil?
for answer in @mark_for_destroy
answer.destroy
end
@mark_for_destroy.clear
end
rescue TypeError
raise answer.inspect
end | [
"def",
"save_response",
"(",
"answer_sheet",
")",
"unless",
"@answers",
".",
"nil?",
"for",
"answer",
"in",
"@answers",
"if",
"answer",
".",
"is_a?",
"(",
"Answer",
")",
"answer",
".",
"answer_sheet_id",
"=",
"answer_sheet",
".",
"id",
"answer",
".",
"save!",
"end",
"end",
"end",
"unless",
"@mark_for_destroy",
".",
"nil?",
"for",
"answer",
"in",
"@mark_for_destroy",
"answer",
".",
"destroy",
"end",
"@mark_for_destroy",
".",
"clear",
"end",
"rescue",
"TypeError",
"raise",
"answer",
".",
"inspect",
"end"
] | save this question's @answers to database | [
"save",
"this",
"question",
"s"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/models/qe/question.rb#L185-L204 | train |
thelabtech/questionnaire | app/models/qe/question.rb | Qe.Question.has_response? | def has_response?(answer_sheet = nil)
if answer_sheet.present?
answers = responses(answer_sheet)
else
answers = Answer.where(:question_id => self.id)
end
return false if answers.length == 0
answers.each do |answer| # loop through Answers
value = answer.is_a?(Answer) ? answer.value : answer
return true if (value.is_a?(FalseClass) && value === false) || value.present?
end
return false
end | ruby | def has_response?(answer_sheet = nil)
if answer_sheet.present?
answers = responses(answer_sheet)
else
answers = Answer.where(:question_id => self.id)
end
return false if answers.length == 0
answers.each do |answer| # loop through Answers
value = answer.is_a?(Answer) ? answer.value : answer
return true if (value.is_a?(FalseClass) && value === false) || value.present?
end
return false
end | [
"def",
"has_response?",
"(",
"answer_sheet",
"=",
"nil",
")",
"if",
"answer_sheet",
".",
"present?",
"answers",
"=",
"responses",
"(",
"answer_sheet",
")",
"else",
"answers",
"=",
"Answer",
".",
"where",
"(",
":question_id",
"=>",
"self",
".",
"id",
")",
"end",
"return",
"false",
"if",
"answers",
".",
"length",
"==",
"0",
"answers",
".",
"each",
"do",
"|",
"answer",
"|",
"value",
"=",
"answer",
".",
"is_a?",
"(",
"Answer",
")",
"?",
"answer",
".",
"value",
":",
"answer",
"return",
"true",
"if",
"(",
"value",
".",
"is_a?",
"(",
"FalseClass",
")",
"&&",
"value",
"===",
"false",
")",
"||",
"value",
".",
"present?",
"end",
"return",
"false",
"end"
] | has any sort of non-empty response? | [
"has",
"any",
"sort",
"of",
"non",
"-",
"empty",
"response?"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/models/qe/question.rb#L207-L219 | train |
postmodern/chars | lib/chars/char_set.rb | Chars.CharSet.<< | def <<(other)
case other
when String
other.each_char do |char|
byte = char_to_byte(char)
@chars[byte] = char
super(byte)
end
return self
when Integer
super(other)
else
raise(TypeError,"can only append Strings and Integers")
end
end | ruby | def <<(other)
case other
when String
other.each_char do |char|
byte = char_to_byte(char)
@chars[byte] = char
super(byte)
end
return self
when Integer
super(other)
else
raise(TypeError,"can only append Strings and Integers")
end
end | [
"def",
"<<",
"(",
"other",
")",
"case",
"other",
"when",
"String",
"other",
".",
"each_char",
"do",
"|",
"char",
"|",
"byte",
"=",
"char_to_byte",
"(",
"char",
")",
"@chars",
"[",
"byte",
"]",
"=",
"char",
"super",
"(",
"byte",
")",
"end",
"return",
"self",
"when",
"Integer",
"super",
"(",
"other",
")",
"else",
"raise",
"(",
"TypeError",
",",
"\"can only append Strings and Integers\"",
")",
"end",
"end"
] | Adds a character to the set.
@param [String, Integer] other
The character(s) or byte to add.
@return [CharSet]
The modified character set.
@raise [TypeError]
The argument was not a {String} or {Integer}.
@since 0.2.1 | [
"Adds",
"a",
"character",
"to",
"the",
"set",
"."
] | bc28b59da07c8310abb15cb9d61cacc30e86ffb9 | https://github.com/postmodern/chars/blob/bc28b59da07c8310abb15cb9d61cacc30e86ffb9/lib/chars/char_set.rb#L57-L73 | train |
postmodern/chars | lib/chars/char_set.rb | Chars.CharSet.include_char? | def include_char?(char)
unless char.empty?
@chars.has_value?(char) || include_byte?(char_to_byte(char))
else
false
end
end | ruby | def include_char?(char)
unless char.empty?
@chars.has_value?(char) || include_byte?(char_to_byte(char))
else
false
end
end | [
"def",
"include_char?",
"(",
"char",
")",
"unless",
"char",
".",
"empty?",
"@chars",
".",
"has_value?",
"(",
"char",
")",
"||",
"include_byte?",
"(",
"char_to_byte",
"(",
"char",
")",
")",
"else",
"false",
"end",
"end"
] | Determines if a character is contained within the character set.
@param [String] char
The character to search for.
@return [Boolean]
Specifies whether the character is contained within the
character set. | [
"Determines",
"if",
"a",
"character",
"is",
"contained",
"within",
"the",
"character",
"set",
"."
] | bc28b59da07c8310abb15cb9d61cacc30e86ffb9 | https://github.com/postmodern/chars/blob/bc28b59da07c8310abb15cb9d61cacc30e86ffb9/lib/chars/char_set.rb#L91-L97 | train |
postmodern/chars | lib/chars/char_set.rb | Chars.CharSet.each_random_char | def each_random_char(n,&block)
return enum_for(:each_random_char,n) unless block_given?
each_random_byte(n) { |byte| yield @chars[byte] }
end | ruby | def each_random_char(n,&block)
return enum_for(:each_random_char,n) unless block_given?
each_random_byte(n) { |byte| yield @chars[byte] }
end | [
"def",
"each_random_char",
"(",
"n",
",",
"&",
"block",
")",
"return",
"enum_for",
"(",
":each_random_char",
",",
"n",
")",
"unless",
"block_given?",
"each_random_byte",
"(",
"n",
")",
"{",
"|",
"byte",
"|",
"yield",
"@chars",
"[",
"byte",
"]",
"}",
"end"
] | Pass random characters to a given block.
@param [Integer] n
Specifies how many times to pass a random character to the block.
@yield [char]
The block will receive the random characters.
@yieldparam [String] char
The random character from the character set.
@return [Enumerator]
If no block is given, an enumerator object will be returned. | [
"Pass",
"random",
"characters",
"to",
"a",
"given",
"block",
"."
] | bc28b59da07c8310abb15cb9d61cacc30e86ffb9 | https://github.com/postmodern/chars/blob/bc28b59da07c8310abb15cb9d61cacc30e86ffb9/lib/chars/char_set.rb#L215-L219 | train |
postmodern/chars | lib/chars/char_set.rb | Chars.CharSet.random_bytes | def random_bytes(length)
if (length.kind_of?(Array) || length.kind_of?(Range))
Array.new(length.sort_by { rand }.first) { random_byte }
else
Array.new(length) { random_byte }
end
end | ruby | def random_bytes(length)
if (length.kind_of?(Array) || length.kind_of?(Range))
Array.new(length.sort_by { rand }.first) { random_byte }
else
Array.new(length) { random_byte }
end
end | [
"def",
"random_bytes",
"(",
"length",
")",
"if",
"(",
"length",
".",
"kind_of?",
"(",
"Array",
")",
"||",
"length",
".",
"kind_of?",
"(",
"Range",
")",
")",
"Array",
".",
"new",
"(",
"length",
".",
"sort_by",
"{",
"rand",
"}",
".",
"first",
")",
"{",
"random_byte",
"}",
"else",
"Array",
".",
"new",
"(",
"length",
")",
"{",
"random_byte",
"}",
"end",
"end"
] | Creates an Array of random bytes from the character set.
@param [Integer, Array, Range] length
The length of the Array of random bytes.
@return [Array<Integer>]
The randomly selected bytes. | [
"Creates",
"an",
"Array",
"of",
"random",
"bytes",
"from",
"the",
"character",
"set",
"."
] | bc28b59da07c8310abb15cb9d61cacc30e86ffb9 | https://github.com/postmodern/chars/blob/bc28b59da07c8310abb15cb9d61cacc30e86ffb9/lib/chars/char_set.rb#L230-L236 | train |
postmodern/chars | lib/chars/char_set.rb | Chars.CharSet.random_distinct_bytes | def random_distinct_bytes(length)
if (length.kind_of?(Array) || length.kind_of?(Range))
self.entries.sort_by { rand }.slice(0...(length.sort_by { rand }.first))
else
self.entries.sort_by { rand }.slice(0...length)
end
end | ruby | def random_distinct_bytes(length)
if (length.kind_of?(Array) || length.kind_of?(Range))
self.entries.sort_by { rand }.slice(0...(length.sort_by { rand }.first))
else
self.entries.sort_by { rand }.slice(0...length)
end
end | [
"def",
"random_distinct_bytes",
"(",
"length",
")",
"if",
"(",
"length",
".",
"kind_of?",
"(",
"Array",
")",
"||",
"length",
".",
"kind_of?",
"(",
"Range",
")",
")",
"self",
".",
"entries",
".",
"sort_by",
"{",
"rand",
"}",
".",
"slice",
"(",
"0",
"...",
"(",
"length",
".",
"sort_by",
"{",
"rand",
"}",
".",
"first",
")",
")",
"else",
"self",
".",
"entries",
".",
"sort_by",
"{",
"rand",
"}",
".",
"slice",
"(",
"0",
"...",
"length",
")",
"end",
"end"
] | Creates an Array of random non-repeating bytes from the character set.
@param [Integer, Array, Range] length
The length of the Array of random non-repeating bytes.
@return [Array<Integer>]
The randomly selected non-repeating bytes. | [
"Creates",
"an",
"Array",
"of",
"random",
"non",
"-",
"repeating",
"bytes",
"from",
"the",
"character",
"set",
"."
] | bc28b59da07c8310abb15cb9d61cacc30e86ffb9 | https://github.com/postmodern/chars/blob/bc28b59da07c8310abb15cb9d61cacc30e86ffb9/lib/chars/char_set.rb#L247-L253 | train |
postmodern/chars | lib/chars/char_set.rb | Chars.CharSet.strings_in | def strings_in(data,options={},&block)
unless block
if options[:offsets]
found = {}
block = lambda { |offset,substring| found[offset] = substring }
else
found = []
block = lambda { |substring| found << substring }
end
strings_in(data,options,&block)
return found
end
min_length = options.fetch(:length,4)
return if data.length < min_length
index = 0
while index <= (data.length - min_length)
if self === data[index,min_length]
sub_index = (index + min_length)
while self.include_char?(data[sub_index,1])
sub_index += 1
end
match = data[index...sub_index]
case block.arity
when 2
yield match, index
else
yield match
end
index = sub_index
else
index += 1
end
end
end | ruby | def strings_in(data,options={},&block)
unless block
if options[:offsets]
found = {}
block = lambda { |offset,substring| found[offset] = substring }
else
found = []
block = lambda { |substring| found << substring }
end
strings_in(data,options,&block)
return found
end
min_length = options.fetch(:length,4)
return if data.length < min_length
index = 0
while index <= (data.length - min_length)
if self === data[index,min_length]
sub_index = (index + min_length)
while self.include_char?(data[sub_index,1])
sub_index += 1
end
match = data[index...sub_index]
case block.arity
when 2
yield match, index
else
yield match
end
index = sub_index
else
index += 1
end
end
end | [
"def",
"strings_in",
"(",
"data",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"unless",
"block",
"if",
"options",
"[",
":offsets",
"]",
"found",
"=",
"{",
"}",
"block",
"=",
"lambda",
"{",
"|",
"offset",
",",
"substring",
"|",
"found",
"[",
"offset",
"]",
"=",
"substring",
"}",
"else",
"found",
"=",
"[",
"]",
"block",
"=",
"lambda",
"{",
"|",
"substring",
"|",
"found",
"<<",
"substring",
"}",
"end",
"strings_in",
"(",
"data",
",",
"options",
",",
"&",
"block",
")",
"return",
"found",
"end",
"min_length",
"=",
"options",
".",
"fetch",
"(",
":length",
",",
"4",
")",
"return",
"if",
"data",
".",
"length",
"<",
"min_length",
"index",
"=",
"0",
"while",
"index",
"<=",
"(",
"data",
".",
"length",
"-",
"min_length",
")",
"if",
"self",
"===",
"data",
"[",
"index",
",",
"min_length",
"]",
"sub_index",
"=",
"(",
"index",
"+",
"min_length",
")",
"while",
"self",
".",
"include_char?",
"(",
"data",
"[",
"sub_index",
",",
"1",
"]",
")",
"sub_index",
"+=",
"1",
"end",
"match",
"=",
"data",
"[",
"index",
"...",
"sub_index",
"]",
"case",
"block",
".",
"arity",
"when",
"2",
"yield",
"match",
",",
"index",
"else",
"yield",
"match",
"end",
"index",
"=",
"sub_index",
"else",
"index",
"+=",
"1",
"end",
"end",
"end"
] | Finds sub-strings within given data that are made of characters within
the character set.
@param [String] data
The data to find sub-strings within.
@param [Hash] options
Additional options.
@option options [Integer] :length (4)
The minimum length of sub-strings found within the given data.
@option options [Boolean] :offsets (false)
Specifies whether to return a Hash of offsets and matched
sub-strings within the data, or to just return the matched
sub-strings themselves.
@yield [match,(index)]
The given block will be passed every matched sub-string, and the
optional index.
@yield [String] match
A sub-string containing the characters from the character set.
@yield [Integer] index
The index the sub-string was found at.
@return [Array, Hash]
If no block is given, an Array or Hash of sub-strings is returned. | [
"Finds",
"sub",
"-",
"strings",
"within",
"given",
"data",
"that",
"are",
"made",
"of",
"characters",
"within",
"the",
"character",
"set",
"."
] | bc28b59da07c8310abb15cb9d61cacc30e86ffb9 | https://github.com/postmodern/chars/blob/bc28b59da07c8310abb15cb9d61cacc30e86ffb9/lib/chars/char_set.rb#L345-L386 | train |
sportngin/hasoffers | lib/has_offers_model.rb | HasOffersModel.ClassMethods.has_offers_model | def has_offers_model(has_offers_class_name)
has_offers_class = "HasOffers::#{has_offers_class_name}".constantize
class_eval do
define_method("has_offers_create") do
if respond_to? :has_offer_id
response = has_offers_class.create(has_offers_params)
if response.success?
if response.data.is_a? Hash
# return_object is true
self.has_offer_id = response.data[has_offers_class_name]["id"].to_i
else
# return_object is false
self.has_offer_id = response.data.to_i
end
end
check_for_errors(response)
end
end
define_method("has_offers_update") do
if respond_to?(:has_offer_id) and has_offer_id
response = has_offers_class.update(has_offer_id, has_offers_params)
check_for_errors(response)
end
end
define_method("check_for_errors") do |response|
unless response.success?
response.error_messages.each do |error_message|
new_error_message = "HasOffers API Error: #{error_message}"
if self.errors.respond_to?(:add_to_base)
self.errors.add_to_base new_error_message
else
self.errors.add :base, new_error_message
end
end
end
response.success?
end
end
end | ruby | def has_offers_model(has_offers_class_name)
has_offers_class = "HasOffers::#{has_offers_class_name}".constantize
class_eval do
define_method("has_offers_create") do
if respond_to? :has_offer_id
response = has_offers_class.create(has_offers_params)
if response.success?
if response.data.is_a? Hash
# return_object is true
self.has_offer_id = response.data[has_offers_class_name]["id"].to_i
else
# return_object is false
self.has_offer_id = response.data.to_i
end
end
check_for_errors(response)
end
end
define_method("has_offers_update") do
if respond_to?(:has_offer_id) and has_offer_id
response = has_offers_class.update(has_offer_id, has_offers_params)
check_for_errors(response)
end
end
define_method("check_for_errors") do |response|
unless response.success?
response.error_messages.each do |error_message|
new_error_message = "HasOffers API Error: #{error_message}"
if self.errors.respond_to?(:add_to_base)
self.errors.add_to_base new_error_message
else
self.errors.add :base, new_error_message
end
end
end
response.success?
end
end
end | [
"def",
"has_offers_model",
"(",
"has_offers_class_name",
")",
"has_offers_class",
"=",
"\"HasOffers::#{has_offers_class_name}\"",
".",
"constantize",
"class_eval",
"do",
"define_method",
"(",
"\"has_offers_create\"",
")",
"do",
"if",
"respond_to?",
":has_offer_id",
"response",
"=",
"has_offers_class",
".",
"create",
"(",
"has_offers_params",
")",
"if",
"response",
".",
"success?",
"if",
"response",
".",
"data",
".",
"is_a?",
"Hash",
"self",
".",
"has_offer_id",
"=",
"response",
".",
"data",
"[",
"has_offers_class_name",
"]",
"[",
"\"id\"",
"]",
".",
"to_i",
"else",
"self",
".",
"has_offer_id",
"=",
"response",
".",
"data",
".",
"to_i",
"end",
"end",
"check_for_errors",
"(",
"response",
")",
"end",
"end",
"define_method",
"(",
"\"has_offers_update\"",
")",
"do",
"if",
"respond_to?",
"(",
":has_offer_id",
")",
"and",
"has_offer_id",
"response",
"=",
"has_offers_class",
".",
"update",
"(",
"has_offer_id",
",",
"has_offers_params",
")",
"check_for_errors",
"(",
"response",
")",
"end",
"end",
"define_method",
"(",
"\"check_for_errors\"",
")",
"do",
"|",
"response",
"|",
"unless",
"response",
".",
"success?",
"response",
".",
"error_messages",
".",
"each",
"do",
"|",
"error_message",
"|",
"new_error_message",
"=",
"\"HasOffers API Error: #{error_message}\"",
"if",
"self",
".",
"errors",
".",
"respond_to?",
"(",
":add_to_base",
")",
"self",
".",
"errors",
".",
"add_to_base",
"new_error_message",
"else",
"self",
".",
"errors",
".",
"add",
":base",
",",
"new_error_message",
"end",
"end",
"end",
"response",
".",
"success?",
"end",
"end",
"end"
] | requires that your model has the column has_offer_id
requires that you implement the method has_offers_params within your model | [
"requires",
"that",
"your",
"model",
"has",
"the",
"column",
"has_offer_id",
"requires",
"that",
"you",
"implement",
"the",
"method",
"has_offers_params",
"within",
"your",
"model"
] | 4127fc0c9a5362eb6a4e4945f8e8762fa3e18756 | https://github.com/sportngin/hasoffers/blob/4127fc0c9a5362eb6a4e4945f8e8762fa3e18756/lib/has_offers_model.rb#L11-L56 | train |
rkday/ruby-diameter | lib/diameter/avp.rb | Diameter.AVP.inner_avps | def inner_avps(name)
code, _type, _vendor = AVPNames.get(name)
grouped_value.select { |a| a.code == code }
end | ruby | def inner_avps(name)
code, _type, _vendor = AVPNames.get(name)
grouped_value.select { |a| a.code == code }
end | [
"def",
"inner_avps",
"(",
"name",
")",
"code",
",",
"_type",
",",
"_vendor",
"=",
"AVPNames",
".",
"get",
"(",
"name",
")",
"grouped_value",
".",
"select",
"{",
"|",
"a",
"|",
"a",
".",
"code",
"==",
"code",
"}",
"end"
] | For a grouped AVP, returns all AVPs it contains with this name.
@param [String] name The AVP name
@return [Array<AVP>] | [
"For",
"a",
"grouped",
"AVP",
"returns",
"all",
"AVPs",
"it",
"contains",
"with",
"this",
"name",
"."
] | 83def68f67cf660aa227eac4c74719dc98aacab2 | https://github.com/rkday/ruby-diameter/blob/83def68f67cf660aa227eac4c74719dc98aacab2/lib/diameter/avp.rb#L205-L209 | train |
rkday/ruby-diameter | lib/diameter/avp.rb | Diameter.AVP.ip_address= | def ip_address=(value)
bytes = if value.ipv4?
[1].pack('n')
else
[2].pack('n')
end
bytes += value.hton
@content = bytes
end | ruby | def ip_address=(value)
bytes = if value.ipv4?
[1].pack('n')
else
[2].pack('n')
end
bytes += value.hton
@content = bytes
end | [
"def",
"ip_address",
"=",
"(",
"value",
")",
"bytes",
"=",
"if",
"value",
".",
"ipv4?",
"[",
"1",
"]",
".",
"pack",
"(",
"'n'",
")",
"else",
"[",
"2",
"]",
".",
"pack",
"(",
"'n'",
")",
"end",
"bytes",
"+=",
"value",
".",
"hton",
"@content",
"=",
"bytes",
"end"
] | Sets this AVP's byte data to an Address.
@param [IPAddr] value
@return [void] | [
"Sets",
"this",
"AVP",
"s",
"byte",
"data",
"to",
"an",
"Address",
"."
] | 83def68f67cf660aa227eac4c74719dc98aacab2 | https://github.com/rkday/ruby-diameter/blob/83def68f67cf660aa227eac4c74719dc98aacab2/lib/diameter/avp.rb#L340-L349 | train |
sleewoo/minispec | lib/minispec/api/instance/mocks/doubles.rb | MiniSpec.InstanceAPI.double | def double *args, &proc
name = args.first.is_a?(Hash) ? nil : args.shift
object = Object.new
object.define_singleton_method(:__ms__double_instance) {true}
object.define_singleton_method(:inspect) {name} if name
hashes, rest = args.partition {|s| s.is_a?(Hash)}
hashes.each {|h| stub(object, h)}
rest.each {|s| stub(object, s, &proc)}
object
end | ruby | def double *args, &proc
name = args.first.is_a?(Hash) ? nil : args.shift
object = Object.new
object.define_singleton_method(:__ms__double_instance) {true}
object.define_singleton_method(:inspect) {name} if name
hashes, rest = args.partition {|s| s.is_a?(Hash)}
hashes.each {|h| stub(object, h)}
rest.each {|s| stub(object, s, &proc)}
object
end | [
"def",
"double",
"*",
"args",
",",
"&",
"proc",
"name",
"=",
"args",
".",
"first",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"nil",
":",
"args",
".",
"shift",
"object",
"=",
"Object",
".",
"new",
"object",
".",
"define_singleton_method",
"(",
":__ms__double_instance",
")",
"{",
"true",
"}",
"object",
".",
"define_singleton_method",
"(",
":inspect",
")",
"{",
"name",
"}",
"if",
"name",
"hashes",
",",
"rest",
"=",
"args",
".",
"partition",
"{",
"|",
"s",
"|",
"s",
".",
"is_a?",
"(",
"Hash",
")",
"}",
"hashes",
".",
"each",
"{",
"|",
"h",
"|",
"stub",
"(",
"object",
",",
"h",
")",
"}",
"rest",
".",
"each",
"{",
"|",
"s",
"|",
"stub",
"(",
"object",
",",
"s",
",",
"&",
"proc",
")",
"}",
"object",
"end"
] | creates a double object.
if one or more arguments given, first argument will be used as name, unless it is a Hash.
arguments that goes after first one are treated as stubs.
@example create a double that will respond to `color` and reported as :apple
apple = double(:apple, :color) { 'Red' }
apple.color # => Red
@example injecting a double into a real battle and expecting it to receive some messages
user = double(:user, :name, :address)
expect(user).to_receive(:name, :address)
Shipping.new.get_address_for(user)
@example spy on a double
user = double(:user, :name, :address)
Shipping.new.get_address_for(user)
assert(user).received(:name, :address) | [
"creates",
"a",
"double",
"object",
".",
"if",
"one",
"or",
"more",
"arguments",
"given",
"first",
"argument",
"will",
"be",
"used",
"as",
"name",
"unless",
"it",
"is",
"a",
"Hash",
".",
"arguments",
"that",
"goes",
"after",
"first",
"one",
"are",
"treated",
"as",
"stubs",
"."
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/api/instance/mocks/doubles.rb#L22-L34 | train |
simon-watiau/qonto_ofx | lib/converter.rb | QontoOfx.Converter.convert | def convert(remove_ns = false)
organization = @gateway.fetch_organization['organization']
builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8')
builder[:ofx].OFX('xmlns:ofx' => 'http://ofx.net/types/2003/04') do |xml|
add_signonmsgsrsv1_block xml
xml.BANKMSGSRSV1 do
xml.parent.namespace = nil
organization['bank_accounts'].each do |bank_account|
xml.STMTTRNRS do
xml.TRNUID 1
add_status_block xml
xml.STMTRS do
xml.CURDEF 'EUR'
add_bankacctfrom_block xml, bank_account
xml.BANKTRANLIST do
process_transactions xml, bank_account
end
xml.LEDGERBAL do
xml.BALAMT bank_account['balance']
xml.DTASOF Time.now.strftime('%Y%m%d%H%M%S')
end
end
end
end
end
end
move_to_first_position(builder, '//DTEND')
move_to_first_position(builder, '//DTSTART')
result = builder.to_xml
raise 'generation failed (invalid OFX)' unless @ofx_validator.valid? result
result = result.gsub(
'ofx:OFX',
'OFX'
).gsub(' xmlns:ofx="http://ofx.net/types/2003/04"', '') if remove_ns
result
end | ruby | def convert(remove_ns = false)
organization = @gateway.fetch_organization['organization']
builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8')
builder[:ofx].OFX('xmlns:ofx' => 'http://ofx.net/types/2003/04') do |xml|
add_signonmsgsrsv1_block xml
xml.BANKMSGSRSV1 do
xml.parent.namespace = nil
organization['bank_accounts'].each do |bank_account|
xml.STMTTRNRS do
xml.TRNUID 1
add_status_block xml
xml.STMTRS do
xml.CURDEF 'EUR'
add_bankacctfrom_block xml, bank_account
xml.BANKTRANLIST do
process_transactions xml, bank_account
end
xml.LEDGERBAL do
xml.BALAMT bank_account['balance']
xml.DTASOF Time.now.strftime('%Y%m%d%H%M%S')
end
end
end
end
end
end
move_to_first_position(builder, '//DTEND')
move_to_first_position(builder, '//DTSTART')
result = builder.to_xml
raise 'generation failed (invalid OFX)' unless @ofx_validator.valid? result
result = result.gsub(
'ofx:OFX',
'OFX'
).gsub(' xmlns:ofx="http://ofx.net/types/2003/04"', '') if remove_ns
result
end | [
"def",
"convert",
"(",
"remove_ns",
"=",
"false",
")",
"organization",
"=",
"@gateway",
".",
"fetch_organization",
"[",
"'organization'",
"]",
"builder",
"=",
"Nokogiri",
"::",
"XML",
"::",
"Builder",
".",
"new",
"(",
"encoding",
":",
"'UTF-8'",
")",
"builder",
"[",
":ofx",
"]",
".",
"OFX",
"(",
"'xmlns:ofx'",
"=>",
"'http://ofx.net/types/2003/04'",
")",
"do",
"|",
"xml",
"|",
"add_signonmsgsrsv1_block",
"xml",
"xml",
".",
"BANKMSGSRSV1",
"do",
"xml",
".",
"parent",
".",
"namespace",
"=",
"nil",
"organization",
"[",
"'bank_accounts'",
"]",
".",
"each",
"do",
"|",
"bank_account",
"|",
"xml",
".",
"STMTTRNRS",
"do",
"xml",
".",
"TRNUID",
"1",
"add_status_block",
"xml",
"xml",
".",
"STMTRS",
"do",
"xml",
".",
"CURDEF",
"'EUR'",
"add_bankacctfrom_block",
"xml",
",",
"bank_account",
"xml",
".",
"BANKTRANLIST",
"do",
"process_transactions",
"xml",
",",
"bank_account",
"end",
"xml",
".",
"LEDGERBAL",
"do",
"xml",
".",
"BALAMT",
"bank_account",
"[",
"'balance'",
"]",
"xml",
".",
"DTASOF",
"Time",
".",
"now",
".",
"strftime",
"(",
"'%Y%m%d%H%M%S'",
")",
"end",
"end",
"end",
"end",
"end",
"end",
"move_to_first_position",
"(",
"builder",
",",
"'//DTEND'",
")",
"move_to_first_position",
"(",
"builder",
",",
"'//DTSTART'",
")",
"result",
"=",
"builder",
".",
"to_xml",
"raise",
"'generation failed (invalid OFX)'",
"unless",
"@ofx_validator",
".",
"valid?",
"result",
"result",
"=",
"result",
".",
"gsub",
"(",
"'ofx:OFX'",
",",
"'OFX'",
")",
".",
"gsub",
"(",
"' xmlns:ofx=\"http://ofx.net/types/2003/04\"'",
",",
"''",
")",
"if",
"remove_ns",
"result",
"end"
] | valid_ofx = false removes the namespaces | [
"valid_ofx",
"=",
"false",
"removes",
"the",
"namespaces"
] | 16b849ab4df1522801a3d262a79270998b5ec6d3 | https://github.com/simon-watiau/qonto_ofx/blob/16b849ab4df1522801a3d262a79270998b5ec6d3/lib/converter.rb#L17-L60 | train |
netskin/ceph-ruby | lib/ceph-ruby/cluster.rb | CephRuby.Cluster.connect | def connect
log("connect")
ret = Lib::Rados.rados_connect(handle)
raise SystemCallError.new("connect to cluster failed", -ret) if ret < 0
end | ruby | def connect
log("connect")
ret = Lib::Rados.rados_connect(handle)
raise SystemCallError.new("connect to cluster failed", -ret) if ret < 0
end | [
"def",
"connect",
"log",
"(",
"\"connect\"",
")",
"ret",
"=",
"Lib",
"::",
"Rados",
".",
"rados_connect",
"(",
"handle",
")",
"raise",
"SystemCallError",
".",
"new",
"(",
"\"connect to cluster failed\"",
",",
"-",
"ret",
")",
"if",
"ret",
"<",
"0",
"end"
] | helper methods below | [
"helper",
"methods",
"below"
] | bf2023b450ffb8ba7b12e5847e475f0f8796d0c7 | https://github.com/netskin/ceph-ruby/blob/bf2023b450ffb8ba7b12e5847e475f0f8796d0c7/lib/ceph-ruby/cluster.rb#L38-L42 | train |
stereobooster/jshintrb | lib/jshintrb/jshinttask.rb | Jshintrb.JshintTask.define | def define # :nodoc:
actual_name = Hash === name ? name.keys.first : name
unless ::Rake.application.last_comment
desc "Run JShint"
end
task name do
unless js_file_list.empty?
result = Jshintrb::report(js_file_list, @options, @globals, STDERR)
if result.size > 0
abort("JSHint check failed") if fail_on_error
end
end
end
self
end | ruby | def define # :nodoc:
actual_name = Hash === name ? name.keys.first : name
unless ::Rake.application.last_comment
desc "Run JShint"
end
task name do
unless js_file_list.empty?
result = Jshintrb::report(js_file_list, @options, @globals, STDERR)
if result.size > 0
abort("JSHint check failed") if fail_on_error
end
end
end
self
end | [
"def",
"define",
"actual_name",
"=",
"Hash",
"===",
"name",
"?",
"name",
".",
"keys",
".",
"first",
":",
"name",
"unless",
"::",
"Rake",
".",
"application",
".",
"last_comment",
"desc",
"\"Run JShint\"",
"end",
"task",
"name",
"do",
"unless",
"js_file_list",
".",
"empty?",
"result",
"=",
"Jshintrb",
"::",
"report",
"(",
"js_file_list",
",",
"@options",
",",
"@globals",
",",
"STDERR",
")",
"if",
"result",
".",
"size",
">",
"0",
"abort",
"(",
"\"JSHint check failed\"",
")",
"if",
"fail_on_error",
"end",
"end",
"end",
"self",
"end"
] | Defines a new task, using the name +name+. | [
"Defines",
"a",
"new",
"task",
"using",
"the",
"name",
"+",
"name",
"+",
"."
] | 5ee7051e3c6df584ea7e020bcffd712ffbdb1b31 | https://github.com/stereobooster/jshintrb/blob/5ee7051e3c6df584ea7e020bcffd712ffbdb1b31/lib/jshintrb/jshinttask.rb#L52-L68 | train |
SSSaaS/sssa-ruby | lib/utils.rb | SSSA.Utils.split_ints | def split_ints(secret)
result = []
secret.split('').map { |x|
data = x.unpack("H*")[0]
"0"*(data.size % 2) + data
}.join("").scan(/.{1,64}/) { |segment|
result.push (segment+"0"*(64-segment.size)).hex
}
return result
end | ruby | def split_ints(secret)
result = []
secret.split('').map { |x|
data = x.unpack("H*")[0]
"0"*(data.size % 2) + data
}.join("").scan(/.{1,64}/) { |segment|
result.push (segment+"0"*(64-segment.size)).hex
}
return result
end | [
"def",
"split_ints",
"(",
"secret",
")",
"result",
"=",
"[",
"]",
"secret",
".",
"split",
"(",
"''",
")",
".",
"map",
"{",
"|",
"x",
"|",
"data",
"=",
"x",
".",
"unpack",
"(",
"\"H*\"",
")",
"[",
"0",
"]",
"\"0\"",
"*",
"(",
"data",
".",
"size",
"%",
"2",
")",
"+",
"data",
"}",
".",
"join",
"(",
"\"\"",
")",
".",
"scan",
"(",
"/",
"/",
")",
"{",
"|",
"segment",
"|",
"result",
".",
"push",
"(",
"segment",
"+",
"\"0\"",
"*",
"(",
"64",
"-",
"segment",
".",
"size",
")",
")",
".",
"hex",
"}",
"return",
"result",
"end"
] | split_ints and merge_ints converts between string and integer array,
where the integer is right-padded until it fits a 256 bit integer. | [
"split_ints",
"and",
"merge_ints",
"converts",
"between",
"string",
"and",
"integer",
"array",
"where",
"the",
"integer",
"is",
"right",
"-",
"padded",
"until",
"it",
"fits",
"a",
"256",
"bit",
"integer",
"."
] | df65db5785d591630e4acdff7d2a65b52d2d9581 | https://github.com/SSSaaS/sssa-ruby/blob/df65db5785d591630e4acdff7d2a65b52d2d9581/lib/utils.rb#L19-L30 | train |
appirits/comable | core/app/models/comable/order.rb | Comable.Order.inherit! | def inherit!(order)
self.bill_address ||= order.bill_address
self.ship_address ||= order.ship_address
self.payment ||= order.payment
self.shipments = order.shipments if shipments.empty?
stated?(order.state) ? save! : next_state!
end | ruby | def inherit!(order)
self.bill_address ||= order.bill_address
self.ship_address ||= order.ship_address
self.payment ||= order.payment
self.shipments = order.shipments if shipments.empty?
stated?(order.state) ? save! : next_state!
end | [
"def",
"inherit!",
"(",
"order",
")",
"self",
".",
"bill_address",
"||=",
"order",
".",
"bill_address",
"self",
".",
"ship_address",
"||=",
"order",
".",
"ship_address",
"self",
".",
"payment",
"||=",
"order",
".",
"payment",
"self",
".",
"shipments",
"=",
"order",
".",
"shipments",
"if",
"shipments",
".",
"empty?",
"stated?",
"(",
"order",
".",
"state",
")",
"?",
"save!",
":",
"next_state!",
"end"
] | Inherit from other Order | [
"Inherit",
"from",
"other",
"Order"
] | b0cf028da35ea9def1c675680e5e5293a969bebc | https://github.com/appirits/comable/blob/b0cf028da35ea9def1c675680e5e5293a969bebc/core/app/models/comable/order.rb#L98-L105 | train |
thelabtech/questionnaire | app/models/qe/element.rb | Qe.Element.duplicate | def duplicate(page, parent = nil)
new_element = self.class.new(self.attributes)
case parent.class.to_s
when ChoiceField
new_element.conditional_id = parent.id
when QuestionGrid, QuestionGridWithTotal
new_element.question_grid_id = parent.id
end
new_element.save(:validate => false)
PageElement.create(:element => new_element, :page => page) unless parent
# duplicate children
if respond_to?(:elements) && elements.present?
elements.each {|e| e.duplicate(page, new_element)}
end
new_element
end | ruby | def duplicate(page, parent = nil)
new_element = self.class.new(self.attributes)
case parent.class.to_s
when ChoiceField
new_element.conditional_id = parent.id
when QuestionGrid, QuestionGridWithTotal
new_element.question_grid_id = parent.id
end
new_element.save(:validate => false)
PageElement.create(:element => new_element, :page => page) unless parent
# duplicate children
if respond_to?(:elements) && elements.present?
elements.each {|e| e.duplicate(page, new_element)}
end
new_element
end | [
"def",
"duplicate",
"(",
"page",
",",
"parent",
"=",
"nil",
")",
"new_element",
"=",
"self",
".",
"class",
".",
"new",
"(",
"self",
".",
"attributes",
")",
"case",
"parent",
".",
"class",
".",
"to_s",
"when",
"ChoiceField",
"new_element",
".",
"conditional_id",
"=",
"parent",
".",
"id",
"when",
"QuestionGrid",
",",
"QuestionGridWithTotal",
"new_element",
".",
"question_grid_id",
"=",
"parent",
".",
"id",
"end",
"new_element",
".",
"save",
"(",
":validate",
"=>",
"false",
")",
"PageElement",
".",
"create",
"(",
":element",
"=>",
"new_element",
",",
":page",
"=>",
"page",
")",
"unless",
"parent",
"if",
"respond_to?",
"(",
":elements",
")",
"&&",
"elements",
".",
"present?",
"elements",
".",
"each",
"{",
"|",
"e",
"|",
"e",
".",
"duplicate",
"(",
"page",
",",
"new_element",
")",
"}",
"end",
"new_element",
"end"
] | copy an item and all it's children | [
"copy",
"an",
"item",
"and",
"all",
"it",
"s",
"children"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/models/qe/element.rb#L116-L133 | train |
nazoking/rehtml | lib/rehtml/tokenizer.rb | REHTML.Tokenizer.decode | def decode(html)
html.gsub(ENTITIES::REGEXP){
if $1
if ENTITIES::MAP[$1]
ENTITIES::MAP[$1]
else
$&
end
elsif $2
[$2.to_i(10)].pack('U')
elsif $3
[$3.to_i(16)].pack('U')
else
$&
end
}
end | ruby | def decode(html)
html.gsub(ENTITIES::REGEXP){
if $1
if ENTITIES::MAP[$1]
ENTITIES::MAP[$1]
else
$&
end
elsif $2
[$2.to_i(10)].pack('U')
elsif $3
[$3.to_i(16)].pack('U')
else
$&
end
}
end | [
"def",
"decode",
"(",
"html",
")",
"html",
".",
"gsub",
"(",
"ENTITIES",
"::",
"REGEXP",
")",
"{",
"if",
"$1",
"if",
"ENTITIES",
"::",
"MAP",
"[",
"$1",
"]",
"ENTITIES",
"::",
"MAP",
"[",
"$1",
"]",
"else",
"$&",
"end",
"elsif",
"$2",
"[",
"$2",
".",
"to_i",
"(",
"10",
")",
"]",
".",
"pack",
"(",
"'U'",
")",
"elsif",
"$3",
"[",
"$3",
".",
"to_i",
"(",
"16",
")",
"]",
".",
"pack",
"(",
"'U'",
")",
"else",
"$&",
"end",
"}",
"end"
] | decode html entity | [
"decode",
"html",
"entity"
] | 4bf9016f5325becd955db777d832a2c90f3407ac | https://github.com/nazoking/rehtml/blob/4bf9016f5325becd955db777d832a2c90f3407ac/lib/rehtml/tokenizer.rb#L42-L58 | train |
thelabtech/questionnaire | app/models/qe/notifier.rb | Qe.Notifier.notification | def notification(p_recipients, p_from, template_name, template_params = {}, options = {})
email_template = EmailTemplate.find_by_name(template_name)
if email_template.nil?
raise "Email Template #{template_name} could not be found"
else
@recipients = p_recipients
@from = p_from
@subject = Liquid::Template.parse(email_template.subject).render(template_params)
@body = Liquid::Template.parse(email_template.content).render(template_params)
end
end | ruby | def notification(p_recipients, p_from, template_name, template_params = {}, options = {})
email_template = EmailTemplate.find_by_name(template_name)
if email_template.nil?
raise "Email Template #{template_name} could not be found"
else
@recipients = p_recipients
@from = p_from
@subject = Liquid::Template.parse(email_template.subject).render(template_params)
@body = Liquid::Template.parse(email_template.content).render(template_params)
end
end | [
"def",
"notification",
"(",
"p_recipients",
",",
"p_from",
",",
"template_name",
",",
"template_params",
"=",
"{",
"}",
",",
"options",
"=",
"{",
"}",
")",
"email_template",
"=",
"EmailTemplate",
".",
"find_by_name",
"(",
"template_name",
")",
"if",
"email_template",
".",
"nil?",
"raise",
"\"Email Template #{template_name} could not be found\"",
"else",
"@recipients",
"=",
"p_recipients",
"@from",
"=",
"p_from",
"@subject",
"=",
"Liquid",
"::",
"Template",
".",
"parse",
"(",
"email_template",
".",
"subject",
")",
".",
"render",
"(",
"template_params",
")",
"@body",
"=",
"Liquid",
"::",
"Template",
".",
"parse",
"(",
"email_template",
".",
"content",
")",
".",
"render",
"(",
"template_params",
")",
"end",
"end"
] | call Notifier.deliver_notification | [
"call",
"Notifier",
".",
"deliver_notification"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/models/qe/notifier.rb#L5-L16 | train |
vchs/ruby_vcloud_sdk | lib/ruby_vcloud_sdk/catalog.rb | VCloudSdk.Catalog.find_item | def find_item(name, item_type = nil)
link = find_item_link(name)
item = VCloudSdk::CatalogItem.new(@session, link)
check_item_type(item, item_type)
item
end | ruby | def find_item(name, item_type = nil)
link = find_item_link(name)
item = VCloudSdk::CatalogItem.new(@session, link)
check_item_type(item, item_type)
item
end | [
"def",
"find_item",
"(",
"name",
",",
"item_type",
"=",
"nil",
")",
"link",
"=",
"find_item_link",
"(",
"name",
")",
"item",
"=",
"VCloudSdk",
"::",
"CatalogItem",
".",
"new",
"(",
"@session",
",",
"link",
")",
"check_item_type",
"(",
"item",
",",
"item_type",
")",
"item",
"end"
] | Find catalog item from catalog by name and type.
If item_type is set to nil, returns catalog item as long as its name match.
Raises an exception if catalog is not found.
Raises ObjectNotFoundError if an item matching the name and type is not found.
Otherwise, returns the catalog item. | [
"Find",
"catalog",
"item",
"from",
"catalog",
"by",
"name",
"and",
"type",
".",
"If",
"item_type",
"is",
"set",
"to",
"nil",
"returns",
"catalog",
"item",
"as",
"long",
"as",
"its",
"name",
"match",
".",
"Raises",
"an",
"exception",
"if",
"catalog",
"is",
"not",
"found",
".",
"Raises",
"ObjectNotFoundError",
"if",
"an",
"item",
"matching",
"the",
"name",
"and",
"type",
"is",
"not",
"found",
".",
"Otherwise",
"returns",
"the",
"catalog",
"item",
"."
] | 92d56db4fea4321068ab300ca60bcc6cec3e459b | https://github.com/vchs/ruby_vcloud_sdk/blob/92d56db4fea4321068ab300ca60bcc6cec3e459b/lib/ruby_vcloud_sdk/catalog.rb#L40-L45 | train |
qw3/getnet_api | lib/getnet_api/configure.rb | GetnetApi.Configure.set_endpoint | def set_endpoint
if ambiente == :producao
return GetnetApi::Configure::URL[:producao]
elsif ambiente == :homologacao
return GetnetApi::Configure::URL[:homologacao]
else
return GetnetApi::Configure::URL[:sandbox]
end
end | ruby | def set_endpoint
if ambiente == :producao
return GetnetApi::Configure::URL[:producao]
elsif ambiente == :homologacao
return GetnetApi::Configure::URL[:homologacao]
else
return GetnetApi::Configure::URL[:sandbox]
end
end | [
"def",
"set_endpoint",
"if",
"ambiente",
"==",
":producao",
"return",
"GetnetApi",
"::",
"Configure",
"::",
"URL",
"[",
":producao",
"]",
"elsif",
"ambiente",
"==",
":homologacao",
"return",
"GetnetApi",
"::",
"Configure",
"::",
"URL",
"[",
":homologacao",
"]",
"else",
"return",
"GetnetApi",
"::",
"Configure",
"::",
"URL",
"[",
":sandbox",
"]",
"end",
"end"
] | Retornar a url conforme o ambiente | [
"Retornar",
"a",
"url",
"conforme",
"o",
"ambiente"
] | 94cbda66aab03d83ea38bc5325ea2a02a639e922 | https://github.com/qw3/getnet_api/blob/94cbda66aab03d83ea38bc5325ea2a02a639e922/lib/getnet_api/configure.rb#L90-L98 | train |
kissmetrics/uri_signer | lib/uri_signer/request_signature.rb | UriSigner.RequestSignature.signature | def signature
core_signature = [self.http_method, self.encoded_base_uri]
core_signature << self.encoded_query_params if self.query_params?
core_signature.join(self.separator)
end | ruby | def signature
core_signature = [self.http_method, self.encoded_base_uri]
core_signature << self.encoded_query_params if self.query_params?
core_signature.join(self.separator)
end | [
"def",
"signature",
"core_signature",
"=",
"[",
"self",
".",
"http_method",
",",
"self",
".",
"encoded_base_uri",
"]",
"core_signature",
"<<",
"self",
".",
"encoded_query_params",
"if",
"self",
".",
"query_params?",
"core_signature",
".",
"join",
"(",
"self",
".",
"separator",
")",
"end"
] | Create a new RequestSignature instance
@param http_method [String] The HTTP method from the request (GET, POST, PUT, or DELETE)
@param base_uri [String] The base URI of the request. This is everything except the query string params
@param query_params [Hash] A hash of the provided query string params
It's required that you provide at least the http_method and base_uri. Params are optional
@return [void]
Returns the full signature string
@return [String] | [
"Create",
"a",
"new",
"RequestSignature",
"instance"
] | 3169df476c7f8ed88c5af6ade2c826ad3e5fa2a3 | https://github.com/kissmetrics/uri_signer/blob/3169df476c7f8ed88c5af6ade2c826ad3e5fa2a3/lib/uri_signer/request_signature.rb#L57-L61 | train |
kissmetrics/uri_signer | lib/uri_signer/query_hash_parser.rb | UriSigner.QueryHashParser.to_s | def to_s
parts = @query_hash.sort.inject([]) do |arr, (key,value)|
if value.kind_of?(Array)
value.each do |nested|
arr << "%s=%s" % [key, nested]
end
else
arr << "%s=%s" % [key, value]
end
arr
end
parts.join('&')
end | ruby | def to_s
parts = @query_hash.sort.inject([]) do |arr, (key,value)|
if value.kind_of?(Array)
value.each do |nested|
arr << "%s=%s" % [key, nested]
end
else
arr << "%s=%s" % [key, value]
end
arr
end
parts.join('&')
end | [
"def",
"to_s",
"parts",
"=",
"@query_hash",
".",
"sort",
".",
"inject",
"(",
"[",
"]",
")",
"do",
"|",
"arr",
",",
"(",
"key",
",",
"value",
")",
"|",
"if",
"value",
".",
"kind_of?",
"(",
"Array",
")",
"value",
".",
"each",
"do",
"|",
"nested",
"|",
"arr",
"<<",
"\"%s=%s\"",
"%",
"[",
"key",
",",
"nested",
"]",
"end",
"else",
"arr",
"<<",
"\"%s=%s\"",
"%",
"[",
"key",
",",
"value",
"]",
"end",
"arr",
"end",
"parts",
".",
"join",
"(",
"'&'",
")",
"end"
] | Creates a new QueryHashParser instance
@param query_hash [Hash] A hash of key/values to turn into a query stringo
@return [void]
Returns the hash (key/values) as an ordered query string. This joins the keys and values, and then
joins it all with the ampersand. This is not escaped
@return [String] | [
"Creates",
"a",
"new",
"QueryHashParser",
"instance"
] | 3169df476c7f8ed88c5af6ade2c826ad3e5fa2a3 | https://github.com/kissmetrics/uri_signer/blob/3169df476c7f8ed88c5af6ade2c826ad3e5fa2a3/lib/uri_signer/query_hash_parser.rb#L28-L40 | train |
plexus/macros | lib/macros/sexp.rb | Macros.Sexp.sfind | def sfind(sexp, specs)
specs.inject(sexp) do |node, spec|
return NotFound if node.nil?
if spec.is_a?(Symbol) && node.type == spec
node
elsif spec.is_a?(Integer) && node.children.length > spec
node.children[spec]
elsif spec.is_a?(Array)
node.children.grep(AST::Node)
.flat_map { |child| sfind(child, spec) }
.reject { |child| child == NotFound }
else
return NotFound
end
end
end | ruby | def sfind(sexp, specs)
specs.inject(sexp) do |node, spec|
return NotFound if node.nil?
if spec.is_a?(Symbol) && node.type == spec
node
elsif spec.is_a?(Integer) && node.children.length > spec
node.children[spec]
elsif spec.is_a?(Array)
node.children.grep(AST::Node)
.flat_map { |child| sfind(child, spec) }
.reject { |child| child == NotFound }
else
return NotFound
end
end
end | [
"def",
"sfind",
"(",
"sexp",
",",
"specs",
")",
"specs",
".",
"inject",
"(",
"sexp",
")",
"do",
"|",
"node",
",",
"spec",
"|",
"return",
"NotFound",
"if",
"node",
".",
"nil?",
"if",
"spec",
".",
"is_a?",
"(",
"Symbol",
")",
"&&",
"node",
".",
"type",
"==",
"spec",
"node",
"elsif",
"spec",
".",
"is_a?",
"(",
"Integer",
")",
"&&",
"node",
".",
"children",
".",
"length",
">",
"spec",
"node",
".",
"children",
"[",
"spec",
"]",
"elsif",
"spec",
".",
"is_a?",
"(",
"Array",
")",
"node",
".",
"children",
".",
"grep",
"(",
"AST",
"::",
"Node",
")",
".",
"flat_map",
"{",
"|",
"child",
"|",
"sfind",
"(",
"child",
",",
"spec",
")",
"}",
".",
"reject",
"{",
"|",
"child",
"|",
"child",
"==",
"NotFound",
"}",
"else",
"return",
"NotFound",
"end",
"end",
"end"
] | Traverse into sexp by type and child position | [
"Traverse",
"into",
"sexp",
"by",
"type",
"and",
"child",
"position"
] | 5a45c8f452695643727383d6e3c0004eb3a1146e | https://github.com/plexus/macros/blob/5a45c8f452695643727383d6e3c0004eb3a1146e/lib/macros/sexp.rb#L11-L27 | train |
sleewoo/minispec | lib/minispec/api/class/helpers.rb | MiniSpec.ClassAPI.helper | def helper helper, opts = {}, &proc
proc || raise(ArgumentError, 'block is missing')
helpers[helper] = [proc, opts]
end | ruby | def helper helper, opts = {}, &proc
proc || raise(ArgumentError, 'block is missing')
helpers[helper] = [proc, opts]
end | [
"def",
"helper",
"helper",
",",
"opts",
"=",
"{",
"}",
",",
"&",
"proc",
"proc",
"||",
"raise",
"(",
"ArgumentError",
",",
"'block is missing'",
")",
"helpers",
"[",
"helper",
"]",
"=",
"[",
"proc",
",",
"opts",
"]",
"end"
] | define custom assertion helpers.
@note helpers can be overridden by name,
that's it, if some spec inherits `:a_duck?` helper
you can use `helper(:a_duck?) { ... }` to override it.
@note tested object are passed to helper via first argument.
any arguments passed to helper are sent after tested object.
@note if a block used on left side,
it will be passed as last argument and the helper is responsible to call it.
please note that block will be passed as usual argument rather than a block.
@note if you need the current context to be passed into helper
use `:with_context` option. when doing so,
the context will come as last argument.
@example
describe SomeTest do
helper :a_pizza? do |food|
does(food) =~ /cheese/
does(food) =~ /olives/
end
testing :foods do
food = Cook.some_food(with: 'cheese', and: 'olives')
is(food).a_pizza? #=> passed
food = Cook.some_food(with: 'potatoes')
is(food).a_pizza? #=> failed
end
end
@example any other arguments are sent after tested object
describe SomeTest do
helper :a_pizza? do |food, ingredients|
does(food) =~ /dough/
does(ingredients).include? 'cheese'
does(ingredients).include? 'olives'
end
testing :foods do
ingredients = ['cheese', 'olives']
food = Cook.some_food(ingredients)
is(food).a_pizza? ingredients
end
end
@example given block passed as last argument
# block comes as a usual argument rather than a block
helper :is_invalid do |attr, block|
e = assert(&block).raise(FormulaValidationError)
assert(e.attr) == attr
end
test 'validates name' do
assert(:name).is_invalid do
formula "name with spaces" do
url "foo"
version "1.0"
end
end
end
@example using `with_context` option to get context as last argument
describe SomeTest do
helper :a_pizza?, with_context: true do |subject, ingredients, context|
# context is a Hash containing :left_method, left_object, :left_proc and :negation keys
end
testing :foods do
is(:smth).a_pizza? ['some', 'ingredients']
# helper's context will look like:
# {left_method: :is, left_object: :smth, left_proc: nil, negation: nil}
is { smth }.a_pizza? ['some', 'ingredients']
# helper's context will look like:
# {left_method: :is, left_object: nil, left_proc: 'the -> { smth } proc', negation: nil}
end
end | [
"define",
"custom",
"assertion",
"helpers",
"."
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/api/class/helpers.rb#L92-L95 | train |
sleewoo/minispec | lib/minispec/utils/throw.rb | MiniSpec.Utils.symbol_thrown? | def symbol_thrown? expected_symbol, expected_value, context, &block
thrown_symbol, thrown_value = catch_symbol(expected_symbol, &block)
if context[:right_proc]
expected_symbol && raise(ArgumentError, 'Both arguments and block given. Please use either one.')
return MiniSpec::ThrowInspector.thrown_as_expected_by_proc?(thrown_symbol, context)
end
MiniSpec::ThrowInspector.thrown_as_expected?(expected_symbol, expected_value, thrown_symbol, thrown_value, context)
end | ruby | def symbol_thrown? expected_symbol, expected_value, context, &block
thrown_symbol, thrown_value = catch_symbol(expected_symbol, &block)
if context[:right_proc]
expected_symbol && raise(ArgumentError, 'Both arguments and block given. Please use either one.')
return MiniSpec::ThrowInspector.thrown_as_expected_by_proc?(thrown_symbol, context)
end
MiniSpec::ThrowInspector.thrown_as_expected?(expected_symbol, expected_value, thrown_symbol, thrown_value, context)
end | [
"def",
"symbol_thrown?",
"expected_symbol",
",",
"expected_value",
",",
"context",
",",
"&",
"block",
"thrown_symbol",
",",
"thrown_value",
"=",
"catch_symbol",
"(",
"expected_symbol",
",",
"&",
"block",
")",
"if",
"context",
"[",
":right_proc",
"]",
"expected_symbol",
"&&",
"raise",
"(",
"ArgumentError",
",",
"'Both arguments and block given. Please use either one.'",
")",
"return",
"MiniSpec",
"::",
"ThrowInspector",
".",
"thrown_as_expected_by_proc?",
"(",
"thrown_symbol",
",",
"context",
")",
"end",
"MiniSpec",
"::",
"ThrowInspector",
".",
"thrown_as_expected?",
"(",
"expected_symbol",
",",
"expected_value",
",",
"thrown_symbol",
",",
"thrown_value",
",",
"context",
")",
"end"
] | checks whether given block throws a symbol
and if yes compare it with expected one.
if a optional value given it will be compared to thrown one.
@param expected_symbol
@param expected_value
@param [Proc] &proc
@return a failure [ThrowError] if expectation not met.
true if expectations met. | [
"checks",
"whether",
"given",
"block",
"throws",
"a",
"symbol",
"and",
"if",
"yes",
"compare",
"it",
"with",
"expected",
"one",
".",
"if",
"a",
"optional",
"value",
"given",
"it",
"will",
"be",
"compared",
"to",
"thrown",
"one",
"."
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/utils/throw.rb#L17-L26 | train |
sleewoo/minispec | lib/minispec/utils/throw.rb | MiniSpec.Utils.catch_symbol | def catch_symbol expected_symbol, &block
thrown_symbol, thrown_value = nil
begin
if expected_symbol
thrown_value = catch :__ms__nothing_thrown do
catch expected_symbol do
block.call
throw :__ms__nothing_thrown, :__ms__nothing_thrown
end
end
thrown_symbol = expected_symbol unless thrown_value == :__ms__nothing_thrown
else
block.call
end
rescue => e
raise(e) unless thrown_symbol = extract_thrown_symbol(e)
end
[thrown_symbol, thrown_value]
end | ruby | def catch_symbol expected_symbol, &block
thrown_symbol, thrown_value = nil
begin
if expected_symbol
thrown_value = catch :__ms__nothing_thrown do
catch expected_symbol do
block.call
throw :__ms__nothing_thrown, :__ms__nothing_thrown
end
end
thrown_symbol = expected_symbol unless thrown_value == :__ms__nothing_thrown
else
block.call
end
rescue => e
raise(e) unless thrown_symbol = extract_thrown_symbol(e)
end
[thrown_symbol, thrown_value]
end | [
"def",
"catch_symbol",
"expected_symbol",
",",
"&",
"block",
"thrown_symbol",
",",
"thrown_value",
"=",
"nil",
"begin",
"if",
"expected_symbol",
"thrown_value",
"=",
"catch",
":__ms__nothing_thrown",
"do",
"catch",
"expected_symbol",
"do",
"block",
".",
"call",
"throw",
":__ms__nothing_thrown",
",",
":__ms__nothing_thrown",
"end",
"end",
"thrown_symbol",
"=",
"expected_symbol",
"unless",
"thrown_value",
"==",
":__ms__nothing_thrown",
"else",
"block",
".",
"call",
"end",
"rescue",
"=>",
"e",
"raise",
"(",
"e",
")",
"unless",
"thrown_symbol",
"=",
"extract_thrown_symbol",
"(",
"e",
")",
"end",
"[",
"thrown_symbol",
",",
"thrown_value",
"]",
"end"
] | calling given block and catching thrown symbol, if any.
@param expected_symbol
@param [Proc] &block | [
"calling",
"given",
"block",
"and",
"catching",
"thrown",
"symbol",
"if",
"any",
"."
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/utils/throw.rb#L33-L51 | train |
sleewoo/minispec | lib/minispec/utils/throw.rb | MiniSpec.Utils.extract_thrown_symbol | def extract_thrown_symbol exception
return unless exception.is_a?(Exception)
return unless s = exception.message.scan(/uncaught throw\W+(\w+)/).flatten[0]
s.to_sym
end | ruby | def extract_thrown_symbol exception
return unless exception.is_a?(Exception)
return unless s = exception.message.scan(/uncaught throw\W+(\w+)/).flatten[0]
s.to_sym
end | [
"def",
"extract_thrown_symbol",
"exception",
"return",
"unless",
"exception",
".",
"is_a?",
"(",
"Exception",
")",
"return",
"unless",
"s",
"=",
"exception",
".",
"message",
".",
"scan",
"(",
"/",
"\\W",
"\\w",
"/",
")",
".",
"flatten",
"[",
"0",
"]",
"s",
".",
"to_sym",
"end"
] | extract thrown symbol from given exception
@param exception | [
"extract",
"thrown",
"symbol",
"from",
"given",
"exception"
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/utils/throw.rb#L57-L61 | train |
pjotrp/bioruby-table | lib/bio-table/table.rb | BioTable.Table.find_fields | def find_fields rowname
row = row_by_name(rowname)
fields = (row ? row.fields : [])
# fill fields with nil to match header length
# say header=5 fields=2 fill=2 (skip rowname)
fields.fill(nil,fields.size,header.size-1-fields.size)
end | ruby | def find_fields rowname
row = row_by_name(rowname)
fields = (row ? row.fields : [])
# fill fields with nil to match header length
# say header=5 fields=2 fill=2 (skip rowname)
fields.fill(nil,fields.size,header.size-1-fields.size)
end | [
"def",
"find_fields",
"rowname",
"row",
"=",
"row_by_name",
"(",
"rowname",
")",
"fields",
"=",
"(",
"row",
"?",
"row",
".",
"fields",
":",
"[",
"]",
")",
"fields",
".",
"fill",
"(",
"nil",
",",
"fields",
".",
"size",
",",
"header",
".",
"size",
"-",
"1",
"-",
"fields",
".",
"size",
")",
"end"
] | Find a record by rowname and return the fields. Empty fields are nils. | [
"Find",
"a",
"record",
"by",
"rowname",
"and",
"return",
"the",
"fields",
".",
"Empty",
"fields",
"are",
"nils",
"."
] | e7cc97bb598743e7d69e63f16f76a2ce0ed9006d | https://github.com/pjotrp/bioruby-table/blob/e7cc97bb598743e7d69e63f16f76a2ce0ed9006d/lib/bio-table/table.rb#L97-L103 | train |
inre/fibre | lib/fibre/fiber_pool.rb | Fibre.FiberPool.checkout | def checkout(&b)
spec = { block: b, parent: ::Fiber.current }
if @pool.empty?
raise "The fiber queue has been overflowed" if @queue.size > @pool_queue_size
@queue.push spec
return
end
@pool.shift.tap do |fiber|
@reserved[fiber.object_id] = spec
fiber.resume(spec)
end
self
end | ruby | def checkout(&b)
spec = { block: b, parent: ::Fiber.current }
if @pool.empty?
raise "The fiber queue has been overflowed" if @queue.size > @pool_queue_size
@queue.push spec
return
end
@pool.shift.tap do |fiber|
@reserved[fiber.object_id] = spec
fiber.resume(spec)
end
self
end | [
"def",
"checkout",
"(",
"&",
"b",
")",
"spec",
"=",
"{",
"block",
":",
"b",
",",
"parent",
":",
"::",
"Fiber",
".",
"current",
"}",
"if",
"@pool",
".",
"empty?",
"raise",
"\"The fiber queue has been overflowed\"",
"if",
"@queue",
".",
"size",
">",
"@pool_queue_size",
"@queue",
".",
"push",
"spec",
"return",
"end",
"@pool",
".",
"shift",
".",
"tap",
"do",
"|",
"fiber",
"|",
"@reserved",
"[",
"fiber",
".",
"object_id",
"]",
"=",
"spec",
"fiber",
".",
"resume",
"(",
"spec",
")",
"end",
"self",
"end"
] | Initialize fiber's pool
Borrow fiber from the pool and call the block inside | [
"Initialize",
"fiber",
"s",
"pool",
"Borrow",
"fiber",
"from",
"the",
"pool",
"and",
"call",
"the",
"block",
"inside"
] | 6b4155b1b0042345154984c088007b63b3b69f20 | https://github.com/inre/fibre/blob/6b4155b1b0042345154984c088007b63b3b69f20/lib/fibre/fiber_pool.rb#L31-L46 | train |
inre/fibre | lib/fibre/fiber_pool.rb | Fibre.FiberPool.fiber_entry | def fiber_entry(spec)
loop do
raise "wrong spec in fiber block" unless spec.is_a?(Hash)
begin
before!(spec)
spec[:block].call# *Fiber.current.args
after!(spec)
# catch ArgumentError, IOError, EOFError, IndexError, LocalJumpError, NameError, NoMethodError
# RangeError, FloatDomainError, RegexpError, RuntimeError, SecurityError, SystemCallError
# SystemStackError, ThreadError, TypeError, ZeroDivisionError
rescue StandardError => e
if error.empty?
raise Fibre::FiberError.new(e)
else
error!(e)
end
# catch NoMemoryError, ScriptError, SignalException, SystemExit, fatal etc
#rescue Exception
end
unless @queue.empty?
spec = @queue.shift
next
end
spec = checkin
end
end | ruby | def fiber_entry(spec)
loop do
raise "wrong spec in fiber block" unless spec.is_a?(Hash)
begin
before!(spec)
spec[:block].call# *Fiber.current.args
after!(spec)
# catch ArgumentError, IOError, EOFError, IndexError, LocalJumpError, NameError, NoMethodError
# RangeError, FloatDomainError, RegexpError, RuntimeError, SecurityError, SystemCallError
# SystemStackError, ThreadError, TypeError, ZeroDivisionError
rescue StandardError => e
if error.empty?
raise Fibre::FiberError.new(e)
else
error!(e)
end
# catch NoMemoryError, ScriptError, SignalException, SystemExit, fatal etc
#rescue Exception
end
unless @queue.empty?
spec = @queue.shift
next
end
spec = checkin
end
end | [
"def",
"fiber_entry",
"(",
"spec",
")",
"loop",
"do",
"raise",
"\"wrong spec in fiber block\"",
"unless",
"spec",
".",
"is_a?",
"(",
"Hash",
")",
"begin",
"before!",
"(",
"spec",
")",
"spec",
"[",
":block",
"]",
".",
"call",
"after!",
"(",
"spec",
")",
"rescue",
"StandardError",
"=>",
"e",
"if",
"error",
".",
"empty?",
"raise",
"Fibre",
"::",
"FiberError",
".",
"new",
"(",
"e",
")",
"else",
"error!",
"(",
"e",
")",
"end",
"end",
"unless",
"@queue",
".",
"empty?",
"spec",
"=",
"@queue",
".",
"shift",
"next",
"end",
"spec",
"=",
"checkin",
"end",
"end"
] | There is entrypoint running fibers | [
"There",
"is",
"entrypoint",
"running",
"fibers"
] | 6b4155b1b0042345154984c088007b63b3b69f20 | https://github.com/inre/fibre/blob/6b4155b1b0042345154984c088007b63b3b69f20/lib/fibre/fiber_pool.rb#L51-L80 | train |
inre/fibre | lib/fibre/fiber_pool.rb | Fibre.FiberPool.checkin | def checkin(result=nil)
@reserved.delete ::Fiber.current.object_id
@pool.unshift ::Fiber.current
::Fiber.yield
end | ruby | def checkin(result=nil)
@reserved.delete ::Fiber.current.object_id
@pool.unshift ::Fiber.current
::Fiber.yield
end | [
"def",
"checkin",
"(",
"result",
"=",
"nil",
")",
"@reserved",
".",
"delete",
"::",
"Fiber",
".",
"current",
".",
"object_id",
"@pool",
".",
"unshift",
"::",
"Fiber",
".",
"current",
"::",
"Fiber",
".",
"yield",
"end"
] | Return the fiber into the pool | [
"Return",
"the",
"fiber",
"into",
"the",
"pool"
] | 6b4155b1b0042345154984c088007b63b3b69f20 | https://github.com/inre/fibre/blob/6b4155b1b0042345154984c088007b63b3b69f20/lib/fibre/fiber_pool.rb#L83-L87 | train |
lloeki/sprockets-less | lib/sprockets/less/functions.rb | Less.Tree.anonymous_function | def anonymous_function(block)
lambda do |*args|
# args: (this, node) v8 >= 0.10, otherwise (node)
raise ArgumentError, "missing node" if args.empty?
@tree[:Anonymous].new block.call(@tree, args.last)
end
end | ruby | def anonymous_function(block)
lambda do |*args|
# args: (this, node) v8 >= 0.10, otherwise (node)
raise ArgumentError, "missing node" if args.empty?
@tree[:Anonymous].new block.call(@tree, args.last)
end
end | [
"def",
"anonymous_function",
"(",
"block",
")",
"lambda",
"do",
"|",
"*",
"args",
"|",
"raise",
"ArgumentError",
",",
"\"missing node\"",
"if",
"args",
".",
"empty?",
"@tree",
"[",
":Anonymous",
"]",
".",
"new",
"block",
".",
"call",
"(",
"@tree",
",",
"args",
".",
"last",
")",
"end",
"end"
] | Creates a JavaScript anonymous function from a Ruby block | [
"Creates",
"a",
"JavaScript",
"anonymous",
"function",
"from",
"a",
"Ruby",
"block"
] | f8cd973dd4dd5111bbda44e6c3fd8f445ab477f7 | https://github.com/lloeki/sprockets-less/blob/f8cd973dd4dd5111bbda44e6c3fd8f445ab477f7/lib/sprockets/less/functions.rb#L111-L117 | train |
lloeki/sprockets-less | lib/sprockets/less/functions.rb | Less.Tree.extend_js | def extend_js(mod)
extend mod
mod.public_instance_methods.each do |method_name|
add_function(sym_to_css(method_name)) { |tree, cxt|
send method_name.to_sym, unquote(cxt.toCSS())
}
end
end | ruby | def extend_js(mod)
extend mod
mod.public_instance_methods.each do |method_name|
add_function(sym_to_css(method_name)) { |tree, cxt|
send method_name.to_sym, unquote(cxt.toCSS())
}
end
end | [
"def",
"extend_js",
"(",
"mod",
")",
"extend",
"mod",
"mod",
".",
"public_instance_methods",
".",
"each",
"do",
"|",
"method_name",
"|",
"add_function",
"(",
"sym_to_css",
"(",
"method_name",
")",
")",
"{",
"|",
"tree",
",",
"cxt",
"|",
"send",
"method_name",
".",
"to_sym",
",",
"unquote",
"(",
"cxt",
".",
"toCSS",
"(",
")",
")",
"}",
"end",
"end"
] | Adds all of a module's public instance methods as Less functions | [
"Adds",
"all",
"of",
"a",
"module",
"s",
"public",
"instance",
"methods",
"as",
"Less",
"functions"
] | f8cd973dd4dd5111bbda44e6c3fd8f445ab477f7 | https://github.com/lloeki/sprockets-less/blob/f8cd973dd4dd5111bbda44e6c3fd8f445ab477f7/lib/sprockets/less/functions.rb#L130-L137 | train |
nazoking/rehtml | lib/rehtml/builder.rb | REHTML.REXMLBuilder.append | def append(node)
if node.is_a?(EndTag)
return if empty_tag?(node.name)
po = @pos
while po.parent and po.name != node.name
po = po.parent
end
if po.name == node.name
@pos = po.parent
end
else
rexml = to_rexml(node)
# if node is second root element, add root element wrap html tag
if rexml.is_a?(REXML::Element) and @pos == @doc and @doc.root
if @doc.root.name != 'html'
html = REXML::Element.new
html.name = "html"
i = @doc.root.index_in_parent-1
while pos = @doc.delete_at(i)
@doc.delete_element(pos) if pos.is_a?(REXML::Element)
html << pos
end
@doc << html
@pos = html
end
@pos = @doc.root
end
@pos << rexml
if rexml.is_a?(REXML::Element) and !empty_tag?(node.name) and !node.empty?
@pos = rexml
end
end
end | ruby | def append(node)
if node.is_a?(EndTag)
return if empty_tag?(node.name)
po = @pos
while po.parent and po.name != node.name
po = po.parent
end
if po.name == node.name
@pos = po.parent
end
else
rexml = to_rexml(node)
# if node is second root element, add root element wrap html tag
if rexml.is_a?(REXML::Element) and @pos == @doc and @doc.root
if @doc.root.name != 'html'
html = REXML::Element.new
html.name = "html"
i = @doc.root.index_in_parent-1
while pos = @doc.delete_at(i)
@doc.delete_element(pos) if pos.is_a?(REXML::Element)
html << pos
end
@doc << html
@pos = html
end
@pos = @doc.root
end
@pos << rexml
if rexml.is_a?(REXML::Element) and !empty_tag?(node.name) and !node.empty?
@pos = rexml
end
end
end | [
"def",
"append",
"(",
"node",
")",
"if",
"node",
".",
"is_a?",
"(",
"EndTag",
")",
"return",
"if",
"empty_tag?",
"(",
"node",
".",
"name",
")",
"po",
"=",
"@pos",
"while",
"po",
".",
"parent",
"and",
"po",
".",
"name",
"!=",
"node",
".",
"name",
"po",
"=",
"po",
".",
"parent",
"end",
"if",
"po",
".",
"name",
"==",
"node",
".",
"name",
"@pos",
"=",
"po",
".",
"parent",
"end",
"else",
"rexml",
"=",
"to_rexml",
"(",
"node",
")",
"if",
"rexml",
".",
"is_a?",
"(",
"REXML",
"::",
"Element",
")",
"and",
"@pos",
"==",
"@doc",
"and",
"@doc",
".",
"root",
"if",
"@doc",
".",
"root",
".",
"name",
"!=",
"'html'",
"html",
"=",
"REXML",
"::",
"Element",
".",
"new",
"html",
".",
"name",
"=",
"\"html\"",
"i",
"=",
"@doc",
".",
"root",
".",
"index_in_parent",
"-",
"1",
"while",
"pos",
"=",
"@doc",
".",
"delete_at",
"(",
"i",
")",
"@doc",
".",
"delete_element",
"(",
"pos",
")",
"if",
"pos",
".",
"is_a?",
"(",
"REXML",
"::",
"Element",
")",
"html",
"<<",
"pos",
"end",
"@doc",
"<<",
"html",
"@pos",
"=",
"html",
"end",
"@pos",
"=",
"@doc",
".",
"root",
"end",
"@pos",
"<<",
"rexml",
"if",
"rexml",
".",
"is_a?",
"(",
"REXML",
"::",
"Element",
")",
"and",
"!",
"empty_tag?",
"(",
"node",
".",
"name",
")",
"and",
"!",
"node",
".",
"empty?",
"@pos",
"=",
"rexml",
"end",
"end",
"end"
] | append node to document | [
"append",
"node",
"to",
"document"
] | 4bf9016f5325becd955db777d832a2c90f3407ac | https://github.com/nazoking/rehtml/blob/4bf9016f5325becd955db777d832a2c90f3407ac/lib/rehtml/builder.rb#L19-L52 | train |
qw3/getnet_api | lib/getnet_api/payment.rb | GetnetApi.Payment.to_request | def to_request obj, type
payment = {
seller_id: GetnetApi.seller_id.to_s,
amount: self.amount.to_i,
currency: self.currency.to_s,
order: self.order.to_request,
customer: self.customer.to_request(:payment),
}
if type == :boleto
payment.merge!({"boleto" => obj.to_request,})
elsif :credit
payment.merge!({"credit" => obj.to_request,})
end
return payment
end | ruby | def to_request obj, type
payment = {
seller_id: GetnetApi.seller_id.to_s,
amount: self.amount.to_i,
currency: self.currency.to_s,
order: self.order.to_request,
customer: self.customer.to_request(:payment),
}
if type == :boleto
payment.merge!({"boleto" => obj.to_request,})
elsif :credit
payment.merge!({"credit" => obj.to_request,})
end
return payment
end | [
"def",
"to_request",
"obj",
",",
"type",
"payment",
"=",
"{",
"seller_id",
":",
"GetnetApi",
".",
"seller_id",
".",
"to_s",
",",
"amount",
":",
"self",
".",
"amount",
".",
"to_i",
",",
"currency",
":",
"self",
".",
"currency",
".",
"to_s",
",",
"order",
":",
"self",
".",
"order",
".",
"to_request",
",",
"customer",
":",
"self",
".",
"customer",
".",
"to_request",
"(",
":payment",
")",
",",
"}",
"if",
"type",
"==",
":boleto",
"payment",
".",
"merge!",
"(",
"{",
"\"boleto\"",
"=>",
"obj",
".",
"to_request",
",",
"}",
")",
"elsif",
":credit",
"payment",
".",
"merge!",
"(",
"{",
"\"credit\"",
"=>",
"obj",
".",
"to_request",
",",
"}",
")",
"end",
"return",
"payment",
"end"
] | Nova instancia da classe Cliente
@param [Hash] campos
Montar o Hash de dados do usuario no padrão utilizado pela Getnet | [
"Nova",
"instancia",
"da",
"classe",
"Cliente"
] | 94cbda66aab03d83ea38bc5325ea2a02a639e922 | https://github.com/qw3/getnet_api/blob/94cbda66aab03d83ea38bc5325ea2a02a639e922/lib/getnet_api/payment.rb#L75-L91 | train |
codefoundry/svn | lib/svn/revisions.rb | Svn.Revision.diff | def diff( path, options={} )
raise Svn::Error, "cannot diff directory #{path}@#{to_s}" if dir? path
other = options[:with] if options[:with].is_a? Root
other = repo.revision(options[:with]) if options[:with].is_a? Numeric
other ||= repo.revision(to_i - 1)
return other.diff( path, :with => self ) if other < self
content = ""
begin
content = file_content_stream( path ).to_counted_string
rescue Svn::Error => err
raise if options[:raise_errors]
end
other_content = ""
begin
other_content= other.file_content_stream( path ).to_counted_string
rescue Svn::Error => err
raise if options[:raise_errors]
end
Diff.string_diff( content, other_content ).unified(
:original_header => "#{path}@#{to_s}",
:modified_header => "#{path}@#{other}"
)
end | ruby | def diff( path, options={} )
raise Svn::Error, "cannot diff directory #{path}@#{to_s}" if dir? path
other = options[:with] if options[:with].is_a? Root
other = repo.revision(options[:with]) if options[:with].is_a? Numeric
other ||= repo.revision(to_i - 1)
return other.diff( path, :with => self ) if other < self
content = ""
begin
content = file_content_stream( path ).to_counted_string
rescue Svn::Error => err
raise if options[:raise_errors]
end
other_content = ""
begin
other_content= other.file_content_stream( path ).to_counted_string
rescue Svn::Error => err
raise if options[:raise_errors]
end
Diff.string_diff( content, other_content ).unified(
:original_header => "#{path}@#{to_s}",
:modified_header => "#{path}@#{other}"
)
end | [
"def",
"diff",
"(",
"path",
",",
"options",
"=",
"{",
"}",
")",
"raise",
"Svn",
"::",
"Error",
",",
"\"cannot diff directory #{path}@#{to_s}\"",
"if",
"dir?",
"path",
"other",
"=",
"options",
"[",
":with",
"]",
"if",
"options",
"[",
":with",
"]",
".",
"is_a?",
"Root",
"other",
"=",
"repo",
".",
"revision",
"(",
"options",
"[",
":with",
"]",
")",
"if",
"options",
"[",
":with",
"]",
".",
"is_a?",
"Numeric",
"other",
"||=",
"repo",
".",
"revision",
"(",
"to_i",
"-",
"1",
")",
"return",
"other",
".",
"diff",
"(",
"path",
",",
":with",
"=>",
"self",
")",
"if",
"other",
"<",
"self",
"content",
"=",
"\"\"",
"begin",
"content",
"=",
"file_content_stream",
"(",
"path",
")",
".",
"to_counted_string",
"rescue",
"Svn",
"::",
"Error",
"=>",
"err",
"raise",
"if",
"options",
"[",
":raise_errors",
"]",
"end",
"other_content",
"=",
"\"\"",
"begin",
"other_content",
"=",
"other",
".",
"file_content_stream",
"(",
"path",
")",
".",
"to_counted_string",
"rescue",
"Svn",
"::",
"Error",
"=>",
"err",
"raise",
"if",
"options",
"[",
":raise_errors",
"]",
"end",
"Diff",
".",
"string_diff",
"(",
"content",
",",
"other_content",
")",
".",
"unified",
"(",
":original_header",
"=>",
"\"#{path}@#{to_s}\"",
",",
":modified_header",
"=>",
"\"#{path}@#{other}\"",
")",
"end"
] | diffs +path+ with another revision. if no revision is specified, the
previous revision is used. | [
"diffs",
"+",
"path",
"+",
"with",
"another",
"revision",
".",
"if",
"no",
"revision",
"is",
"specified",
"the",
"previous",
"revision",
"is",
"used",
"."
] | 930a8da65fbecf3ffed50655e1cb10fcbc484be4 | https://github.com/codefoundry/svn/blob/930a8da65fbecf3ffed50655e1cb10fcbc484be4/lib/svn/revisions.rb#L98-L125 | train |
Nakilon/reddit_bot | lib/reddit_bot.rb | RedditBot.Bot.resp_with_token | def resp_with_token mtd, path, form
fail unless path.start_with? ?/
timeout = 5
begin
reddit_resp mtd, "https://oauth.reddit.com" + path, form, {
"Authorization" => "bearer #{token}",
"User-Agent" => "bot/#{@user_agent || @name}/#{RedditBot::VERSION} by /u/nakilon",
}
rescue NetHTTPUtils::Error => e
sleep timeout
Module.nesting[1].logger.info "sleeping #{timeout} seconds because of #{e.code}"
timeout *= 2
raise unless e.code == 401
@token_cached = nil
retry
end
end | ruby | def resp_with_token mtd, path, form
fail unless path.start_with? ?/
timeout = 5
begin
reddit_resp mtd, "https://oauth.reddit.com" + path, form, {
"Authorization" => "bearer #{token}",
"User-Agent" => "bot/#{@user_agent || @name}/#{RedditBot::VERSION} by /u/nakilon",
}
rescue NetHTTPUtils::Error => e
sleep timeout
Module.nesting[1].logger.info "sleeping #{timeout} seconds because of #{e.code}"
timeout *= 2
raise unless e.code == 401
@token_cached = nil
retry
end
end | [
"def",
"resp_with_token",
"mtd",
",",
"path",
",",
"form",
"fail",
"unless",
"path",
".",
"start_with?",
"?/",
"timeout",
"=",
"5",
"begin",
"reddit_resp",
"mtd",
",",
"\"https://oauth.reddit.com\"",
"+",
"path",
",",
"form",
",",
"{",
"\"Authorization\"",
"=>",
"\"bearer #{token}\"",
",",
"\"User-Agent\"",
"=>",
"\"bot/#{@user_agent || @name}/#{RedditBot::VERSION} by /u/nakilon\"",
",",
"}",
"rescue",
"NetHTTPUtils",
"::",
"Error",
"=>",
"e",
"sleep",
"timeout",
"Module",
".",
"nesting",
"[",
"1",
"]",
".",
"logger",
".",
"info",
"\"sleeping #{timeout} seconds because of #{e.code}\"",
"timeout",
"*=",
"2",
"raise",
"unless",
"e",
".",
"code",
"==",
"401",
"@token_cached",
"=",
"nil",
"retry",
"end",
"end"
] | def update_captcha
return if @ignore_captcha
pp iden_json = json(:post, "/api/new_captcha")
iden = iden_json["json"]["data"]["iden"]
# return @iden_and_captcha = [iden, "\n"] if @ignore_captcha
# pp resp_with_token(:get, "/captcha/#{iden_json["json"]["data"]["iden"]}", {})
puts "CAPTCHA: https://reddit.com/captcha/#{iden}"
@iden_and_captcha = [iden, gets.strip]
end | [
"def",
"update_captcha",
"return",
"if"
] | e18e498b807b81a49b5ea87b9b294a14b96f9f78 | https://github.com/Nakilon/reddit_bot/blob/e18e498b807b81a49b5ea87b9b294a14b96f9f78/lib/reddit_bot.rb#L228-L244 | train |
kennym/ideone-ruby-api | lib/ideone.rb | Ideone.Client.languages | def languages
unless @languages_cache
response = call_request(:get_languages)
languages = response.to_hash[:get_languages_response][:return][:item][1][:value][:item]
# Create a sorted hash
@languages_cache = Hash[create_dict(languages).sort_by{|k,v| k.to_i}]
end
return @languages_cache
end | ruby | def languages
unless @languages_cache
response = call_request(:get_languages)
languages = response.to_hash[:get_languages_response][:return][:item][1][:value][:item]
# Create a sorted hash
@languages_cache = Hash[create_dict(languages).sort_by{|k,v| k.to_i}]
end
return @languages_cache
end | [
"def",
"languages",
"unless",
"@languages_cache",
"response",
"=",
"call_request",
"(",
":get_languages",
")",
"languages",
"=",
"response",
".",
"to_hash",
"[",
":get_languages_response",
"]",
"[",
":return",
"]",
"[",
":item",
"]",
"[",
"1",
"]",
"[",
":value",
"]",
"[",
":item",
"]",
"@languages_cache",
"=",
"Hash",
"[",
"create_dict",
"(",
"languages",
")",
".",
"sort_by",
"{",
"|",
"k",
",",
"v",
"|",
"k",
".",
"to_i",
"}",
"]",
"end",
"return",
"@languages_cache",
"end"
] | Get a list of supported languages and cache it. | [
"Get",
"a",
"list",
"of",
"supported",
"languages",
"and",
"cache",
"it",
"."
] | d682c8a1c673579c399b834bff7dbcbba648fb81 | https://github.com/kennym/ideone-ruby-api/blob/d682c8a1c673579c399b834bff7dbcbba648fb81/lib/ideone.rb#L79-L88 | train |
qw3/getnet_api | lib/getnet_api/boleto.rb | GetnetApi.Boleto.to_request | def to_request
boleto = {
our_number: self.our_number,
document_number: self.document_number,
expiration_date: self.expiration_date,
instructions: self.instructions,
provider: self.provider
}
return boleto
end | ruby | def to_request
boleto = {
our_number: self.our_number,
document_number: self.document_number,
expiration_date: self.expiration_date,
instructions: self.instructions,
provider: self.provider
}
return boleto
end | [
"def",
"to_request",
"boleto",
"=",
"{",
"our_number",
":",
"self",
".",
"our_number",
",",
"document_number",
":",
"self",
".",
"document_number",
",",
"expiration_date",
":",
"self",
".",
"expiration_date",
",",
"instructions",
":",
"self",
".",
"instructions",
",",
"provider",
":",
"self",
".",
"provider",
"}",
"return",
"boleto",
"end"
] | Nova instancia da classe Boleto
@param [Hash] campos
Montar o Hash de dados do pagamento no padrão utilizado pela Getnet | [
"Nova",
"instancia",
"da",
"classe",
"Boleto"
] | 94cbda66aab03d83ea38bc5325ea2a02a639e922 | https://github.com/qw3/getnet_api/blob/94cbda66aab03d83ea38bc5325ea2a02a639e922/lib/getnet_api/boleto.rb#L49-L59 | train |
rkday/ruby-diameter | lib/diameter/message.rb | Diameter.Message.all_avps_by_name | def all_avps_by_name(name)
code, _type, vendor = Internals::AVPNames.get(name)
all_avps_by_code(code, vendor)
end | ruby | def all_avps_by_name(name)
code, _type, vendor = Internals::AVPNames.get(name)
all_avps_by_code(code, vendor)
end | [
"def",
"all_avps_by_name",
"(",
"name",
")",
"code",
",",
"_type",
",",
"vendor",
"=",
"Internals",
"::",
"AVPNames",
".",
"get",
"(",
"name",
")",
"all_avps_by_code",
"(",
"code",
",",
"vendor",
")",
"end"
] | Returns all AVPs with the given name. Only covers "top-level"
AVPs - it won't look inside Grouped AVPs.
@param name [String] The AVP name, either one predefined in
{Constants::AVAILABLE_AVPS} or user-defined with {AVP.define}
@return [Array<AVP>] | [
"Returns",
"all",
"AVPs",
"with",
"the",
"given",
"name",
".",
"Only",
"covers",
"top",
"-",
"level",
"AVPs",
"-",
"it",
"won",
"t",
"look",
"inside",
"Grouped",
"AVPs",
"."
] | 83def68f67cf660aa227eac4c74719dc98aacab2 | https://github.com/rkday/ruby-diameter/blob/83def68f67cf660aa227eac4c74719dc98aacab2/lib/diameter/message.rb#L113-L116 | train |
johnl/web-page-parser | lib/web-page-parser/base_parser.rb | WebPageParser.BaseRegexpParser.encode | def encode(s)
return s if s.nil?
return s if s.valid_encoding?
if s.force_encoding("iso-8859-1").valid_encoding?
return s.encode('utf-8', 'iso-8859-1')
end
s
end | ruby | def encode(s)
return s if s.nil?
return s if s.valid_encoding?
if s.force_encoding("iso-8859-1").valid_encoding?
return s.encode('utf-8', 'iso-8859-1')
end
s
end | [
"def",
"encode",
"(",
"s",
")",
"return",
"s",
"if",
"s",
".",
"nil?",
"return",
"s",
"if",
"s",
".",
"valid_encoding?",
"if",
"s",
".",
"force_encoding",
"(",
"\"iso-8859-1\"",
")",
".",
"valid_encoding?",
"return",
"s",
".",
"encode",
"(",
"'utf-8'",
",",
"'iso-8859-1'",
")",
"end",
"s",
"end"
] | Handle any string encoding | [
"Handle",
"any",
"string",
"encoding"
] | 105cbe6fda569c6c6667ed655ea6c6771c1d9037 | https://github.com/johnl/web-page-parser/blob/105cbe6fda569c6c6667ed655ea6c6771c1d9037/lib/web-page-parser/base_parser.rb#L103-L110 | train |
johnl/web-page-parser | lib/web-page-parser/base_parser.rb | WebPageParser.BaseRegexpParser.retrieve_page | def retrieve_page(rurl = nil)
durl = rurl || url
return nil unless durl
durl = filter_url(durl) if self.respond_to?(:filter_url)
self.class.retrieve_session ||= WebPageParser::HTTP::Session.new
encode(self.class.retrieve_session.get(durl))
end | ruby | def retrieve_page(rurl = nil)
durl = rurl || url
return nil unless durl
durl = filter_url(durl) if self.respond_to?(:filter_url)
self.class.retrieve_session ||= WebPageParser::HTTP::Session.new
encode(self.class.retrieve_session.get(durl))
end | [
"def",
"retrieve_page",
"(",
"rurl",
"=",
"nil",
")",
"durl",
"=",
"rurl",
"||",
"url",
"return",
"nil",
"unless",
"durl",
"durl",
"=",
"filter_url",
"(",
"durl",
")",
"if",
"self",
".",
"respond_to?",
"(",
":filter_url",
")",
"self",
".",
"class",
".",
"retrieve_session",
"||=",
"WebPageParser",
"::",
"HTTP",
"::",
"Session",
".",
"new",
"encode",
"(",
"self",
".",
"class",
".",
"retrieve_session",
".",
"get",
"(",
"durl",
")",
")",
"end"
] | request the page from the server and return the raw contents | [
"request",
"the",
"page",
"from",
"the",
"server",
"and",
"return",
"the",
"raw",
"contents"
] | 105cbe6fda569c6c6667ed655ea6c6771c1d9037 | https://github.com/johnl/web-page-parser/blob/105cbe6fda569c6c6667ed655ea6c6771c1d9037/lib/web-page-parser/base_parser.rb#L118-L124 | train |
johnl/web-page-parser | lib/web-page-parser/base_parser.rb | WebPageParser.BaseRegexpParser.title | def title
return @title if @title
if matches = class_const(:TITLE_RE).match(page)
@title = matches[1].to_s.strip
title_processor
@title = decode_entities(@title)
end
end | ruby | def title
return @title if @title
if matches = class_const(:TITLE_RE).match(page)
@title = matches[1].to_s.strip
title_processor
@title = decode_entities(@title)
end
end | [
"def",
"title",
"return",
"@title",
"if",
"@title",
"if",
"matches",
"=",
"class_const",
"(",
":TITLE_RE",
")",
".",
"match",
"(",
"page",
")",
"@title",
"=",
"matches",
"[",
"1",
"]",
".",
"to_s",
".",
"strip",
"title_processor",
"@title",
"=",
"decode_entities",
"(",
"@title",
")",
"end",
"end"
] | The title method returns the title of the web page.
It does the basic extraction using the TITLE_RE regular
expression and handles text encoding. More advanced parsing can
be done by overriding the title_processor method. | [
"The",
"title",
"method",
"returns",
"the",
"title",
"of",
"the",
"web",
"page",
"."
] | 105cbe6fda569c6c6667ed655ea6c6771c1d9037 | https://github.com/johnl/web-page-parser/blob/105cbe6fda569c6c6667ed655ea6c6771c1d9037/lib/web-page-parser/base_parser.rb#L131-L138 | train |
johnl/web-page-parser | lib/web-page-parser/base_parser.rb | WebPageParser.BaseRegexpParser.content | def content
return @content if @content
matches = class_const(:CONTENT_RE).match(page)
if matches
@content = class_const(:KILL_CHARS_RE).gsub(matches[1].to_s, '')
content_processor
@content.collect! { |p| decode_entities(p.strip) }
@content.delete_if { |p| p == '' or p.nil? }
end
@content = [] if @content.nil?
@content
end | ruby | def content
return @content if @content
matches = class_const(:CONTENT_RE).match(page)
if matches
@content = class_const(:KILL_CHARS_RE).gsub(matches[1].to_s, '')
content_processor
@content.collect! { |p| decode_entities(p.strip) }
@content.delete_if { |p| p == '' or p.nil? }
end
@content = [] if @content.nil?
@content
end | [
"def",
"content",
"return",
"@content",
"if",
"@content",
"matches",
"=",
"class_const",
"(",
":CONTENT_RE",
")",
".",
"match",
"(",
"page",
")",
"if",
"matches",
"@content",
"=",
"class_const",
"(",
":KILL_CHARS_RE",
")",
".",
"gsub",
"(",
"matches",
"[",
"1",
"]",
".",
"to_s",
",",
"''",
")",
"content_processor",
"@content",
".",
"collect!",
"{",
"|",
"p",
"|",
"decode_entities",
"(",
"p",
".",
"strip",
")",
"}",
"@content",
".",
"delete_if",
"{",
"|",
"p",
"|",
"p",
"==",
"''",
"or",
"p",
".",
"nil?",
"}",
"end",
"@content",
"=",
"[",
"]",
"if",
"@content",
".",
"nil?",
"@content",
"end"
] | The content method returns the important body text of the web page.
It does basic extraction and pre-processing of the page content
and then calls the content_processor method for any other more
custom processing work that needs doing. Lastly, it does some
basic post processing and returns the content as a string.
When writing a new parser, the CONTENT_RE constant should be
defined in the subclass. The KILL_CHARS_RE constant can be
overridden if necessary. | [
"The",
"content",
"method",
"returns",
"the",
"important",
"body",
"text",
"of",
"the",
"web",
"page",
"."
] | 105cbe6fda569c6c6667ed655ea6c6771c1d9037 | https://github.com/johnl/web-page-parser/blob/105cbe6fda569c6c6667ed655ea6c6771c1d9037/lib/web-page-parser/base_parser.rb#L165-L176 | train |
brainmap/nifti | lib/nifti/n_image.rb | NIFTI.NImage.[] | def [](index)
# Dealing with Ranges is useful when the image represents a tensor
if (index.is_a?(Fixnum) && index >= self.shape[0]) || (index.is_a?(Range) && index.last >= self.shape[0])
raise IndexError.new("Index over bounds")
elsif self.shape.count == 1
if index.is_a?(Range)
value = []
index.each { |i| value << self.array_image[get_index_value(i)] }
value
else
self.array_image[get_index_value(index)]
end
else
NImage.new(self.array_image, self.dim, self.previous_indexes.clone << index)
end
end | ruby | def [](index)
# Dealing with Ranges is useful when the image represents a tensor
if (index.is_a?(Fixnum) && index >= self.shape[0]) || (index.is_a?(Range) && index.last >= self.shape[0])
raise IndexError.new("Index over bounds")
elsif self.shape.count == 1
if index.is_a?(Range)
value = []
index.each { |i| value << self.array_image[get_index_value(i)] }
value
else
self.array_image[get_index_value(index)]
end
else
NImage.new(self.array_image, self.dim, self.previous_indexes.clone << index)
end
end | [
"def",
"[]",
"(",
"index",
")",
"if",
"(",
"index",
".",
"is_a?",
"(",
"Fixnum",
")",
"&&",
"index",
">=",
"self",
".",
"shape",
"[",
"0",
"]",
")",
"||",
"(",
"index",
".",
"is_a?",
"(",
"Range",
")",
"&&",
"index",
".",
"last",
">=",
"self",
".",
"shape",
"[",
"0",
"]",
")",
"raise",
"IndexError",
".",
"new",
"(",
"\"Index over bounds\"",
")",
"elsif",
"self",
".",
"shape",
".",
"count",
"==",
"1",
"if",
"index",
".",
"is_a?",
"(",
"Range",
")",
"value",
"=",
"[",
"]",
"index",
".",
"each",
"{",
"|",
"i",
"|",
"value",
"<<",
"self",
".",
"array_image",
"[",
"get_index_value",
"(",
"i",
")",
"]",
"}",
"value",
"else",
"self",
".",
"array_image",
"[",
"get_index_value",
"(",
"index",
")",
"]",
"end",
"else",
"NImage",
".",
"new",
"(",
"self",
".",
"array_image",
",",
"self",
".",
"dim",
",",
"self",
".",
"previous_indexes",
".",
"clone",
"<<",
"index",
")",
"end",
"end"
] | Creates an NImage instance.
The NImages instance provides a user friendly interface to the NIFTI Image
A NImage is typically built by NObject instance
=== Parameters
* <tt>array_image</tt> -- The NIFTI image contained on and one dimensional array
* <tt>dim</tt> -- The dimensions array from the NIFTI header.
=== Examples
# Creates an NImage to deal with an 9 position array that represents a 3x3 matrix
img = Nimage.new(Array.new(9,0.0), [2,3,3])
Retrieves an element or partition of the dataset
=== Parameters
* <tt>index</tt> -- The desired index on the dataset
=== Options
=== Examples
img[0][0]
img[0][0..1] | [
"Creates",
"an",
"NImage",
"instance",
"."
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_image.rb#L41-L56 | train |
brainmap/nifti | lib/nifti/n_image.rb | NIFTI.NImage.[]= | def []=(index,value)
if self.shape.count != 1 or index >= self.shape[0]
raise IndexError.new("You can only set values for array values")
else
@array_image[get_index_value(index)] = value
end
end | ruby | def []=(index,value)
if self.shape.count != 1 or index >= self.shape[0]
raise IndexError.new("You can only set values for array values")
else
@array_image[get_index_value(index)] = value
end
end | [
"def",
"[]=",
"(",
"index",
",",
"value",
")",
"if",
"self",
".",
"shape",
".",
"count",
"!=",
"1",
"or",
"index",
">=",
"self",
".",
"shape",
"[",
"0",
"]",
"raise",
"IndexError",
".",
"new",
"(",
"\"You can only set values for array values\"",
")",
"else",
"@array_image",
"[",
"get_index_value",
"(",
"index",
")",
"]",
"=",
"value",
"end",
"end"
] | Set the value for an element of the dataset
=== Parameters
* <tt>index</tt> -- The desired index on the dataset
* <tt>value</tt> -- The value that the will be set
=== Options
=== Examples
img[0][0] = 1.0 | [
"Set",
"the",
"value",
"for",
"an",
"element",
"of",
"the",
"dataset"
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_image.rb#L71-L77 | train |
thelabtech/questionnaire | app/models/qe/question_set.rb | Qe.QuestionSet.post | def post(params, answer_sheet)
questions_indexed = @questions.index_by {|q| q.id}
# loop over form values
params ||= {}
params.each do |question_id, response|
next if questions_indexed[question_id.to_i].nil? # the rare case where a question was removed after the app was opened.
# update each question with the posted response
questions_indexed[question_id.to_i].set_response(posted_values(response), answer_sheet)
end
end | ruby | def post(params, answer_sheet)
questions_indexed = @questions.index_by {|q| q.id}
# loop over form values
params ||= {}
params.each do |question_id, response|
next if questions_indexed[question_id.to_i].nil? # the rare case where a question was removed after the app was opened.
# update each question with the posted response
questions_indexed[question_id.to_i].set_response(posted_values(response), answer_sheet)
end
end | [
"def",
"post",
"(",
"params",
",",
"answer_sheet",
")",
"questions_indexed",
"=",
"@questions",
".",
"index_by",
"{",
"|",
"q",
"|",
"q",
".",
"id",
"}",
"params",
"||=",
"{",
"}",
"params",
".",
"each",
"do",
"|",
"question_id",
",",
"response",
"|",
"next",
"if",
"questions_indexed",
"[",
"question_id",
".",
"to_i",
"]",
".",
"nil?",
"questions_indexed",
"[",
"question_id",
".",
"to_i",
"]",
".",
"set_response",
"(",
"posted_values",
"(",
"response",
")",
",",
"answer_sheet",
")",
"end",
"end"
] | associate answers from database with a set of elements
update with responses from form | [
"associate",
"answers",
"from",
"database",
"with",
"a",
"set",
"of",
"elements",
"update",
"with",
"responses",
"from",
"form"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/models/qe/question_set.rb#L24-L34 | train |
thelabtech/questionnaire | app/models/qe/question_set.rb | Qe.QuestionSet.posted_values | def posted_values(param)
if param.kind_of?(Hash) and param.has_key?('year') and param.has_key?('month')
year = param['year']
month = param['month']
if month.blank? or year.blank?
values = ''
else
values = [Date.new(year.to_i, month.to_i, 1).strftime('%m/%d/%Y')] # for mm/yy drop downs
end
elsif param.kind_of?(Hash)
# from Hash with multiple answers per question
values = param.values.map {|v| CGI.unescape(v)}
elsif param.kind_of?(String)
values = [CGI.unescape(param)]
end
# Hash may contain empty string to force post for no checkboxes
# values = values.reject {|r| r == ''}
end | ruby | def posted_values(param)
if param.kind_of?(Hash) and param.has_key?('year') and param.has_key?('month')
year = param['year']
month = param['month']
if month.blank? or year.blank?
values = ''
else
values = [Date.new(year.to_i, month.to_i, 1).strftime('%m/%d/%Y')] # for mm/yy drop downs
end
elsif param.kind_of?(Hash)
# from Hash with multiple answers per question
values = param.values.map {|v| CGI.unescape(v)}
elsif param.kind_of?(String)
values = [CGI.unescape(param)]
end
# Hash may contain empty string to force post for no checkboxes
# values = values.reject {|r| r == ''}
end | [
"def",
"posted_values",
"(",
"param",
")",
"if",
"param",
".",
"kind_of?",
"(",
"Hash",
")",
"and",
"param",
".",
"has_key?",
"(",
"'year'",
")",
"and",
"param",
".",
"has_key?",
"(",
"'month'",
")",
"year",
"=",
"param",
"[",
"'year'",
"]",
"month",
"=",
"param",
"[",
"'month'",
"]",
"if",
"month",
".",
"blank?",
"or",
"year",
".",
"blank?",
"values",
"=",
"''",
"else",
"values",
"=",
"[",
"Date",
".",
"new",
"(",
"year",
".",
"to_i",
",",
"month",
".",
"to_i",
",",
"1",
")",
".",
"strftime",
"(",
"'%m/%d/%Y'",
")",
"]",
"end",
"elsif",
"param",
".",
"kind_of?",
"(",
"Hash",
")",
"values",
"=",
"param",
".",
"values",
".",
"map",
"{",
"|",
"v",
"|",
"CGI",
".",
"unescape",
"(",
"v",
")",
"}",
"elsif",
"param",
".",
"kind_of?",
"(",
"String",
")",
"values",
"=",
"[",
"CGI",
".",
"unescape",
"(",
"param",
")",
"]",
"end",
"end"
] | convert posted response to a question into Array of values | [
"convert",
"posted",
"response",
"to",
"a",
"question",
"into",
"Array",
"of",
"values"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/models/qe/question_set.rb#L60-L79 | train |
sleewoo/minispec | lib/minispec/api/instance/mocks/mocks.rb | MiniSpec.InstanceAPI.mock | def mock object, method, visibility = nil, &proc
if method.is_a?(Hash)
proc && raise(ArgumentError, 'Both Hash and block given. Please use either one.')
method.each_pair {|m,r| mock(object, m, visibility, &proc {r})}
return MiniSpec::Mocks::HashedStub
end
visibility ||= MiniSpec::Utils.method_visibility(object, method) || :public
# IMPORTANT! stub should be defined before expectation
stub = stub(object, method, visibility, &proc)
expect(object).to_receive(method)
stub
end | ruby | def mock object, method, visibility = nil, &proc
if method.is_a?(Hash)
proc && raise(ArgumentError, 'Both Hash and block given. Please use either one.')
method.each_pair {|m,r| mock(object, m, visibility, &proc {r})}
return MiniSpec::Mocks::HashedStub
end
visibility ||= MiniSpec::Utils.method_visibility(object, method) || :public
# IMPORTANT! stub should be defined before expectation
stub = stub(object, method, visibility, &proc)
expect(object).to_receive(method)
stub
end | [
"def",
"mock",
"object",
",",
"method",
",",
"visibility",
"=",
"nil",
",",
"&",
"proc",
"if",
"method",
".",
"is_a?",
"(",
"Hash",
")",
"proc",
"&&",
"raise",
"(",
"ArgumentError",
",",
"'Both Hash and block given. Please use either one.'",
")",
"method",
".",
"each_pair",
"{",
"|",
"m",
",",
"r",
"|",
"mock",
"(",
"object",
",",
"m",
",",
"visibility",
",",
"&",
"proc",
"{",
"r",
"}",
")",
"}",
"return",
"MiniSpec",
"::",
"Mocks",
"::",
"HashedStub",
"end",
"visibility",
"||=",
"MiniSpec",
"::",
"Utils",
".",
"method_visibility",
"(",
"object",
",",
"method",
")",
"||",
":public",
"stub",
"=",
"stub",
"(",
"object",
",",
"method",
",",
"visibility",
",",
"&",
"proc",
")",
"expect",
"(",
"object",
")",
".",
"to_receive",
"(",
"method",
")",
"stub",
"end"
] | the mock is basically a stub with difference it will also add a expectation.
that's it, a mock will stub a method on a object and
will expect that stub to be called before test finished.
the `mock` method will return the actual stub
so you can build chained constraints on it.
@note if mocked method exists it's visibility will be kept
@example make `some_object` to respond to `:some_method`
and expect `:some_method` to be called before current test finished.
also make `:some_method` to behave differently depending on given arguments.
so if called with [:a, :b] arguments it will return 'called with a, b'.
called with [:x, :y] arguments it will return 'called with x, y'.
called with any other arguments or without arguments at all it returns 'whatever'.
mock(some_object, :some_method).
with(:a, :b) { 'called with a, b' }.
with(:x, :y) { 'called with x, y' }.
with_any { 'whatever' } | [
"the",
"mock",
"is",
"basically",
"a",
"stub",
"with",
"difference",
"it",
"will",
"also",
"add",
"a",
"expectation",
".",
"that",
"s",
"it",
"a",
"mock",
"will",
"stub",
"a",
"method",
"on",
"a",
"object",
"and",
"will",
"expect",
"that",
"stub",
"to",
"be",
"called",
"before",
"test",
"finished",
"."
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/api/instance/mocks/mocks.rb#L25-L36 | train |
sleewoo/minispec | lib/minispec/api/instance/mocks/mocks.rb | MiniSpec.InstanceAPI.proxy | def proxy object, method_name
# do not proxify doubles
return if object.respond_to?(:__ms__double_instance)
# do not proxify stubs
return if (x = @__ms__stubs__originals) && (x = x[object]) && x[method_name]
proxies = (@__ms__proxies[object] ||= [])
return if proxies.include?(method_name)
proxies << method_name
# method exists and it is a singleton.
# `nil?` method can be overridden only through a singleton
if method_name == :nil? || object.singleton_methods.include?(method_name)
return __ms__mocks__define_singleton_proxy(object, method_name)
end
# method exists and it is not a singleton, define a regular proxy
if visibility = MiniSpec::Utils.method_visibility(object, method_name)
return __ms__mocks__define_regular_proxy(object, method_name, visibility)
end
raise(NoMethodError, '%s does not respond to %s. Can not proxify an un-existing method.' % [
object.inspect, method_name.inspect
])
end | ruby | def proxy object, method_name
# do not proxify doubles
return if object.respond_to?(:__ms__double_instance)
# do not proxify stubs
return if (x = @__ms__stubs__originals) && (x = x[object]) && x[method_name]
proxies = (@__ms__proxies[object] ||= [])
return if proxies.include?(method_name)
proxies << method_name
# method exists and it is a singleton.
# `nil?` method can be overridden only through a singleton
if method_name == :nil? || object.singleton_methods.include?(method_name)
return __ms__mocks__define_singleton_proxy(object, method_name)
end
# method exists and it is not a singleton, define a regular proxy
if visibility = MiniSpec::Utils.method_visibility(object, method_name)
return __ms__mocks__define_regular_proxy(object, method_name, visibility)
end
raise(NoMethodError, '%s does not respond to %s. Can not proxify an un-existing method.' % [
object.inspect, method_name.inspect
])
end | [
"def",
"proxy",
"object",
",",
"method_name",
"return",
"if",
"object",
".",
"respond_to?",
"(",
":__ms__double_instance",
")",
"return",
"if",
"(",
"x",
"=",
"@__ms__stubs__originals",
")",
"&&",
"(",
"x",
"=",
"x",
"[",
"object",
"]",
")",
"&&",
"x",
"[",
"method_name",
"]",
"proxies",
"=",
"(",
"@__ms__proxies",
"[",
"object",
"]",
"||=",
"[",
"]",
")",
"return",
"if",
"proxies",
".",
"include?",
"(",
"method_name",
")",
"proxies",
"<<",
"method_name",
"if",
"method_name",
"==",
":nil?",
"||",
"object",
".",
"singleton_methods",
".",
"include?",
"(",
"method_name",
")",
"return",
"__ms__mocks__define_singleton_proxy",
"(",
"object",
",",
"method_name",
")",
"end",
"if",
"visibility",
"=",
"MiniSpec",
"::",
"Utils",
".",
"method_visibility",
"(",
"object",
",",
"method_name",
")",
"return",
"__ms__mocks__define_regular_proxy",
"(",
"object",
",",
"method_name",
",",
"visibility",
")",
"end",
"raise",
"(",
"NoMethodError",
",",
"'%s does not respond to %s. Can not proxify an un-existing method.'",
"%",
"[",
"object",
".",
"inspect",
",",
"method_name",
".",
"inspect",
"]",
")",
"end"
] | overriding given method of given object with a proxy
so MiniSpec can later check whether given method was called.
if given method does not exists a NoMethodError raised
@note doubles and stubs will be skipped as they are already proxified
@example
proxy(obj, :a)
assert(obj).received(:a) # checking whether obj received :a message
@param object
@param method_name | [
"overriding",
"given",
"method",
"of",
"given",
"object",
"with",
"a",
"proxy",
"so",
"MiniSpec",
"can",
"later",
"check",
"whether",
"given",
"method",
"was",
"called",
"."
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/api/instance/mocks/mocks.rb#L87-L112 | train |
thelabtech/questionnaire | app/controllers/qe/answer_sheets_controller.rb | Qe.AnswerSheetsController.index | def index
# TODO dynamically reference this
# @answer_sheets = answer_sheet_type.find(:all, :order => 'created_at')
@answer_sheets = AnswerSheet.find(:all, :order => 'created_at')
# drop down of sheets to capture data for
@question_sheets = QuestionSheet.find(:all, :order => 'label').map {|s| [s.label, s.id]}
end | ruby | def index
# TODO dynamically reference this
# @answer_sheets = answer_sheet_type.find(:all, :order => 'created_at')
@answer_sheets = AnswerSheet.find(:all, :order => 'created_at')
# drop down of sheets to capture data for
@question_sheets = QuestionSheet.find(:all, :order => 'label').map {|s| [s.label, s.id]}
end | [
"def",
"index",
"@answer_sheets",
"=",
"AnswerSheet",
".",
"find",
"(",
":all",
",",
":order",
"=>",
"'created_at'",
")",
"@question_sheets",
"=",
"QuestionSheet",
".",
"find",
"(",
":all",
",",
":order",
"=>",
"'label'",
")",
".",
"map",
"{",
"|",
"s",
"|",
"[",
"s",
".",
"label",
",",
"s",
".",
"id",
"]",
"}",
"end"
] | list existing answer sheets | [
"list",
"existing",
"answer",
"sheets"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/controllers/qe/answer_sheets_controller.rb#L11-L19 | train |
Telestream/telestream-cloud-ruby-sdk | qc/lib/telestream_cloud_qc/api/qc_api.rb | TelestreamCloud::Qc.QcApi.create_job | def create_job(project_id, data, opts = {})
data, _status_code, _headers = create_job_with_http_info(project_id, data, opts)
return data
end | ruby | def create_job(project_id, data, opts = {})
data, _status_code, _headers = create_job_with_http_info(project_id, data, opts)
return data
end | [
"def",
"create_job",
"(",
"project_id",
",",
"data",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"create_job_with_http_info",
"(",
"project_id",
",",
"data",
",",
"opts",
")",
"return",
"data",
"end"
] | Create a new job
@param project_id A unique identifier of a Project.
@param data
@param [Hash] opts the optional parameters
@return [Job] | [
"Create",
"a",
"new",
"job"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/qc/lib/telestream_cloud_qc/api/qc_api.rb#L89-L92 | train |
Telestream/telestream-cloud-ruby-sdk | qc/lib/telestream_cloud_qc/api/qc_api.rb | TelestreamCloud::Qc.QcApi.get_job | def get_job(project_id, job_id, opts = {})
data, _status_code, _headers = get_job_with_http_info(project_id, job_id, opts)
return data
end | ruby | def get_job(project_id, job_id, opts = {})
data, _status_code, _headers = get_job_with_http_info(project_id, job_id, opts)
return data
end | [
"def",
"get_job",
"(",
"project_id",
",",
"job_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"get_job_with_http_info",
"(",
"project_id",
",",
"job_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Get QC job
@param project_id A unique identifier of a Project.
@param job_id A unique identifier of a Job.
@param [Hash] opts the optional parameters
@return [Job] | [
"Get",
"QC",
"job"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/qc/lib/telestream_cloud_qc/api/qc_api.rb#L201-L204 | train |
Telestream/telestream-cloud-ruby-sdk | qc/lib/telestream_cloud_qc/api/qc_api.rb | TelestreamCloud::Qc.QcApi.get_project | def get_project(project_id, opts = {})
data, _status_code, _headers = get_project_with_http_info(project_id, opts)
return data
end | ruby | def get_project(project_id, opts = {})
data, _status_code, _headers = get_project_with_http_info(project_id, opts)
return data
end | [
"def",
"get_project",
"(",
"project_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"get_project_with_http_info",
"(",
"project_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Get project by Id
@param project_id A unique identifier of a Project.
@param [Hash] opts the optional parameters
@return [Project] | [
"Get",
"project",
"by",
"Id"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/qc/lib/telestream_cloud_qc/api/qc_api.rb#L261-L264 | train |
Telestream/telestream-cloud-ruby-sdk | qc/lib/telestream_cloud_qc/api/qc_api.rb | TelestreamCloud::Qc.QcApi.list_jobs | def list_jobs(project_id, opts = {})
data, _status_code, _headers = list_jobs_with_http_info(project_id, opts)
return data
end | ruby | def list_jobs(project_id, opts = {})
data, _status_code, _headers = list_jobs_with_http_info(project_id, opts)
return data
end | [
"def",
"list_jobs",
"(",
"project_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"list_jobs_with_http_info",
"(",
"project_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Get jobs form projects
@param project_id A unique identifier of a Project.
@param [Hash] opts the optional parameters
@option opts [BOOLEAN] :expand Expand details of job
@option opts [String] :status Filter jobs by status
@option opts [Integer] :per_page Limit number of listed jobs (default to 30)
@option opts [Integer] :page Index of jobs page to be listed
@return [JobsCollection] | [
"Get",
"jobs",
"form",
"projects"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/qc/lib/telestream_cloud_qc/api/qc_api.rb#L320-L323 | train |
mlomnicki/automatic_foreign_key | lib/automatic_foreign_key/active_record/connection_adapters/table_definition.rb | AutomaticForeignKey::ActiveRecord::ConnectionAdapters.TableDefinition.belongs_to | def belongs_to(table, options = {})
options = options.merge(:references => table)
options[:on_delete] = options.delete(:dependent) if options.has_key?(:dependent)
column("#{table.to_s.singularize}_id".to_sym, :integer, options)
end | ruby | def belongs_to(table, options = {})
options = options.merge(:references => table)
options[:on_delete] = options.delete(:dependent) if options.has_key?(:dependent)
column("#{table.to_s.singularize}_id".to_sym, :integer, options)
end | [
"def",
"belongs_to",
"(",
"table",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"options",
".",
"merge",
"(",
":references",
"=>",
"table",
")",
"options",
"[",
":on_delete",
"]",
"=",
"options",
".",
"delete",
"(",
":dependent",
")",
"if",
"options",
".",
"has_key?",
"(",
":dependent",
")",
"column",
"(",
"\"#{table.to_s.singularize}_id\"",
".",
"to_sym",
",",
":integer",
",",
"options",
")",
"end"
] | Some people liked this; personally I've decided against using it but I'll keep it nonetheless | [
"Some",
"people",
"liked",
"this",
";",
"personally",
"I",
"ve",
"decided",
"against",
"using",
"it",
"but",
"I",
"ll",
"keep",
"it",
"nonetheless"
] | c87676f8ebca0a1326c5b5c48ae166fdefd3fd2a | https://github.com/mlomnicki/automatic_foreign_key/blob/c87676f8ebca0a1326c5b5c48ae166fdefd3fd2a/lib/automatic_foreign_key/active_record/connection_adapters/table_definition.rb#L40-L44 | train |
codefoundry/svn | lib/svn/streams.rb | Svn.Stream.read_all | def read_all
content = String.new
while bytes = read and !bytes.empty?
content << bytes
end
content
end | ruby | def read_all
content = String.new
while bytes = read and !bytes.empty?
content << bytes
end
content
end | [
"def",
"read_all",
"content",
"=",
"String",
".",
"new",
"while",
"bytes",
"=",
"read",
"and",
"!",
"bytes",
".",
"empty?",
"content",
"<<",
"bytes",
"end",
"content",
"end"
] | reads the stream contents into a String object | [
"reads",
"the",
"stream",
"contents",
"into",
"a",
"String",
"object"
] | 930a8da65fbecf3ffed50655e1cb10fcbc484be4 | https://github.com/codefoundry/svn/blob/930a8da65fbecf3ffed50655e1cb10fcbc484be4/lib/svn/streams.rb#L118-L124 | train |
codefoundry/svn | lib/svn/streams.rb | Svn.Stream.to_string_io | def to_string_io
content = StringIO.new
while bytes = read and !bytes.empty?
content.write( bytes )
end
content.rewind
content
end | ruby | def to_string_io
content = StringIO.new
while bytes = read and !bytes.empty?
content.write( bytes )
end
content.rewind
content
end | [
"def",
"to_string_io",
"content",
"=",
"StringIO",
".",
"new",
"while",
"bytes",
"=",
"read",
"and",
"!",
"bytes",
".",
"empty?",
"content",
".",
"write",
"(",
"bytes",
")",
"end",
"content",
".",
"rewind",
"content",
"end"
] | reads the stream contents into a StringIO object | [
"reads",
"the",
"stream",
"contents",
"into",
"a",
"StringIO",
"object"
] | 930a8da65fbecf3ffed50655e1cb10fcbc484be4 | https://github.com/codefoundry/svn/blob/930a8da65fbecf3ffed50655e1cb10fcbc484be4/lib/svn/streams.rb#L138-L145 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.