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
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
ryanlecompte/redis_failover | lib/redis_failover/node_manager.rb | RedisFailover.NodeManager.create_path | def create_path(path, options = {})
unless @zk.exists?(path)
@zk.create(path,
options[:initial_value],
:ephemeral => options.fetch(:ephemeral, false))
logger.info("Created ZK node #{path}")
end
rescue ZK::Exceptions::NodeExists
# best effort
end | ruby | def create_path(path, options = {})
unless @zk.exists?(path)
@zk.create(path,
options[:initial_value],
:ephemeral => options.fetch(:ephemeral, false))
logger.info("Created ZK node #{path}")
end
rescue ZK::Exceptions::NodeExists
# best effort
end | [
"def",
"create_path",
"(",
"path",
",",
"options",
"=",
"{",
"}",
")",
"unless",
"@zk",
".",
"exists?",
"(",
"path",
")",
"@zk",
".",
"create",
"(",
"path",
",",
"options",
"[",
":initial_value",
"]",
",",
":ephemeral",
"=>",
"options",
".",
"fetch",
"(",
":ephemeral",
",",
"false",
")",
")",
"logger",
".",
"info",
"(",
"\"Created ZK node #{path}\"",
")",
"end",
"rescue",
"ZK",
"::",
"Exceptions",
"::",
"NodeExists",
"end"
]
| Creates a znode path.
@param [String] path the znode path to create
@param [Hash] options the options used to create the path
@option options [String] :initial_value an initial value for the znode
@option options [Boolean] :ephemeral true if node is ephemeral, false otherwise | [
"Creates",
"a",
"znode",
"path",
"."
]
| be1208240b9b817fb0288edc7535e3f445f767cd | https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L388-L397 | train |
ryanlecompte/redis_failover | lib/redis_failover/node_manager.rb | RedisFailover.NodeManager.write_state | def write_state(path, value, options = {})
create_path(path, options.merge(:initial_value => value))
@zk.set(path, value)
end | ruby | def write_state(path, value, options = {})
create_path(path, options.merge(:initial_value => value))
@zk.set(path, value)
end | [
"def",
"write_state",
"(",
"path",
",",
"value",
",",
"options",
"=",
"{",
"}",
")",
"create_path",
"(",
"path",
",",
"options",
".",
"merge",
"(",
":initial_value",
"=>",
"value",
")",
")",
"@zk",
".",
"set",
"(",
"path",
",",
"value",
")",
"end"
]
| Writes state to a particular znode path.
@param [String] path the znode path that should be written to
@param [String] value the value to write to the znode
@param [Hash] options the default options to be used when creating the node
@note the path will be created if it doesn't exist | [
"Writes",
"state",
"to",
"a",
"particular",
"znode",
"path",
"."
]
| be1208240b9b817fb0288edc7535e3f445f767cd | https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L405-L408 | train |
ryanlecompte/redis_failover | lib/redis_failover/node_manager.rb | RedisFailover.NodeManager.handle_manual_failover_update | def handle_manual_failover_update(event)
if event.node_created? || event.node_changed?
perform_manual_failover
end
rescue => ex
logger.error("Error scheduling a manual failover: #{ex.inspect}")
logger.error(ex.backtrace.join("\n"))
ensure
@zk.stat(manual_failover_path, :watch => true)
end | ruby | def handle_manual_failover_update(event)
if event.node_created? || event.node_changed?
perform_manual_failover
end
rescue => ex
logger.error("Error scheduling a manual failover: #{ex.inspect}")
logger.error(ex.backtrace.join("\n"))
ensure
@zk.stat(manual_failover_path, :watch => true)
end | [
"def",
"handle_manual_failover_update",
"(",
"event",
")",
"if",
"event",
".",
"node_created?",
"||",
"event",
".",
"node_changed?",
"perform_manual_failover",
"end",
"rescue",
"=>",
"ex",
"logger",
".",
"error",
"(",
"\"Error scheduling a manual failover: #{ex.inspect}\"",
")",
"logger",
".",
"error",
"(",
"ex",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"ensure",
"@zk",
".",
"stat",
"(",
"manual_failover_path",
",",
":watch",
"=>",
"true",
")",
"end"
]
| Handles a manual failover znode update.
@param [ZK::Event] event the ZK event to handle | [
"Handles",
"a",
"manual",
"failover",
"znode",
"update",
"."
]
| be1208240b9b817fb0288edc7535e3f445f767cd | https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L413-L422 | train |
ryanlecompte/redis_failover | lib/redis_failover/node_manager.rb | RedisFailover.NodeManager.update_master_state | def update_master_state(node, snapshots)
state = @node_strategy.determine_state(node, snapshots)
case state
when :unavailable
handle_unavailable(node, snapshots)
when :available
if node.syncing_with_master?
handle_syncing(node, snapshots)
else
handle_available(node, snapshots)
end
else
raise InvalidNodeStateError.new(node, state)
end
rescue *ZK_ERRORS
# fail hard if this is a ZK connection-related error
raise
rescue => ex
logger.error("Error handling state report for #{[node, state].inspect}: #{ex.inspect}")
end | ruby | def update_master_state(node, snapshots)
state = @node_strategy.determine_state(node, snapshots)
case state
when :unavailable
handle_unavailable(node, snapshots)
when :available
if node.syncing_with_master?
handle_syncing(node, snapshots)
else
handle_available(node, snapshots)
end
else
raise InvalidNodeStateError.new(node, state)
end
rescue *ZK_ERRORS
# fail hard if this is a ZK connection-related error
raise
rescue => ex
logger.error("Error handling state report for #{[node, state].inspect}: #{ex.inspect}")
end | [
"def",
"update_master_state",
"(",
"node",
",",
"snapshots",
")",
"state",
"=",
"@node_strategy",
".",
"determine_state",
"(",
"node",
",",
"snapshots",
")",
"case",
"state",
"when",
":unavailable",
"handle_unavailable",
"(",
"node",
",",
"snapshots",
")",
"when",
":available",
"if",
"node",
".",
"syncing_with_master?",
"handle_syncing",
"(",
"node",
",",
"snapshots",
")",
"else",
"handle_available",
"(",
"node",
",",
"snapshots",
")",
"end",
"else",
"raise",
"InvalidNodeStateError",
".",
"new",
"(",
"node",
",",
"state",
")",
"end",
"rescue",
"*",
"ZK_ERRORS",
"raise",
"rescue",
"=>",
"ex",
"logger",
".",
"error",
"(",
"\"Error handling state report for #{[node, state].inspect}: #{ex.inspect}\"",
")",
"end"
]
| Used to update the master node manager state. These states are only handled if
this node manager instance is serving as the master manager.
@param [Node] node the node to handle
@param [Hash<Node, NodeSnapshot>] snapshots the current set of snapshots | [
"Used",
"to",
"update",
"the",
"master",
"node",
"manager",
"state",
".",
"These",
"states",
"are",
"only",
"handled",
"if",
"this",
"node",
"manager",
"instance",
"is",
"serving",
"as",
"the",
"master",
"manager",
"."
]
| be1208240b9b817fb0288edc7535e3f445f767cd | https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L482-L501 | train |
ryanlecompte/redis_failover | lib/redis_failover/node_manager.rb | RedisFailover.NodeManager.update_current_state | def update_current_state(node, state, latency = nil)
old_unavailable = @monitored_unavailable.dup
old_available = @monitored_available.dup
case state
when :unavailable
unless @monitored_unavailable.include?(node)
@monitored_unavailable << node
@monitored_available.delete(node)
write_current_monitored_state
end
when :available
last_latency = @monitored_available[node]
if last_latency.nil? || (latency - last_latency) > LATENCY_THRESHOLD
@monitored_available[node] = latency
@monitored_unavailable.delete(node)
write_current_monitored_state
end
else
raise InvalidNodeStateError.new(node, state)
end
rescue => ex
# if an error occurs, make sure that we rollback to the old state
@monitored_unavailable = old_unavailable
@monitored_available = old_available
raise
end | ruby | def update_current_state(node, state, latency = nil)
old_unavailable = @monitored_unavailable.dup
old_available = @monitored_available.dup
case state
when :unavailable
unless @monitored_unavailable.include?(node)
@monitored_unavailable << node
@monitored_available.delete(node)
write_current_monitored_state
end
when :available
last_latency = @monitored_available[node]
if last_latency.nil? || (latency - last_latency) > LATENCY_THRESHOLD
@monitored_available[node] = latency
@monitored_unavailable.delete(node)
write_current_monitored_state
end
else
raise InvalidNodeStateError.new(node, state)
end
rescue => ex
# if an error occurs, make sure that we rollback to the old state
@monitored_unavailable = old_unavailable
@monitored_available = old_available
raise
end | [
"def",
"update_current_state",
"(",
"node",
",",
"state",
",",
"latency",
"=",
"nil",
")",
"old_unavailable",
"=",
"@monitored_unavailable",
".",
"dup",
"old_available",
"=",
"@monitored_available",
".",
"dup",
"case",
"state",
"when",
":unavailable",
"unless",
"@monitored_unavailable",
".",
"include?",
"(",
"node",
")",
"@monitored_unavailable",
"<<",
"node",
"@monitored_available",
".",
"delete",
"(",
"node",
")",
"write_current_monitored_state",
"end",
"when",
":available",
"last_latency",
"=",
"@monitored_available",
"[",
"node",
"]",
"if",
"last_latency",
".",
"nil?",
"||",
"(",
"latency",
"-",
"last_latency",
")",
">",
"LATENCY_THRESHOLD",
"@monitored_available",
"[",
"node",
"]",
"=",
"latency",
"@monitored_unavailable",
".",
"delete",
"(",
"node",
")",
"write_current_monitored_state",
"end",
"else",
"raise",
"InvalidNodeStateError",
".",
"new",
"(",
"node",
",",
"state",
")",
"end",
"rescue",
"=>",
"ex",
"@monitored_unavailable",
"=",
"old_unavailable",
"@monitored_available",
"=",
"old_available",
"raise",
"end"
]
| Updates the current view of the world for this particular node
manager instance. All node managers write this state regardless
of whether they are the master manager or not.
@param [Node] node the node to handle
@param [Symbol] state the node state
@param [Integer] latency an optional latency | [
"Updates",
"the",
"current",
"view",
"of",
"the",
"world",
"for",
"this",
"particular",
"node",
"manager",
"instance",
".",
"All",
"node",
"managers",
"write",
"this",
"state",
"regardless",
"of",
"whether",
"they",
"are",
"the",
"master",
"manager",
"or",
"not",
"."
]
| be1208240b9b817fb0288edc7535e3f445f767cd | https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L510-L536 | train |
ryanlecompte/redis_failover | lib/redis_failover/node_manager.rb | RedisFailover.NodeManager.current_node_snapshots | def current_node_snapshots
nodes = {}
snapshots = Hash.new { |h, k| h[k] = NodeSnapshot.new(k) }
fetch_node_manager_states.each do |node_manager, states|
available, unavailable = states.values_at(:available, :unavailable)
available.each do |node_string, latency|
node = nodes[node_string] ||= node_from(node_string)
snapshots[node].viewable_by(node_manager, latency)
end
unavailable.each do |node_string|
node = nodes[node_string] ||= node_from(node_string)
snapshots[node].unviewable_by(node_manager)
end
end
snapshots
end | ruby | def current_node_snapshots
nodes = {}
snapshots = Hash.new { |h, k| h[k] = NodeSnapshot.new(k) }
fetch_node_manager_states.each do |node_manager, states|
available, unavailable = states.values_at(:available, :unavailable)
available.each do |node_string, latency|
node = nodes[node_string] ||= node_from(node_string)
snapshots[node].viewable_by(node_manager, latency)
end
unavailable.each do |node_string|
node = nodes[node_string] ||= node_from(node_string)
snapshots[node].unviewable_by(node_manager)
end
end
snapshots
end | [
"def",
"current_node_snapshots",
"nodes",
"=",
"{",
"}",
"snapshots",
"=",
"Hash",
".",
"new",
"{",
"|",
"h",
",",
"k",
"|",
"h",
"[",
"k",
"]",
"=",
"NodeSnapshot",
".",
"new",
"(",
"k",
")",
"}",
"fetch_node_manager_states",
".",
"each",
"do",
"|",
"node_manager",
",",
"states",
"|",
"available",
",",
"unavailable",
"=",
"states",
".",
"values_at",
"(",
":available",
",",
":unavailable",
")",
"available",
".",
"each",
"do",
"|",
"node_string",
",",
"latency",
"|",
"node",
"=",
"nodes",
"[",
"node_string",
"]",
"||=",
"node_from",
"(",
"node_string",
")",
"snapshots",
"[",
"node",
"]",
".",
"viewable_by",
"(",
"node_manager",
",",
"latency",
")",
"end",
"unavailable",
".",
"each",
"do",
"|",
"node_string",
"|",
"node",
"=",
"nodes",
"[",
"node_string",
"]",
"||=",
"node_from",
"(",
"node_string",
")",
"snapshots",
"[",
"node",
"]",
".",
"unviewable_by",
"(",
"node_manager",
")",
"end",
"end",
"snapshots",
"end"
]
| Builds current snapshots of nodes across all running node managers.
@return [Hash<Node, NodeSnapshot>] the snapshots for all nodes | [
"Builds",
"current",
"snapshots",
"of",
"nodes",
"across",
"all",
"running",
"node",
"managers",
"."
]
| be1208240b9b817fb0288edc7535e3f445f767cd | https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L561-L577 | train |
ryanlecompte/redis_failover | lib/redis_failover/node_manager.rb | RedisFailover.NodeManager.wait_until_master | def wait_until_master
logger.info('Waiting to become master Node Manager ...')
with_lock do
@master_manager = true
logger.info('Acquired master Node Manager lock.')
logger.info("Configured node strategy #{@node_strategy.class}")
logger.info("Configured failover strategy #{@failover_strategy.class}")
logger.info("Required Node Managers to make a decision: #{@required_node_managers}")
manage_nodes
end
end | ruby | def wait_until_master
logger.info('Waiting to become master Node Manager ...')
with_lock do
@master_manager = true
logger.info('Acquired master Node Manager lock.')
logger.info("Configured node strategy #{@node_strategy.class}")
logger.info("Configured failover strategy #{@failover_strategy.class}")
logger.info("Required Node Managers to make a decision: #{@required_node_managers}")
manage_nodes
end
end | [
"def",
"wait_until_master",
"logger",
".",
"info",
"(",
"'Waiting to become master Node Manager ...'",
")",
"with_lock",
"do",
"@master_manager",
"=",
"true",
"logger",
".",
"info",
"(",
"'Acquired master Node Manager lock.'",
")",
"logger",
".",
"info",
"(",
"\"Configured node strategy #{@node_strategy.class}\"",
")",
"logger",
".",
"info",
"(",
"\"Configured failover strategy #{@failover_strategy.class}\"",
")",
"logger",
".",
"info",
"(",
"\"Required Node Managers to make a decision: #{@required_node_managers}\"",
")",
"manage_nodes",
"end",
"end"
]
| Waits until this node manager becomes the master. | [
"Waits",
"until",
"this",
"node",
"manager",
"becomes",
"the",
"master",
"."
]
| be1208240b9b817fb0288edc7535e3f445f767cd | https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L580-L591 | train |
ryanlecompte/redis_failover | lib/redis_failover/node_manager.rb | RedisFailover.NodeManager.manage_nodes | def manage_nodes
# Re-discover nodes, since the state of the world may have been changed
# by the time we've become the primary node manager.
discover_nodes
# ensure that slaves are correctly pointing to this master
redirect_slaves_to(@master)
# Periodically update master config state.
while running? && master_manager?
@zk_lock.assert!
sleep(CHECK_INTERVAL)
@lock.synchronize do
snapshots = current_node_snapshots
if ensure_sufficient_node_managers(snapshots)
snapshots.each_key do |node|
update_master_state(node, snapshots)
end
# flush current master state
write_current_redis_nodes
# check if we've exhausted our attempts to promote a master
unless @master
@master_promotion_attempts += 1
raise NoMasterError if @master_promotion_attempts > MAX_PROMOTION_ATTEMPTS
end
end
end
end
end | ruby | def manage_nodes
# Re-discover nodes, since the state of the world may have been changed
# by the time we've become the primary node manager.
discover_nodes
# ensure that slaves are correctly pointing to this master
redirect_slaves_to(@master)
# Periodically update master config state.
while running? && master_manager?
@zk_lock.assert!
sleep(CHECK_INTERVAL)
@lock.synchronize do
snapshots = current_node_snapshots
if ensure_sufficient_node_managers(snapshots)
snapshots.each_key do |node|
update_master_state(node, snapshots)
end
# flush current master state
write_current_redis_nodes
# check if we've exhausted our attempts to promote a master
unless @master
@master_promotion_attempts += 1
raise NoMasterError if @master_promotion_attempts > MAX_PROMOTION_ATTEMPTS
end
end
end
end
end | [
"def",
"manage_nodes",
"discover_nodes",
"redirect_slaves_to",
"(",
"@master",
")",
"while",
"running?",
"&&",
"master_manager?",
"@zk_lock",
".",
"assert!",
"sleep",
"(",
"CHECK_INTERVAL",
")",
"@lock",
".",
"synchronize",
"do",
"snapshots",
"=",
"current_node_snapshots",
"if",
"ensure_sufficient_node_managers",
"(",
"snapshots",
")",
"snapshots",
".",
"each_key",
"do",
"|",
"node",
"|",
"update_master_state",
"(",
"node",
",",
"snapshots",
")",
"end",
"write_current_redis_nodes",
"unless",
"@master",
"@master_promotion_attempts",
"+=",
"1",
"raise",
"NoMasterError",
"if",
"@master_promotion_attempts",
">",
"MAX_PROMOTION_ATTEMPTS",
"end",
"end",
"end",
"end",
"end"
]
| Manages the redis nodes by periodically processing snapshots. | [
"Manages",
"the",
"redis",
"nodes",
"by",
"periodically",
"processing",
"snapshots",
"."
]
| be1208240b9b817fb0288edc7535e3f445f767cd | https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L594-L625 | train |
ryanlecompte/redis_failover | lib/redis_failover/node_manager.rb | RedisFailover.NodeManager.with_lock | def with_lock
@zk_lock ||= @zk.locker(current_lock_path)
begin
@zk_lock.lock!(true)
rescue Exception
# handle shutdown case
running? ? raise : return
end
if running?
@zk_lock.assert!
yield
end
ensure
if @zk_lock
begin
@zk_lock.unlock!
rescue => ex
logger.warn("Failed to release lock: #{ex.inspect}")
end
end
end | ruby | def with_lock
@zk_lock ||= @zk.locker(current_lock_path)
begin
@zk_lock.lock!(true)
rescue Exception
# handle shutdown case
running? ? raise : return
end
if running?
@zk_lock.assert!
yield
end
ensure
if @zk_lock
begin
@zk_lock.unlock!
rescue => ex
logger.warn("Failed to release lock: #{ex.inspect}")
end
end
end | [
"def",
"with_lock",
"@zk_lock",
"||=",
"@zk",
".",
"locker",
"(",
"current_lock_path",
")",
"begin",
"@zk_lock",
".",
"lock!",
"(",
"true",
")",
"rescue",
"Exception",
"running?",
"?",
"raise",
":",
"return",
"end",
"if",
"running?",
"@zk_lock",
".",
"assert!",
"yield",
"end",
"ensure",
"if",
"@zk_lock",
"begin",
"@zk_lock",
".",
"unlock!",
"rescue",
"=>",
"ex",
"logger",
".",
"warn",
"(",
"\"Failed to release lock: #{ex.inspect}\"",
")",
"end",
"end",
"end"
]
| Executes a block wrapped in a ZK exclusive lock. | [
"Executes",
"a",
"block",
"wrapped",
"in",
"a",
"ZK",
"exclusive",
"lock",
"."
]
| be1208240b9b817fb0288edc7535e3f445f767cd | https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L638-L660 | train |
ryanlecompte/redis_failover | lib/redis_failover/node_manager.rb | RedisFailover.NodeManager.perform_manual_failover | def perform_manual_failover
@lock.synchronize do
return unless running? && @master_manager && @zk_lock
@zk_lock.assert!
new_master = @zk.get(manual_failover_path, :watch => true).first
return unless new_master && new_master.size > 0
logger.info("Received manual failover request for: #{new_master}")
logger.info("Current nodes: #{current_nodes.inspect}")
snapshots = current_node_snapshots
node = if new_master == ManualFailover::ANY_SLAVE
failover_strategy_candidate(snapshots)
else
node_from(new_master)
end
if node
handle_manual_failover(node, snapshots)
else
logger.error('Failed to perform manual failover, no candidate found.')
end
end
rescue => ex
logger.error("Error handling manual failover: #{ex.inspect}")
logger.error(ex.backtrace.join("\n"))
ensure
@zk.stat(manual_failover_path, :watch => true)
end | ruby | def perform_manual_failover
@lock.synchronize do
return unless running? && @master_manager && @zk_lock
@zk_lock.assert!
new_master = @zk.get(manual_failover_path, :watch => true).first
return unless new_master && new_master.size > 0
logger.info("Received manual failover request for: #{new_master}")
logger.info("Current nodes: #{current_nodes.inspect}")
snapshots = current_node_snapshots
node = if new_master == ManualFailover::ANY_SLAVE
failover_strategy_candidate(snapshots)
else
node_from(new_master)
end
if node
handle_manual_failover(node, snapshots)
else
logger.error('Failed to perform manual failover, no candidate found.')
end
end
rescue => ex
logger.error("Error handling manual failover: #{ex.inspect}")
logger.error(ex.backtrace.join("\n"))
ensure
@zk.stat(manual_failover_path, :watch => true)
end | [
"def",
"perform_manual_failover",
"@lock",
".",
"synchronize",
"do",
"return",
"unless",
"running?",
"&&",
"@master_manager",
"&&",
"@zk_lock",
"@zk_lock",
".",
"assert!",
"new_master",
"=",
"@zk",
".",
"get",
"(",
"manual_failover_path",
",",
":watch",
"=>",
"true",
")",
".",
"first",
"return",
"unless",
"new_master",
"&&",
"new_master",
".",
"size",
">",
"0",
"logger",
".",
"info",
"(",
"\"Received manual failover request for: #{new_master}\"",
")",
"logger",
".",
"info",
"(",
"\"Current nodes: #{current_nodes.inspect}\"",
")",
"snapshots",
"=",
"current_node_snapshots",
"node",
"=",
"if",
"new_master",
"==",
"ManualFailover",
"::",
"ANY_SLAVE",
"failover_strategy_candidate",
"(",
"snapshots",
")",
"else",
"node_from",
"(",
"new_master",
")",
"end",
"if",
"node",
"handle_manual_failover",
"(",
"node",
",",
"snapshots",
")",
"else",
"logger",
".",
"error",
"(",
"'Failed to perform manual failover, no candidate found.'",
")",
"end",
"end",
"rescue",
"=>",
"ex",
"logger",
".",
"error",
"(",
"\"Error handling manual failover: #{ex.inspect}\"",
")",
"logger",
".",
"error",
"(",
"ex",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"ensure",
"@zk",
".",
"stat",
"(",
"manual_failover_path",
",",
":watch",
"=>",
"true",
")",
"end"
]
| Perform a manual failover to a redis node. | [
"Perform",
"a",
"manual",
"failover",
"to",
"a",
"redis",
"node",
"."
]
| be1208240b9b817fb0288edc7535e3f445f767cd | https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L663-L690 | train |
ryanlecompte/redis_failover | lib/redis_failover/node_manager.rb | RedisFailover.NodeManager.ensure_sufficient_node_managers | def ensure_sufficient_node_managers(snapshots)
currently_sufficient = true
snapshots.each do |node, snapshot|
node_managers = snapshot.node_managers
if node_managers.size < @required_node_managers
logger.error("Not enough Node Managers in snapshot for node #{node}. " +
"Required: #{@required_node_managers}, " +
"Available: #{node_managers.size} #{node_managers}")
currently_sufficient = false
end
end
if currently_sufficient && !@sufficient_node_managers
logger.info("Required Node Managers are visible: #{@required_node_managers}")
end
@sufficient_node_managers = currently_sufficient
@sufficient_node_managers
end | ruby | def ensure_sufficient_node_managers(snapshots)
currently_sufficient = true
snapshots.each do |node, snapshot|
node_managers = snapshot.node_managers
if node_managers.size < @required_node_managers
logger.error("Not enough Node Managers in snapshot for node #{node}. " +
"Required: #{@required_node_managers}, " +
"Available: #{node_managers.size} #{node_managers}")
currently_sufficient = false
end
end
if currently_sufficient && !@sufficient_node_managers
logger.info("Required Node Managers are visible: #{@required_node_managers}")
end
@sufficient_node_managers = currently_sufficient
@sufficient_node_managers
end | [
"def",
"ensure_sufficient_node_managers",
"(",
"snapshots",
")",
"currently_sufficient",
"=",
"true",
"snapshots",
".",
"each",
"do",
"|",
"node",
",",
"snapshot",
"|",
"node_managers",
"=",
"snapshot",
".",
"node_managers",
"if",
"node_managers",
".",
"size",
"<",
"@required_node_managers",
"logger",
".",
"error",
"(",
"\"Not enough Node Managers in snapshot for node #{node}. \"",
"+",
"\"Required: #{@required_node_managers}, \"",
"+",
"\"Available: #{node_managers.size} #{node_managers}\"",
")",
"currently_sufficient",
"=",
"false",
"end",
"end",
"if",
"currently_sufficient",
"&&",
"!",
"@sufficient_node_managers",
"logger",
".",
"info",
"(",
"\"Required Node Managers are visible: #{@required_node_managers}\"",
")",
"end",
"@sufficient_node_managers",
"=",
"currently_sufficient",
"@sufficient_node_managers",
"end"
]
| Determines if each snapshot has a sufficient number of node managers.
@param [Hash<Node, Snapshot>] snapshots the current snapshots
@return [Boolean] true if sufficient, false otherwise | [
"Determines",
"if",
"each",
"snapshot",
"has",
"a",
"sufficient",
"number",
"of",
"node",
"managers",
"."
]
| be1208240b9b817fb0288edc7535e3f445f767cd | https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L706-L724 | train |
ryanlecompte/redis_failover | lib/redis_failover/node_manager.rb | RedisFailover.NodeManager.failover_strategy_candidate | def failover_strategy_candidate(snapshots)
# only include nodes that this master Node Manager can see
filtered_snapshots = snapshots.select do |node, snapshot|
snapshot.viewable_by?(manager_id)
end
logger.info('Attempting to find candidate from snapshots:')
logger.info("\n" + filtered_snapshots.values.join("\n"))
@failover_strategy.find_candidate(filtered_snapshots)
end | ruby | def failover_strategy_candidate(snapshots)
# only include nodes that this master Node Manager can see
filtered_snapshots = snapshots.select do |node, snapshot|
snapshot.viewable_by?(manager_id)
end
logger.info('Attempting to find candidate from snapshots:')
logger.info("\n" + filtered_snapshots.values.join("\n"))
@failover_strategy.find_candidate(filtered_snapshots)
end | [
"def",
"failover_strategy_candidate",
"(",
"snapshots",
")",
"filtered_snapshots",
"=",
"snapshots",
".",
"select",
"do",
"|",
"node",
",",
"snapshot",
"|",
"snapshot",
".",
"viewable_by?",
"(",
"manager_id",
")",
"end",
"logger",
".",
"info",
"(",
"'Attempting to find candidate from snapshots:'",
")",
"logger",
".",
"info",
"(",
"\"\\n\"",
"+",
"filtered_snapshots",
".",
"values",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"@failover_strategy",
".",
"find_candidate",
"(",
"filtered_snapshots",
")",
"end"
]
| Invokes the configured failover strategy.
@param [Hash<Node, NodeSnapshot>] snapshots the node snapshots
@return [Node] a failover candidate | [
"Invokes",
"the",
"configured",
"failover",
"strategy",
"."
]
| be1208240b9b817fb0288edc7535e3f445f767cd | https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L730-L739 | train |
larskanis/pkcs11 | lib/pkcs11/library.rb | PKCS11.Library.C_Initialize | def C_Initialize(args=nil)
case args
when Hash
pargs = CK_C_INITIALIZE_ARGS.new
args.each{|k,v| pargs.send("#{k}=", v) }
else
pargs = args
end
unwrapped_C_Initialize(pargs)
end | ruby | def C_Initialize(args=nil)
case args
when Hash
pargs = CK_C_INITIALIZE_ARGS.new
args.each{|k,v| pargs.send("#{k}=", v) }
else
pargs = args
end
unwrapped_C_Initialize(pargs)
end | [
"def",
"C_Initialize",
"(",
"args",
"=",
"nil",
")",
"case",
"args",
"when",
"Hash",
"pargs",
"=",
"CK_C_INITIALIZE_ARGS",
".",
"new",
"args",
".",
"each",
"{",
"|",
"k",
",",
"v",
"|",
"pargs",
".",
"send",
"(",
"\"#{k}=\"",
",",
"v",
")",
"}",
"else",
"pargs",
"=",
"args",
"end",
"unwrapped_C_Initialize",
"(",
"pargs",
")",
"end"
]
| Initialize a pkcs11 dynamic library.
@param [Hash, CK_C_INITIALIZE_ARGS] args A Hash or CK_C_INITIALIZE_ARGS instance with load params. | [
"Initialize",
"a",
"pkcs11",
"dynamic",
"library",
"."
]
| 4f39c54a932face8b3d87c157d8d56469c43c6bc | https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/library.rb#L49-L58 | train |
larskanis/pkcs11 | lib/pkcs11/library.rb | PKCS11.Library.C_GetSlotList | def C_GetSlotList(tokenPresent=false)
slots = unwrapped_C_GetSlotList(tokenPresent)
slots.map{|slot|
Slot.new self, slot
}
end | ruby | def C_GetSlotList(tokenPresent=false)
slots = unwrapped_C_GetSlotList(tokenPresent)
slots.map{|slot|
Slot.new self, slot
}
end | [
"def",
"C_GetSlotList",
"(",
"tokenPresent",
"=",
"false",
")",
"slots",
"=",
"unwrapped_C_GetSlotList",
"(",
"tokenPresent",
")",
"slots",
".",
"map",
"{",
"|",
"slot",
"|",
"Slot",
".",
"new",
"self",
",",
"slot",
"}",
"end"
]
| Obtain an array of Slot objects in the system.
@param [true, false] tokenPresent indicates whether the list
obtained includes only those slots with a token present (true), or
all slots (false);
@return [Array<Slot>] | [
"Obtain",
"an",
"array",
"of",
"Slot",
"objects",
"in",
"the",
"system",
"."
]
| 4f39c54a932face8b3d87c157d8d56469c43c6bc | https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/library.rb#L76-L81 | train |
larskanis/pkcs11 | lib/pkcs11/session.rb | PKCS11.Session.C_FindObjects | def C_FindObjects(max_count)
objs = @pk.C_FindObjects(@sess, max_count)
objs.map{|obj| Object.new @pk, @sess, obj }
end | ruby | def C_FindObjects(max_count)
objs = @pk.C_FindObjects(@sess, max_count)
objs.map{|obj| Object.new @pk, @sess, obj }
end | [
"def",
"C_FindObjects",
"(",
"max_count",
")",
"objs",
"=",
"@pk",
".",
"C_FindObjects",
"(",
"@sess",
",",
"max_count",
")",
"objs",
".",
"map",
"{",
"|",
"obj",
"|",
"Object",
".",
"new",
"@pk",
",",
"@sess",
",",
"obj",
"}",
"end"
]
| Continues a search for token and session objects that match a template,
obtaining additional object handles.
See {Session#find_objects} for convenience
@return [Array<PKCS11::Object>] Returns an array of Object instances. | [
"Continues",
"a",
"search",
"for",
"token",
"and",
"session",
"objects",
"that",
"match",
"a",
"template",
"obtaining",
"additional",
"object",
"handles",
"."
]
| 4f39c54a932face8b3d87c157d8d56469c43c6bc | https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/session.rb#L91-L94 | train |
larskanis/pkcs11 | lib/pkcs11/session.rb | PKCS11.Session.C_GenerateKey | def C_GenerateKey(mechanism, template={})
obj = @pk.C_GenerateKey(@sess, to_mechanism(mechanism), to_attributes(template))
Object.new @pk, @sess, obj
end | ruby | def C_GenerateKey(mechanism, template={})
obj = @pk.C_GenerateKey(@sess, to_mechanism(mechanism), to_attributes(template))
Object.new @pk, @sess, obj
end | [
"def",
"C_GenerateKey",
"(",
"mechanism",
",",
"template",
"=",
"{",
"}",
")",
"obj",
"=",
"@pk",
".",
"C_GenerateKey",
"(",
"@sess",
",",
"to_mechanism",
"(",
"mechanism",
")",
",",
"to_attributes",
"(",
"template",
")",
")",
"Object",
".",
"new",
"@pk",
",",
"@sess",
",",
"obj",
"end"
]
| Generates a secret key Object or set of domain parameters, creating a new
Object.
@param [Hash, Symbol, Integer, PKCS11::CK_MECHANISM] mechanism used mechanism
@param [Hash] template Attributes of the key to create.
@return [PKCS11::Object] key Object of the new created key.
@example generate 112 bit DES key
key = session.generate_key(:DES2_KEY_GEN,
{:ENCRYPT=>true, :WRAP=>true, :DECRYPT=>true, :UNWRAP=>true}) | [
"Generates",
"a",
"secret",
"key",
"Object",
"or",
"set",
"of",
"domain",
"parameters",
"creating",
"a",
"new",
"Object",
"."
]
| 4f39c54a932face8b3d87c157d8d56469c43c6bc | https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/session.rb#L653-L656 | train |
larskanis/pkcs11 | lib/pkcs11/session.rb | PKCS11.Session.C_DeriveKey | def C_DeriveKey(mechanism, base_key, template={})
obj = @pk.C_DeriveKey(@sess, to_mechanism(mechanism), base_key, to_attributes(template))
Object.new @pk, @sess, obj
end | ruby | def C_DeriveKey(mechanism, base_key, template={})
obj = @pk.C_DeriveKey(@sess, to_mechanism(mechanism), base_key, to_attributes(template))
Object.new @pk, @sess, obj
end | [
"def",
"C_DeriveKey",
"(",
"mechanism",
",",
"base_key",
",",
"template",
"=",
"{",
"}",
")",
"obj",
"=",
"@pk",
".",
"C_DeriveKey",
"(",
"@sess",
",",
"to_mechanism",
"(",
"mechanism",
")",
",",
"base_key",
",",
"to_attributes",
"(",
"template",
")",
")",
"Object",
".",
"new",
"@pk",
",",
"@sess",
",",
"obj",
"end"
]
| Derives a key from a base key, creating a new key object.
@param [Hash, Symbol, Integer, PKCS11::CK_MECHANISM] mechanism used mechanism
@param [PKCS11::Object] base_key key to derive
@param [Hash] template Attributes of the object to create.
@return [PKCS11::Object] key object of the new created key.
@example Derive a AES key by XORing with some derivation data
deriv_data = "\0"*16
new_key = session.derive_key( {CKM_XOR_BASE_AND_DATA => {:pData => deriv_data}}, secret_key,
:CLASS=>CKO_SECRET_KEY, :KEY_TYPE=>CKK_AES, :VALUE_LEN=>16, :ENCRYPT=>true ) | [
"Derives",
"a",
"key",
"from",
"a",
"base",
"key",
"creating",
"a",
"new",
"key",
"object",
"."
]
| 4f39c54a932face8b3d87c157d8d56469c43c6bc | https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/session.rb#L718-L721 | train |
larskanis/pkcs11 | lib/pkcs11/slot.rb | PKCS11.Slot.C_OpenSession | def C_OpenSession(flags=CKF_SERIAL_SESSION)
nr = @pk.C_OpenSession(@slot, flags)
sess = Session.new @pk, nr
if block_given?
begin
yield sess
ensure
sess.close
end
else
sess
end
end | ruby | def C_OpenSession(flags=CKF_SERIAL_SESSION)
nr = @pk.C_OpenSession(@slot, flags)
sess = Session.new @pk, nr
if block_given?
begin
yield sess
ensure
sess.close
end
else
sess
end
end | [
"def",
"C_OpenSession",
"(",
"flags",
"=",
"CKF_SERIAL_SESSION",
")",
"nr",
"=",
"@pk",
".",
"C_OpenSession",
"(",
"@slot",
",",
"flags",
")",
"sess",
"=",
"Session",
".",
"new",
"@pk",
",",
"nr",
"if",
"block_given?",
"begin",
"yield",
"sess",
"ensure",
"sess",
".",
"close",
"end",
"else",
"sess",
"end",
"end"
]
| Opens a Session between an application and a token in a particular slot.
@param [Integer] flags indicates the type of session. Default is read-only,
use <tt>CKF_SERIAL_SESSION | CKF_RW_SESSION</tt> for read-write session.
* If called with block, yields the block with the session and closes the session
when the is finished.
* If called without block, returns the session object.
@return [PKCS11::Session] | [
"Opens",
"a",
"Session",
"between",
"an",
"application",
"and",
"a",
"token",
"in",
"a",
"particular",
"slot",
"."
]
| 4f39c54a932face8b3d87c157d8d56469c43c6bc | https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/slot.rb#L79-L91 | train |
larskanis/pkcs11 | lib/pkcs11/object.rb | PKCS11.Object.[] | def [](*attributes)
attrs = C_GetAttributeValue( attributes.flatten )
if attrs.length>1 || attributes.first.kind_of?(Array)
attrs.map(&:value)
else
attrs.first.value unless attrs.empty?
end
end | ruby | def [](*attributes)
attrs = C_GetAttributeValue( attributes.flatten )
if attrs.length>1 || attributes.first.kind_of?(Array)
attrs.map(&:value)
else
attrs.first.value unless attrs.empty?
end
end | [
"def",
"[]",
"(",
"*",
"attributes",
")",
"attrs",
"=",
"C_GetAttributeValue",
"(",
"attributes",
".",
"flatten",
")",
"if",
"attrs",
".",
"length",
">",
"1",
"||",
"attributes",
".",
"first",
".",
"kind_of?",
"(",
"Array",
")",
"attrs",
".",
"map",
"(",
"&",
":value",
")",
"else",
"attrs",
".",
"first",
".",
"value",
"unless",
"attrs",
".",
"empty?",
"end",
"end"
]
| Get the value of one or several attributes of the object.
@param [String, Symbol, Integer, Array] attribute can be String or Symbol
of the attribute(s) constant or the attribute(s) number as Integer.
@return [String, Integer, Boolean, Array, nil] the attribute value as String,
Integer or true/false depending on the attribute type.
If called with more than one parameter or with an Array, a Array
of attribute values is returned.
Unknown attributes (out of PKCS#11 v2.2) are not converted to adequate
ruby objects but returned as String.
That is true/false will be returned as "\\001" respectively "\\000".
@example
object[:VALUE] # => "\000\000\000\000\000\000\000\000"
object[:MODULUS_BITS] # => 768
object[:MODULUS_BITS, :LABEL] # => [1024, "MyKey"]
See PKCS#11 for attribute definitions. | [
"Get",
"the",
"value",
"of",
"one",
"or",
"several",
"attributes",
"of",
"the",
"object",
"."
]
| 4f39c54a932face8b3d87c157d8d56469c43c6bc | https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/object.rb#L48-L55 | train |
larskanis/pkcs11 | lib/pkcs11/object.rb | PKCS11.Object.[]= | def []=(*attributes)
values = attributes.pop
values = [values] unless values.kind_of?(Array)
raise ArgumentError, "different number of attributes to set (#{attributes.length}) and given values (#{values.length})" unless attributes.length == values.length
map = values.each.with_index.inject({}){|s, v| s[attributes[v[1]]] = v[0]; s }
C_SetAttributeValue( map )
end | ruby | def []=(*attributes)
values = attributes.pop
values = [values] unless values.kind_of?(Array)
raise ArgumentError, "different number of attributes to set (#{attributes.length}) and given values (#{values.length})" unless attributes.length == values.length
map = values.each.with_index.inject({}){|s, v| s[attributes[v[1]]] = v[0]; s }
C_SetAttributeValue( map )
end | [
"def",
"[]=",
"(",
"*",
"attributes",
")",
"values",
"=",
"attributes",
".",
"pop",
"values",
"=",
"[",
"values",
"]",
"unless",
"values",
".",
"kind_of?",
"(",
"Array",
")",
"raise",
"ArgumentError",
",",
"\"different number of attributes to set (#{attributes.length}) and given values (#{values.length})\"",
"unless",
"attributes",
".",
"length",
"==",
"values",
".",
"length",
"map",
"=",
"values",
".",
"each",
".",
"with_index",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"s",
",",
"v",
"|",
"s",
"[",
"attributes",
"[",
"v",
"[",
"1",
"]",
"]",
"]",
"=",
"v",
"[",
"0",
"]",
";",
"s",
"}",
"C_SetAttributeValue",
"(",
"map",
")",
"end"
]
| Modifies the value of one or several attributes of the object.
@param [String, Symbol, Integer] attribute can be String or Symbol of the attribute constant
or the attribute value as Integer.
@param [String, Integer, Boolean, Array, nil] value value(s) the attribute(s) will be set to.
Following value conversations are done from Ruby to C:
true -> 0x01
false -> 0x00
nil -> NULL pointer
Integer-> binary encoded unsigned long
@example
object[:VALUE] = "\000\000\000\000\000\000\000\000"
object[:MODULUS_BITS] = 768
object[:MODULUS_BITS, :LABEL] = 1024, 'MyKey'
See PKCS#11 for attribute definitions.
@return value | [
"Modifies",
"the",
"value",
"of",
"one",
"or",
"several",
"attributes",
"of",
"the",
"object",
"."
]
| 4f39c54a932face8b3d87c157d8d56469c43c6bc | https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/object.rb#L76-L82 | train |
larskanis/pkcs11 | lib/pkcs11/object.rb | PKCS11.Object.C_GetAttributeValue | def C_GetAttributeValue(*template)
case template.length
when 0
return @pk.vendor_all_attribute_names.map{|attr|
begin
attributes(@pk.vendor_const_get(attr))
rescue PKCS11::Error
end
}.flatten.compact
when 1
template = template[0]
end
template = to_attributes template
@pk.C_GetAttributeValue(@sess, @obj, template)
end | ruby | def C_GetAttributeValue(*template)
case template.length
when 0
return @pk.vendor_all_attribute_names.map{|attr|
begin
attributes(@pk.vendor_const_get(attr))
rescue PKCS11::Error
end
}.flatten.compact
when 1
template = template[0]
end
template = to_attributes template
@pk.C_GetAttributeValue(@sess, @obj, template)
end | [
"def",
"C_GetAttributeValue",
"(",
"*",
"template",
")",
"case",
"template",
".",
"length",
"when",
"0",
"return",
"@pk",
".",
"vendor_all_attribute_names",
".",
"map",
"{",
"|",
"attr",
"|",
"begin",
"attributes",
"(",
"@pk",
".",
"vendor_const_get",
"(",
"attr",
")",
")",
"rescue",
"PKCS11",
"::",
"Error",
"end",
"}",
".",
"flatten",
".",
"compact",
"when",
"1",
"template",
"=",
"template",
"[",
"0",
"]",
"end",
"template",
"=",
"to_attributes",
"template",
"@pk",
".",
"C_GetAttributeValue",
"(",
"@sess",
",",
"@obj",
",",
"template",
")",
"end"
]
| Obtains the value of one or more attributes of the object in a single call.
@param [Array<String, Symbol, Integer>, Hash, String, Integer] attribute attribute names
whose values should be returned
Without params all known attributes are tried to read from the Object.
This is significant slower then naming the needed attributes and should
be used for debug purposes only.
@return [Array<PKCS11::CK_ATTRIBUTE>] Requested attributes with values.
@example
certificate.attributes :VALUE, :CLASS
=> [#<PKCS11::CK_ATTRIBUTE CKA_VALUE (17) value="0\x82...">, #<PKCS11::CK_ATTRIBUTE CKA_CLASS (0) value=1>] | [
"Obtains",
"the",
"value",
"of",
"one",
"or",
"more",
"attributes",
"of",
"the",
"object",
"in",
"a",
"single",
"call",
"."
]
| 4f39c54a932face8b3d87c157d8d56469c43c6bc | https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/object.rb#L109-L123 | train |
mailin-api/sendinblue-ruby-gem | lib/sendinblue.rb | Sendinblue.Mailin.get_campaigns_v2 | def get_campaigns_v2(data)
if data['type'] == "" and data['status'] == "" and data['page'] == "" and data['page_limit'] == ""
return self.get("campaign/detailsv2/","")
else
return self.get("campaign/detailsv2/type/" + data['type'] + "/status/" + data['status'] + "/page/" + data['page'].to_s + "/page_limit/" + data['page_limit'].to_s + "/","")
end
end | ruby | def get_campaigns_v2(data)
if data['type'] == "" and data['status'] == "" and data['page'] == "" and data['page_limit'] == ""
return self.get("campaign/detailsv2/","")
else
return self.get("campaign/detailsv2/type/" + data['type'] + "/status/" + data['status'] + "/page/" + data['page'].to_s + "/page_limit/" + data['page_limit'].to_s + "/","")
end
end | [
"def",
"get_campaigns_v2",
"(",
"data",
")",
"if",
"data",
"[",
"'type'",
"]",
"==",
"\"\"",
"and",
"data",
"[",
"'status'",
"]",
"==",
"\"\"",
"and",
"data",
"[",
"'page'",
"]",
"==",
"\"\"",
"and",
"data",
"[",
"'page_limit'",
"]",
"==",
"\"\"",
"return",
"self",
".",
"get",
"(",
"\"campaign/detailsv2/\"",
",",
"\"\"",
")",
"else",
"return",
"self",
".",
"get",
"(",
"\"campaign/detailsv2/type/\"",
"+",
"data",
"[",
"'type'",
"]",
"+",
"\"/status/\"",
"+",
"data",
"[",
"'status'",
"]",
"+",
"\"/page/\"",
"+",
"data",
"[",
"'page'",
"]",
".",
"to_s",
"+",
"\"/page_limit/\"",
"+",
"data",
"[",
"'page_limit'",
"]",
".",
"to_s",
"+",
"\"/\"",
",",
"\"\"",
")",
"end",
"end"
]
| Get all campaigns detail.
@param {Array} data contains php array with key value pair.
@options data {String} type: Type of campaign. Possible values – classic, trigger, sms, template ( case sensitive ) [Optional]
@options data {String} status: Status of campaign. Possible values – draft, sent, archive, queued, suspended, in_process, temp_active, temp_inactive ( case sensitive ) [Optional]
@options data {Integer} page: Maximum number of records per request is 500, if there are more than 500 campaigns then you can use this parameter to get next 500 results [Optional]
@options data {Integer} page_limit: This should be a valid number between 1-500 [Optional] | [
"Get",
"all",
"campaigns",
"detail",
"."
]
| 670d38921c9893e653fab07dc5b9ecfb86628460 | https://github.com/mailin-api/sendinblue-ruby-gem/blob/670d38921c9893e653fab07dc5b9ecfb86628460/lib/sendinblue.rb#L169-L175 | train |
podio/podio-rb | lib/podio/client.rb | Podio.Client.authenticate_with_auth_code | def authenticate_with_auth_code(authorization_code, redirect_uri)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'authorization_code', :client_id => api_key, :client_secret => api_secret, :code => authorization_code, :redirect_uri => redirect_uri}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end | ruby | def authenticate_with_auth_code(authorization_code, redirect_uri)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'authorization_code', :client_id => api_key, :client_secret => api_secret, :code => authorization_code, :redirect_uri => redirect_uri}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end | [
"def",
"authenticate_with_auth_code",
"(",
"authorization_code",
",",
"redirect_uri",
")",
"response",
"=",
"@oauth_connection",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"'/oauth/token'",
"req",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/x-www-form-urlencoded'",
"req",
".",
"body",
"=",
"{",
":grant_type",
"=>",
"'authorization_code'",
",",
":client_id",
"=>",
"api_key",
",",
":client_secret",
"=>",
"api_secret",
",",
":code",
"=>",
"authorization_code",
",",
":redirect_uri",
"=>",
"redirect_uri",
"}",
"end",
"@oauth_token",
"=",
"OAuthToken",
".",
"new",
"(",
"response",
".",
"body",
")",
"configure_oauth",
"@oauth_token",
"end"
]
| sign in as a user using the server side flow | [
"sign",
"in",
"as",
"a",
"user",
"using",
"the",
"server",
"side",
"flow"
]
| 66137e685a494bc188ced542ae8e872d14b90a74 | https://github.com/podio/podio-rb/blob/66137e685a494bc188ced542ae8e872d14b90a74/lib/podio/client.rb#L43-L53 | train |
podio/podio-rb | lib/podio/client.rb | Podio.Client.authenticate_with_credentials | def authenticate_with_credentials(username, password, offering_id=nil)
body = {:grant_type => 'password', :client_id => api_key, :client_secret => api_secret, :username => username, :password => password}
body[:offering_id] = offering_id if offering_id.present?
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = body
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end | ruby | def authenticate_with_credentials(username, password, offering_id=nil)
body = {:grant_type => 'password', :client_id => api_key, :client_secret => api_secret, :username => username, :password => password}
body[:offering_id] = offering_id if offering_id.present?
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = body
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end | [
"def",
"authenticate_with_credentials",
"(",
"username",
",",
"password",
",",
"offering_id",
"=",
"nil",
")",
"body",
"=",
"{",
":grant_type",
"=>",
"'password'",
",",
":client_id",
"=>",
"api_key",
",",
":client_secret",
"=>",
"api_secret",
",",
":username",
"=>",
"username",
",",
":password",
"=>",
"password",
"}",
"body",
"[",
":offering_id",
"]",
"=",
"offering_id",
"if",
"offering_id",
".",
"present?",
"response",
"=",
"@oauth_connection",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"'/oauth/token'",
"req",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/x-www-form-urlencoded'",
"req",
".",
"body",
"=",
"body",
"end",
"@oauth_token",
"=",
"OAuthToken",
".",
"new",
"(",
"response",
".",
"body",
")",
"configure_oauth",
"@oauth_token",
"end"
]
| Sign in as a user using credentials | [
"Sign",
"in",
"as",
"a",
"user",
"using",
"credentials"
]
| 66137e685a494bc188ced542ae8e872d14b90a74 | https://github.com/podio/podio-rb/blob/66137e685a494bc188ced542ae8e872d14b90a74/lib/podio/client.rb#L56-L69 | train |
podio/podio-rb | lib/podio/client.rb | Podio.Client.authenticate_with_app | def authenticate_with_app(app_id, app_token)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'app', :client_id => api_key, :client_secret => api_secret, :app_id => app_id, :app_token => app_token}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end | ruby | def authenticate_with_app(app_id, app_token)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'app', :client_id => api_key, :client_secret => api_secret, :app_id => app_id, :app_token => app_token}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end | [
"def",
"authenticate_with_app",
"(",
"app_id",
",",
"app_token",
")",
"response",
"=",
"@oauth_connection",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"'/oauth/token'",
"req",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/x-www-form-urlencoded'",
"req",
".",
"body",
"=",
"{",
":grant_type",
"=>",
"'app'",
",",
":client_id",
"=>",
"api_key",
",",
":client_secret",
"=>",
"api_secret",
",",
":app_id",
"=>",
"app_id",
",",
":app_token",
"=>",
"app_token",
"}",
"end",
"@oauth_token",
"=",
"OAuthToken",
".",
"new",
"(",
"response",
".",
"body",
")",
"configure_oauth",
"@oauth_token",
"end"
]
| Sign in as an app | [
"Sign",
"in",
"as",
"an",
"app"
]
| 66137e685a494bc188ced542ae8e872d14b90a74 | https://github.com/podio/podio-rb/blob/66137e685a494bc188ced542ae8e872d14b90a74/lib/podio/client.rb#L72-L82 | train |
podio/podio-rb | lib/podio/client.rb | Podio.Client.authenticate_with_transfer_token | def authenticate_with_transfer_token(transfer_token)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'transfer_token', :client_id => api_key, :client_secret => api_secret, :transfer_token => transfer_token}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end | ruby | def authenticate_with_transfer_token(transfer_token)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'transfer_token', :client_id => api_key, :client_secret => api_secret, :transfer_token => transfer_token}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end | [
"def",
"authenticate_with_transfer_token",
"(",
"transfer_token",
")",
"response",
"=",
"@oauth_connection",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"'/oauth/token'",
"req",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/x-www-form-urlencoded'",
"req",
".",
"body",
"=",
"{",
":grant_type",
"=>",
"'transfer_token'",
",",
":client_id",
"=>",
"api_key",
",",
":client_secret",
"=>",
"api_secret",
",",
":transfer_token",
"=>",
"transfer_token",
"}",
"end",
"@oauth_token",
"=",
"OAuthToken",
".",
"new",
"(",
"response",
".",
"body",
")",
"configure_oauth",
"@oauth_token",
"end"
]
| Sign in with an transfer token, only available for Podio | [
"Sign",
"in",
"with",
"an",
"transfer",
"token",
"only",
"available",
"for",
"Podio"
]
| 66137e685a494bc188ced542ae8e872d14b90a74 | https://github.com/podio/podio-rb/blob/66137e685a494bc188ced542ae8e872d14b90a74/lib/podio/client.rb#L85-L95 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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",
")",
"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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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",
")",
"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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.