id
int32 0
24.9k
| repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
|
|---|---|---|---|---|---|---|---|---|---|---|---|
20,400
|
podio/podio-rb
|
lib/podio/client.rb
|
Podio.Client.authenticate_with_sso
|
def authenticate_with_sso(attributes)
response = @oauth_connection.post do |req|
req.url '/oauth/token', :grant_type => 'sso', :client_id => api_key, :client_secret => api_secret
req.body = attributes
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
[@oauth_token, response.body['new_user_created']]
end
|
ruby
|
def authenticate_with_sso(attributes)
response = @oauth_connection.post do |req|
req.url '/oauth/token', :grant_type => 'sso', :client_id => api_key, :client_secret => api_secret
req.body = attributes
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
[@oauth_token, response.body['new_user_created']]
end
|
[
"def",
"authenticate_with_sso",
"(",
"attributes",
")",
"response",
"=",
"@oauth_connection",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"'/oauth/token'",
",",
":grant_type",
"=>",
"'sso'",
",",
":client_id",
"=>",
"api_key",
",",
":client_secret",
"=>",
"api_secret",
"req",
".",
"body",
"=",
"attributes",
"end",
"@oauth_token",
"=",
"OAuthToken",
".",
"new",
"(",
"response",
".",
"body",
")",
"configure_oauth",
"[",
"@oauth_token",
",",
"response",
".",
"body",
"[",
"'new_user_created'",
"]",
"]",
"end"
] |
Sign in with SSO
|
[
"Sign",
"in",
"with",
"SSO"
] |
66137e685a494bc188ced542ae8e872d14b90a74
|
https://github.com/podio/podio-rb/blob/66137e685a494bc188ced542ae8e872d14b90a74/lib/podio/client.rb#L98-L107
|
20,401
|
podio/podio-rb
|
lib/podio/client.rb
|
Podio.Client.authenticate_with_openid
|
def authenticate_with_openid(identifier, type)
response = @trusted_connection.post do |req|
req.url '/oauth/token_by_openid'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => type, :client_id => api_key, :client_secret => api_secret, :identifier => identifier}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end
|
ruby
|
def authenticate_with_openid(identifier, type)
response = @trusted_connection.post do |req|
req.url '/oauth/token_by_openid'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => type, :client_id => api_key, :client_secret => api_secret, :identifier => identifier}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end
|
[
"def",
"authenticate_with_openid",
"(",
"identifier",
",",
"type",
")",
"response",
"=",
"@trusted_connection",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"'/oauth/token_by_openid'",
"req",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/x-www-form-urlencoded'",
"req",
".",
"body",
"=",
"{",
":grant_type",
"=>",
"type",
",",
":client_id",
"=>",
"api_key",
",",
":client_secret",
"=>",
"api_secret",
",",
":identifier",
"=>",
"identifier",
"}",
"end",
"@oauth_token",
"=",
"OAuthToken",
".",
"new",
"(",
"response",
".",
"body",
")",
"configure_oauth",
"@oauth_token",
"end"
] |
Sign in with an OpenID, only available for Podio
|
[
"Sign",
"in",
"with",
"an",
"OpenID",
"only",
"available",
"for",
"Podio"
] |
66137e685a494bc188ced542ae8e872d14b90a74
|
https://github.com/podio/podio-rb/blob/66137e685a494bc188ced542ae8e872d14b90a74/lib/podio/client.rb#L110-L120
|
20,402
|
podio/podio-rb
|
lib/podio/client.rb
|
Podio.Client.authenticate_with_activation_code
|
def authenticate_with_activation_code(activation_code)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'activation_code', :client_id => api_key, :client_secret => api_secret, :activation_code => activation_code}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end
|
ruby
|
def authenticate_with_activation_code(activation_code)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'activation_code', :client_id => api_key, :client_secret => api_secret, :activation_code => activation_code}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end
|
[
"def",
"authenticate_with_activation_code",
"(",
"activation_code",
")",
"response",
"=",
"@oauth_connection",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"'/oauth/token'",
"req",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/x-www-form-urlencoded'",
"req",
".",
"body",
"=",
"{",
":grant_type",
"=>",
"'activation_code'",
",",
":client_id",
"=>",
"api_key",
",",
":client_secret",
"=>",
"api_secret",
",",
":activation_code",
"=>",
"activation_code",
"}",
"end",
"@oauth_token",
"=",
"OAuthToken",
".",
"new",
"(",
"response",
".",
"body",
")",
"configure_oauth",
"@oauth_token",
"end"
] |
Sign in with an activation code, only available for Podio
|
[
"Sign",
"in",
"with",
"an",
"activation",
"code",
"only",
"available",
"for",
"Podio"
] |
66137e685a494bc188ced542ae8e872d14b90a74
|
https://github.com/podio/podio-rb/blob/66137e685a494bc188ced542ae8e872d14b90a74/lib/podio/client.rb#L123-L133
|
20,403
|
podio/podio-rb
|
lib/podio/client.rb
|
Podio.Client.oauth_token=
|
def oauth_token=(new_oauth_token)
@oauth_token = new_oauth_token.is_a?(Hash) ? OAuthToken.new(new_oauth_token) : new_oauth_token
configure_oauth
end
|
ruby
|
def oauth_token=(new_oauth_token)
@oauth_token = new_oauth_token.is_a?(Hash) ? OAuthToken.new(new_oauth_token) : new_oauth_token
configure_oauth
end
|
[
"def",
"oauth_token",
"=",
"(",
"new_oauth_token",
")",
"@oauth_token",
"=",
"new_oauth_token",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"OAuthToken",
".",
"new",
"(",
"new_oauth_token",
")",
":",
"new_oauth_token",
"configure_oauth",
"end"
] |
reconfigure the client with a different access token
|
[
"reconfigure",
"the",
"client",
"with",
"a",
"different",
"access",
"token"
] |
66137e685a494bc188ced542ae8e872d14b90a74
|
https://github.com/podio/podio-rb/blob/66137e685a494bc188ced542ae8e872d14b90a74/lib/podio/client.rb#L136-L139
|
20,404
|
klaxit/loc
|
lib/loc/location_collection.rb
|
Loc.LocationCollection.distance
|
def distance
return nil unless @locations.size > 1
locations.each_cons(2).reduce(0) do |acc, (loc1, loc2)|
acc + loc1.distance_to(loc2)
end
end
|
ruby
|
def distance
return nil unless @locations.size > 1
locations.each_cons(2).reduce(0) do |acc, (loc1, loc2)|
acc + loc1.distance_to(loc2)
end
end
|
[
"def",
"distance",
"return",
"nil",
"unless",
"@locations",
".",
"size",
">",
"1",
"locations",
".",
"each_cons",
"(",
"2",
")",
".",
"reduce",
"(",
"0",
")",
"do",
"|",
"acc",
",",
"(",
"loc1",
",",
"loc2",
")",
"|",
"acc",
"+",
"loc1",
".",
"distance_to",
"(",
"loc2",
")",
"end",
"end"
] |
Give the distance in meters between ordered
location points using the 'Haversine' formula
|
[
"Give",
"the",
"distance",
"in",
"meters",
"between",
"ordered",
"location",
"points",
"using",
"the",
"Haversine",
"formula"
] |
f0e5519dab8524247c6d1b38e9071072591d17ff
|
https://github.com/klaxit/loc/blob/f0e5519dab8524247c6d1b38e9071072591d17ff/lib/loc/location_collection.rb#L24-L29
|
20,405
|
olabini/codebot
|
lib/codebot/integration.rb
|
Codebot.Integration.update!
|
def update!(params)
self.name = params[:name]
self.endpoint = params[:endpoint]
self.secret = params[:secret]
self.gitlab = params[:gitlab] || false
self.shortener_url = params[:shortener_url]
self.shortener_secret = params[:shortener_secret]
set_channels params[:channels], params[:config]
end
|
ruby
|
def update!(params)
self.name = params[:name]
self.endpoint = params[:endpoint]
self.secret = params[:secret]
self.gitlab = params[:gitlab] || false
self.shortener_url = params[:shortener_url]
self.shortener_secret = params[:shortener_secret]
set_channels params[:channels], params[:config]
end
|
[
"def",
"update!",
"(",
"params",
")",
"self",
".",
"name",
"=",
"params",
"[",
":name",
"]",
"self",
".",
"endpoint",
"=",
"params",
"[",
":endpoint",
"]",
"self",
".",
"secret",
"=",
"params",
"[",
":secret",
"]",
"self",
".",
"gitlab",
"=",
"params",
"[",
":gitlab",
"]",
"||",
"false",
"self",
".",
"shortener_url",
"=",
"params",
"[",
":shortener_url",
"]",
"self",
".",
"shortener_secret",
"=",
"params",
"[",
":shortener_secret",
"]",
"set_channels",
"params",
"[",
":channels",
"]",
",",
"params",
"[",
":config",
"]",
"end"
] |
Creates a new integration from the supplied hash.
@param params [Hash] A hash with symbolic keys representing the instance
attributes of this integration. The key +:name+ is
required.
Updates the integration from the supplied hash.
@param params [Hash] A hash with symbolic keys representing the instance
attributes of this integration.
|
[
"Creates",
"a",
"new",
"integration",
"from",
"the",
"supplied",
"hash",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration.rb#L44-L52
|
20,406
|
olabini/codebot
|
lib/codebot/integration.rb
|
Codebot.Integration.add_channels!
|
def add_channels!(channels, conf)
channels.each_key do |identifier|
if @channels.any? { |chan| chan.identifier_eql?(identifier) }
raise CommandError, "channel #{identifier.inspect} already exists"
end
end
new_channels = Channel.deserialize_all(channels, conf)
@channels.push(*new_channels)
end
|
ruby
|
def add_channels!(channels, conf)
channels.each_key do |identifier|
if @channels.any? { |chan| chan.identifier_eql?(identifier) }
raise CommandError, "channel #{identifier.inspect} already exists"
end
end
new_channels = Channel.deserialize_all(channels, conf)
@channels.push(*new_channels)
end
|
[
"def",
"add_channels!",
"(",
"channels",
",",
"conf",
")",
"channels",
".",
"each_key",
"do",
"|",
"identifier",
"|",
"if",
"@channels",
".",
"any?",
"{",
"|",
"chan",
"|",
"chan",
".",
"identifier_eql?",
"(",
"identifier",
")",
"}",
"raise",
"CommandError",
",",
"\"channel #{identifier.inspect} already exists\"",
"end",
"end",
"new_channels",
"=",
"Channel",
".",
"deserialize_all",
"(",
"channels",
",",
"conf",
")",
"@channels",
".",
"push",
"(",
"new_channels",
")",
"end"
] |
Adds the specified channels to this integration.
@note This method is not thread-safe and should only be called from an
active transaction.
@param channels [Hash] the channel data to add
@param conf [Hash] the previously deserialized configuration
@raise [CommandError] if one of the channel identifiers already exists
|
[
"Adds",
"the",
"specified",
"channels",
"to",
"this",
"integration",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration.rb#L61-L69
|
20,407
|
olabini/codebot
|
lib/codebot/integration.rb
|
Codebot.Integration.delete_channels!
|
def delete_channels!(identifiers)
identifiers.each do |identifier|
channel = @channels.find { |chan| chan.identifier_eql? identifier }
if channel.nil?
raise CommandError, "channel #{identifier.inspect} does not exist"
end
@channels.delete channel
end
end
|
ruby
|
def delete_channels!(identifiers)
identifiers.each do |identifier|
channel = @channels.find { |chan| chan.identifier_eql? identifier }
if channel.nil?
raise CommandError, "channel #{identifier.inspect} does not exist"
end
@channels.delete channel
end
end
|
[
"def",
"delete_channels!",
"(",
"identifiers",
")",
"identifiers",
".",
"each",
"do",
"|",
"identifier",
"|",
"channel",
"=",
"@channels",
".",
"find",
"{",
"|",
"chan",
"|",
"chan",
".",
"identifier_eql?",
"identifier",
"}",
"if",
"channel",
".",
"nil?",
"raise",
"CommandError",
",",
"\"channel #{identifier.inspect} does not exist\"",
"end",
"@channels",
".",
"delete",
"channel",
"end",
"end"
] |
Deletes the specified channels from this integration.
@note This method is not thread-safe and should only be called from an
active transaction.
@param identifiers [Array<String>] the channel identifiers to remove
@raise [CommandError] if one of the channel identifiers does not exist
|
[
"Deletes",
"the",
"specified",
"channels",
"from",
"this",
"integration",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration.rb#L77-L86
|
20,408
|
olabini/codebot
|
lib/codebot/integration.rb
|
Codebot.Integration.set_channels
|
def set_channels(channels, conf)
if channels.nil?
@channels = [] if @channels.nil?
return
end
@channels = valid!(channels, Channel.deserialize_all(channels, conf),
:@channels,
invalid_error: 'invalid channel list %s') { [] }
end
|
ruby
|
def set_channels(channels, conf)
if channels.nil?
@channels = [] if @channels.nil?
return
end
@channels = valid!(channels, Channel.deserialize_all(channels, conf),
:@channels,
invalid_error: 'invalid channel list %s') { [] }
end
|
[
"def",
"set_channels",
"(",
"channels",
",",
"conf",
")",
"if",
"channels",
".",
"nil?",
"@channels",
"=",
"[",
"]",
"if",
"@channels",
".",
"nil?",
"return",
"end",
"@channels",
"=",
"valid!",
"(",
"channels",
",",
"Channel",
".",
"deserialize_all",
"(",
"channels",
",",
"conf",
")",
",",
":@channels",
",",
"invalid_error",
":",
"'invalid channel list %s'",
")",
"{",
"[",
"]",
"}",
"end"
] |
Sets the list of channels.
@param channels [Array<Channel>] the list of channels
@param conf [Hash] the previously deserialized configuration
|
[
"Sets",
"the",
"list",
"of",
"channels",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration.rb#L120-L128
|
20,409
|
olabini/codebot
|
lib/codebot/integration.rb
|
Codebot.Integration.serialize
|
def serialize(conf)
check_channel_networks!(conf)
[name, {
'endpoint' => endpoint,
'secret' => secret,
'gitlab' => gitlab,
'shortener_url' => shortener_url,
'shortener_secret' => shortener_secret,
'channels' => Channel.serialize_all(channels, conf)
}]
end
|
ruby
|
def serialize(conf)
check_channel_networks!(conf)
[name, {
'endpoint' => endpoint,
'secret' => secret,
'gitlab' => gitlab,
'shortener_url' => shortener_url,
'shortener_secret' => shortener_secret,
'channels' => Channel.serialize_all(channels, conf)
}]
end
|
[
"def",
"serialize",
"(",
"conf",
")",
"check_channel_networks!",
"(",
"conf",
")",
"[",
"name",
",",
"{",
"'endpoint'",
"=>",
"endpoint",
",",
"'secret'",
"=>",
"secret",
",",
"'gitlab'",
"=>",
"gitlab",
",",
"'shortener_url'",
"=>",
"shortener_url",
",",
"'shortener_secret'",
"=>",
"shortener_secret",
",",
"'channels'",
"=>",
"Channel",
".",
"serialize_all",
"(",
"channels",
",",
"conf",
")",
"}",
"]",
"end"
] |
Serializes this integration.
@param conf [Hash] the deserialized configuration
@return [Array, Hash] the serialized object
|
[
"Serializes",
"this",
"integration",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration.rb#L151-L161
|
20,410
|
olabini/codebot
|
lib/codebot/ipc_client.rb
|
Codebot.IPCClient.command
|
def command(cmd, explicit)
return false unless check_pipe_exist(explicit)
Timeout.timeout 5 do
File.open @pipe, 'w' do |p|
p.puts cmd
end
end
true
rescue Timeout::Error
communication_error! 'no response'
end
|
ruby
|
def command(cmd, explicit)
return false unless check_pipe_exist(explicit)
Timeout.timeout 5 do
File.open @pipe, 'w' do |p|
p.puts cmd
end
end
true
rescue Timeout::Error
communication_error! 'no response'
end
|
[
"def",
"command",
"(",
"cmd",
",",
"explicit",
")",
"return",
"false",
"unless",
"check_pipe_exist",
"(",
"explicit",
")",
"Timeout",
".",
"timeout",
"5",
"do",
"File",
".",
"open",
"@pipe",
",",
"'w'",
"do",
"|",
"p",
"|",
"p",
".",
"puts",
"cmd",
"end",
"end",
"true",
"rescue",
"Timeout",
"::",
"Error",
"communication_error!",
"'no response'",
"end"
] |
Sends a command to the named pipe.
@param cmd [String] the command
@param explicit [Boolean] whether this command was invoked explicitly
@return [Boolean] whether the command was sent successfully
|
[
"Sends",
"a",
"command",
"to",
"the",
"named",
"pipe",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/ipc_client.rb#L48-L59
|
20,411
|
olabini/codebot
|
lib/codebot/integration_manager.rb
|
Codebot.IntegrationManager.create
|
def create(params)
integration = Integration.new(
params.merge(config: { networks: @config.networks })
)
@config.transaction do
check_available!(integration.name, integration.endpoint)
NetworkManager.new(@config).check_channels!(integration)
@config.integrations << integration
integration_feedback(integration, :created) unless params[:quiet]
end
end
|
ruby
|
def create(params)
integration = Integration.new(
params.merge(config: { networks: @config.networks })
)
@config.transaction do
check_available!(integration.name, integration.endpoint)
NetworkManager.new(@config).check_channels!(integration)
@config.integrations << integration
integration_feedback(integration, :created) unless params[:quiet]
end
end
|
[
"def",
"create",
"(",
"params",
")",
"integration",
"=",
"Integration",
".",
"new",
"(",
"params",
".",
"merge",
"(",
"config",
":",
"{",
"networks",
":",
"@config",
".",
"networks",
"}",
")",
")",
"@config",
".",
"transaction",
"do",
"check_available!",
"(",
"integration",
".",
"name",
",",
"integration",
".",
"endpoint",
")",
"NetworkManager",
".",
"new",
"(",
"@config",
")",
".",
"check_channels!",
"(",
"integration",
")",
"@config",
".",
"integrations",
"<<",
"integration",
"integration_feedback",
"(",
"integration",
",",
":created",
")",
"unless",
"params",
"[",
":quiet",
"]",
"end",
"end"
] |
Constructs a new integration manager for a specified configuration.
@param config [Config] the configuration to manage
Creates a new integration from the given parameters.
@param params [Hash] the parameters to initialize the integration with
|
[
"Constructs",
"a",
"new",
"integration",
"manager",
"for",
"a",
"specified",
"configuration",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration_manager.rb#L22-L32
|
20,412
|
olabini/codebot
|
lib/codebot/integration_manager.rb
|
Codebot.IntegrationManager.update
|
def update(name, params)
@config.transaction do
integration = find_integration!(name)
check_available_except!(params[:name], params[:endpoint], integration)
update_channels!(integration, params)
NetworkManager.new(@config).check_channels!(integration)
integration.update!(params)
integration_feedback(integration, :updated) unless params[:quiet]
end
end
|
ruby
|
def update(name, params)
@config.transaction do
integration = find_integration!(name)
check_available_except!(params[:name], params[:endpoint], integration)
update_channels!(integration, params)
NetworkManager.new(@config).check_channels!(integration)
integration.update!(params)
integration_feedback(integration, :updated) unless params[:quiet]
end
end
|
[
"def",
"update",
"(",
"name",
",",
"params",
")",
"@config",
".",
"transaction",
"do",
"integration",
"=",
"find_integration!",
"(",
"name",
")",
"check_available_except!",
"(",
"params",
"[",
":name",
"]",
",",
"params",
"[",
":endpoint",
"]",
",",
"integration",
")",
"update_channels!",
"(",
"integration",
",",
"params",
")",
"NetworkManager",
".",
"new",
"(",
"@config",
")",
".",
"check_channels!",
"(",
"integration",
")",
"integration",
".",
"update!",
"(",
"params",
")",
"integration_feedback",
"(",
"integration",
",",
":updated",
")",
"unless",
"params",
"[",
":quiet",
"]",
"end",
"end"
] |
Updates an integration with the given parameters.
@param name [String] the current name of the integration to update
@param params [Hash] the parameters to update the integration with
|
[
"Updates",
"an",
"integration",
"with",
"the",
"given",
"parameters",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration_manager.rb#L38-L47
|
20,413
|
olabini/codebot
|
lib/codebot/integration_manager.rb
|
Codebot.IntegrationManager.destroy
|
def destroy(name, params)
@config.transaction do
integration = find_integration!(name)
@config.integrations.delete integration
integration_feedback(integration, :destroyed) unless params[:quiet]
end
end
|
ruby
|
def destroy(name, params)
@config.transaction do
integration = find_integration!(name)
@config.integrations.delete integration
integration_feedback(integration, :destroyed) unless params[:quiet]
end
end
|
[
"def",
"destroy",
"(",
"name",
",",
"params",
")",
"@config",
".",
"transaction",
"do",
"integration",
"=",
"find_integration!",
"(",
"name",
")",
"@config",
".",
"integrations",
".",
"delete",
"integration",
"integration_feedback",
"(",
"integration",
",",
":destroyed",
")",
"unless",
"params",
"[",
":quiet",
"]",
"end",
"end"
] |
Destroys an integration.
@param name [String] the name of the integration to destroy
@param params [Hash] the command-line options
|
[
"Destroys",
"an",
"integration",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration_manager.rb#L53-L59
|
20,414
|
olabini/codebot
|
lib/codebot/integration_manager.rb
|
Codebot.IntegrationManager.list
|
def list(search)
@config.transaction do
integrations = @config.integrations.dup
unless search.nil?
integrations.select! do |intg|
intg.name.downcase.include? search.downcase
end
end
puts 'No integrations found' if integrations.empty?
integrations.each { |intg| show_integration intg }
end
end
|
ruby
|
def list(search)
@config.transaction do
integrations = @config.integrations.dup
unless search.nil?
integrations.select! do |intg|
intg.name.downcase.include? search.downcase
end
end
puts 'No integrations found' if integrations.empty?
integrations.each { |intg| show_integration intg }
end
end
|
[
"def",
"list",
"(",
"search",
")",
"@config",
".",
"transaction",
"do",
"integrations",
"=",
"@config",
".",
"integrations",
".",
"dup",
"unless",
"search",
".",
"nil?",
"integrations",
".",
"select!",
"do",
"|",
"intg",
"|",
"intg",
".",
"name",
".",
"downcase",
".",
"include?",
"search",
".",
"downcase",
"end",
"end",
"puts",
"'No integrations found'",
"if",
"integrations",
".",
"empty?",
"integrations",
".",
"each",
"{",
"|",
"intg",
"|",
"show_integration",
"intg",
"}",
"end",
"end"
] |
Lists all integrations, or integrations with names containing the given
search term.
@param search [String, nil] an optional search term
|
[
"Lists",
"all",
"integrations",
"or",
"integrations",
"with",
"names",
"containing",
"the",
"given",
"search",
"term",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration_manager.rb#L65-L76
|
20,415
|
olabini/codebot
|
lib/codebot/integration_manager.rb
|
Codebot.IntegrationManager.find_integration!
|
def find_integration!(name)
integration = find_integration(name)
return integration unless integration.nil?
raise CommandError, "an integration with the name #{name.inspect} " \
'does not exist'
end
|
ruby
|
def find_integration!(name)
integration = find_integration(name)
return integration unless integration.nil?
raise CommandError, "an integration with the name #{name.inspect} " \
'does not exist'
end
|
[
"def",
"find_integration!",
"(",
"name",
")",
"integration",
"=",
"find_integration",
"(",
"name",
")",
"return",
"integration",
"unless",
"integration",
".",
"nil?",
"raise",
"CommandError",
",",
"\"an integration with the name #{name.inspect} \"",
"'does not exist'",
"end"
] |
Finds an integration given its name.
@param name [String] the name to search for
@raise [CommandError] if no integration with the given name exists
@return [Integration] the integration
|
[
"Finds",
"an",
"integration",
"given",
"its",
"name",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration_manager.rb#L99-L105
|
20,416
|
olabini/codebot
|
lib/codebot/integration_manager.rb
|
Codebot.IntegrationManager.check_available!
|
def check_available!(name, endpoint)
check_name_available!(name) unless name.nil?
check_endpoint_available!(endpoint) unless endpoint.nil?
end
|
ruby
|
def check_available!(name, endpoint)
check_name_available!(name) unless name.nil?
check_endpoint_available!(endpoint) unless endpoint.nil?
end
|
[
"def",
"check_available!",
"(",
"name",
",",
"endpoint",
")",
"check_name_available!",
"(",
"name",
")",
"unless",
"name",
".",
"nil?",
"check_endpoint_available!",
"(",
"endpoint",
")",
"unless",
"endpoint",
".",
"nil?",
"end"
] |
Checks that the specified name and endpoint are available for use.
@param name [String] the name to check for
@param endpoint [String] the endpoint to check for
@raise [CommandError] if name or endpoint are already taken
|
[
"Checks",
"that",
"the",
"specified",
"name",
"and",
"endpoint",
"are",
"available",
"for",
"use",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration_manager.rb#L136-L139
|
20,417
|
olabini/codebot
|
lib/codebot/integration_manager.rb
|
Codebot.IntegrationManager.check_available_except!
|
def check_available_except!(name, endpoint, intg)
check_name_available!(name) unless name.nil? || intg.name_eql?(name)
return if endpoint.nil? || intg.endpoint_eql?(endpoint)
check_endpoint_available!(endpoint)
end
|
ruby
|
def check_available_except!(name, endpoint, intg)
check_name_available!(name) unless name.nil? || intg.name_eql?(name)
return if endpoint.nil? || intg.endpoint_eql?(endpoint)
check_endpoint_available!(endpoint)
end
|
[
"def",
"check_available_except!",
"(",
"name",
",",
"endpoint",
",",
"intg",
")",
"check_name_available!",
"(",
"name",
")",
"unless",
"name",
".",
"nil?",
"||",
"intg",
".",
"name_eql?",
"(",
"name",
")",
"return",
"if",
"endpoint",
".",
"nil?",
"||",
"intg",
".",
"endpoint_eql?",
"(",
"endpoint",
")",
"check_endpoint_available!",
"(",
"endpoint",
")",
"end"
] |
Checks that the specified name and endpoint are available for use by the
specified integration.
@param name [String] the name to check for
@param endpoint [String] the endpoint to check for
@param intg [Integration] the integration to ignore
@raise [CommandError] if name or endpoint are already taken
|
[
"Checks",
"that",
"the",
"specified",
"name",
"and",
"endpoint",
"are",
"available",
"for",
"use",
"by",
"the",
"specified",
"integration",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration_manager.rb#L148-L153
|
20,418
|
olabini/codebot
|
lib/codebot/integration_manager.rb
|
Codebot.IntegrationManager.update_channels!
|
def update_channels!(integration, params)
integration.channels.clear if params[:clear_channels]
if params[:delete_channel]
integration.delete_channels!(params[:delete_channel])
end
return unless params[:add_channel]
integration.add_channels!(params[:add_channel],
networks: @config.networks)
end
|
ruby
|
def update_channels!(integration, params)
integration.channels.clear if params[:clear_channels]
if params[:delete_channel]
integration.delete_channels!(params[:delete_channel])
end
return unless params[:add_channel]
integration.add_channels!(params[:add_channel],
networks: @config.networks)
end
|
[
"def",
"update_channels!",
"(",
"integration",
",",
"params",
")",
"integration",
".",
"channels",
".",
"clear",
"if",
"params",
"[",
":clear_channels",
"]",
"if",
"params",
"[",
":delete_channel",
"]",
"integration",
".",
"delete_channels!",
"(",
"params",
"[",
":delete_channel",
"]",
")",
"end",
"return",
"unless",
"params",
"[",
":add_channel",
"]",
"integration",
".",
"add_channels!",
"(",
"params",
"[",
":add_channel",
"]",
",",
"networks",
":",
"@config",
".",
"networks",
")",
"end"
] |
Updates the channels associated with an integration from the specified
parameters.
@param integration [Integration] the integration
@param params [Hash] the parameters to update the integration with. Valid
keys are +:clear_channels+ to clear the channel list
before proceeding, +:add_channel+ to add the given
channels, and +:delete_channel+ to delete the given
channels from the integration. All keys are optional.
The value of +:clear_channels+ should be a boolean.
The value of +:add_channel+ should be a hash of the
form +identifier => params+, and +:remove_channel+
should be an array of channel identifiers to remove.
|
[
"Updates",
"the",
"channels",
"associated",
"with",
"an",
"integration",
"from",
"the",
"specified",
"parameters",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration_manager.rb#L168-L177
|
20,419
|
olabini/codebot
|
lib/codebot/integration_manager.rb
|
Codebot.IntegrationManager.show_integration
|
def show_integration(integration)
puts "Integration: #{integration.name}"
puts "\tEndpoint: #{integration.endpoint}"
puts "\tSecret: #{show_integration_secret(integration)}"
if integration.channels.empty?
puts "\tChannels: (none)"
else
puts "\tChannels:"
show_integration_channels(integration)
end
end
|
ruby
|
def show_integration(integration)
puts "Integration: #{integration.name}"
puts "\tEndpoint: #{integration.endpoint}"
puts "\tSecret: #{show_integration_secret(integration)}"
if integration.channels.empty?
puts "\tChannels: (none)"
else
puts "\tChannels:"
show_integration_channels(integration)
end
end
|
[
"def",
"show_integration",
"(",
"integration",
")",
"puts",
"\"Integration: #{integration.name}\"",
"puts",
"\"\\tEndpoint: #{integration.endpoint}\"",
"puts",
"\"\\tSecret: #{show_integration_secret(integration)}\"",
"if",
"integration",
".",
"channels",
".",
"empty?",
"puts",
"\"\\tChannels: (none)\"",
"else",
"puts",
"\"\\tChannels:\"",
"show_integration_channels",
"(",
"integration",
")",
"end",
"end"
] |
Prints information about an integration.
@param integration [Integration] the integration
|
[
"Prints",
"information",
"about",
"an",
"integration",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration_manager.rb#L191-L201
|
20,420
|
olabini/codebot
|
lib/codebot/integration_manager.rb
|
Codebot.IntegrationManager.show_integration_channels
|
def show_integration_channels(integration)
integration.channels.each do |channel|
puts "\t\t- #{channel.name} on #{channel.network.name}"
puts "\t\t\tKey: #{channel.key}" if channel.key?
puts "\t\t\tMessages are sent without joining" if channel.send_external
end
end
|
ruby
|
def show_integration_channels(integration)
integration.channels.each do |channel|
puts "\t\t- #{channel.name} on #{channel.network.name}"
puts "\t\t\tKey: #{channel.key}" if channel.key?
puts "\t\t\tMessages are sent without joining" if channel.send_external
end
end
|
[
"def",
"show_integration_channels",
"(",
"integration",
")",
"integration",
".",
"channels",
".",
"each",
"do",
"|",
"channel",
"|",
"puts",
"\"\\t\\t- #{channel.name} on #{channel.network.name}\"",
"puts",
"\"\\t\\t\\tKey: #{channel.key}\"",
"if",
"channel",
".",
"key?",
"puts",
"\"\\t\\t\\tMessages are sent without joining\"",
"if",
"channel",
".",
"send_external",
"end",
"end"
] |
Prints information about the channels associated with an integration.
@param integration [Integration] the integration
|
[
"Prints",
"information",
"about",
"the",
"channels",
"associated",
"with",
"an",
"integration",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/integration_manager.rb#L217-L223
|
20,421
|
olabini/codebot
|
lib/codebot/network_manager.rb
|
Codebot.NetworkManager.create
|
def create(params)
network = Network.new(params.merge(config: {}))
@config.transaction do
check_name_available!(network.name)
@config.networks << network
network_feedback(network, :created) unless params[:quiet]
end
end
|
ruby
|
def create(params)
network = Network.new(params.merge(config: {}))
@config.transaction do
check_name_available!(network.name)
@config.networks << network
network_feedback(network, :created) unless params[:quiet]
end
end
|
[
"def",
"create",
"(",
"params",
")",
"network",
"=",
"Network",
".",
"new",
"(",
"params",
".",
"merge",
"(",
"config",
":",
"{",
"}",
")",
")",
"@config",
".",
"transaction",
"do",
"check_name_available!",
"(",
"network",
".",
"name",
")",
"@config",
".",
"networks",
"<<",
"network",
"network_feedback",
"(",
"network",
",",
":created",
")",
"unless",
"params",
"[",
":quiet",
"]",
"end",
"end"
] |
Constructs a new network manager for a specified configuration.
@param config [Config] the configuration to manage
Creates a new network from the given parameters.
@param params [Hash] the parameters to initialize the network with
|
[
"Constructs",
"a",
"new",
"network",
"manager",
"for",
"a",
"specified",
"configuration",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network_manager.rb#L21-L28
|
20,422
|
olabini/codebot
|
lib/codebot/network_manager.rb
|
Codebot.NetworkManager.update
|
def update(name, params)
@config.transaction do
network = find_network!(name)
unless params[:name].nil?
check_name_available_except!(params[:name], network)
end
network.update!(params)
network_feedback(network, :updated) unless params[:quiet]
end
end
|
ruby
|
def update(name, params)
@config.transaction do
network = find_network!(name)
unless params[:name].nil?
check_name_available_except!(params[:name], network)
end
network.update!(params)
network_feedback(network, :updated) unless params[:quiet]
end
end
|
[
"def",
"update",
"(",
"name",
",",
"params",
")",
"@config",
".",
"transaction",
"do",
"network",
"=",
"find_network!",
"(",
"name",
")",
"unless",
"params",
"[",
":name",
"]",
".",
"nil?",
"check_name_available_except!",
"(",
"params",
"[",
":name",
"]",
",",
"network",
")",
"end",
"network",
".",
"update!",
"(",
"params",
")",
"network_feedback",
"(",
"network",
",",
":updated",
")",
"unless",
"params",
"[",
":quiet",
"]",
"end",
"end"
] |
Updates a network with the given parameters.
@param name [String] the current name of the network to update
@param params [Hash] the parameters to update the network with
|
[
"Updates",
"a",
"network",
"with",
"the",
"given",
"parameters",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network_manager.rb#L34-L43
|
20,423
|
olabini/codebot
|
lib/codebot/network_manager.rb
|
Codebot.NetworkManager.destroy
|
def destroy(name, params)
@config.transaction do
network = find_network!(name)
@config.networks.delete network
network_feedback(network, :destroyed) unless params[:quiet]
end
end
|
ruby
|
def destroy(name, params)
@config.transaction do
network = find_network!(name)
@config.networks.delete network
network_feedback(network, :destroyed) unless params[:quiet]
end
end
|
[
"def",
"destroy",
"(",
"name",
",",
"params",
")",
"@config",
".",
"transaction",
"do",
"network",
"=",
"find_network!",
"(",
"name",
")",
"@config",
".",
"networks",
".",
"delete",
"network",
"network_feedback",
"(",
"network",
",",
":destroyed",
")",
"unless",
"params",
"[",
":quiet",
"]",
"end",
"end"
] |
Destroys a network.
@param name [String] the name of the network to destroy
@param params [Hash] the command-line options
|
[
"Destroys",
"a",
"network",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network_manager.rb#L49-L55
|
20,424
|
olabini/codebot
|
lib/codebot/network_manager.rb
|
Codebot.NetworkManager.list
|
def list(search)
@config.transaction do
networks = @config.networks.dup
unless search.nil?
networks.select! { |net| net.name.downcase.include? search.downcase }
end
puts 'No networks found' if networks.empty?
networks.each { |net| show_network net }
end
end
|
ruby
|
def list(search)
@config.transaction do
networks = @config.networks.dup
unless search.nil?
networks.select! { |net| net.name.downcase.include? search.downcase }
end
puts 'No networks found' if networks.empty?
networks.each { |net| show_network net }
end
end
|
[
"def",
"list",
"(",
"search",
")",
"@config",
".",
"transaction",
"do",
"networks",
"=",
"@config",
".",
"networks",
".",
"dup",
"unless",
"search",
".",
"nil?",
"networks",
".",
"select!",
"{",
"|",
"net",
"|",
"net",
".",
"name",
".",
"downcase",
".",
"include?",
"search",
".",
"downcase",
"}",
"end",
"puts",
"'No networks found'",
"if",
"networks",
".",
"empty?",
"networks",
".",
"each",
"{",
"|",
"net",
"|",
"show_network",
"net",
"}",
"end",
"end"
] |
Lists all networks, or networks with names containing the given search
term.
@param search [String, nil] an optional search term
|
[
"Lists",
"all",
"networks",
"or",
"networks",
"with",
"names",
"containing",
"the",
"given",
"search",
"term",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network_manager.rb#L61-L70
|
20,425
|
olabini/codebot
|
lib/codebot/network_manager.rb
|
Codebot.NetworkManager.find_network!
|
def find_network!(name)
network = find_network(name)
return network unless network.nil?
raise CommandError, "a network with the name #{name.inspect} " \
'does not exist'
end
|
ruby
|
def find_network!(name)
network = find_network(name)
return network unless network.nil?
raise CommandError, "a network with the name #{name.inspect} " \
'does not exist'
end
|
[
"def",
"find_network!",
"(",
"name",
")",
"network",
"=",
"find_network",
"(",
"name",
")",
"return",
"network",
"unless",
"network",
".",
"nil?",
"raise",
"CommandError",
",",
"\"a network with the name #{name.inspect} \"",
"'does not exist'",
"end"
] |
Finds a network given its name.
@param name [String] the name to search for
@raise [CommandError] if no network with the given name exists
@return [Network] the network
|
[
"Finds",
"a",
"network",
"given",
"its",
"name",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network_manager.rb#L85-L91
|
20,426
|
olabini/codebot
|
lib/codebot/network_manager.rb
|
Codebot.NetworkManager.check_channels!
|
def check_channels!(integration)
integration.channels.map(&:network).map(&:name).each do |network|
find_network!(network)
end
end
|
ruby
|
def check_channels!(integration)
integration.channels.map(&:network).map(&:name).each do |network|
find_network!(network)
end
end
|
[
"def",
"check_channels!",
"(",
"integration",
")",
"integration",
".",
"channels",
".",
"map",
"(",
":network",
")",
".",
"map",
"(",
":name",
")",
".",
"each",
"do",
"|",
"network",
"|",
"find_network!",
"(",
"network",
")",
"end",
"end"
] |
Checks that all channels associated with an integration belong to a valid
network.
@param integration [Integration] the integration to check
|
[
"Checks",
"that",
"all",
"channels",
"associated",
"with",
"an",
"integration",
"belong",
"to",
"a",
"valid",
"network",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network_manager.rb#L97-L101
|
20,427
|
olabini/codebot
|
lib/codebot/network_manager.rb
|
Codebot.NetworkManager.check_name_available_except!
|
def check_name_available_except!(name, network)
return if name.nil? || network.name_eql?(name) || !find_network(name)
raise CommandError, "a network with the name #{name.inspect} " \
'already exists'
end
|
ruby
|
def check_name_available_except!(name, network)
return if name.nil? || network.name_eql?(name) || !find_network(name)
raise CommandError, "a network with the name #{name.inspect} " \
'already exists'
end
|
[
"def",
"check_name_available_except!",
"(",
"name",
",",
"network",
")",
"return",
"if",
"name",
".",
"nil?",
"||",
"network",
".",
"name_eql?",
"(",
"name",
")",
"||",
"!",
"find_network",
"(",
"name",
")",
"raise",
"CommandError",
",",
"\"a network with the name #{name.inspect} \"",
"'already exists'",
"end"
] |
Checks that the specified name is available for use by the specified
network.
@param name [String] the name to check for
@param network [Network] the network to ignore
@raise [CommandError] if the name is already taken
|
[
"Checks",
"that",
"the",
"specified",
"name",
"is",
"available",
"for",
"use",
"by",
"the",
"specified",
"network",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network_manager.rb#L122-L127
|
20,428
|
olabini/codebot
|
lib/codebot/network_manager.rb
|
Codebot.NetworkManager.show_network
|
def show_network(network) # rubocop:disable Metrics/AbcSize
puts "Network: #{network.name}"
security = "#{network.secure ? 'secure' : 'insecure'} connection"
password = network.server_password
puts "\tServer: #{network.host}:#{network.real_port} (#{security})"
puts "\tPassword: #{'*' * password.length}" unless password.to_s.empty?
puts "\tNickname: #{network.nick}"
puts "\tBind to: #{network.bind}" unless network.bind.to_s.empty?
puts "\tUser modes: #{network.modes}" unless network.modes.to_s.empty?
show_network_sasl(network)
show_network_nickserv(network)
end
|
ruby
|
def show_network(network) # rubocop:disable Metrics/AbcSize
puts "Network: #{network.name}"
security = "#{network.secure ? 'secure' : 'insecure'} connection"
password = network.server_password
puts "\tServer: #{network.host}:#{network.real_port} (#{security})"
puts "\tPassword: #{'*' * password.length}" unless password.to_s.empty?
puts "\tNickname: #{network.nick}"
puts "\tBind to: #{network.bind}" unless network.bind.to_s.empty?
puts "\tUser modes: #{network.modes}" unless network.modes.to_s.empty?
show_network_sasl(network)
show_network_nickserv(network)
end
|
[
"def",
"show_network",
"(",
"network",
")",
"# rubocop:disable Metrics/AbcSize",
"puts",
"\"Network: #{network.name}\"",
"security",
"=",
"\"#{network.secure ? 'secure' : 'insecure'} connection\"",
"password",
"=",
"network",
".",
"server_password",
"puts",
"\"\\tServer: #{network.host}:#{network.real_port} (#{security})\"",
"puts",
"\"\\tPassword: #{'*' * password.length}\"",
"unless",
"password",
".",
"to_s",
".",
"empty?",
"puts",
"\"\\tNickname: #{network.nick}\"",
"puts",
"\"\\tBind to: #{network.bind}\"",
"unless",
"network",
".",
"bind",
".",
"to_s",
".",
"empty?",
"puts",
"\"\\tUser modes: #{network.modes}\"",
"unless",
"network",
".",
"modes",
".",
"to_s",
".",
"empty?",
"show_network_sasl",
"(",
"network",
")",
"show_network_nickserv",
"(",
"network",
")",
"end"
] |
Prints information about a network.
@param network [Network] the network
|
[
"Prints",
"information",
"about",
"a",
"network",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network_manager.rb#L141-L152
|
20,429
|
olabini/codebot
|
lib/codebot/core.rb
|
Codebot.Core.join
|
def join
ipc = Thread.new { @ipc_server.join && stop }
web = Thread.new { @web_server.join && stop }
ipc.join
web.join
@irc_client.join
end
|
ruby
|
def join
ipc = Thread.new { @ipc_server.join && stop }
web = Thread.new { @web_server.join && stop }
ipc.join
web.join
@irc_client.join
end
|
[
"def",
"join",
"ipc",
"=",
"Thread",
".",
"new",
"{",
"@ipc_server",
".",
"join",
"&&",
"stop",
"}",
"web",
"=",
"Thread",
".",
"new",
"{",
"@web_server",
".",
"join",
"&&",
"stop",
"}",
"ipc",
".",
"join",
"web",
".",
"join",
"@irc_client",
".",
"join",
"end"
] |
Waits for this bot to stop. If any of the managed threads finish early,
the bot is shut down immediately.
|
[
"Waits",
"for",
"this",
"bot",
"to",
"stop",
".",
"If",
"any",
"of",
"the",
"managed",
"threads",
"finish",
"early",
"the",
"bot",
"is",
"shut",
"down",
"immediately",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/core.rb#L51-L57
|
20,430
|
olabini/codebot
|
lib/codebot/core.rb
|
Codebot.Core.trap_signals
|
def trap_signals
shutdown = proc do |signal|
STDERR.puts "\nReceived #{signal}, shutting down..."
stop
join
exit 1
end
trap('INT') { shutdown.call 'SIGINT' }
trap('TERM') { shutdown.call 'SIGTERM' }
end
|
ruby
|
def trap_signals
shutdown = proc do |signal|
STDERR.puts "\nReceived #{signal}, shutting down..."
stop
join
exit 1
end
trap('INT') { shutdown.call 'SIGINT' }
trap('TERM') { shutdown.call 'SIGTERM' }
end
|
[
"def",
"trap_signals",
"shutdown",
"=",
"proc",
"do",
"|",
"signal",
"|",
"STDERR",
".",
"puts",
"\"\\nReceived #{signal}, shutting down...\"",
"stop",
"join",
"exit",
"1",
"end",
"trap",
"(",
"'INT'",
")",
"{",
"shutdown",
".",
"call",
"'SIGINT'",
"}",
"trap",
"(",
"'TERM'",
")",
"{",
"shutdown",
".",
"call",
"'SIGTERM'",
"}",
"end"
] |
Sets traps for SIGINT and SIGTERM so Codebot can shut down gracefully.
|
[
"Sets",
"traps",
"for",
"SIGINT",
"and",
"SIGTERM",
"so",
"Codebot",
"can",
"shut",
"down",
"gracefully",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/core.rb#L65-L74
|
20,431
|
olabini/codebot
|
lib/codebot/web_server.rb
|
Codebot.WebServer.create_server
|
def create_server
core = @core
Sinatra.new do
include WebListener
configure { instance_eval(&WebServer.configuration) }
post('/*') { handle_post(core, request, params) }
error(Sinatra::NotFound) { [405, 'Method not allowed'] }
end
end
|
ruby
|
def create_server
core = @core
Sinatra.new do
include WebListener
configure { instance_eval(&WebServer.configuration) }
post('/*') { handle_post(core, request, params) }
error(Sinatra::NotFound) { [405, 'Method not allowed'] }
end
end
|
[
"def",
"create_server",
"core",
"=",
"@core",
"Sinatra",
".",
"new",
"do",
"include",
"WebListener",
"configure",
"{",
"instance_eval",
"(",
"WebServer",
".",
"configuration",
")",
"}",
"post",
"(",
"'/*'",
")",
"{",
"handle_post",
"(",
"core",
",",
"request",
",",
"params",
")",
"}",
"error",
"(",
"Sinatra",
"::",
"NotFound",
")",
"{",
"[",
"405",
",",
"'Method not allowed'",
"]",
"}",
"end",
"end"
] |
Creates a new Sinatra server for handling incoming requests.
@return [Class] the created server
|
[
"Creates",
"a",
"new",
"Sinatra",
"server",
"for",
"handling",
"incoming",
"requests",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/web_server.rb#L47-L56
|
20,432
|
olabini/codebot
|
lib/codebot/web_listener.rb
|
Codebot.WebListener.handle_post
|
def handle_post(core, request, params)
payload = params['payload'] || request.body.read
dispatch(core, request, *params['splat'], payload)
rescue JSON::ParserError
[400, 'Invalid JSON payload']
end
|
ruby
|
def handle_post(core, request, params)
payload = params['payload'] || request.body.read
dispatch(core, request, *params['splat'], payload)
rescue JSON::ParserError
[400, 'Invalid JSON payload']
end
|
[
"def",
"handle_post",
"(",
"core",
",",
"request",
",",
"params",
")",
"payload",
"=",
"params",
"[",
"'payload'",
"]",
"||",
"request",
".",
"body",
".",
"read",
"dispatch",
"(",
"core",
",",
"request",
",",
"params",
"[",
"'splat'",
"]",
",",
"payload",
")",
"rescue",
"JSON",
"::",
"ParserError",
"[",
"400",
",",
"'Invalid JSON payload'",
"]",
"end"
] |
Handles a POST request.
@param core [Core] the bot to dispatch requests to
@param request [Sinatra::Request] the request to handle
@param params [Hash] the request parameters
|
[
"Handles",
"a",
"POST",
"request",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/web_listener.rb#L17-L22
|
20,433
|
olabini/codebot
|
lib/codebot/web_listener.rb
|
Codebot.WebListener.dispatch
|
def dispatch(core, request, endpoint, payload)
intg = integration_for(core.config, endpoint)
return [404, 'Endpoint not registered'] if intg.nil?
return [403, 'Invalid signature'] unless valid?(request, intg, payload)
req = create_request(intg, request, payload)
return req if req.is_a? Array
core.irc_client.dispatch(req)
[202, 'Accepted']
end
|
ruby
|
def dispatch(core, request, endpoint, payload)
intg = integration_for(core.config, endpoint)
return [404, 'Endpoint not registered'] if intg.nil?
return [403, 'Invalid signature'] unless valid?(request, intg, payload)
req = create_request(intg, request, payload)
return req if req.is_a? Array
core.irc_client.dispatch(req)
[202, 'Accepted']
end
|
[
"def",
"dispatch",
"(",
"core",
",",
"request",
",",
"endpoint",
",",
"payload",
")",
"intg",
"=",
"integration_for",
"(",
"core",
".",
"config",
",",
"endpoint",
")",
"return",
"[",
"404",
",",
"'Endpoint not registered'",
"]",
"if",
"intg",
".",
"nil?",
"return",
"[",
"403",
",",
"'Invalid signature'",
"]",
"unless",
"valid?",
"(",
"request",
",",
"intg",
",",
"payload",
")",
"req",
"=",
"create_request",
"(",
"intg",
",",
"request",
",",
"payload",
")",
"return",
"req",
"if",
"req",
".",
"is_a?",
"Array",
"core",
".",
"irc_client",
".",
"dispatch",
"(",
"req",
")",
"[",
"202",
",",
"'Accepted'",
"]",
"end"
] |
Dispatches a received payload to the IRC client.
@param core [Core] the bot to dispatch this request to
@param request [Sinatra::Request] the request received by the web server
@param endpoint [String] the endpoint at which the request was received
@param payload [String] the payload that was sent to the endpoint
@return [Array<Integer, String>] HTTP status code and response
|
[
"Dispatches",
"a",
"received",
"payload",
"to",
"the",
"IRC",
"client",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/web_listener.rb#L39-L49
|
20,434
|
olabini/codebot
|
lib/codebot/web_listener.rb
|
Codebot.WebListener.create_request
|
def create_request(integration, request, payload)
event = if integration.gitlab
create_gitlab_event(request)
else
create_github_event(request)
end
return event if event.is_a? Array
return [501, 'Event not yet supported'] if event.nil?
Request.new(integration, event, payload)
end
|
ruby
|
def create_request(integration, request, payload)
event = if integration.gitlab
create_gitlab_event(request)
else
create_github_event(request)
end
return event if event.is_a? Array
return [501, 'Event not yet supported'] if event.nil?
Request.new(integration, event, payload)
end
|
[
"def",
"create_request",
"(",
"integration",
",",
"request",
",",
"payload",
")",
"event",
"=",
"if",
"integration",
".",
"gitlab",
"create_gitlab_event",
"(",
"request",
")",
"else",
"create_github_event",
"(",
"request",
")",
"end",
"return",
"event",
"if",
"event",
".",
"is_a?",
"Array",
"return",
"[",
"501",
",",
"'Event not yet supported'",
"]",
"if",
"event",
".",
"nil?",
"Request",
".",
"new",
"(",
"integration",
",",
"event",
",",
"payload",
")",
"end"
] |
Creates a new request for the webhook.
@param integration [Integration] the integration for which the request
was made
@param request [Sinatra::Request] the request received by the web server
@param payload [String] the payload that was sent to the endpoint
@return [Request, Array<Integer, String>] the created request, or an
array containing HTTP status
code and response if the
request was invalid
|
[
"Creates",
"a",
"new",
"request",
"for",
"the",
"webhook",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/web_listener.rb#L75-L86
|
20,435
|
olabini/codebot
|
lib/codebot/web_listener.rb
|
Codebot.WebListener.valid?
|
def valid?(request, integration, payload)
return true unless integration.verify_payloads?
secret = integration.secret
if integration.gitlab
secret == request.env['HTTP_X_GITLAB_TOKEN']
else
request_signature = request.env['HTTP_X_HUB_SIGNATURE']
Cryptography.valid_signature?(payload, secret, request_signature)
end
end
|
ruby
|
def valid?(request, integration, payload)
return true unless integration.verify_payloads?
secret = integration.secret
if integration.gitlab
secret == request.env['HTTP_X_GITLAB_TOKEN']
else
request_signature = request.env['HTTP_X_HUB_SIGNATURE']
Cryptography.valid_signature?(payload, secret, request_signature)
end
end
|
[
"def",
"valid?",
"(",
"request",
",",
"integration",
",",
"payload",
")",
"return",
"true",
"unless",
"integration",
".",
"verify_payloads?",
"secret",
"=",
"integration",
".",
"secret",
"if",
"integration",
".",
"gitlab",
"secret",
"==",
"request",
".",
"env",
"[",
"'HTTP_X_GITLAB_TOKEN'",
"]",
"else",
"request_signature",
"=",
"request",
".",
"env",
"[",
"'HTTP_X_HUB_SIGNATURE'",
"]",
"Cryptography",
".",
"valid_signature?",
"(",
"payload",
",",
"secret",
",",
"request_signature",
")",
"end",
"end"
] |
Verifies a webhook signature.
@param request [Sinatra::Request] the request received by the web server
@param integration [Integration] the integration for which the request
was made
@param payload [String] the payload that was sent to the endpoint
@return [Boolean] whether the signature is valid
|
[
"Verifies",
"a",
"webhook",
"signature",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/web_listener.rb#L95-L105
|
20,436
|
olabini/codebot
|
lib/codebot/irc_client.rb
|
Codebot.IRCClient.dispatch
|
def dispatch(request)
request.each_network do |network, channels|
connection = connection_to(network)
next if connection.nil?
channels.each do |channel|
message = request.to_message_for channel
connection.enqueue message
end
end
end
|
ruby
|
def dispatch(request)
request.each_network do |network, channels|
connection = connection_to(network)
next if connection.nil?
channels.each do |channel|
message = request.to_message_for channel
connection.enqueue message
end
end
end
|
[
"def",
"dispatch",
"(",
"request",
")",
"request",
".",
"each_network",
"do",
"|",
"network",
",",
"channels",
"|",
"connection",
"=",
"connection_to",
"(",
"network",
")",
"next",
"if",
"connection",
".",
"nil?",
"channels",
".",
"each",
"do",
"|",
"channel",
"|",
"message",
"=",
"request",
".",
"to_message_for",
"channel",
"connection",
".",
"enqueue",
"message",
"end",
"end",
"end"
] |
Creates a new IRC client.
@param core [Core] the bot this client belongs to
Dispatches a new request.
@param request [Request] the request to dispatch
|
[
"Creates",
"a",
"new",
"IRC",
"client",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/irc_client.rb#L22-L32
|
20,437
|
olabini/codebot
|
lib/codebot/irc_client.rb
|
Codebot.IRCClient.migrate!
|
def migrate!
@semaphore.synchronize do
return unless @active
networks = @core.config.networks
(@checkpoint - networks).each { |network| disconnect_from network }
(networks - @checkpoint).each { |network| connect_to network }
@checkpoint = networks
end
end
|
ruby
|
def migrate!
@semaphore.synchronize do
return unless @active
networks = @core.config.networks
(@checkpoint - networks).each { |network| disconnect_from network }
(networks - @checkpoint).each { |network| connect_to network }
@checkpoint = networks
end
end
|
[
"def",
"migrate!",
"@semaphore",
".",
"synchronize",
"do",
"return",
"unless",
"@active",
"networks",
"=",
"@core",
".",
"config",
".",
"networks",
"(",
"@checkpoint",
"-",
"networks",
")",
".",
"each",
"{",
"|",
"network",
"|",
"disconnect_from",
"network",
"}",
"(",
"networks",
"-",
"@checkpoint",
")",
".",
"each",
"{",
"|",
"network",
"|",
"connect_to",
"network",
"}",
"@checkpoint",
"=",
"networks",
"end",
"end"
] |
Connects to and disconnects from networks as necessary in order for the
list of connections to reflect changes to the configuration.
|
[
"Connects",
"to",
"and",
"disconnects",
"from",
"networks",
"as",
"necessary",
"in",
"order",
"for",
"the",
"list",
"of",
"connections",
"to",
"reflect",
"changes",
"to",
"the",
"configuration",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/irc_client.rb#L56-L65
|
20,438
|
olabini/codebot
|
lib/codebot/irc_client.rb
|
Codebot.IRCClient.disconnect_from
|
def disconnect_from(network)
connection = @connections.delete connection_to(network)
connection.tap(&:stop).tap(&:join) unless connection.nil?
end
|
ruby
|
def disconnect_from(network)
connection = @connections.delete connection_to(network)
connection.tap(&:stop).tap(&:join) unless connection.nil?
end
|
[
"def",
"disconnect_from",
"(",
"network",
")",
"connection",
"=",
"@connections",
".",
"delete",
"connection_to",
"(",
"network",
")",
"connection",
".",
"tap",
"(",
":stop",
")",
".",
"tap",
"(",
":join",
")",
"unless",
"connection",
".",
"nil?",
"end"
] |
Disconnects from a given network if the network is currently connected.
@param network [Network] the network to disconnected from
|
[
"Disconnects",
"from",
"a",
"given",
"network",
"if",
"the",
"network",
"is",
"currently",
"connected",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/irc_client.rb#L97-L100
|
20,439
|
olabini/codebot
|
lib/codebot/formatter.rb
|
Codebot.Formatter.format_number
|
def format_number(num, singular = nil, plural = nil)
bold_num = ::Cinch::Formatting.format(:bold, num.to_s)
(bold_num + ' ' + (num == 1 ? singular : plural).to_s).strip
end
|
ruby
|
def format_number(num, singular = nil, plural = nil)
bold_num = ::Cinch::Formatting.format(:bold, num.to_s)
(bold_num + ' ' + (num == 1 ? singular : plural).to_s).strip
end
|
[
"def",
"format_number",
"(",
"num",
",",
"singular",
"=",
"nil",
",",
"plural",
"=",
"nil",
")",
"bold_num",
"=",
"::",
"Cinch",
"::",
"Formatting",
".",
"format",
"(",
":bold",
",",
"num",
".",
"to_s",
")",
"(",
"bold_num",
"+",
"' '",
"+",
"(",
"num",
"==",
"1",
"?",
"singular",
":",
"plural",
")",
".",
"to_s",
")",
".",
"strip",
"end"
] |
Formats a number.
@param num [Integer] the number
@param singular [String, nil] the singular noun to append to the number
@param plural [String, nil] the plural noun to append to the number
@return [String] the formatted number
|
[
"Formats",
"a",
"number",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/formatter.rb#L85-L88
|
20,440
|
olabini/codebot
|
lib/codebot/formatter.rb
|
Codebot.Formatter.ary_to_sentence
|
def ary_to_sentence(ary, empty_sentence = nil)
case ary.length
when 0 then empty_sentence.to_s
when 1 then ary.first
when 2 then ary.join(' and ')
else
*ary, last_element = ary
ary_to_sentence([ary.join(', '), last_element])
end
end
|
ruby
|
def ary_to_sentence(ary, empty_sentence = nil)
case ary.length
when 0 then empty_sentence.to_s
when 1 then ary.first
when 2 then ary.join(' and ')
else
*ary, last_element = ary
ary_to_sentence([ary.join(', '), last_element])
end
end
|
[
"def",
"ary_to_sentence",
"(",
"ary",
",",
"empty_sentence",
"=",
"nil",
")",
"case",
"ary",
".",
"length",
"when",
"0",
"then",
"empty_sentence",
".",
"to_s",
"when",
"1",
"then",
"ary",
".",
"first",
"when",
"2",
"then",
"ary",
".",
"join",
"(",
"' and '",
")",
"else",
"*",
"ary",
",",
"last_element",
"=",
"ary",
"ary_to_sentence",
"(",
"[",
"ary",
".",
"join",
"(",
"', '",
")",
",",
"last_element",
"]",
")",
"end",
"end"
] |
Constructs a sentence from array elements, connecting them with commas
and conjunctions.
@param ary [Array<String>] the array
@param empty_sentence [String, nil] the sentence to return if the array
is empty
@return [String] the constructed sentence
|
[
"Constructs",
"a",
"sentence",
"from",
"array",
"elements",
"connecting",
"them",
"with",
"commas",
"and",
"conjunctions",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/formatter.rb#L114-L123
|
20,441
|
olabini/codebot
|
lib/codebot/formatter.rb
|
Codebot.Formatter.abbreviate
|
def abbreviate(text, suffix: ' ...', length: 200)
content_length = length - suffix.length
short = text.to_s.lines.first.to_s.strip[0...content_length].strip
yield text if block_given?
short << suffix unless short.eql? text.to_s.strip
short
end
|
ruby
|
def abbreviate(text, suffix: ' ...', length: 200)
content_length = length - suffix.length
short = text.to_s.lines.first.to_s.strip[0...content_length].strip
yield text if block_given?
short << suffix unless short.eql? text.to_s.strip
short
end
|
[
"def",
"abbreviate",
"(",
"text",
",",
"suffix",
":",
"' ...'",
",",
"length",
":",
"200",
")",
"content_length",
"=",
"length",
"-",
"suffix",
".",
"length",
"short",
"=",
"text",
".",
"to_s",
".",
"lines",
".",
"first",
".",
"to_s",
".",
"strip",
"[",
"0",
"...",
"content_length",
"]",
".",
"strip",
"yield",
"text",
"if",
"block_given?",
"short",
"<<",
"suffix",
"unless",
"short",
".",
"eql?",
"text",
".",
"to_s",
".",
"strip",
"short",
"end"
] |
Truncates the given text, appending a suffix if it was above the allowed
length.
@param text [String] the text to truncate
@param suffix [String] the suffix to append if the text is truncated
@param length [Integer] the maximum length including the suffix
@yield [String] the truncated string before the ellipsis is appended
@return short [String] the abbreviated text
|
[
"Truncates",
"the",
"given",
"text",
"appending",
"a",
"suffix",
"if",
"it",
"was",
"above",
"the",
"allowed",
"length",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/formatter.rb#L144-L150
|
20,442
|
olabini/codebot
|
lib/codebot/formatter.rb
|
Codebot.Formatter.prettify
|
def prettify(text)
pretty = abbreviate(text) { |short| short.sub!(/[[:punct:]]+\z/, '') }
sanitize pretty
end
|
ruby
|
def prettify(text)
pretty = abbreviate(text) { |short| short.sub!(/[[:punct:]]+\z/, '') }
sanitize pretty
end
|
[
"def",
"prettify",
"(",
"text",
")",
"pretty",
"=",
"abbreviate",
"(",
"text",
")",
"{",
"|",
"short",
"|",
"short",
".",
"sub!",
"(",
"/",
"\\z",
"/",
",",
"''",
")",
"}",
"sanitize",
"pretty",
"end"
] |
Abbreviates the given text, removes any trailing punctuation except for
the ellipsis appended if the text was truncated, and sanitizes the text
for delivery to IRC.
@param text [String] the text to process
@return [String] the processed text
|
[
"Abbreviates",
"the",
"given",
"text",
"removes",
"any",
"trailing",
"punctuation",
"except",
"for",
"the",
"ellipsis",
"appended",
"if",
"the",
"text",
"was",
"truncated",
"and",
"sanitizes",
"the",
"text",
"for",
"delivery",
"to",
"IRC",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/formatter.rb#L158-L161
|
20,443
|
olabini/codebot
|
lib/codebot/formatter.rb
|
Codebot.Formatter.extract
|
def extract(*path)
node = payload
node if path.all? do |sub|
break unless node.is_a? Hash
node = node[sub.to_s]
end
end
|
ruby
|
def extract(*path)
node = payload
node if path.all? do |sub|
break unless node.is_a? Hash
node = node[sub.to_s]
end
end
|
[
"def",
"extract",
"(",
"*",
"path",
")",
"node",
"=",
"payload",
"node",
"if",
"path",
".",
"all?",
"do",
"|",
"sub",
"|",
"break",
"unless",
"node",
".",
"is_a?",
"Hash",
"node",
"=",
"node",
"[",
"sub",
".",
"to_s",
"]",
"end",
"end"
] |
Safely extracts a value from a JSON object.
@param path [Array<#to_s>] the path to traverse
@return [Object, nil] the extracted object or +nil+ if no object was
found at the given path
|
[
"Safely",
"extracts",
"a",
"value",
"from",
"a",
"JSON",
"object",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/formatter.rb#L229-L236
|
20,444
|
olabini/codebot
|
lib/codebot/ipc_server.rb
|
Codebot.IPCServer.run
|
def run(*)
create_pipe
file = File.open @pipe, 'r+'
while (line = file.gets.strip)
handle_command line
end
ensure
delete_pipe
end
|
ruby
|
def run(*)
create_pipe
file = File.open @pipe, 'r+'
while (line = file.gets.strip)
handle_command line
end
ensure
delete_pipe
end
|
[
"def",
"run",
"(",
"*",
")",
"create_pipe",
"file",
"=",
"File",
".",
"open",
"@pipe",
",",
"'r+'",
"while",
"(",
"line",
"=",
"file",
".",
"gets",
".",
"strip",
")",
"handle_command",
"line",
"end",
"ensure",
"delete_pipe",
"end"
] |
Starts this IPC server.
|
[
"Starts",
"this",
"IPC",
"server",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/ipc_server.rb#L58-L66
|
20,445
|
olabini/codebot
|
lib/codebot/ipc_server.rb
|
Codebot.IPCServer.handle_command
|
def handle_command(command)
case command
when 'REHASH' then @core.config.load!
when 'STOP' then Thread.new { @core.stop }
else STDERR.puts "Unknown IPC command: #{command.inspect}"
end
end
|
ruby
|
def handle_command(command)
case command
when 'REHASH' then @core.config.load!
when 'STOP' then Thread.new { @core.stop }
else STDERR.puts "Unknown IPC command: #{command.inspect}"
end
end
|
[
"def",
"handle_command",
"(",
"command",
")",
"case",
"command",
"when",
"'REHASH'",
"then",
"@core",
".",
"config",
".",
"load!",
"when",
"'STOP'",
"then",
"Thread",
".",
"new",
"{",
"@core",
".",
"stop",
"}",
"else",
"STDERR",
".",
"puts",
"\"Unknown IPC command: #{command.inspect}\"",
"end",
"end"
] |
Handles an incoming IPC command.
@param command [String] the command
|
[
"Handles",
"an",
"incoming",
"IPC",
"command",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/ipc_server.rb#L71-L77
|
20,446
|
olabini/codebot
|
lib/codebot/sanitizers.rb
|
Codebot.Sanitizers.valid_network
|
def valid_network(name, conf)
return if name.nil?
conf[:networks].find { |net| net.name_eql? name }
end
|
ruby
|
def valid_network(name, conf)
return if name.nil?
conf[:networks].find { |net| net.name_eql? name }
end
|
[
"def",
"valid_network",
"(",
"name",
",",
"conf",
")",
"return",
"if",
"name",
".",
"nil?",
"conf",
"[",
":networks",
"]",
".",
"find",
"{",
"|",
"net",
"|",
"net",
".",
"name_eql?",
"name",
"}",
"end"
] |
Sanitizes a network name.
@param name [String] the name of the network
@param conf [Hash] the configuration containing all networks
@return [Network, nil] the corresponding network or +nil+ on error
|
[
"Sanitizes",
"a",
"network",
"name",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/sanitizers.rb#L90-L94
|
20,447
|
olabini/codebot
|
lib/codebot/channel.rb
|
Codebot.Channel.update!
|
def update!(params)
set_identifier params[:identifier], params[:config] if params[:identifier]
self.name = params[:name]
self.key = params[:key]
self.send_external = params[:send_external]
set_network params[:network], params[:config]
end
|
ruby
|
def update!(params)
set_identifier params[:identifier], params[:config] if params[:identifier]
self.name = params[:name]
self.key = params[:key]
self.send_external = params[:send_external]
set_network params[:network], params[:config]
end
|
[
"def",
"update!",
"(",
"params",
")",
"set_identifier",
"params",
"[",
":identifier",
"]",
",",
"params",
"[",
":config",
"]",
"if",
"params",
"[",
":identifier",
"]",
"self",
".",
"name",
"=",
"params",
"[",
":name",
"]",
"self",
".",
"key",
"=",
"params",
"[",
":key",
"]",
"self",
".",
"send_external",
"=",
"params",
"[",
":send_external",
"]",
"set_network",
"params",
"[",
":network",
"]",
",",
"params",
"[",
":config",
"]",
"end"
] |
Creates a new channel from the supplied hash.
@param params [Hash] A hash with symbolic keys representing the instance
attributes of this channel. The keys +:name+ and
+:network+ are required. Alternatively, the key
+:identifier+, which should use the format
+network/name+, can be specified.
Updates the channel from the supplied hash.
@param params [Hash] A hash with symbolic keys representing the instance
attributes of this channel.
|
[
"Creates",
"a",
"new",
"channel",
"from",
"the",
"supplied",
"hash",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/channel.rb#L38-L44
|
20,448
|
olabini/codebot
|
lib/codebot/channel.rb
|
Codebot.Channel.set_network
|
def set_network(network, conf)
@network = valid! network, valid_network(network, conf), :@network,
required: true,
required_error: 'channels must have a network',
invalid_error: 'invalid channel network %s'
end
|
ruby
|
def set_network(network, conf)
@network = valid! network, valid_network(network, conf), :@network,
required: true,
required_error: 'channels must have a network',
invalid_error: 'invalid channel network %s'
end
|
[
"def",
"set_network",
"(",
"network",
",",
"conf",
")",
"@network",
"=",
"valid!",
"network",
",",
"valid_network",
"(",
"network",
",",
"conf",
")",
",",
":@network",
",",
"required",
":",
"true",
",",
"required_error",
":",
"'channels must have a network'",
",",
"invalid_error",
":",
"'invalid channel network %s'",
"end"
] |
Sets the network for this channel.
@param network [String] the name of the network
@param conf [Hash] the configuration containing all networks
|
[
"Sets",
"the",
"network",
"for",
"this",
"channel",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/channel.rb#L57-L62
|
20,449
|
olabini/codebot
|
lib/codebot/channel.rb
|
Codebot.Channel.set_identifier
|
def set_identifier(identifier, conf)
network_name, self.name = identifier.split('/', 2) if identifier
set_network(network_name, conf)
end
|
ruby
|
def set_identifier(identifier, conf)
network_name, self.name = identifier.split('/', 2) if identifier
set_network(network_name, conf)
end
|
[
"def",
"set_identifier",
"(",
"identifier",
",",
"conf",
")",
"network_name",
",",
"self",
".",
"name",
"=",
"identifier",
".",
"split",
"(",
"'/'",
",",
"2",
")",
"if",
"identifier",
"set_network",
"(",
"network_name",
",",
"conf",
")",
"end"
] |
Sets network and channel name based on the given identifier.
@param identifier [String] the identifier
@param conf [Hash] the configuration containing all networks
|
[
"Sets",
"network",
"and",
"channel",
"name",
"based",
"on",
"the",
"given",
"identifier",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/channel.rb#L100-L103
|
20,450
|
olabini/codebot
|
lib/codebot/config.rb
|
Codebot.Config.load_from_file!
|
def load_from_file!(file)
data = Psych.safe_load(File.read(file)) if File.file? file
data = {} unless data.is_a? Hash
conf = {}
conf[:networks] = Network.deserialize_all data['networks'], conf
conf[:integrations] = Integration.deserialize_all data['integrations'],
conf
conf
end
|
ruby
|
def load_from_file!(file)
data = Psych.safe_load(File.read(file)) if File.file? file
data = {} unless data.is_a? Hash
conf = {}
conf[:networks] = Network.deserialize_all data['networks'], conf
conf[:integrations] = Integration.deserialize_all data['integrations'],
conf
conf
end
|
[
"def",
"load_from_file!",
"(",
"file",
")",
"data",
"=",
"Psych",
".",
"safe_load",
"(",
"File",
".",
"read",
"(",
"file",
")",
")",
"if",
"File",
".",
"file?",
"file",
"data",
"=",
"{",
"}",
"unless",
"data",
".",
"is_a?",
"Hash",
"conf",
"=",
"{",
"}",
"conf",
"[",
":networks",
"]",
"=",
"Network",
".",
"deserialize_all",
"data",
"[",
"'networks'",
"]",
",",
"conf",
"conf",
"[",
":integrations",
"]",
"=",
"Integration",
".",
"deserialize_all",
"data",
"[",
"'integrations'",
"]",
",",
"conf",
"conf",
"end"
] |
Loads the configuration from the specified file.
@param file [String] the path to the configuration file
@return [Hash] the loaded configuration, or the default configuration if
the file did not exist
|
[
"Loads",
"the",
"configuration",
"from",
"the",
"specified",
"file",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/config.rb#L104-L112
|
20,451
|
olabini/codebot
|
lib/codebot/config.rb
|
Codebot.Config.save_to_file!
|
def save_to_file!(file)
data = {}
data['networks'] = Network.serialize_all @conf[:networks], @conf
data['integrations'] = Integration.serialize_all @conf[:integrations],
@conf
File.write file, Psych.dump(data)
end
|
ruby
|
def save_to_file!(file)
data = {}
data['networks'] = Network.serialize_all @conf[:networks], @conf
data['integrations'] = Integration.serialize_all @conf[:integrations],
@conf
File.write file, Psych.dump(data)
end
|
[
"def",
"save_to_file!",
"(",
"file",
")",
"data",
"=",
"{",
"}",
"data",
"[",
"'networks'",
"]",
"=",
"Network",
".",
"serialize_all",
"@conf",
"[",
":networks",
"]",
",",
"@conf",
"data",
"[",
"'integrations'",
"]",
"=",
"Integration",
".",
"serialize_all",
"@conf",
"[",
":integrations",
"]",
",",
"@conf",
"File",
".",
"write",
"file",
",",
"Psych",
".",
"dump",
"(",
"data",
")",
"end"
] |
Saves the configuration to the specified file.
@param file [String] the path to the configuration file
|
[
"Saves",
"the",
"configuration",
"to",
"the",
"specified",
"file",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/config.rb#L117-L123
|
20,452
|
olabini/codebot
|
lib/codebot/network.rb
|
Codebot.Network.update!
|
def update!(params)
self.name = params[:name]
self.server_password = params[:server_password]
self.nick = params[:nick]
self.bind = params[:bind]
self.modes = params[:modes]
update_complicated!(params)
end
|
ruby
|
def update!(params)
self.name = params[:name]
self.server_password = params[:server_password]
self.nick = params[:nick]
self.bind = params[:bind]
self.modes = params[:modes]
update_complicated!(params)
end
|
[
"def",
"update!",
"(",
"params",
")",
"self",
".",
"name",
"=",
"params",
"[",
":name",
"]",
"self",
".",
"server_password",
"=",
"params",
"[",
":server_password",
"]",
"self",
".",
"nick",
"=",
"params",
"[",
":nick",
"]",
"self",
".",
"bind",
"=",
"params",
"[",
":bind",
"]",
"self",
".",
"modes",
"=",
"params",
"[",
":modes",
"]",
"update_complicated!",
"(",
"params",
")",
"end"
] |
Creates a new network from the supplied hash.
@param params [Hash] A hash with symbolic keys representing the instance
attributes of this network. The keys +:name+ and
+:host+ are required.
Updates the network from the supplied hash.
@param params [Hash] A hash with symbolic keys representing the instance
attributes of this network.
|
[
"Creates",
"a",
"new",
"network",
"from",
"the",
"supplied",
"hash",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network.rb#L62-L69
|
20,453
|
olabini/codebot
|
lib/codebot/network.rb
|
Codebot.Network.update_connection
|
def update_connection(host, port, secure)
@host = valid! host, valid_host(host), :@host,
required: true,
required_error: 'networks must have a hostname',
invalid_error: 'invalid hostname %s'
@port = valid! port, valid_port(port), :@port,
invalid_error: 'invalid port number %s'
@secure = valid!(secure, valid_boolean(secure), :@secure,
invalid_error: 'secure must be a boolean') { false }
end
|
ruby
|
def update_connection(host, port, secure)
@host = valid! host, valid_host(host), :@host,
required: true,
required_error: 'networks must have a hostname',
invalid_error: 'invalid hostname %s'
@port = valid! port, valid_port(port), :@port,
invalid_error: 'invalid port number %s'
@secure = valid!(secure, valid_boolean(secure), :@secure,
invalid_error: 'secure must be a boolean') { false }
end
|
[
"def",
"update_connection",
"(",
"host",
",",
"port",
",",
"secure",
")",
"@host",
"=",
"valid!",
"host",
",",
"valid_host",
"(",
"host",
")",
",",
":@host",
",",
"required",
":",
"true",
",",
"required_error",
":",
"'networks must have a hostname'",
",",
"invalid_error",
":",
"'invalid hostname %s'",
"@port",
"=",
"valid!",
"port",
",",
"valid_port",
"(",
"port",
")",
",",
":@port",
",",
"invalid_error",
":",
"'invalid port number %s'",
"@secure",
"=",
"valid!",
"(",
"secure",
",",
"valid_boolean",
"(",
"secure",
")",
",",
":@secure",
",",
"invalid_error",
":",
"'secure must be a boolean'",
")",
"{",
"false",
"}",
"end"
] |
Updates the connection details of this network.
@param host [String] the new hostname, or +nil+ to keep the current value
@param port [Integer] the new port, or +nil+ to keep the current value
@param secure [Boolean] whether to connect over TLS, or +nil+ to keep the
current value
|
[
"Updates",
"the",
"connection",
"details",
"of",
"this",
"network",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network.rb#L92-L101
|
20,454
|
olabini/codebot
|
lib/codebot/network.rb
|
Codebot.Network.update_sasl
|
def update_sasl(disable, user, pass)
@sasl_username = valid! user, valid_string(user), :@sasl_username,
invalid_error: 'invalid SASL username %s'
@sasl_password = valid! pass, valid_string(pass), :@sasl_password,
invalid_error: 'invalid SASL password %s'
return unless disable
@sasl_username = nil
@sasl_password = nil
end
|
ruby
|
def update_sasl(disable, user, pass)
@sasl_username = valid! user, valid_string(user), :@sasl_username,
invalid_error: 'invalid SASL username %s'
@sasl_password = valid! pass, valid_string(pass), :@sasl_password,
invalid_error: 'invalid SASL password %s'
return unless disable
@sasl_username = nil
@sasl_password = nil
end
|
[
"def",
"update_sasl",
"(",
"disable",
",",
"user",
",",
"pass",
")",
"@sasl_username",
"=",
"valid!",
"user",
",",
"valid_string",
"(",
"user",
")",
",",
":@sasl_username",
",",
"invalid_error",
":",
"'invalid SASL username %s'",
"@sasl_password",
"=",
"valid!",
"pass",
",",
"valid_string",
"(",
"pass",
")",
",",
":@sasl_password",
",",
"invalid_error",
":",
"'invalid SASL password %s'",
"return",
"unless",
"disable",
"@sasl_username",
"=",
"nil",
"@sasl_password",
"=",
"nil",
"end"
] |
Updates the SASL authentication details of this network.
@param disable [Boolean] whether to disable SASL, or +nil+ to keep the
current value.
@param user [String] the SASL username, or +nil+ to keep the current value
@param pass [String] the SASL password, or +nil+ to keep the current value
|
[
"Updates",
"the",
"SASL",
"authentication",
"details",
"of",
"this",
"network",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network.rb#L121-L130
|
20,455
|
olabini/codebot
|
lib/codebot/network.rb
|
Codebot.Network.update_nickserv
|
def update_nickserv(disable, user, pass)
@nickserv_username = valid! user, valid_string(user), :@nickserv_username,
invalid_error: 'invalid NickServ username %s'
@nickserv_password = valid! pass, valid_string(pass), :@nickserv_password,
invalid_error: 'invalid NickServ password %s'
return unless disable
@nickserv_username = nil
@nickserv_password = nil
end
|
ruby
|
def update_nickserv(disable, user, pass)
@nickserv_username = valid! user, valid_string(user), :@nickserv_username,
invalid_error: 'invalid NickServ username %s'
@nickserv_password = valid! pass, valid_string(pass), :@nickserv_password,
invalid_error: 'invalid NickServ password %s'
return unless disable
@nickserv_username = nil
@nickserv_password = nil
end
|
[
"def",
"update_nickserv",
"(",
"disable",
",",
"user",
",",
"pass",
")",
"@nickserv_username",
"=",
"valid!",
"user",
",",
"valid_string",
"(",
"user",
")",
",",
":@nickserv_username",
",",
"invalid_error",
":",
"'invalid NickServ username %s'",
"@nickserv_password",
"=",
"valid!",
"pass",
",",
"valid_string",
"(",
"pass",
")",
",",
":@nickserv_password",
",",
"invalid_error",
":",
"'invalid NickServ password %s'",
"return",
"unless",
"disable",
"@nickserv_username",
"=",
"nil",
"@nickserv_password",
"=",
"nil",
"end"
] |
Updates the NickServ authentication details of this network.
@param disable [Boolean] whether to disable NickServ, or +nil+ to keep the
current value.
@param user [String] the NickServ username, or +nil+ to keep the
current value
@param pass [String] the NickServ password, or +nil+ to keep the
current value
|
[
"Updates",
"the",
"NickServ",
"authentication",
"details",
"of",
"this",
"network",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network.rb#L140-L149
|
20,456
|
olabini/codebot
|
lib/codebot/network.rb
|
Codebot.Network.serialize
|
def serialize(_conf)
[name, Network.fields.map { |sym| [sym.to_s, send(sym)] }.to_h]
end
|
ruby
|
def serialize(_conf)
[name, Network.fields.map { |sym| [sym.to_s, send(sym)] }.to_h]
end
|
[
"def",
"serialize",
"(",
"_conf",
")",
"[",
"name",
",",
"Network",
".",
"fields",
".",
"map",
"{",
"|",
"sym",
"|",
"[",
"sym",
".",
"to_s",
",",
"send",
"(",
"sym",
")",
"]",
"}",
".",
"to_h",
"]",
"end"
] |
Serializes this network.
@param _conf [Hash] the deserialized configuration
@return [Array, Hash] the serialized object
|
[
"Serializes",
"this",
"network",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/network.rb#L216-L218
|
20,457
|
olabini/codebot
|
lib/codebot/thread_controller.rb
|
Codebot.ThreadController.start
|
def start(arg = nil)
return if running?
@thread = Thread.new do
Thread.current.abort_on_exception = true
run(arg)
end
end
|
ruby
|
def start(arg = nil)
return if running?
@thread = Thread.new do
Thread.current.abort_on_exception = true
run(arg)
end
end
|
[
"def",
"start",
"(",
"arg",
"=",
"nil",
")",
"return",
"if",
"running?",
"@thread",
"=",
"Thread",
".",
"new",
"do",
"Thread",
".",
"current",
".",
"abort_on_exception",
"=",
"true",
"run",
"(",
"arg",
")",
"end",
"end"
] |
Starts a new managed thread if no thread is currently running.
The thread invokes the +run+ method of the class that manages it.
@param arg the argument to pass to the +#run+ method
@return [Thread, nil] the newly created thread, or +nil+ if
there was already a running thread
|
[
"Starts",
"a",
"new",
"managed",
"thread",
"if",
"no",
"thread",
"is",
"currently",
"running",
".",
"The",
"thread",
"invokes",
"the",
"+",
"run",
"+",
"method",
"of",
"the",
"class",
"that",
"manages",
"it",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/thread_controller.rb#L33-L40
|
20,458
|
olabini/codebot
|
lib/codebot/irc_connection.rb
|
Codebot.IRCConnection.run
|
def run(connection)
@connection = connection
bot = create_bot(connection)
thread = Thread.new { bot.start }
@ready.pop
loop { deliver bot, dequeue }
ensure
thread.exit unless thread.nil?
end
|
ruby
|
def run(connection)
@connection = connection
bot = create_bot(connection)
thread = Thread.new { bot.start }
@ready.pop
loop { deliver bot, dequeue }
ensure
thread.exit unless thread.nil?
end
|
[
"def",
"run",
"(",
"connection",
")",
"@connection",
"=",
"connection",
"bot",
"=",
"create_bot",
"(",
"connection",
")",
"thread",
"=",
"Thread",
".",
"new",
"{",
"bot",
".",
"start",
"}",
"@ready",
".",
"pop",
"loop",
"{",
"deliver",
"bot",
",",
"dequeue",
"}",
"ensure",
"thread",
".",
"exit",
"unless",
"thread",
".",
"nil?",
"end"
] |
Starts this IRC thread.
@param connection [IRCConnection] the connection the thread controls
|
[
"Starts",
"this",
"IRC",
"thread",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/irc_connection.rb#L66-L74
|
20,459
|
olabini/codebot
|
lib/codebot/irc_connection.rb
|
Codebot.IRCConnection.deliver
|
def deliver(bot, message)
channel = bot.Channel(message.channel.name)
message.format.to_a.each do |msg|
channel.send msg
end
end
|
ruby
|
def deliver(bot, message)
channel = bot.Channel(message.channel.name)
message.format.to_a.each do |msg|
channel.send msg
end
end
|
[
"def",
"deliver",
"(",
"bot",
",",
"message",
")",
"channel",
"=",
"bot",
".",
"Channel",
"(",
"message",
".",
"channel",
".",
"name",
")",
"message",
".",
"format",
".",
"to_a",
".",
"each",
"do",
"|",
"msg",
"|",
"channel",
".",
"send",
"msg",
"end",
"end"
] |
Delivers a message to an IRC channel.
@param bot [Cinch::Bot] the IRC bot
@param message [Message] the message to deliver
|
[
"Delivers",
"a",
"message",
"to",
"an",
"IRC",
"channel",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/irc_connection.rb#L87-L92
|
20,460
|
olabini/codebot
|
lib/codebot/irc_connection.rb
|
Codebot.IRCConnection.channels
|
def channels(config, network)
config.integrations.map(&:channels).flatten.select do |channel|
network == channel.network
end
end
|
ruby
|
def channels(config, network)
config.integrations.map(&:channels).flatten.select do |channel|
network == channel.network
end
end
|
[
"def",
"channels",
"(",
"config",
",",
"network",
")",
"config",
".",
"integrations",
".",
"map",
"(",
":channels",
")",
".",
"flatten",
".",
"select",
"do",
"|",
"channel",
"|",
"network",
"==",
"channel",
".",
"network",
"end",
"end"
] |
Gets the list of channels associated with this network.
@param config [Config] the configuration to search
@param network [Network] the network to search for
@return [Array<Channel>] the list of channels
|
[
"Gets",
"the",
"list",
"of",
"channels",
"associated",
"with",
"this",
"network",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/irc_connection.rb#L99-L103
|
20,461
|
olabini/codebot
|
lib/codebot/irc_connection.rb
|
Codebot.IRCConnection.create_bot
|
def create_bot(con) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
net = con.network
chan_ary = channel_array(con.core.config, network)
cc = self
Cinch::Bot.new do
configure do |c|
c.channels = chan_ary
c.local_host = net.bind
c.modes = net.modes.to_s.gsub(/\A\+/, '').chars.uniq
c.nick = net.nick
c.password = net.server_password
c.port = net.real_port
c.realname = Codebot::WEBSITE
if net.sasl?
c.sasl.username = net.sasl_username
c.sasl.password = net.sasl_password
end
c.server = net.host
c.ssl.use = net.secure
c.ssl.verify = net.secure
c.user = Codebot::PROJECT.downcase
cc.configure_nickserv_identification(net, c)
end
on(:join) { con.set_ready! }
end
end
|
ruby
|
def create_bot(con) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
net = con.network
chan_ary = channel_array(con.core.config, network)
cc = self
Cinch::Bot.new do
configure do |c|
c.channels = chan_ary
c.local_host = net.bind
c.modes = net.modes.to_s.gsub(/\A\+/, '').chars.uniq
c.nick = net.nick
c.password = net.server_password
c.port = net.real_port
c.realname = Codebot::WEBSITE
if net.sasl?
c.sasl.username = net.sasl_username
c.sasl.password = net.sasl_password
end
c.server = net.host
c.ssl.use = net.secure
c.ssl.verify = net.secure
c.user = Codebot::PROJECT.downcase
cc.configure_nickserv_identification(net, c)
end
on(:join) { con.set_ready! }
end
end
|
[
"def",
"create_bot",
"(",
"con",
")",
"# rubocop:disable Metrics/AbcSize, Metrics/MethodLength",
"net",
"=",
"con",
".",
"network",
"chan_ary",
"=",
"channel_array",
"(",
"con",
".",
"core",
".",
"config",
",",
"network",
")",
"cc",
"=",
"self",
"Cinch",
"::",
"Bot",
".",
"new",
"do",
"configure",
"do",
"|",
"c",
"|",
"c",
".",
"channels",
"=",
"chan_ary",
"c",
".",
"local_host",
"=",
"net",
".",
"bind",
"c",
".",
"modes",
"=",
"net",
".",
"modes",
".",
"to_s",
".",
"gsub",
"(",
"/",
"\\A",
"\\+",
"/",
",",
"''",
")",
".",
"chars",
".",
"uniq",
"c",
".",
"nick",
"=",
"net",
".",
"nick",
"c",
".",
"password",
"=",
"net",
".",
"server_password",
"c",
".",
"port",
"=",
"net",
".",
"real_port",
"c",
".",
"realname",
"=",
"Codebot",
"::",
"WEBSITE",
"if",
"net",
".",
"sasl?",
"c",
".",
"sasl",
".",
"username",
"=",
"net",
".",
"sasl_username",
"c",
".",
"sasl",
".",
"password",
"=",
"net",
".",
"sasl_password",
"end",
"c",
".",
"server",
"=",
"net",
".",
"host",
"c",
".",
"ssl",
".",
"use",
"=",
"net",
".",
"secure",
"c",
".",
"ssl",
".",
"verify",
"=",
"net",
".",
"secure",
"c",
".",
"user",
"=",
"Codebot",
"::",
"PROJECT",
".",
"downcase",
"cc",
".",
"configure_nickserv_identification",
"(",
"net",
",",
"c",
")",
"end",
"on",
"(",
":join",
")",
"{",
"con",
".",
"set_ready!",
"}",
"end",
"end"
] |
Constructs a new bot for the given IRC network.
@param con [IRCConnection] the connection the thread controls
|
[
"Constructs",
"a",
"new",
"bot",
"for",
"the",
"given",
"IRC",
"network",
"."
] |
031ddf427fd4a245ee6ff6414c4e28dab31679c1
|
https://github.com/olabini/codebot/blob/031ddf427fd4a245ee6ff6414c4e28dab31679c1/lib/codebot/irc_connection.rb#L129-L154
|
20,462
|
collectiveidea/tinder
|
lib/tinder/room.rb
|
Tinder.Room.user
|
def user(id)
if id
cached_user = users.detect {|u| u[:id] == id }
user = cached_user || fetch_user(id)
self.users << user
user
end
end
|
ruby
|
def user(id)
if id
cached_user = users.detect {|u| u[:id] == id }
user = cached_user || fetch_user(id)
self.users << user
user
end
end
|
[
"def",
"user",
"(",
"id",
")",
"if",
"id",
"cached_user",
"=",
"users",
".",
"detect",
"{",
"|",
"u",
"|",
"u",
"[",
":id",
"]",
"==",
"id",
"}",
"user",
"=",
"cached_user",
"||",
"fetch_user",
"(",
"id",
")",
"self",
".",
"users",
"<<",
"user",
"user",
"end",
"end"
] |
return the user with the given id; if it isn't in our room cache,
do a request to get it
|
[
"return",
"the",
"user",
"with",
"the",
"given",
"id",
";",
"if",
"it",
"isn",
"t",
"in",
"our",
"room",
"cache",
"do",
"a",
"request",
"to",
"get",
"it"
] |
daf7a3d7884b59953544e480a8543ac1a81e285f
|
https://github.com/collectiveidea/tinder/blob/daf7a3d7884b59953544e480a8543ac1a81e285f/lib/tinder/room.rb#L107-L114
|
20,463
|
collectiveidea/tinder
|
lib/tinder/room.rb
|
Tinder.Room.fetch_user
|
def fetch_user(id)
user_data = connection.get("/users/#{id}.json")
user = user_data && user_data[:user]
user[:created_at] = Time.parse(user[:created_at])
user
end
|
ruby
|
def fetch_user(id)
user_data = connection.get("/users/#{id}.json")
user = user_data && user_data[:user]
user[:created_at] = Time.parse(user[:created_at])
user
end
|
[
"def",
"fetch_user",
"(",
"id",
")",
"user_data",
"=",
"connection",
".",
"get",
"(",
"\"/users/#{id}.json\"",
")",
"user",
"=",
"user_data",
"&&",
"user_data",
"[",
":user",
"]",
"user",
"[",
":created_at",
"]",
"=",
"Time",
".",
"parse",
"(",
"user",
"[",
":created_at",
"]",
")",
"user",
"end"
] |
Perform a request for the user with the given ID
|
[
"Perform",
"a",
"request",
"for",
"the",
"user",
"with",
"the",
"given",
"ID"
] |
daf7a3d7884b59953544e480a8543ac1a81e285f
|
https://github.com/collectiveidea/tinder/blob/daf7a3d7884b59953544e480a8543ac1a81e285f/lib/tinder/room.rb#L117-L122
|
20,464
|
tpitale/mail_room
|
lib/mail_room/cli.rb
|
MailRoom.CLI.start
|
def start
Signal.trap(:INT) do
coordinator.running = false
end
Signal.trap(:TERM) do
exit
end
coordinator.run
end
|
ruby
|
def start
Signal.trap(:INT) do
coordinator.running = false
end
Signal.trap(:TERM) do
exit
end
coordinator.run
end
|
[
"def",
"start",
"Signal",
".",
"trap",
"(",
":INT",
")",
"do",
"coordinator",
".",
"running",
"=",
"false",
"end",
"Signal",
".",
"trap",
"(",
":TERM",
")",
"do",
"exit",
"end",
"coordinator",
".",
"run",
"end"
] |
Initialize a new CLI instance to handle option parsing from arguments
into configuration to start the coordinator running on all mailboxes
@param args [Array] `ARGV` passed from `bin/mail_room`
Start the coordinator running, sets up signal traps
|
[
"Initialize",
"a",
"new",
"CLI",
"instance",
"to",
"handle",
"option",
"parsing",
"from",
"arguments",
"into",
"configuration",
"to",
"start",
"the",
"coordinator",
"running",
"on",
"all",
"mailboxes"
] |
c25f790da167b856f4195a20065e2c62874ef50b
|
https://github.com/tpitale/mail_room/blob/c25f790da167b856f4195a20065e2c62874ef50b/lib/mail_room/cli.rb#L43-L53
|
20,465
|
tpitale/mail_room
|
lib/mail_room/mailbox_watcher.rb
|
MailRoom.MailboxWatcher.run
|
def run
@running = true
connection.on_new_message do |message|
@mailbox.deliver(message)
end
self.watching_thread = Thread.start do
while(running?) do
connection.wait
end
end
watching_thread.abort_on_exception = true
end
|
ruby
|
def run
@running = true
connection.on_new_message do |message|
@mailbox.deliver(message)
end
self.watching_thread = Thread.start do
while(running?) do
connection.wait
end
end
watching_thread.abort_on_exception = true
end
|
[
"def",
"run",
"@running",
"=",
"true",
"connection",
".",
"on_new_message",
"do",
"|",
"message",
"|",
"@mailbox",
".",
"deliver",
"(",
"message",
")",
"end",
"self",
".",
"watching_thread",
"=",
"Thread",
".",
"start",
"do",
"while",
"(",
"running?",
")",
"do",
"connection",
".",
"wait",
"end",
"end",
"watching_thread",
".",
"abort_on_exception",
"=",
"true",
"end"
] |
run the mailbox watcher
|
[
"run",
"the",
"mailbox",
"watcher"
] |
c25f790da167b856f4195a20065e2c62874ef50b
|
https://github.com/tpitale/mail_room/blob/c25f790da167b856f4195a20065e2c62874ef50b/lib/mail_room/mailbox_watcher.rb#L25-L39
|
20,466
|
ruby-processing/JRubyArt
|
lib/jruby_art/runners/watch.rb
|
Processing.Watcher.start_watching
|
def start_watching
start_original
Kernel.loop do
if @files.find { |file| FileTest.exist?(file) && File.stat(file).mtime > @time }
puts 'reloading sketch...'
Processing.app && Processing.app.close
java.lang.System.gc
@time = Time.now
start_runner
reload_files_to_watch
end
sleep SLEEP_TIME
end
end
|
ruby
|
def start_watching
start_original
Kernel.loop do
if @files.find { |file| FileTest.exist?(file) && File.stat(file).mtime > @time }
puts 'reloading sketch...'
Processing.app && Processing.app.close
java.lang.System.gc
@time = Time.now
start_runner
reload_files_to_watch
end
sleep SLEEP_TIME
end
end
|
[
"def",
"start_watching",
"start_original",
"Kernel",
".",
"loop",
"do",
"if",
"@files",
".",
"find",
"{",
"|",
"file",
"|",
"FileTest",
".",
"exist?",
"(",
"file",
")",
"&&",
"File",
".",
"stat",
"(",
"file",
")",
".",
"mtime",
">",
"@time",
"}",
"puts",
"'reloading sketch...'",
"Processing",
".",
"app",
"&&",
"Processing",
".",
"app",
".",
"close",
"java",
".",
"lang",
".",
"System",
".",
"gc",
"@time",
"=",
"Time",
".",
"now",
"start_runner",
"reload_files_to_watch",
"end",
"sleep",
"SLEEP_TIME",
"end",
"end"
] |
Kicks off a thread to watch the sketch, reloading JRubyArt
and restarting the sketch whenever it changes.
|
[
"Kicks",
"off",
"a",
"thread",
"to",
"watch",
"the",
"sketch",
"reloading",
"JRubyArt",
"and",
"restarting",
"the",
"sketch",
"whenever",
"it",
"changes",
"."
] |
3bd44d4e762d0184c714c4641a5cc3a6891aecf7
|
https://github.com/ruby-processing/JRubyArt/blob/3bd44d4e762d0184c714c4641a5cc3a6891aecf7/lib/jruby_art/runners/watch.rb#L34-L47
|
20,467
|
ruby-processing/JRubyArt
|
lib/jruby_art/runners/watch.rb
|
Processing.Watcher.report_errors
|
def report_errors
yield
rescue Exception => e
wformat = 'Exception occured while running sketch %s...'
tformat = "Backtrace:\n\t%s"
warn format(wformat, File.basename(SKETCH_PATH))
puts format(tformat, e.backtrace.join("\n\t"))
end
|
ruby
|
def report_errors
yield
rescue Exception => e
wformat = 'Exception occured while running sketch %s...'
tformat = "Backtrace:\n\t%s"
warn format(wformat, File.basename(SKETCH_PATH))
puts format(tformat, e.backtrace.join("\n\t"))
end
|
[
"def",
"report_errors",
"yield",
"rescue",
"Exception",
"=>",
"e",
"wformat",
"=",
"'Exception occured while running sketch %s...'",
"tformat",
"=",
"\"Backtrace:\\n\\t%s\"",
"warn",
"format",
"(",
"wformat",
",",
"File",
".",
"basename",
"(",
"SKETCH_PATH",
")",
")",
"puts",
"format",
"(",
"tformat",
",",
"e",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\\t\"",
")",
")",
"end"
] |
Convenience function to report errors when loading and running a sketch,
instead of having them eaten by the thread they are loaded in.
|
[
"Convenience",
"function",
"to",
"report",
"errors",
"when",
"loading",
"and",
"running",
"a",
"sketch",
"instead",
"of",
"having",
"them",
"eaten",
"by",
"the",
"thread",
"they",
"are",
"loaded",
"in",
"."
] |
3bd44d4e762d0184c714c4641a5cc3a6891aecf7
|
https://github.com/ruby-processing/JRubyArt/blob/3bd44d4e762d0184c714c4641a5cc3a6891aecf7/lib/jruby_art/runners/watch.rb#L51-L58
|
20,468
|
ruby-processing/JRubyArt
|
lib/jruby_art/app.rb
|
Processing.App.close
|
def close
control_panel.remove if respond_to?(:control_panel)
surface.stopThread
surface.setVisible(false) if surface.isStopped
dispose
Processing.app = nil
end
|
ruby
|
def close
control_panel.remove if respond_to?(:control_panel)
surface.stopThread
surface.setVisible(false) if surface.isStopped
dispose
Processing.app = nil
end
|
[
"def",
"close",
"control_panel",
".",
"remove",
"if",
"respond_to?",
"(",
":control_panel",
")",
"surface",
".",
"stopThread",
"surface",
".",
"setVisible",
"(",
"false",
")",
"if",
"surface",
".",
"isStopped",
"dispose",
"Processing",
".",
"app",
"=",
"nil",
"end"
] |
Close and shutter a running sketch. But don't exit.
@HACK seems to work with watch until we find a better
way of disposing of sketch window...
|
[
"Close",
"and",
"shutter",
"a",
"running",
"sketch",
".",
"But",
"don",
"t",
"exit",
"."
] |
3bd44d4e762d0184c714c4641a5cc3a6891aecf7
|
https://github.com/ruby-processing/JRubyArt/blob/3bd44d4e762d0184c714c4641a5cc3a6891aecf7/lib/jruby_art/app.rb#L166-L172
|
20,469
|
ruby-processing/JRubyArt
|
lib/jruby_art/helper_methods.rb
|
Processing.HelperMethods.buffer
|
def buffer(buf_width = width, buf_height = height, renderer = @render_mode)
create_graphics(buf_width, buf_height, renderer).tap do |buffer|
buffer.begin_draw
yield buffer
buffer.end_draw
end
end
|
ruby
|
def buffer(buf_width = width, buf_height = height, renderer = @render_mode)
create_graphics(buf_width, buf_height, renderer).tap do |buffer|
buffer.begin_draw
yield buffer
buffer.end_draw
end
end
|
[
"def",
"buffer",
"(",
"buf_width",
"=",
"width",
",",
"buf_height",
"=",
"height",
",",
"renderer",
"=",
"@render_mode",
")",
"create_graphics",
"(",
"buf_width",
",",
"buf_height",
",",
"renderer",
")",
".",
"tap",
"do",
"|",
"buffer",
"|",
"buffer",
".",
"begin_draw",
"yield",
"buffer",
"buffer",
".",
"end_draw",
"end",
"end"
] |
Nice block method to draw to a buffer.
You can optionally pass it a width, a height, and a renderer.
Takes care of starting and ending the draw for you.
|
[
"Nice",
"block",
"method",
"to",
"draw",
"to",
"a",
"buffer",
".",
"You",
"can",
"optionally",
"pass",
"it",
"a",
"width",
"a",
"height",
"and",
"a",
"renderer",
".",
"Takes",
"care",
"of",
"starting",
"and",
"ending",
"the",
"draw",
"for",
"you",
"."
] |
3bd44d4e762d0184c714c4641a5cc3a6891aecf7
|
https://github.com/ruby-processing/JRubyArt/blob/3bd44d4e762d0184c714c4641a5cc3a6891aecf7/lib/jruby_art/helper_methods.rb#L13-L19
|
20,470
|
ruby-processing/JRubyArt
|
lib/jruby_art/helper_methods.rb
|
Processing.HelperMethods.hsb_color
|
def hsb_color(hue, sat, brightness)
Java::Monkstone::ColorUtil.hsbToRgB(hue, sat, brightness)
end
|
ruby
|
def hsb_color(hue, sat, brightness)
Java::Monkstone::ColorUtil.hsbToRgB(hue, sat, brightness)
end
|
[
"def",
"hsb_color",
"(",
"hue",
",",
"sat",
",",
"brightness",
")",
"Java",
"::",
"Monkstone",
"::",
"ColorUtil",
".",
"hsbToRgB",
"(",
"hue",
",",
"sat",
",",
"brightness",
")",
"end"
] |
hue, sat, brightness in range 0..1.0 returns RGB color int
|
[
"hue",
"sat",
"brightness",
"in",
"range",
"0",
"..",
"1",
".",
"0",
"returns",
"RGB",
"color",
"int"
] |
3bd44d4e762d0184c714c4641a5cc3a6891aecf7
|
https://github.com/ruby-processing/JRubyArt/blob/3bd44d4e762d0184c714c4641a5cc3a6891aecf7/lib/jruby_art/helper_methods.rb#L50-L52
|
20,471
|
ruby-processing/JRubyArt
|
lib/jruby_art/helper_methods.rb
|
Processing.HelperMethods.dist
|
def dist(*args)
case args.length
when 4
return dist2d(*args)
when 6
return dist3d(*args)
else
raise ArgumentError, 'takes 4 or 6 parameters'
end
end
|
ruby
|
def dist(*args)
case args.length
when 4
return dist2d(*args)
when 6
return dist3d(*args)
else
raise ArgumentError, 'takes 4 or 6 parameters'
end
end
|
[
"def",
"dist",
"(",
"*",
"args",
")",
"case",
"args",
".",
"length",
"when",
"4",
"return",
"dist2d",
"(",
"args",
")",
"when",
"6",
"return",
"dist3d",
"(",
"args",
")",
"else",
"raise",
"ArgumentError",
",",
"'takes 4 or 6 parameters'",
"end",
"end"
] |
explicitly provide 'processing.org' dist instance method
|
[
"explicitly",
"provide",
"processing",
".",
"org",
"dist",
"instance",
"method"
] |
3bd44d4e762d0184c714c4641a5cc3a6891aecf7
|
https://github.com/ruby-processing/JRubyArt/blob/3bd44d4e762d0184c714c4641a5cc3a6891aecf7/lib/jruby_art/helper_methods.rb#L100-L109
|
20,472
|
ruby-processing/JRubyArt
|
lib/jruby_art/helper_methods.rb
|
Processing.HelperMethods.blend_color
|
def blend_color(c1, c2, mode)
Java::ProcessingCore::PImage.blendColor(c1, c2, mode)
end
|
ruby
|
def blend_color(c1, c2, mode)
Java::ProcessingCore::PImage.blendColor(c1, c2, mode)
end
|
[
"def",
"blend_color",
"(",
"c1",
",",
"c2",
",",
"mode",
")",
"Java",
"::",
"ProcessingCore",
"::",
"PImage",
".",
"blendColor",
"(",
"c1",
",",
"c2",
",",
"mode",
")",
"end"
] |
Uses PImage class method under hood
|
[
"Uses",
"PImage",
"class",
"method",
"under",
"hood"
] |
3bd44d4e762d0184c714c4641a5cc3a6891aecf7
|
https://github.com/ruby-processing/JRubyArt/blob/3bd44d4e762d0184c714c4641a5cc3a6891aecf7/lib/jruby_art/helper_methods.rb#L112-L114
|
20,473
|
ruby-processing/JRubyArt
|
lib/jruby_art/helper_methods.rb
|
Processing.HelperMethods.find_method
|
def find_method(method_name)
reg = Regexp.new(method_name.to_s, true)
methods.sort.select { |meth| reg.match(meth) }
end
|
ruby
|
def find_method(method_name)
reg = Regexp.new(method_name.to_s, true)
methods.sort.select { |meth| reg.match(meth) }
end
|
[
"def",
"find_method",
"(",
"method_name",
")",
"reg",
"=",
"Regexp",
".",
"new",
"(",
"method_name",
".",
"to_s",
",",
"true",
")",
"methods",
".",
"sort",
".",
"select",
"{",
"|",
"meth",
"|",
"reg",
".",
"match",
"(",
"meth",
")",
"}",
"end"
] |
There's just so many functions in Processing,
Here's a convenient way to look for them.
|
[
"There",
"s",
"just",
"so",
"many",
"functions",
"in",
"Processing",
"Here",
"s",
"a",
"convenient",
"way",
"to",
"look",
"for",
"them",
"."
] |
3bd44d4e762d0184c714c4641a5cc3a6891aecf7
|
https://github.com/ruby-processing/JRubyArt/blob/3bd44d4e762d0184c714c4641a5cc3a6891aecf7/lib/jruby_art/helper_methods.rb#L118-L121
|
20,474
|
ruby-processing/JRubyArt
|
lib/jruby_art/helper_methods.rb
|
Processing.HelperMethods.proxy_java_fields
|
def proxy_java_fields
fields = %w(key frameRate mousePressed keyPressed)
methods = fields.map { |field| java_class.declared_field(field) }
@declared_fields = Hash[fields.zip(methods)]
end
|
ruby
|
def proxy_java_fields
fields = %w(key frameRate mousePressed keyPressed)
methods = fields.map { |field| java_class.declared_field(field) }
@declared_fields = Hash[fields.zip(methods)]
end
|
[
"def",
"proxy_java_fields",
"fields",
"=",
"%w(",
"key",
"frameRate",
"mousePressed",
"keyPressed",
")",
"methods",
"=",
"fields",
".",
"map",
"{",
"|",
"field",
"|",
"java_class",
".",
"declared_field",
"(",
"field",
")",
"}",
"@declared_fields",
"=",
"Hash",
"[",
"fields",
".",
"zip",
"(",
"methods",
")",
"]",
"end"
] |
Proxy over a list of Java declared fields that have the same name as
some methods. Add to this list as needed.
|
[
"Proxy",
"over",
"a",
"list",
"of",
"Java",
"declared",
"fields",
"that",
"have",
"the",
"same",
"name",
"as",
"some",
"methods",
".",
"Add",
"to",
"this",
"list",
"as",
"needed",
"."
] |
3bd44d4e762d0184c714c4641a5cc3a6891aecf7
|
https://github.com/ruby-processing/JRubyArt/blob/3bd44d4e762d0184c714c4641a5cc3a6891aecf7/lib/jruby_art/helper_methods.rb#L125-L129
|
20,475
|
ruby-processing/JRubyArt
|
lib/jruby_art/runner.rb
|
Processing.Runner.execute!
|
def execute!
show_help if options.empty?
show_version if options[:version]
run_sketch if options[:run]
watch_sketch if options[:watch]
live if options[:live]
create if options[:create]
check if options[:check]
install if options[:install]
end
|
ruby
|
def execute!
show_help if options.empty?
show_version if options[:version]
run_sketch if options[:run]
watch_sketch if options[:watch]
live if options[:live]
create if options[:create]
check if options[:check]
install if options[:install]
end
|
[
"def",
"execute!",
"show_help",
"if",
"options",
".",
"empty?",
"show_version",
"if",
"options",
"[",
":version",
"]",
"run_sketch",
"if",
"options",
"[",
":run",
"]",
"watch_sketch",
"if",
"options",
"[",
":watch",
"]",
"live",
"if",
"options",
"[",
":live",
"]",
"create",
"if",
"options",
"[",
":create",
"]",
"check",
"if",
"options",
"[",
":check",
"]",
"install",
"if",
"options",
"[",
":install",
"]",
"end"
] |
Dispatch central.
|
[
"Dispatch",
"central",
"."
] |
3bd44d4e762d0184c714c4641a5cc3a6891aecf7
|
https://github.com/ruby-processing/JRubyArt/blob/3bd44d4e762d0184c714c4641a5cc3a6891aecf7/lib/jruby_art/runner.rb#L38-L47
|
20,476
|
ruby-processing/JRubyArt
|
lib/jruby_art/runner.rb
|
Processing.Runner.parse_options
|
def parse_options(args)
opt_parser = OptionParser.new do |opts|
# Set a banner, displayed at the top
# of the help screen.
opts.banner = 'Usage: k9 [options] [<filename.rb>]'
# Define the options, and what they do
options[:version] = false
opts.on('-v', '--version', 'JRubyArt Version') do
options[:version] = true
end
options[:install] = false
opts.on('-i', '--install', 'Installs jruby-complete and examples') do
options[:install] = true
end
options[:check] = false
opts.on('-?', '--check', 'Prints configuration') do
options[:check] = true
end
options[:app] = false
opts.on('-a', '--app', 'Export as app NOT IMPLEMENTED YET') do
options[:export] = true
end
options[:watch] = false
opts.on('-w', '--watch', 'Watch/run the sketch') do
options[:watch] = true
end
options[:run] = false
opts.on('-r', '--run', 'Run the sketch') do
options[:run] = true
end
options[:live] = false
opts.on('-l', '--live', 'As above, with pry console bound to Processing.app') do
options[:live] = true
end
options[:create] = false
opts.on('-c', '--create', 'Create new outline sketch') do
options[:create] = true
end
# This displays the help screen, all programs are
# assumed to have this option.
opts.on('-h', '--help', 'Display this screen') do
puts opts
exit
end
end
@argc = opt_parser.parse(args)
@filename = argc.shift
end
|
ruby
|
def parse_options(args)
opt_parser = OptionParser.new do |opts|
# Set a banner, displayed at the top
# of the help screen.
opts.banner = 'Usage: k9 [options] [<filename.rb>]'
# Define the options, and what they do
options[:version] = false
opts.on('-v', '--version', 'JRubyArt Version') do
options[:version] = true
end
options[:install] = false
opts.on('-i', '--install', 'Installs jruby-complete and examples') do
options[:install] = true
end
options[:check] = false
opts.on('-?', '--check', 'Prints configuration') do
options[:check] = true
end
options[:app] = false
opts.on('-a', '--app', 'Export as app NOT IMPLEMENTED YET') do
options[:export] = true
end
options[:watch] = false
opts.on('-w', '--watch', 'Watch/run the sketch') do
options[:watch] = true
end
options[:run] = false
opts.on('-r', '--run', 'Run the sketch') do
options[:run] = true
end
options[:live] = false
opts.on('-l', '--live', 'As above, with pry console bound to Processing.app') do
options[:live] = true
end
options[:create] = false
opts.on('-c', '--create', 'Create new outline sketch') do
options[:create] = true
end
# This displays the help screen, all programs are
# assumed to have this option.
opts.on('-h', '--help', 'Display this screen') do
puts opts
exit
end
end
@argc = opt_parser.parse(args)
@filename = argc.shift
end
|
[
"def",
"parse_options",
"(",
"args",
")",
"opt_parser",
"=",
"OptionParser",
".",
"new",
"do",
"|",
"opts",
"|",
"# Set a banner, displayed at the top",
"# of the help screen.",
"opts",
".",
"banner",
"=",
"'Usage: k9 [options] [<filename.rb>]'",
"# Define the options, and what they do",
"options",
"[",
":version",
"]",
"=",
"false",
"opts",
".",
"on",
"(",
"'-v'",
",",
"'--version'",
",",
"'JRubyArt Version'",
")",
"do",
"options",
"[",
":version",
"]",
"=",
"true",
"end",
"options",
"[",
":install",
"]",
"=",
"false",
"opts",
".",
"on",
"(",
"'-i'",
",",
"'--install'",
",",
"'Installs jruby-complete and examples'",
")",
"do",
"options",
"[",
":install",
"]",
"=",
"true",
"end",
"options",
"[",
":check",
"]",
"=",
"false",
"opts",
".",
"on",
"(",
"'-?'",
",",
"'--check'",
",",
"'Prints configuration'",
")",
"do",
"options",
"[",
":check",
"]",
"=",
"true",
"end",
"options",
"[",
":app",
"]",
"=",
"false",
"opts",
".",
"on",
"(",
"'-a'",
",",
"'--app'",
",",
"'Export as app NOT IMPLEMENTED YET'",
")",
"do",
"options",
"[",
":export",
"]",
"=",
"true",
"end",
"options",
"[",
":watch",
"]",
"=",
"false",
"opts",
".",
"on",
"(",
"'-w'",
",",
"'--watch'",
",",
"'Watch/run the sketch'",
")",
"do",
"options",
"[",
":watch",
"]",
"=",
"true",
"end",
"options",
"[",
":run",
"]",
"=",
"false",
"opts",
".",
"on",
"(",
"'-r'",
",",
"'--run'",
",",
"'Run the sketch'",
")",
"do",
"options",
"[",
":run",
"]",
"=",
"true",
"end",
"options",
"[",
":live",
"]",
"=",
"false",
"opts",
".",
"on",
"(",
"'-l'",
",",
"'--live'",
",",
"'As above, with pry console bound to Processing.app'",
")",
"do",
"options",
"[",
":live",
"]",
"=",
"true",
"end",
"options",
"[",
":create",
"]",
"=",
"false",
"opts",
".",
"on",
"(",
"'-c'",
",",
"'--create'",
",",
"'Create new outline sketch'",
")",
"do",
"options",
"[",
":create",
"]",
"=",
"true",
"end",
"# This displays the help screen, all programs are",
"# assumed to have this option.",
"opts",
".",
"on",
"(",
"'-h'",
",",
"'--help'",
",",
"'Display this screen'",
")",
"do",
"puts",
"opts",
"exit",
"end",
"end",
"@argc",
"=",
"opt_parser",
".",
"parse",
"(",
"args",
")",
"@filename",
"=",
"argc",
".",
"shift",
"end"
] |
Parse the command-line options.
|
[
"Parse",
"the",
"command",
"-",
"line",
"options",
"."
] |
3bd44d4e762d0184c714c4641a5cc3a6891aecf7
|
https://github.com/ruby-processing/JRubyArt/blob/3bd44d4e762d0184c714c4641a5cc3a6891aecf7/lib/jruby_art/runner.rb#L50-L105
|
20,477
|
berk/will_filter
|
app/models/will_filter/filter.rb
|
WillFilter.Filter.model_class
|
def model_class
if WillFilter::Config.require_filter_extensions?
raise WillFilter::FilterException.new("model_class method must be overloaded in the extending class.")
end
if model_class_name.blank?
raise WillFilter::FilterException.new("model_class_name was not specified.")
end
@model_class ||= model_class_name.constantize
end
|
ruby
|
def model_class
if WillFilter::Config.require_filter_extensions?
raise WillFilter::FilterException.new("model_class method must be overloaded in the extending class.")
end
if model_class_name.blank?
raise WillFilter::FilterException.new("model_class_name was not specified.")
end
@model_class ||= model_class_name.constantize
end
|
[
"def",
"model_class",
"if",
"WillFilter",
"::",
"Config",
".",
"require_filter_extensions?",
"raise",
"WillFilter",
"::",
"FilterException",
".",
"new",
"(",
"\"model_class method must be overloaded in the extending class.\"",
")",
"end",
"if",
"model_class_name",
".",
"blank?",
"raise",
"WillFilter",
"::",
"FilterException",
".",
"new",
"(",
"\"model_class_name was not specified.\"",
")",
"end",
"@model_class",
"||=",
"model_class_name",
".",
"constantize",
"end"
] |
For extra security, this method must be overloaded by the extending class.
|
[
"For",
"extra",
"security",
"this",
"method",
"must",
"be",
"overloaded",
"by",
"the",
"extending",
"class",
"."
] |
53ff0c925f55c60b879aea8b3c323655dad7ea07
|
https://github.com/berk/will_filter/blob/53ff0c925f55c60b879aea8b3c323655dad7ea07/app/models/will_filter/filter.rb#L134-L144
|
20,478
|
berk/will_filter
|
app/models/will_filter/filter.rb
|
WillFilter.Filter.condition_title_for
|
def condition_title_for(key)
title_parts = key.to_s.split('.')
title = key.to_s.gsub(".", ": ").gsub("_", " ")
title = title.split(" ").collect{|part| part.split("/").last.capitalize}.join(" ")
if title_parts.size > 1
"#{JOIN_NAME_INDICATOR} #{title}"
else
title
end
end
|
ruby
|
def condition_title_for(key)
title_parts = key.to_s.split('.')
title = key.to_s.gsub(".", ": ").gsub("_", " ")
title = title.split(" ").collect{|part| part.split("/").last.capitalize}.join(" ")
if title_parts.size > 1
"#{JOIN_NAME_INDICATOR} #{title}"
else
title
end
end
|
[
"def",
"condition_title_for",
"(",
"key",
")",
"title_parts",
"=",
"key",
".",
"to_s",
".",
"split",
"(",
"'.'",
")",
"title",
"=",
"key",
".",
"to_s",
".",
"gsub",
"(",
"\".\"",
",",
"\": \"",
")",
".",
"gsub",
"(",
"\"_\"",
",",
"\" \"",
")",
"title",
"=",
"title",
".",
"split",
"(",
"\" \"",
")",
".",
"collect",
"{",
"|",
"part",
"|",
"part",
".",
"split",
"(",
"\"/\"",
")",
".",
"last",
".",
"capitalize",
"}",
".",
"join",
"(",
"\" \"",
")",
"if",
"title_parts",
".",
"size",
">",
"1",
"\"#{JOIN_NAME_INDICATOR} #{title}\"",
"else",
"title",
"end",
"end"
] |
Can be overloaded for custom titles
|
[
"Can",
"be",
"overloaded",
"for",
"custom",
"titles"
] |
53ff0c925f55c60b879aea8b3c323655dad7ea07
|
https://github.com/berk/will_filter/blob/53ff0c925f55c60b879aea8b3c323655dad7ea07/app/models/will_filter/filter.rb#L338-L347
|
20,479
|
berk/will_filter
|
app/models/will_filter/filter.rb
|
WillFilter.Filter.export_formats
|
def export_formats
formats = []
formats << ["-- Generic Formats --", -1]
WillFilter::Config.default_export_formats.each do |frmt|
formats << [frmt, frmt]
end
if custom_formats.size > 0
formats << ["-- Custom Formats --", -2]
custom_formats.each do |frmt|
formats << frmt
end
end
formats
end
|
ruby
|
def export_formats
formats = []
formats << ["-- Generic Formats --", -1]
WillFilter::Config.default_export_formats.each do |frmt|
formats << [frmt, frmt]
end
if custom_formats.size > 0
formats << ["-- Custom Formats --", -2]
custom_formats.each do |frmt|
formats << frmt
end
end
formats
end
|
[
"def",
"export_formats",
"formats",
"=",
"[",
"]",
"formats",
"<<",
"[",
"\"-- Generic Formats --\"",
",",
"-",
"1",
"]",
"WillFilter",
"::",
"Config",
".",
"default_export_formats",
".",
"each",
"do",
"|",
"frmt",
"|",
"formats",
"<<",
"[",
"frmt",
",",
"frmt",
"]",
"end",
"if",
"custom_formats",
".",
"size",
">",
"0",
"formats",
"<<",
"[",
"\"-- Custom Formats --\"",
",",
"-",
"2",
"]",
"custom_formats",
".",
"each",
"do",
"|",
"frmt",
"|",
"formats",
"<<",
"frmt",
"end",
"end",
"formats",
"end"
] |
Export Filter Data
|
[
"Export",
"Filter",
"Data"
] |
53ff0c925f55c60b879aea8b3c323655dad7ea07
|
https://github.com/berk/will_filter/blob/53ff0c925f55c60b879aea8b3c323655dad7ea07/app/models/will_filter/filter.rb#L832-L845
|
20,480
|
berk/will_filter
|
app/models/will_filter/filter.rb
|
WillFilter.Filter.joins
|
def joins
return nil if inner_joins.empty?
inner_joins.collect do |inner_join|
join_table_name = association_class(inner_join).table_name
join_on_field = inner_join.last.to_s
"INNER JOIN #{join_table_name} ON #{join_table_name}.id = #{table_name}.#{join_on_field}"
end
end
|
ruby
|
def joins
return nil if inner_joins.empty?
inner_joins.collect do |inner_join|
join_table_name = association_class(inner_join).table_name
join_on_field = inner_join.last.to_s
"INNER JOIN #{join_table_name} ON #{join_table_name}.id = #{table_name}.#{join_on_field}"
end
end
|
[
"def",
"joins",
"return",
"nil",
"if",
"inner_joins",
".",
"empty?",
"inner_joins",
".",
"collect",
"do",
"|",
"inner_join",
"|",
"join_table_name",
"=",
"association_class",
"(",
"inner_join",
")",
".",
"table_name",
"join_on_field",
"=",
"inner_join",
".",
"last",
".",
"to_s",
"\"INNER JOIN #{join_table_name} ON #{join_table_name}.id = #{table_name}.#{join_on_field}\"",
"end",
"end"
] |
deprecated for Rails 3.0 and up
|
[
"deprecated",
"for",
"Rails",
"3",
".",
"0",
"and",
"up"
] |
53ff0c925f55c60b879aea8b3c323655dad7ea07
|
https://github.com/berk/will_filter/blob/53ff0c925f55c60b879aea8b3c323655dad7ea07/app/models/will_filter/filter.rb#L871-L878
|
20,481
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/client.rb
|
Bandwidth.Client.make_request
|
def make_request(method, path, data = {}, api_version = 'v1', api_endpoint = '')
d = camelcase(data)
build_path = lambda {|path| "/#{api_version}" + (if path[0] == "/" then path else "/#{path}" end) }
# A somewhat less ideal solution to the V1/V2 endpoint split
# If no endpoint is defined, use default connection
if api_endpoint.length == 0
create_connection = @create_connection
# Otherwise retrieve (or create if needed) the connection based on the given api_endpoint
else
if not @created_connections.key?(api_endpoint)
new_connection = lambda{||
Faraday.new(api_endpoint) { |faraday|
faraday.basic_auth(@api_token, @api_secret)
faraday.headers['Accept'] = 'application/json'
faraday.headers['User-Agent'] = "ruby-bandwidth/v#{Bandwidth::VERSION}"
@set_adapter.call(faraday)
@configure_connection.call(faraday) if @configure_connection
}
}
@created_connections[api_endpoint] = new_connection
end
create_connection = @created_connections[api_endpoint]
end
connection = create_connection.call()
response = if method == :get || method == :delete
connection.run_request(method, build_path.call(path), nil, nil) do |req|
req.params = d unless d == nil || d.empty?
end
else
connection.run_request(method, build_path.call(path), d.to_json(), {'Content-Type' => 'application/json'})
end
check_response(response)
r = if response.body.strip().size > 0 then symbolize(JSON.parse(response.body)) else {} end
[r, symbolize(response.headers || {})]
end
|
ruby
|
def make_request(method, path, data = {}, api_version = 'v1', api_endpoint = '')
d = camelcase(data)
build_path = lambda {|path| "/#{api_version}" + (if path[0] == "/" then path else "/#{path}" end) }
# A somewhat less ideal solution to the V1/V2 endpoint split
# If no endpoint is defined, use default connection
if api_endpoint.length == 0
create_connection = @create_connection
# Otherwise retrieve (or create if needed) the connection based on the given api_endpoint
else
if not @created_connections.key?(api_endpoint)
new_connection = lambda{||
Faraday.new(api_endpoint) { |faraday|
faraday.basic_auth(@api_token, @api_secret)
faraday.headers['Accept'] = 'application/json'
faraday.headers['User-Agent'] = "ruby-bandwidth/v#{Bandwidth::VERSION}"
@set_adapter.call(faraday)
@configure_connection.call(faraday) if @configure_connection
}
}
@created_connections[api_endpoint] = new_connection
end
create_connection = @created_connections[api_endpoint]
end
connection = create_connection.call()
response = if method == :get || method == :delete
connection.run_request(method, build_path.call(path), nil, nil) do |req|
req.params = d unless d == nil || d.empty?
end
else
connection.run_request(method, build_path.call(path), d.to_json(), {'Content-Type' => 'application/json'})
end
check_response(response)
r = if response.body.strip().size > 0 then symbolize(JSON.parse(response.body)) else {} end
[r, symbolize(response.headers || {})]
end
|
[
"def",
"make_request",
"(",
"method",
",",
"path",
",",
"data",
"=",
"{",
"}",
",",
"api_version",
"=",
"'v1'",
",",
"api_endpoint",
"=",
"''",
")",
"d",
"=",
"camelcase",
"(",
"data",
")",
"build_path",
"=",
"lambda",
"{",
"|",
"path",
"|",
"\"/#{api_version}\"",
"+",
"(",
"if",
"path",
"[",
"0",
"]",
"==",
"\"/\"",
"then",
"path",
"else",
"\"/#{path}\"",
"end",
")",
"}",
"# A somewhat less ideal solution to the V1/V2 endpoint split",
"# If no endpoint is defined, use default connection",
"if",
"api_endpoint",
".",
"length",
"==",
"0",
"create_connection",
"=",
"@create_connection",
"# Otherwise retrieve (or create if needed) the connection based on the given api_endpoint",
"else",
"if",
"not",
"@created_connections",
".",
"key?",
"(",
"api_endpoint",
")",
"new_connection",
"=",
"lambda",
"{",
"|",
"|",
"Faraday",
".",
"new",
"(",
"api_endpoint",
")",
"{",
"|",
"faraday",
"|",
"faraday",
".",
"basic_auth",
"(",
"@api_token",
",",
"@api_secret",
")",
"faraday",
".",
"headers",
"[",
"'Accept'",
"]",
"=",
"'application/json'",
"faraday",
".",
"headers",
"[",
"'User-Agent'",
"]",
"=",
"\"ruby-bandwidth/v#{Bandwidth::VERSION}\"",
"@set_adapter",
".",
"call",
"(",
"faraday",
")",
"@configure_connection",
".",
"call",
"(",
"faraday",
")",
"if",
"@configure_connection",
"}",
"}",
"@created_connections",
"[",
"api_endpoint",
"]",
"=",
"new_connection",
"end",
"create_connection",
"=",
"@created_connections",
"[",
"api_endpoint",
"]",
"end",
"connection",
"=",
"create_connection",
".",
"call",
"(",
")",
"response",
"=",
"if",
"method",
"==",
":get",
"||",
"method",
"==",
":delete",
"connection",
".",
"run_request",
"(",
"method",
",",
"build_path",
".",
"call",
"(",
"path",
")",
",",
"nil",
",",
"nil",
")",
"do",
"|",
"req",
"|",
"req",
".",
"params",
"=",
"d",
"unless",
"d",
"==",
"nil",
"||",
"d",
".",
"empty?",
"end",
"else",
"connection",
".",
"run_request",
"(",
"method",
",",
"build_path",
".",
"call",
"(",
"path",
")",
",",
"d",
".",
"to_json",
"(",
")",
",",
"{",
"'Content-Type'",
"=>",
"'application/json'",
"}",
")",
"end",
"check_response",
"(",
"response",
")",
"r",
"=",
"if",
"response",
".",
"body",
".",
"strip",
"(",
")",
".",
"size",
">",
"0",
"then",
"symbolize",
"(",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
")",
"else",
"{",
"}",
"end",
"[",
"r",
",",
"symbolize",
"(",
"response",
".",
"headers",
"||",
"{",
"}",
")",
"]",
"end"
] |
Make HTTP request to Catapult API
@param method [Symbol] http method to make
@param path [String] path of url (exclude api verion and endpoint) to make call
@param data [Hash] data which will be sent with request (for :get and :delete request they will be sent with query in url)
@return [Array] array with 2 elements: parsed json data of response and response headers
|
[
"Make",
"HTTP",
"request",
"to",
"Catapult",
"API"
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/client.rb#L89-L125
|
20,482
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/client.rb
|
Bandwidth.Client.check_response
|
def check_response(response)
if response.status >= 400
parsed_body = JSON.parse(response.body)
raise Errors::GenericError.new(parsed_body['code'], parsed_body['message'])
end
end
|
ruby
|
def check_response(response)
if response.status >= 400
parsed_body = JSON.parse(response.body)
raise Errors::GenericError.new(parsed_body['code'], parsed_body['message'])
end
end
|
[
"def",
"check_response",
"(",
"response",
")",
"if",
"response",
".",
"status",
">=",
"400",
"parsed_body",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"raise",
"Errors",
"::",
"GenericError",
".",
"new",
"(",
"parsed_body",
"[",
"'code'",
"]",
",",
"parsed_body",
"[",
"'message'",
"]",
")",
"end",
"end"
] |
Check response object and raise error if status code >= 400
@param response response object
|
[
"Check",
"response",
"object",
"and",
"raise",
"error",
"if",
"status",
"code",
">",
"=",
"400"
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/client.rb#L129-L134
|
20,483
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/client.rb
|
Bandwidth.Client.camelcase
|
def camelcase v
case
when v.is_a?(Array)
v.map {|i| camelcase(i)}
when v.is_a?(Hash)
result = {}
v.each do |k, val|
result[k.to_s().camelcase(:lower)] = camelcase(val)
end
result
else
v
end
end
|
ruby
|
def camelcase v
case
when v.is_a?(Array)
v.map {|i| camelcase(i)}
when v.is_a?(Hash)
result = {}
v.each do |k, val|
result[k.to_s().camelcase(:lower)] = camelcase(val)
end
result
else
v
end
end
|
[
"def",
"camelcase",
"v",
"case",
"when",
"v",
".",
"is_a?",
"(",
"Array",
")",
"v",
".",
"map",
"{",
"|",
"i",
"|",
"camelcase",
"(",
"i",
")",
"}",
"when",
"v",
".",
"is_a?",
"(",
"Hash",
")",
"result",
"=",
"{",
"}",
"v",
".",
"each",
"do",
"|",
"k",
",",
"val",
"|",
"result",
"[",
"k",
".",
"to_s",
"(",
")",
".",
"camelcase",
"(",
":lower",
")",
"]",
"=",
"camelcase",
"(",
"val",
")",
"end",
"result",
"else",
"v",
"end",
"end"
] |
Convert all keys of a hash to camel cased strings
|
[
"Convert",
"all",
"keys",
"of",
"a",
"hash",
"to",
"camel",
"cased",
"strings"
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/client.rb#L150-L163
|
20,484
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/client.rb
|
Bandwidth.Client.symbolize
|
def symbolize v
case
when v.is_a?(Array)
v.map {|i| symbolize(i)}
when v.is_a?(Hash)
result = {}
v.each do |k, val|
result[k.underscore().to_sym()] = symbolize(val)
end
result
else
v
end
end
|
ruby
|
def symbolize v
case
when v.is_a?(Array)
v.map {|i| symbolize(i)}
when v.is_a?(Hash)
result = {}
v.each do |k, val|
result[k.underscore().to_sym()] = symbolize(val)
end
result
else
v
end
end
|
[
"def",
"symbolize",
"v",
"case",
"when",
"v",
".",
"is_a?",
"(",
"Array",
")",
"v",
".",
"map",
"{",
"|",
"i",
"|",
"symbolize",
"(",
"i",
")",
"}",
"when",
"v",
".",
"is_a?",
"(",
"Hash",
")",
"result",
"=",
"{",
"}",
"v",
".",
"each",
"do",
"|",
"k",
",",
"val",
"|",
"result",
"[",
"k",
".",
"underscore",
"(",
")",
".",
"to_sym",
"(",
")",
"]",
"=",
"symbolize",
"(",
"val",
")",
"end",
"result",
"else",
"v",
"end",
"end"
] |
Convert all keys of hash to underscored symbols
|
[
"Convert",
"all",
"keys",
"of",
"hash",
"to",
"underscored",
"symbols"
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/client.rb#L166-L179
|
20,485
|
superp/rails-uploader
|
lib/uploader/asset.rb
|
Uploader.Asset.to_fileupload
|
def to_fileupload
{
id: id,
name: filename,
content_type: content_type,
size: size,
url: url,
thumb_url: thumb_url
}
end
|
ruby
|
def to_fileupload
{
id: id,
name: filename,
content_type: content_type,
size: size,
url: url,
thumb_url: thumb_url
}
end
|
[
"def",
"to_fileupload",
"{",
"id",
":",
"id",
",",
"name",
":",
"filename",
",",
"content_type",
":",
"content_type",
",",
"size",
":",
"size",
",",
"url",
":",
"url",
",",
"thumb_url",
":",
"thumb_url",
"}",
"end"
] |
Serialize asset to fileupload JSON format
|
[
"Serialize",
"asset",
"to",
"fileupload",
"JSON",
"format"
] |
5a37278ce77292d65b790995d2b4613688b8d7f1
|
https://github.com/superp/rails-uploader/blob/5a37278ce77292d65b790995d2b4613688b8d7f1/lib/uploader/asset.rb#L79-L88
|
20,486
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/recording.rb
|
Bandwidth.Recording.create_transcription
|
def create_transcription()
headers = @client.make_request(:post, @client.concat_user_path("#{RECORDING_PATH}/#{id}/transcriptions"), {})[1]
id = Client.get_id_from_location_header(headers[:location])
get_transcription(id)
end
|
ruby
|
def create_transcription()
headers = @client.make_request(:post, @client.concat_user_path("#{RECORDING_PATH}/#{id}/transcriptions"), {})[1]
id = Client.get_id_from_location_header(headers[:location])
get_transcription(id)
end
|
[
"def",
"create_transcription",
"(",
")",
"headers",
"=",
"@client",
".",
"make_request",
"(",
":post",
",",
"@client",
".",
"concat_user_path",
"(",
"\"#{RECORDING_PATH}/#{id}/transcriptions\"",
")",
",",
"{",
"}",
")",
"[",
"1",
"]",
"id",
"=",
"Client",
".",
"get_id_from_location_header",
"(",
"headers",
"[",
":location",
"]",
")",
"get_transcription",
"(",
"id",
")",
"end"
] |
Request the transcription process to be started for the given recording id.
@return [Hash] created transcription
@example
transcription = recording.create_transcription()
|
[
"Request",
"the",
"transcription",
"process",
"to",
"be",
"started",
"for",
"the",
"given",
"recording",
"id",
"."
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/recording.rb#L38-L42
|
20,487
|
superp/rails-uploader
|
lib/uploader/authorization.rb
|
Uploader.Authorization.uploader_authorization_adapter
|
def uploader_authorization_adapter
adapter = Uploader.authorization_adapter
if adapter.is_a? String
ActiveSupport::Dependencies.constantize(adapter)
else
adapter
end
end
|
ruby
|
def uploader_authorization_adapter
adapter = Uploader.authorization_adapter
if adapter.is_a? String
ActiveSupport::Dependencies.constantize(adapter)
else
adapter
end
end
|
[
"def",
"uploader_authorization_adapter",
"adapter",
"=",
"Uploader",
".",
"authorization_adapter",
"if",
"adapter",
".",
"is_a?",
"String",
"ActiveSupport",
"::",
"Dependencies",
".",
"constantize",
"(",
"adapter",
")",
"else",
"adapter",
"end",
"end"
] |
Returns the class to be used as the authorization adapter
|
[
"Returns",
"the",
"class",
"to",
"be",
"used",
"as",
"the",
"authorization",
"adapter"
] |
5a37278ce77292d65b790995d2b4613688b8d7f1
|
https://github.com/superp/rails-uploader/blob/5a37278ce77292d65b790995d2b4613688b8d7f1/lib/uploader/authorization.rb#L36-L44
|
20,488
|
superp/rails-uploader
|
lib/uploader/fileupload_glue.rb
|
Uploader.FileuploadGlue.multiple?
|
def multiple?(method_name)
return false if association(method_name).nil?
name = association(method_name).respond_to?(:many?) ? :many? : :collection?
association(method_name).send(name)
end
|
ruby
|
def multiple?(method_name)
return false if association(method_name).nil?
name = association(method_name).respond_to?(:many?) ? :many? : :collection?
association(method_name).send(name)
end
|
[
"def",
"multiple?",
"(",
"method_name",
")",
"return",
"false",
"if",
"association",
"(",
"method_name",
")",
".",
"nil?",
"name",
"=",
"association",
"(",
"method_name",
")",
".",
"respond_to?",
"(",
":many?",
")",
"?",
":many?",
":",
":collection?",
"association",
"(",
"method_name",
")",
".",
"send",
"(",
"name",
")",
"end"
] |
many? for Mongoid and collection? for AR
|
[
"many?",
"for",
"Mongoid",
"and",
"collection?",
"for",
"AR"
] |
5a37278ce77292d65b790995d2b4613688b8d7f1
|
https://github.com/superp/rails-uploader/blob/5a37278ce77292d65b790995d2b4613688b8d7f1/lib/uploader/fileupload_glue.rb#L58-L63
|
20,489
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/conference.rb
|
Bandwidth.Conference.create_member
|
def create_member(data)
headers = @client.make_request(:post, @client.concat_user_path("#{CONFERENCE_PATH}/#{id}/members"), data)[1]
id = Client.get_id_from_location_header(headers[:location])
get_member(id)
end
|
ruby
|
def create_member(data)
headers = @client.make_request(:post, @client.concat_user_path("#{CONFERENCE_PATH}/#{id}/members"), data)[1]
id = Client.get_id_from_location_header(headers[:location])
get_member(id)
end
|
[
"def",
"create_member",
"(",
"data",
")",
"headers",
"=",
"@client",
".",
"make_request",
"(",
":post",
",",
"@client",
".",
"concat_user_path",
"(",
"\"#{CONFERENCE_PATH}/#{id}/members\"",
")",
",",
"data",
")",
"[",
"1",
"]",
"id",
"=",
"Client",
".",
"get_id_from_location_header",
"(",
"headers",
"[",
":location",
"]",
")",
"get_member",
"(",
"id",
")",
"end"
] |
Add a member to a conference.
@param data [Hash] data to add member to a conference
@return [ConferenceMember] created member
@example
member = conference.create_member(:call_id=>"id")
|
[
"Add",
"a",
"member",
"to",
"a",
"conference",
"."
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/conference.rb#L65-L69
|
20,490
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/conference.rb
|
Bandwidth.Conference.get_member
|
def get_member(member_id)
member = ConferenceMember.new(@client.make_request(:get, @client.concat_user_path("#{CONFERENCE_PATH}/#{id}/members/#{member_id}"))[0],
@client)
member.conference_id = id
member
end
|
ruby
|
def get_member(member_id)
member = ConferenceMember.new(@client.make_request(:get, @client.concat_user_path("#{CONFERENCE_PATH}/#{id}/members/#{member_id}"))[0],
@client)
member.conference_id = id
member
end
|
[
"def",
"get_member",
"(",
"member_id",
")",
"member",
"=",
"ConferenceMember",
".",
"new",
"(",
"@client",
".",
"make_request",
"(",
":get",
",",
"@client",
".",
"concat_user_path",
"(",
"\"#{CONFERENCE_PATH}/#{id}/members/#{member_id}\"",
")",
")",
"[",
"0",
"]",
",",
"@client",
")",
"member",
".",
"conference_id",
"=",
"id",
"member",
"end"
] |
Retrieve information about a particular conference member
@param member_id [String] id of member
@return [ConferenceMember] member information
@example
member = conference.get_member("id")
|
[
"Retrieve",
"information",
"about",
"a",
"particular",
"conference",
"member"
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/conference.rb#L76-L81
|
20,491
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/conference.rb
|
Bandwidth.Conference.get_members
|
def get_members()
@client.make_request(:get, @client.concat_user_path("#{CONFERENCE_PATH}/#{id}/members"))[0].map do |i|
member = ConferenceMember.new(i, @client)
member.conference_id = id
member
end
end
|
ruby
|
def get_members()
@client.make_request(:get, @client.concat_user_path("#{CONFERENCE_PATH}/#{id}/members"))[0].map do |i|
member = ConferenceMember.new(i, @client)
member.conference_id = id
member
end
end
|
[
"def",
"get_members",
"(",
")",
"@client",
".",
"make_request",
"(",
":get",
",",
"@client",
".",
"concat_user_path",
"(",
"\"#{CONFERENCE_PATH}/#{id}/members\"",
")",
")",
"[",
"0",
"]",
".",
"map",
"do",
"|",
"i",
"|",
"member",
"=",
"ConferenceMember",
".",
"new",
"(",
"i",
",",
"@client",
")",
"member",
".",
"conference_id",
"=",
"id",
"member",
"end",
"end"
] |
List all members from a conference
@return [Array] array of ConferenceMember instances
@example
members = conference.get_members()
|
[
"List",
"all",
"members",
"from",
"a",
"conference"
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/conference.rb#L87-L93
|
20,492
|
jabbrwcky/prawn-qrcode
|
lib/prawn/qrcode.rb
|
Prawn.QRCode.print_qr_code
|
def print_qr_code(content, level: :m, dot: DEFAULT_DOTSIZE, pos: [0,cursor], stroke: true, margin: 4, **options)
qr_version = 0
dot_size = dot
begin
qr_version += 1
qr_code = RQRCode::QRCode.new(content, size: qr_version, level: level)
dot = options[:extent] / (2*margin + qr_code.modules.length) if options[:extent]
render_qr_code(qr_code, dot: dot, pos: pos, stroke: stroke, margin: margin, **options)
rescue RQRCode::QRCodeRunTimeError
if qr_version < 40
retry
else
raise
end
end
end
|
ruby
|
def print_qr_code(content, level: :m, dot: DEFAULT_DOTSIZE, pos: [0,cursor], stroke: true, margin: 4, **options)
qr_version = 0
dot_size = dot
begin
qr_version += 1
qr_code = RQRCode::QRCode.new(content, size: qr_version, level: level)
dot = options[:extent] / (2*margin + qr_code.modules.length) if options[:extent]
render_qr_code(qr_code, dot: dot, pos: pos, stroke: stroke, margin: margin, **options)
rescue RQRCode::QRCodeRunTimeError
if qr_version < 40
retry
else
raise
end
end
end
|
[
"def",
"print_qr_code",
"(",
"content",
",",
"level",
":",
":m",
",",
"dot",
":",
"DEFAULT_DOTSIZE",
",",
"pos",
":",
"[",
"0",
",",
"cursor",
"]",
",",
"stroke",
":",
"true",
",",
"margin",
":",
"4",
",",
"**",
"options",
")",
"qr_version",
"=",
"0",
"dot_size",
"=",
"dot",
"begin",
"qr_version",
"+=",
"1",
"qr_code",
"=",
"RQRCode",
"::",
"QRCode",
".",
"new",
"(",
"content",
",",
"size",
":",
"qr_version",
",",
"level",
":",
"level",
")",
"dot",
"=",
"options",
"[",
":extent",
"]",
"/",
"(",
"2",
"*",
"margin",
"+",
"qr_code",
".",
"modules",
".",
"length",
")",
"if",
"options",
"[",
":extent",
"]",
"render_qr_code",
"(",
"qr_code",
",",
"dot",
":",
"dot",
",",
"pos",
":",
"pos",
",",
"stroke",
":",
"stroke",
",",
"margin",
":",
"margin",
",",
"**",
"options",
")",
"rescue",
"RQRCode",
"::",
"QRCodeRunTimeError",
"if",
"qr_version",
"<",
"40",
"retry",
"else",
"raise",
"end",
"end",
"end"
] |
Prints a QR Code to the PDF document. The QR Code creation happens on the fly.
content:: The string to render as content of the QR Code
*options:: Named optional parameters
+:level+:: Error correction level to use. One of: (:l,:m,:h,:q), Defaults to :m
+:extent+:: Size of QR Code given in pt (1 pt == 1/72 in)
+:pos+:: Two-element array containing the position at which the QR-Code should be rendered. Defaults to [0,cursor]
+:dot+:: Size of QR Code module/dot. Calculated from extent or defaulting to 1pt
+:stroke+:: boolean value whether to draw bounds around the QR Code.
Defaults to true.
+:margin+:: Size of margin around code in QR-Code modules/dots, Default to 4
+:align+:: Optional alignment within the current bounding box. Valid values are :left, :right, and :center. If set
This option overrides the horizontal positioning specified in :pos. Defaults to nil.
+:debug+:: Optional boolean, renders a coordinate grid around the QRCode if true (uses Prawn#stroke_axis)
|
[
"Prints",
"a",
"QR",
"Code",
"to",
"the",
"PDF",
"document",
".",
"The",
"QR",
"Code",
"creation",
"happens",
"on",
"the",
"fly",
"."
] |
8616dda00cd1f4ef296e283e53793edb3f56bb1f
|
https://github.com/jabbrwcky/prawn-qrcode/blob/8616dda00cd1f4ef296e283e53793edb3f56bb1f/lib/prawn/qrcode.rb#L50-L67
|
20,493
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/domain.rb
|
Bandwidth.Domain.create_endpoint
|
def create_endpoint(data)
headers = @client.make_request(:post, @client.concat_user_path("#{DOMAIN_PATH}/#{id}/endpoints"), data)[1]
id = Client.get_id_from_location_header(headers[:location])
get_endpoint(id)
end
|
ruby
|
def create_endpoint(data)
headers = @client.make_request(:post, @client.concat_user_path("#{DOMAIN_PATH}/#{id}/endpoints"), data)[1]
id = Client.get_id_from_location_header(headers[:location])
get_endpoint(id)
end
|
[
"def",
"create_endpoint",
"(",
"data",
")",
"headers",
"=",
"@client",
".",
"make_request",
"(",
":post",
",",
"@client",
".",
"concat_user_path",
"(",
"\"#{DOMAIN_PATH}/#{id}/endpoints\"",
")",
",",
"data",
")",
"[",
"1",
"]",
"id",
"=",
"Client",
".",
"get_id_from_location_header",
"(",
"headers",
"[",
":location",
"]",
")",
"get_endpoint",
"(",
"id",
")",
"end"
] |
Add a endpoint to a domain.
@param data [Hash] data to add endpoint to a domain
@return [EndPoint] created endpoint
@example
endpoint = domain.create_endpoint(:name=>"name", :application_id => "id")
|
[
"Add",
"a",
"endpoint",
"to",
"a",
"domain",
"."
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/domain.rb#L47-L51
|
20,494
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/domain.rb
|
Bandwidth.Domain.get_endpoint
|
def get_endpoint(endpoint_id)
endpoint = EndPoint.new(@client.make_request(:get, @client.concat_user_path("#{DOMAIN_PATH}/#{id}/endpoints/#{endpoint_id}"))[0],
@client)
endpoint.domain_id = id
endpoint
end
|
ruby
|
def get_endpoint(endpoint_id)
endpoint = EndPoint.new(@client.make_request(:get, @client.concat_user_path("#{DOMAIN_PATH}/#{id}/endpoints/#{endpoint_id}"))[0],
@client)
endpoint.domain_id = id
endpoint
end
|
[
"def",
"get_endpoint",
"(",
"endpoint_id",
")",
"endpoint",
"=",
"EndPoint",
".",
"new",
"(",
"@client",
".",
"make_request",
"(",
":get",
",",
"@client",
".",
"concat_user_path",
"(",
"\"#{DOMAIN_PATH}/#{id}/endpoints/#{endpoint_id}\"",
")",
")",
"[",
"0",
"]",
",",
"@client",
")",
"endpoint",
".",
"domain_id",
"=",
"id",
"endpoint",
"end"
] |
Retrieve information about an endpoint
@param endpoint_id [String] id of endpoint
@return [EndPoint] endpoint information
@example
endpoint = domain.get_endpoint("id")
|
[
"Retrieve",
"information",
"about",
"an",
"endpoint"
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/domain.rb#L58-L63
|
20,495
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/domain.rb
|
Bandwidth.Domain.get_endpoints
|
def get_endpoints(query = nil)
@client.make_request(:get, @client.concat_user_path("#{DOMAIN_PATH}/#{id}/endpoints"), query)[0].map do |i|
endpoint = EndPoint.new(i, @client)
endpoint.domain_id = id
endpoint
end
end
|
ruby
|
def get_endpoints(query = nil)
@client.make_request(:get, @client.concat_user_path("#{DOMAIN_PATH}/#{id}/endpoints"), query)[0].map do |i|
endpoint = EndPoint.new(i, @client)
endpoint.domain_id = id
endpoint
end
end
|
[
"def",
"get_endpoints",
"(",
"query",
"=",
"nil",
")",
"@client",
".",
"make_request",
"(",
":get",
",",
"@client",
".",
"concat_user_path",
"(",
"\"#{DOMAIN_PATH}/#{id}/endpoints\"",
")",
",",
"query",
")",
"[",
"0",
"]",
".",
"map",
"do",
"|",
"i",
"|",
"endpoint",
"=",
"EndPoint",
".",
"new",
"(",
"i",
",",
"@client",
")",
"endpoint",
".",
"domain_id",
"=",
"id",
"endpoint",
"end",
"end"
] |
List all endpoints from a domain
@return [Array] array of EndPoint instances
@example
endpoints = domain.get_endpoints()
|
[
"List",
"all",
"endpoints",
"from",
"a",
"domain"
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/domain.rb#L69-L75
|
20,496
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/domain.rb
|
Bandwidth.Domain.delete_endpoint
|
def delete_endpoint(endpoint_id)
endpoint = EndPoint.new({:id => endpoint_id}, @client)
endpoint.domain_id = id
endpoint.delete()
end
|
ruby
|
def delete_endpoint(endpoint_id)
endpoint = EndPoint.new({:id => endpoint_id}, @client)
endpoint.domain_id = id
endpoint.delete()
end
|
[
"def",
"delete_endpoint",
"(",
"endpoint_id",
")",
"endpoint",
"=",
"EndPoint",
".",
"new",
"(",
"{",
":id",
"=>",
"endpoint_id",
"}",
",",
"@client",
")",
"endpoint",
".",
"domain_id",
"=",
"id",
"endpoint",
".",
"delete",
"(",
")",
"end"
] |
Delete an endpoint
@example
domain.delete_endpoint("id")
|
[
"Delete",
"an",
"endpoint"
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/domain.rb#L80-L84
|
20,497
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/call.rb
|
Bandwidth.Call.create_gather
|
def create_gather(data)
d = if data.is_a?(String)
{
:tag => id, :max_digits => 1,
:prompt => {:locale => 'en_US', :gender => 'female', :sentence => data, :voice => 'kate', :bargeable => true }
}
else
data
end
headers = @client.make_request(:post, @client.concat_user_path("#{CALL_PATH}/#{id}/gather"), d)[1]
id = Client.get_id_from_location_header(headers[:location])
get_gather(id)
end
|
ruby
|
def create_gather(data)
d = if data.is_a?(String)
{
:tag => id, :max_digits => 1,
:prompt => {:locale => 'en_US', :gender => 'female', :sentence => data, :voice => 'kate', :bargeable => true }
}
else
data
end
headers = @client.make_request(:post, @client.concat_user_path("#{CALL_PATH}/#{id}/gather"), d)[1]
id = Client.get_id_from_location_header(headers[:location])
get_gather(id)
end
|
[
"def",
"create_gather",
"(",
"data",
")",
"d",
"=",
"if",
"data",
".",
"is_a?",
"(",
"String",
")",
"{",
":tag",
"=>",
"id",
",",
":max_digits",
"=>",
"1",
",",
":prompt",
"=>",
"{",
":locale",
"=>",
"'en_US'",
",",
":gender",
"=>",
"'female'",
",",
":sentence",
"=>",
"data",
",",
":voice",
"=>",
"'kate'",
",",
":bargeable",
"=>",
"true",
"}",
"}",
"else",
"data",
"end",
"headers",
"=",
"@client",
".",
"make_request",
"(",
":post",
",",
"@client",
".",
"concat_user_path",
"(",
"\"#{CALL_PATH}/#{id}/gather\"",
")",
",",
"d",
")",
"[",
"1",
"]",
"id",
"=",
"Client",
".",
"get_id_from_location_header",
"(",
"headers",
"[",
":location",
"]",
")",
"get_gather",
"(",
"id",
")",
"end"
] |
Gather the DTMF digits pressed
@param data [String|Hash] sentence to speak on creating cather if string, otherwise it is hash with gather options
@return [Hash] created gather
@example
gather = call.create_gather("Press a digit")
gather = call.create_gather(:max_digits => 1, :prompt => {:sentence => "Press a digit", :bargeable => true })
|
[
"Gather",
"the",
"DTMF",
"digits",
"pressed"
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/call.rb#L81-L93
|
20,498
|
Bandwidth/ruby-bandwidth
|
lib/bandwidth/play_audio_extensions.rb
|
Bandwidth.PlayAudioExtensions.speak_sentence
|
def speak_sentence(sentence, tag = nil, gender = "female", voice = "kate")
play_audio({:gender => gender || "female", :locale => "en_US",
:voice => voice || "kate", :sentence => sentence, :tag => tag})
end
|
ruby
|
def speak_sentence(sentence, tag = nil, gender = "female", voice = "kate")
play_audio({:gender => gender || "female", :locale => "en_US",
:voice => voice || "kate", :sentence => sentence, :tag => tag})
end
|
[
"def",
"speak_sentence",
"(",
"sentence",
",",
"tag",
"=",
"nil",
",",
"gender",
"=",
"\"female\"",
",",
"voice",
"=",
"\"kate\"",
")",
"play_audio",
"(",
"{",
":gender",
"=>",
"gender",
"||",
"\"female\"",
",",
":locale",
"=>",
"\"en_US\"",
",",
":voice",
"=>",
"voice",
"||",
"\"kate\"",
",",
":sentence",
"=>",
"sentence",
",",
":tag",
"=>",
"tag",
"}",
")",
"end"
] |
Speak a sentence
@param sentence [String[ sentence to speak
@param tag [String] optional tag value
@param gender [String] optional gender of voice
@param voice [String] optional voice name
|
[
"Speak",
"a",
"sentence"
] |
896df7a12e2992b5558514db943997d930ef416f
|
https://github.com/Bandwidth/ruby-bandwidth/blob/896df7a12e2992b5558514db943997d930ef416f/lib/bandwidth/play_audio_extensions.rb#L9-L12
|
20,499
|
projecttacoma/cqm-parsers
|
lib/hqmf-parser/cql/document.rb
|
HQMF2CQL.Document.extract_criteria
|
def extract_criteria
# Grab each data criteria entry from the HQMF
extracted_data_criteria = []
@doc.xpath('cda:QualityMeasureDocument/cda:component/cda:dataCriteriaSection/cda:entry', NAMESPACES).each do |entry|
extracted_data_criteria << entry
dc = HQMF2CQL::DataCriteria.new(entry) # Create new data criteria
sdc = dc.clone # Clone data criteria
sdc.id += '_source' # Make it a source
@data_criteria << dc
@source_data_criteria << sdc
end
make_positive_entry
end
|
ruby
|
def extract_criteria
# Grab each data criteria entry from the HQMF
extracted_data_criteria = []
@doc.xpath('cda:QualityMeasureDocument/cda:component/cda:dataCriteriaSection/cda:entry', NAMESPACES).each do |entry|
extracted_data_criteria << entry
dc = HQMF2CQL::DataCriteria.new(entry) # Create new data criteria
sdc = dc.clone # Clone data criteria
sdc.id += '_source' # Make it a source
@data_criteria << dc
@source_data_criteria << sdc
end
make_positive_entry
end
|
[
"def",
"extract_criteria",
"# Grab each data criteria entry from the HQMF",
"extracted_data_criteria",
"=",
"[",
"]",
"@doc",
".",
"xpath",
"(",
"'cda:QualityMeasureDocument/cda:component/cda:dataCriteriaSection/cda:entry'",
",",
"NAMESPACES",
")",
".",
"each",
"do",
"|",
"entry",
"|",
"extracted_data_criteria",
"<<",
"entry",
"dc",
"=",
"HQMF2CQL",
"::",
"DataCriteria",
".",
"new",
"(",
"entry",
")",
"# Create new data criteria",
"sdc",
"=",
"dc",
".",
"clone",
"# Clone data criteria",
"sdc",
".",
"id",
"+=",
"'_source'",
"# Make it a source",
"@data_criteria",
"<<",
"dc",
"@source_data_criteria",
"<<",
"sdc",
"end",
"make_positive_entry",
"end"
] |
Extracts data criteria from the HQMF document.
|
[
"Extracts",
"data",
"criteria",
"from",
"the",
"HQMF",
"document",
"."
] |
8ac8a7afcf299def0e652286dce06a7bd8c1de94
|
https://github.com/projecttacoma/cqm-parsers/blob/8ac8a7afcf299def0e652286dce06a7bd8c1de94/lib/hqmf-parser/cql/document.rb#L33-L46
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.