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
zendesk/ruby-kafka
lib/kafka/message_buffer.rb
Kafka.MessageBuffer.clear_messages
def clear_messages(topic:, partition:) return unless @buffer.key?(topic) && @buffer[topic].key?(partition) @size -= @buffer[topic][partition].count @bytesize -= @buffer[topic][partition].map(&:bytesize).reduce(0, :+) @buffer[topic].delete(partition) @buffer.delete(topic) if @buffer[topic...
ruby
def clear_messages(topic:, partition:) return unless @buffer.key?(topic) && @buffer[topic].key?(partition) @size -= @buffer[topic][partition].count @bytesize -= @buffer[topic][partition].map(&:bytesize).reduce(0, :+) @buffer[topic].delete(partition) @buffer.delete(topic) if @buffer[topic...
[ "def", "clear_messages", "(", "topic", ":", ",", "partition", ":", ")", "return", "unless", "@buffer", ".", "key?", "(", "topic", ")", "&&", "@buffer", "[", "topic", "]", ".", "key?", "(", "partition", ")", "@size", "-=", "@buffer", "[", "topic", "]", ...
Clears buffered messages for the given topic and partition. @param topic [String] the name of the topic. @param partition [Integer] the partition id. @return [nil]
[ "Clears", "buffered", "messages", "for", "the", "given", "topic", "and", "partition", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/message_buffer.rb#L57-L65
train
zendesk/ruby-kafka
lib/kafka/client.rb
Kafka.Client.deliver_message
def deliver_message(value, key: nil, headers: {}, topic:, partition: nil, partition_key: nil, retries: 1) create_time = Time.now message = PendingMessage.new( value: value, key: key, headers: headers, topic: topic, partition: partition, partition_key: partiti...
ruby
def deliver_message(value, key: nil, headers: {}, topic:, partition: nil, partition_key: nil, retries: 1) create_time = Time.now message = PendingMessage.new( value: value, key: key, headers: headers, topic: topic, partition: partition, partition_key: partiti...
[ "def", "deliver_message", "(", "value", ",", "key", ":", "nil", ",", "headers", ":", "{", "}", ",", "topic", ":", ",", "partition", ":", "nil", ",", "partition_key", ":", "nil", ",", "retries", ":", "1", ")", "create_time", "=", "Time", ".", "now", ...
Initializes a new Kafka client. @param seed_brokers [Array<String>, String] the list of brokers used to initialize the client. Either an Array of connections, or a comma separated string of connections. A connection can either be a string of "host:port" or a full URI with a scheme. If there's a scheme it's i...
[ "Initializes", "a", "new", "Kafka", "client", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/client.rb#L137-L212
train
zendesk/ruby-kafka
lib/kafka/client.rb
Kafka.Client.producer
def producer( compression_codec: nil, compression_threshold: 1, ack_timeout: 5, required_acks: :all, max_retries: 2, retry_backoff: 1, max_buffer_size: 1000, max_buffer_bytesize: 10_000_000, idempotent: false, transactional: false, transactional_id: nil,...
ruby
def producer( compression_codec: nil, compression_threshold: 1, ack_timeout: 5, required_acks: :all, max_retries: 2, retry_backoff: 1, max_buffer_size: 1000, max_buffer_bytesize: 10_000_000, idempotent: false, transactional: false, transactional_id: nil,...
[ "def", "producer", "(", "compression_codec", ":", "nil", ",", "compression_threshold", ":", "1", ",", "ack_timeout", ":", "5", ",", "required_acks", ":", ":all", ",", "max_retries", ":", "2", ",", "retry_backoff", ":", "1", ",", "max_buffer_size", ":", "1000...
Initializes a new Kafka producer. @param ack_timeout [Integer] The number of seconds a broker can wait for replicas to acknowledge a write before responding with a timeout. @param required_acks [Integer, Symbol] The number of replicas that must acknowledge a write, or `:all` if all in-sync replicas must ackno...
[ "Initializes", "a", "new", "Kafka", "producer", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/client.rb#L244-L287
train
zendesk/ruby-kafka
lib/kafka/client.rb
Kafka.Client.async_producer
def async_producer(delivery_interval: 0, delivery_threshold: 0, max_queue_size: 1000, max_retries: -1, retry_backoff: 0, **options) sync_producer = producer(**options) AsyncProducer.new( sync_producer: sync_producer, delivery_interval: delivery_interval, delivery_threshold: delivery...
ruby
def async_producer(delivery_interval: 0, delivery_threshold: 0, max_queue_size: 1000, max_retries: -1, retry_backoff: 0, **options) sync_producer = producer(**options) AsyncProducer.new( sync_producer: sync_producer, delivery_interval: delivery_interval, delivery_threshold: delivery...
[ "def", "async_producer", "(", "delivery_interval", ":", "0", ",", "delivery_threshold", ":", "0", ",", "max_queue_size", ":", "1000", ",", "max_retries", ":", "-", "1", ",", "retry_backoff", ":", "0", ",", "**", "options", ")", "sync_producer", "=", "produce...
Creates a new AsyncProducer instance. All parameters allowed by {#producer} can be passed. In addition to this, a few extra parameters can be passed when creating an async producer. @param max_queue_size [Integer] the maximum number of messages allowed in the queue. @param delivery_threshold [Integer] if great...
[ "Creates", "a", "new", "AsyncProducer", "instance", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/client.rb#L303-L316
train
zendesk/ruby-kafka
lib/kafka/client.rb
Kafka.Client.consumer
def consumer( group_id:, session_timeout: 30, offset_commit_interval: 10, offset_commit_threshold: 0, heartbeat_interval: 10, offset_retention_time: nil, fetcher_max_queue_size: 100 ) cluster = initialize_cluster instrumenter = DecoratingInstrumen...
ruby
def consumer( group_id:, session_timeout: 30, offset_commit_interval: 10, offset_commit_threshold: 0, heartbeat_interval: 10, offset_retention_time: nil, fetcher_max_queue_size: 100 ) cluster = initialize_cluster instrumenter = DecoratingInstrumen...
[ "def", "consumer", "(", "group_id", ":", ",", "session_timeout", ":", "30", ",", "offset_commit_interval", ":", "10", ",", "offset_commit_threshold", ":", "0", ",", "heartbeat_interval", ":", "10", ",", "offset_retention_time", ":", "nil", ",", "fetcher_max_queue_...
Creates a new Kafka consumer. @param group_id [String] the id of the group that the consumer should join. @param session_timeout [Integer] the number of seconds after which, if a client hasn't contacted the Kafka cluster, it will be kicked out of the group. @param offset_commit_interval [Integer] the interval be...
[ "Creates", "a", "new", "Kafka", "consumer", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/client.rb#L336-L397
train
zendesk/ruby-kafka
lib/kafka/client.rb
Kafka.Client.fetch_messages
def fetch_messages(topic:, partition:, offset: :latest, max_wait_time: 5, min_bytes: 1, max_bytes: 1048576, retries: 1) operation = FetchOperation.new( cluster: @cluster, logger: @logger, min_bytes: min_bytes, max_bytes: max_bytes, max_wait_time: max_wait_time, ) ...
ruby
def fetch_messages(topic:, partition:, offset: :latest, max_wait_time: 5, min_bytes: 1, max_bytes: 1048576, retries: 1) operation = FetchOperation.new( cluster: @cluster, logger: @logger, min_bytes: min_bytes, max_bytes: max_bytes, max_wait_time: max_wait_time, ) ...
[ "def", "fetch_messages", "(", "topic", ":", ",", "partition", ":", ",", "offset", ":", ":latest", ",", "max_wait_time", ":", "5", ",", "min_bytes", ":", "1", ",", "max_bytes", ":", "1048576", ",", "retries", ":", "1", ")", "operation", "=", "FetchOperati...
Fetches a batch of messages from a single partition. Note that it's possible to get back empty batches. The starting point for the fetch can be configured with the `:offset` argument. If you pass a number, the fetch will start at that offset. However, there are two special Symbol values that can be passed instead:...
[ "Fetches", "a", "batch", "of", "messages", "from", "a", "single", "partition", ".", "Note", "that", "it", "s", "possible", "to", "get", "back", "empty", "batches", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/client.rb#L458-L484
train
zendesk/ruby-kafka
lib/kafka/client.rb
Kafka.Client.each_message
def each_message(topic:, start_from_beginning: true, max_wait_time: 5, min_bytes: 1, max_bytes: 1048576, &block) default_offset ||= start_from_beginning ? :earliest : :latest offsets = Hash.new { default_offset } loop do operation = FetchOperation.new( cluster: @cluster, l...
ruby
def each_message(topic:, start_from_beginning: true, max_wait_time: 5, min_bytes: 1, max_bytes: 1048576, &block) default_offset ||= start_from_beginning ? :earliest : :latest offsets = Hash.new { default_offset } loop do operation = FetchOperation.new( cluster: @cluster, l...
[ "def", "each_message", "(", "topic", ":", ",", "start_from_beginning", ":", "true", ",", "max_wait_time", ":", "5", ",", "min_bytes", ":", "1", ",", "max_bytes", ":", "1048576", ",", "&", "block", ")", "default_offset", "||=", "start_from_beginning", "?", ":...
Enumerate all messages in a topic. @param topic [String] the topic to consume messages from. @param start_from_beginning [Boolean] whether to start from the beginning of the topic or just subscribe to new messages being produced. @param max_wait_time [Integer] the maximum amount of time to wait before the s...
[ "Enumerate", "all", "messages", "in", "a", "topic", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/client.rb#L506-L530
train
zendesk/ruby-kafka
lib/kafka/client.rb
Kafka.Client.create_topic
def create_topic(name, num_partitions: 1, replication_factor: 1, timeout: 30, config: {}) @cluster.create_topic( name, num_partitions: num_partitions, replication_factor: replication_factor, timeout: timeout, config: config, ) end
ruby
def create_topic(name, num_partitions: 1, replication_factor: 1, timeout: 30, config: {}) @cluster.create_topic( name, num_partitions: num_partitions, replication_factor: replication_factor, timeout: timeout, config: config, ) end
[ "def", "create_topic", "(", "name", ",", "num_partitions", ":", "1", ",", "replication_factor", ":", "1", ",", "timeout", ":", "30", ",", "config", ":", "{", "}", ")", "@cluster", ".", "create_topic", "(", "name", ",", "num_partitions", ":", "num_partition...
Creates a topic in the cluster. @example Creating a topic with log compaction # Enable log compaction: config = { "cleanup.policy" => "compact" } # Create the topic: kafka.create_topic("dns-mappings", config: config) @param name [String] the name of the topic. @param num_partitions [Integer] the numbe...
[ "Creates", "a", "topic", "in", "the", "cluster", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/client.rb#L552-L560
train
zendesk/ruby-kafka
lib/kafka/client.rb
Kafka.Client.create_partitions_for
def create_partitions_for(name, num_partitions: 1, timeout: 30) @cluster.create_partitions_for(name, num_partitions: num_partitions, timeout: timeout) end
ruby
def create_partitions_for(name, num_partitions: 1, timeout: 30) @cluster.create_partitions_for(name, num_partitions: num_partitions, timeout: timeout) end
[ "def", "create_partitions_for", "(", "name", ",", "num_partitions", ":", "1", ",", "timeout", ":", "30", ")", "@cluster", ".", "create_partitions_for", "(", "name", ",", "num_partitions", ":", "num_partitions", ",", "timeout", ":", "timeout", ")", "end" ]
Create partitions for a topic. @param name [String] the name of the topic. @param num_partitions [Integer] the number of desired partitions for the topic @param timeout [Integer] a duration of time to wait for the new partitions to be added. @return [nil]
[ "Create", "partitions", "for", "a", "topic", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/client.rb#L625-L627
train
zendesk/ruby-kafka
lib/kafka/client.rb
Kafka.Client.last_offsets_for
def last_offsets_for(*topics) @cluster.add_target_topics(topics) topics.map {|topic| partition_ids = @cluster.partitions_for(topic).collect(&:partition_id) partition_offsets = @cluster.resolve_offsets(topic, partition_ids, :latest) [topic, partition_offsets.collect { |k, v| [k, v - 1...
ruby
def last_offsets_for(*topics) @cluster.add_target_topics(topics) topics.map {|topic| partition_ids = @cluster.partitions_for(topic).collect(&:partition_id) partition_offsets = @cluster.resolve_offsets(topic, partition_ids, :latest) [topic, partition_offsets.collect { |k, v| [k, v - 1...
[ "def", "last_offsets_for", "(", "*", "topics", ")", "@cluster", ".", "add_target_topics", "(", "topics", ")", "topics", ".", "map", "{", "|", "topic", "|", "partition_ids", "=", "@cluster", ".", "partitions_for", "(", "topic", ")", ".", "collect", "(", ":p...
Retrieve the offset of the last message in each partition of the specified topics. @param topics [Array<String>] topic names. @return [Hash<String, Hash<Integer, Integer>>] @example last_offsets_for('topic-1', 'topic-2') # => # { # 'topic-1' => { 0 => 100, 1 => 100 }, # 'topic-2' => { 0 => 100, 1 =>...
[ "Retrieve", "the", "offset", "of", "the", "last", "message", "in", "each", "partition", "of", "the", "specified", "topics", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/client.rb#L688-L695
train
zendesk/ruby-kafka
lib/kafka/cluster.rb
Kafka.Cluster.add_target_topics
def add_target_topics(topics) topics = Set.new(topics) unless topics.subset?(@target_topics) new_topics = topics - @target_topics unless new_topics.empty? @logger.info "New topics added to target list: #{new_topics.to_a.join(', ')}" @target_topics.merge(new_topics) ...
ruby
def add_target_topics(topics) topics = Set.new(topics) unless topics.subset?(@target_topics) new_topics = topics - @target_topics unless new_topics.empty? @logger.info "New topics added to target list: #{new_topics.to_a.join(', ')}" @target_topics.merge(new_topics) ...
[ "def", "add_target_topics", "(", "topics", ")", "topics", "=", "Set", ".", "new", "(", "topics", ")", "unless", "topics", ".", "subset?", "(", "@target_topics", ")", "new_topics", "=", "topics", "-", "@target_topics", "unless", "new_topics", ".", "empty?", "...
Initializes a Cluster with a set of seed brokers. The cluster will try to fetch cluster metadata from one of the brokers. @param seed_brokers [Array<URI>] @param broker_pool [Kafka::BrokerPool] @param logger [Logger] Adds a list of topics to the target list. Only the topics on this list will be queried for meta...
[ "Initializes", "a", "Cluster", "with", "a", "set", "of", "seed", "brokers", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/cluster.rb#L42-L55
train
zendesk/ruby-kafka
lib/kafka/cluster.rb
Kafka.Cluster.get_transaction_coordinator
def get_transaction_coordinator(transactional_id:) @logger.debug "Getting transaction coordinator for `#{transactional_id}`" refresh_metadata_if_necessary! if transactional_id.nil? # Get a random_broker @logger.debug "Transaction ID is not available. Choose a random broker." ...
ruby
def get_transaction_coordinator(transactional_id:) @logger.debug "Getting transaction coordinator for `#{transactional_id}`" refresh_metadata_if_necessary! if transactional_id.nil? # Get a random_broker @logger.debug "Transaction ID is not available. Choose a random broker." ...
[ "def", "get_transaction_coordinator", "(", "transactional_id", ":", ")", "@logger", ".", "debug", "\"Getting transaction coordinator for `#{transactional_id}`\"", "refresh_metadata_if_necessary!", "if", "transactional_id", ".", "nil?", "# Get a random_broker", "@logger", ".", "de...
Finds the broker acting as the coordinator of the given transaction. @param transactional_id: [String] @return [Broker] the broker that's currently coordinator.
[ "Finds", "the", "broker", "acting", "as", "the", "coordinator", "of", "the", "given", "transaction", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/cluster.rb#L128-L140
train
zendesk/ruby-kafka
lib/kafka/cluster.rb
Kafka.Cluster.list_topics
def list_topics response = random_broker.fetch_metadata(topics: nil) response.topics.select do |topic| topic.topic_error_code == 0 end.map(&:topic_name) end
ruby
def list_topics response = random_broker.fetch_metadata(topics: nil) response.topics.select do |topic| topic.topic_error_code == 0 end.map(&:topic_name) end
[ "def", "list_topics", "response", "=", "random_broker", ".", "fetch_metadata", "(", "topics", ":", "nil", ")", "response", ".", "topics", ".", "select", "do", "|", "topic", "|", "topic", ".", "topic_error_code", "==", "0", "end", ".", "map", "(", ":topic_n...
Lists all topics in the cluster.
[ "Lists", "all", "topics", "in", "the", "cluster", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/cluster.rb#L329-L334
train
zendesk/ruby-kafka
lib/kafka/cluster.rb
Kafka.Cluster.fetch_cluster_info
def fetch_cluster_info errors = [] @seed_brokers.shuffle.each do |node| @logger.info "Fetching cluster metadata from #{node}" begin broker = @broker_pool.connect(node.hostname, node.port) cluster_info = broker.fetch_metadata(topics: @target_topics) if cluster...
ruby
def fetch_cluster_info errors = [] @seed_brokers.shuffle.each do |node| @logger.info "Fetching cluster metadata from #{node}" begin broker = @broker_pool.connect(node.hostname, node.port) cluster_info = broker.fetch_metadata(topics: @target_topics) if cluster...
[ "def", "fetch_cluster_info", "errors", "=", "[", "]", "@seed_brokers", ".", "shuffle", ".", "each", "do", "|", "node", "|", "@logger", ".", "info", "\"Fetching cluster metadata from #{node}\"", "begin", "broker", "=", "@broker_pool", ".", "connect", "(", "node", ...
Fetches the cluster metadata. This is used to update the partition leadership information, among other things. The methods will go through each node listed in `seed_brokers`, connecting to the first one that is available. This node will be queried for the cluster metadata. @raise [ConnectionError] if none of the ...
[ "Fetches", "the", "cluster", "metadata", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/cluster.rb#L367-L397
train
zendesk/ruby-kafka
lib/kafka/async_producer.rb
Kafka.AsyncProducer.produce
def produce(value, topic:, **options) ensure_threads_running! if @queue.size >= @max_queue_size buffer_overflow topic, "Cannot produce to #{topic}, max queue size (#{@max_queue_size} messages) reached" end args = [value, **options.merge(topic: topic)] @queue << [:produc...
ruby
def produce(value, topic:, **options) ensure_threads_running! if @queue.size >= @max_queue_size buffer_overflow topic, "Cannot produce to #{topic}, max queue size (#{@max_queue_size} messages) reached" end args = [value, **options.merge(topic: topic)] @queue << [:produc...
[ "def", "produce", "(", "value", ",", "topic", ":", ",", "**", "options", ")", "ensure_threads_running!", "if", "@queue", ".", "size", ">=", "@max_queue_size", "buffer_overflow", "topic", ",", "\"Cannot produce to #{topic}, max queue size (#{@max_queue_size} messages) reache...
Initializes a new AsyncProducer. @param sync_producer [Kafka::Producer] the synchronous producer that should be used in the background. @param max_queue_size [Integer] the maximum number of messages allowed in the queue. @param delivery_threshold [Integer] if greater than zero, the number of buffered messa...
[ "Initializes", "a", "new", "AsyncProducer", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/async_producer.rb#L105-L123
train
zendesk/ruby-kafka
lib/kafka/ssl_socket_with_timeout.rb
Kafka.SSLSocketWithTimeout.write
def write(bytes) loop do written = 0 begin # unlike plain tcp sockets, ssl sockets don't support IO.select # properly. # Instead, timeouts happen on a per write basis, and we have to # catch exceptions from write_nonblock, and gradually build up # ...
ruby
def write(bytes) loop do written = 0 begin # unlike plain tcp sockets, ssl sockets don't support IO.select # properly. # Instead, timeouts happen on a per write basis, and we have to # catch exceptions from write_nonblock, and gradually build up # ...
[ "def", "write", "(", "bytes", ")", "loop", "do", "written", "=", "0", "begin", "# unlike plain tcp sockets, ssl sockets don't support IO.select", "# properly.", "# Instead, timeouts happen on a per write basis, and we have to", "# catch exceptions from write_nonblock, and gradually build...
Writes bytes to the socket, possible with a timeout. @param bytes [String] the data that should be written to the socket. @raise [Errno::ETIMEDOUT] if the timeout is exceeded. @return [Integer] the number of bytes written.
[ "Writes", "bytes", "to", "the", "socket", "possible", "with", "a", "timeout", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/ssl_socket_with_timeout.rb#L126-L159
train
zendesk/ruby-kafka
lib/kafka/consumer.rb
Kafka.Consumer.subscribe
def subscribe(topic_or_regex, default_offset: nil, start_from_beginning: true, max_bytes_per_partition: 1048576) default_offset ||= start_from_beginning ? :earliest : :latest if topic_or_regex.is_a?(Regexp) cluster_topics.select { |topic| topic =~ topic_or_regex }.each do |topic| subscrib...
ruby
def subscribe(topic_or_regex, default_offset: nil, start_from_beginning: true, max_bytes_per_partition: 1048576) default_offset ||= start_from_beginning ? :earliest : :latest if topic_or_regex.is_a?(Regexp) cluster_topics.select { |topic| topic =~ topic_or_regex }.each do |topic| subscrib...
[ "def", "subscribe", "(", "topic_or_regex", ",", "default_offset", ":", "nil", ",", "start_from_beginning", ":", "true", ",", "max_bytes_per_partition", ":", "1048576", ")", "default_offset", "||=", "start_from_beginning", "?", ":earliest", ":", ":latest", "if", "top...
Subscribes the consumer to a topic. Typically you either want to start reading messages from the very beginning of the topic's partitions or you simply want to wait for new messages to be written. In the former case, set `start_from_beginning` to true (the default); in the latter, set it to false. @param topic_o...
[ "Subscribes", "the", "consumer", "to", "a", "topic", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/consumer.rb#L97-L109
train
zendesk/ruby-kafka
lib/kafka/consumer.rb
Kafka.Consumer.pause
def pause(topic, partition, timeout: nil, max_timeout: nil, exponential_backoff: false) if max_timeout && !exponential_backoff raise ArgumentError, "`max_timeout` only makes sense when `exponential_backoff` is enabled" end pause_for(topic, partition).pause!( timeout: timeout, ...
ruby
def pause(topic, partition, timeout: nil, max_timeout: nil, exponential_backoff: false) if max_timeout && !exponential_backoff raise ArgumentError, "`max_timeout` only makes sense when `exponential_backoff` is enabled" end pause_for(topic, partition).pause!( timeout: timeout, ...
[ "def", "pause", "(", "topic", ",", "partition", ",", "timeout", ":", "nil", ",", "max_timeout", ":", "nil", ",", "exponential_backoff", ":", "false", ")", "if", "max_timeout", "&&", "!", "exponential_backoff", "raise", "ArgumentError", ",", "\"`max_timeout` only...
Pause processing of a specific topic partition. When a specific message causes the processor code to fail, it can be a good idea to simply pause the partition until the error can be resolved, allowing the rest of the partitions to continue being processed. If the `timeout` argument is passed, the partition will a...
[ "Pause", "processing", "of", "a", "specific", "topic", "partition", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/consumer.rb#L141-L151
train
zendesk/ruby-kafka
lib/kafka/consumer.rb
Kafka.Consumer.resume
def resume(topic, partition) pause_for(topic, partition).resume! # During re-balancing we might have lost the paused partition. Check if partition is still in group before seek. seek_to_next(topic, partition) if @group.assigned_to?(topic, partition) end
ruby
def resume(topic, partition) pause_for(topic, partition).resume! # During re-balancing we might have lost the paused partition. Check if partition is still in group before seek. seek_to_next(topic, partition) if @group.assigned_to?(topic, partition) end
[ "def", "resume", "(", "topic", ",", "partition", ")", "pause_for", "(", "topic", ",", "partition", ")", ".", "resume!", "# During re-balancing we might have lost the paused partition. Check if partition is still in group before seek.", "seek_to_next", "(", "topic", ",", "part...
Resume processing of a topic partition. @see #pause @param topic [String] @param partition [Integer] @return [nil]
[ "Resume", "processing", "of", "a", "topic", "partition", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/consumer.rb#L159-L164
train
zendesk/ruby-kafka
lib/kafka/consumer.rb
Kafka.Consumer.paused?
def paused?(topic, partition) pause = pause_for(topic, partition) pause.paused? && !pause.expired? end
ruby
def paused?(topic, partition) pause = pause_for(topic, partition) pause.paused? && !pause.expired? end
[ "def", "paused?", "(", "topic", ",", "partition", ")", "pause", "=", "pause_for", "(", "topic", ",", "partition", ")", "pause", ".", "paused?", "&&", "!", "pause", ".", "expired?", "end" ]
Whether the topic partition is currently paused. @see #pause @param topic [String] @param partition [Integer] @return [Boolean] true if the partition is paused, false otherwise.
[ "Whether", "the", "topic", "partition", "is", "currently", "paused", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/consumer.rb#L172-L175
train
zendesk/ruby-kafka
lib/kafka/offset_manager.rb
Kafka.OffsetManager.seek_to_default
def seek_to_default(topic, partition) # Remove any cached offset, in case things have changed broker-side. clear_resolved_offset(topic) offset = resolve_offset(topic, partition) seek_to(topic, partition, offset) end
ruby
def seek_to_default(topic, partition) # Remove any cached offset, in case things have changed broker-side. clear_resolved_offset(topic) offset = resolve_offset(topic, partition) seek_to(topic, partition, offset) end
[ "def", "seek_to_default", "(", "topic", ",", "partition", ")", "# Remove any cached offset, in case things have changed broker-side.", "clear_resolved_offset", "(", "topic", ")", "offset", "=", "resolve_offset", "(", "topic", ",", "partition", ")", "seek_to", "(", "topic"...
Move the consumer's position in the partition back to the configured default offset, either the first or latest in the partition. @param topic [String] the name of the topic. @param partition [Integer] the partition number. @return [nil]
[ "Move", "the", "consumer", "s", "position", "in", "the", "partition", "back", "to", "the", "configured", "default", "offset", "either", "the", "first", "or", "latest", "in", "the", "partition", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/offset_manager.rb#L68-L75
train
zendesk/ruby-kafka
lib/kafka/offset_manager.rb
Kafka.OffsetManager.seek_to
def seek_to(topic, partition, offset) @processed_offsets[topic] ||= {} @processed_offsets[topic][partition] = offset @fetcher.seek(topic, partition, offset) end
ruby
def seek_to(topic, partition, offset) @processed_offsets[topic] ||= {} @processed_offsets[topic][partition] = offset @fetcher.seek(topic, partition, offset) end
[ "def", "seek_to", "(", "topic", ",", "partition", ",", "offset", ")", "@processed_offsets", "[", "topic", "]", "||=", "{", "}", "@processed_offsets", "[", "topic", "]", "[", "partition", "]", "=", "offset", "@fetcher", ".", "seek", "(", "topic", ",", "pa...
Move the consumer's position in the partition to the specified offset. @param topic [String] the name of the topic. @param partition [Integer] the partition number. @param offset [Integer] the offset that the consumer position should be moved to. @return [nil]
[ "Move", "the", "consumer", "s", "position", "in", "the", "partition", "to", "the", "specified", "offset", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/offset_manager.rb#L83-L88
train
zendesk/ruby-kafka
lib/kafka/offset_manager.rb
Kafka.OffsetManager.next_offset_for
def next_offset_for(topic, partition) offset = @processed_offsets.fetch(topic, {}).fetch(partition) { committed_offset_for(topic, partition) } # A negative offset means that no offset has been committed, so we need to # resolve the default offset for the topic. if offset < 0 ...
ruby
def next_offset_for(topic, partition) offset = @processed_offsets.fetch(topic, {}).fetch(partition) { committed_offset_for(topic, partition) } # A negative offset means that no offset has been committed, so we need to # resolve the default offset for the topic. if offset < 0 ...
[ "def", "next_offset_for", "(", "topic", ",", "partition", ")", "offset", "=", "@processed_offsets", ".", "fetch", "(", "topic", ",", "{", "}", ")", ".", "fetch", "(", "partition", ")", "{", "committed_offset_for", "(", "topic", ",", "partition", ")", "}", ...
Return the next offset that should be fetched for the specified partition. @param topic [String] the name of the topic. @param partition [Integer] the partition number. @return [Integer] the next offset that should be fetched.
[ "Return", "the", "next", "offset", "that", "should", "be", "fetched", "for", "the", "specified", "partition", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/offset_manager.rb#L95-L108
train
zendesk/ruby-kafka
lib/kafka/offset_manager.rb
Kafka.OffsetManager.commit_offsets
def commit_offsets(recommit = false) offsets = offsets_to_commit(recommit) unless offsets.empty? @logger.debug "Committing offsets#{recommit ? ' with recommit' : ''}: #{prettify_offsets(offsets)}" @group.commit_offsets(offsets) @last_commit = Time.now @last_recommit = Time....
ruby
def commit_offsets(recommit = false) offsets = offsets_to_commit(recommit) unless offsets.empty? @logger.debug "Committing offsets#{recommit ? ' with recommit' : ''}: #{prettify_offsets(offsets)}" @group.commit_offsets(offsets) @last_commit = Time.now @last_recommit = Time....
[ "def", "commit_offsets", "(", "recommit", "=", "false", ")", "offsets", "=", "offsets_to_commit", "(", "recommit", ")", "unless", "offsets", ".", "empty?", "@logger", ".", "debug", "\"Committing offsets#{recommit ? ' with recommit' : ''}: #{prettify_offsets(offsets)}\"", "@...
Commit offsets of messages that have been marked as processed. If `recommit` is set to true, we will also commit the existing positions even if no messages have been processed on a partition. This is done in order to avoid the offset information expiring in cases where messages are very rare -- it's essentially a ...
[ "Commit", "offsets", "of", "messages", "that", "have", "been", "marked", "as", "processed", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/offset_manager.rb#L120-L133
train
zendesk/ruby-kafka
lib/kafka/offset_manager.rb
Kafka.OffsetManager.clear_offsets_excluding
def clear_offsets_excluding(excluded) # Clear all offsets that aren't in `excluded`. @processed_offsets.each do |topic, partitions| partitions.keep_if do |partition, _| excluded.fetch(topic, []).include?(partition) end end # Clear the cached commits from the brokers. ...
ruby
def clear_offsets_excluding(excluded) # Clear all offsets that aren't in `excluded`. @processed_offsets.each do |topic, partitions| partitions.keep_if do |partition, _| excluded.fetch(topic, []).include?(partition) end end # Clear the cached commits from the brokers. ...
[ "def", "clear_offsets_excluding", "(", "excluded", ")", "# Clear all offsets that aren't in `excluded`.", "@processed_offsets", ".", "each", "do", "|", "topic", ",", "partitions", "|", "partitions", ".", "keep_if", "do", "|", "partition", ",", "_", "|", "excluded", ...
Clear stored offset information for all partitions except those specified in `excluded`. offset_manager.clear_offsets_excluding("my-topic" => [1, 2, 3]) @return [nil]
[ "Clear", "stored", "offset", "information", "for", "all", "partitions", "except", "those", "specified", "in", "excluded", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/offset_manager.rb#L163-L174
train
zendesk/ruby-kafka
lib/kafka/connection.rb
Kafka.Connection.send_request
def send_request(request) api_name = Protocol.api_name(request.api_key) # Default notification payload. notification = { broker_host: @host, api: api_name, request_size: 0, response_size: 0, } raise IdleConnection if idle? @logger.push_tags(api_name...
ruby
def send_request(request) api_name = Protocol.api_name(request.api_key) # Default notification payload. notification = { broker_host: @host, api: api_name, request_size: 0, response_size: 0, } raise IdleConnection if idle? @logger.push_tags(api_name...
[ "def", "send_request", "(", "request", ")", "api_name", "=", "Protocol", ".", "api_name", "(", "request", ".", "api_key", ")", "# Default notification payload.", "notification", "=", "{", "broker_host", ":", "@host", ",", "api", ":", "api_name", ",", "request_si...
Sends a request over the connection. @param request [#encode, #response_class] the request that should be encoded and written. @return [Object] the response.
[ "Sends", "a", "request", "over", "the", "connection", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/connection.rb#L83-L119
train
zendesk/ruby-kafka
lib/kafka/connection.rb
Kafka.Connection.write_request
def write_request(request, notification) message = Kafka::Protocol::RequestMessage.new( api_key: request.api_key, api_version: request.respond_to?(:api_version) ? request.api_version : 0, correlation_id: @correlation_id, client_id: @client_id, request: request, ) ...
ruby
def write_request(request, notification) message = Kafka::Protocol::RequestMessage.new( api_key: request.api_key, api_version: request.respond_to?(:api_version) ? request.api_version : 0, correlation_id: @correlation_id, client_id: @client_id, request: request, ) ...
[ "def", "write_request", "(", "request", ",", "notification", ")", "message", "=", "Kafka", "::", "Protocol", "::", "RequestMessage", ".", "new", "(", "api_key", ":", "request", ".", "api_key", ",", "api_version", ":", "request", ".", "respond_to?", "(", ":ap...
Writes a request over the connection. @param request [#encode] the request that should be encoded and written. @return [nil]
[ "Writes", "a", "request", "over", "the", "connection", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/connection.rb#L156-L174
train
zendesk/ruby-kafka
lib/kafka/connection.rb
Kafka.Connection.read_response
def read_response(response_class, notification) @logger.debug "Waiting for response #{@correlation_id} from #{to_s}" data = @decoder.bytes notification[:response_size] = data.bytesize buffer = StringIO.new(data) response_decoder = Kafka::Protocol::Decoder.new(buffer) correlation_i...
ruby
def read_response(response_class, notification) @logger.debug "Waiting for response #{@correlation_id} from #{to_s}" data = @decoder.bytes notification[:response_size] = data.bytesize buffer = StringIO.new(data) response_decoder = Kafka::Protocol::Decoder.new(buffer) correlation_i...
[ "def", "read_response", "(", "response_class", ",", "notification", ")", "@logger", ".", "debug", "\"Waiting for response #{@correlation_id} from #{to_s}\"", "data", "=", "@decoder", ".", "bytes", "notification", "[", ":response_size", "]", "=", "data", ".", "bytesize",...
Reads a response from the connection. @param response_class [#decode] an object that can decode the response from a given Decoder. @return [nil]
[ "Reads", "a", "response", "from", "the", "connection", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/connection.rb#L182-L200
train
zendesk/ruby-kafka
lib/kafka/producer.rb
Kafka.Producer.deliver_messages
def deliver_messages # There's no need to do anything if the buffer is empty. return if buffer_size == 0 @instrumenter.instrument("deliver_messages.producer") do |notification| message_count = buffer_size notification[:message_count] = message_count notification[:attempts] = ...
ruby
def deliver_messages # There's no need to do anything if the buffer is empty. return if buffer_size == 0 @instrumenter.instrument("deliver_messages.producer") do |notification| message_count = buffer_size notification[:message_count] = message_count notification[:attempts] = ...
[ "def", "deliver_messages", "# There's no need to do anything if the buffer is empty.", "return", "if", "buffer_size", "==", "0", "@instrumenter", ".", "instrument", "(", "\"deliver_messages.producer\"", ")", "do", "|", "notification", "|", "message_count", "=", "buffer_size",...
Sends all buffered messages to the Kafka brokers. Depending on the value of `required_acks` used when initializing the producer, this call may block until the specified number of replicas have acknowledged the writes. The `ack_timeout` setting places an upper bound on the amount of time the call will block before ...
[ "Sends", "all", "buffered", "messages", "to", "the", "Kafka", "brokers", "." ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/producer.rb#L242-L258
train
zendesk/ruby-kafka
lib/kafka/producer.rb
Kafka.Producer.send_offsets_to_transaction
def send_offsets_to_transaction(batch:, group_id:) @transaction_manager.send_offsets_to_txn(offsets: { batch.topic => { batch.partition => { offset: batch.last_offset + 1, leader_epoch: batch.leader_epoch } } }, group_id: group_id) end
ruby
def send_offsets_to_transaction(batch:, group_id:) @transaction_manager.send_offsets_to_txn(offsets: { batch.topic => { batch.partition => { offset: batch.last_offset + 1, leader_epoch: batch.leader_epoch } } }, group_id: group_id) end
[ "def", "send_offsets_to_transaction", "(", "batch", ":", ",", "group_id", ":", ")", "@transaction_manager", ".", "send_offsets_to_txn", "(", "offsets", ":", "{", "batch", ".", "topic", "=>", "{", "batch", ".", "partition", "=>", "{", "offset", ":", "batch", ...
Sends batch last offset to the consumer group coordinator, and also marks this offset as part of the current transaction. This offset will be considered committed only if the transaction is committed successfully. This method should be used when you need to batch consumed and produced messages together, typically ...
[ "Sends", "batch", "last", "offset", "to", "the", "consumer", "group", "coordinator", "and", "also", "marks", "this", "offset", "as", "part", "of", "the", "current", "transaction", ".", "This", "offset", "will", "be", "considered", "committed", "only", "if", ...
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/producer.rb#L343-L345
train
zendesk/ruby-kafka
lib/kafka/producer.rb
Kafka.Producer.transaction
def transaction raise 'This method requires a block' unless block_given? begin_transaction yield commit_transaction rescue Kafka::Producer::AbortTransaction abort_transaction rescue abort_transaction raise end
ruby
def transaction raise 'This method requires a block' unless block_given? begin_transaction yield commit_transaction rescue Kafka::Producer::AbortTransaction abort_transaction rescue abort_transaction raise end
[ "def", "transaction", "raise", "'This method requires a block'", "unless", "block_given?", "begin_transaction", "yield", "commit_transaction", "rescue", "Kafka", "::", "Producer", "::", "AbortTransaction", "abort_transaction", "rescue", "abort_transaction", "raise", "end" ]
Syntactic sugar to enable easier transaction usage. Do the following steps - Start the transaction (with Producer#begin_transaction) - Yield the given block - Commit the transaction (with Producer#commit_transaction) If the block raises exception, the transaction is automatically aborted *before* bubble up the e...
[ "Syntactic", "sugar", "to", "enable", "easier", "transaction", "usage", ".", "Do", "the", "following", "steps" ]
2a73471b6a607a52dc85c79301ba522acb4566b5
https://github.com/zendesk/ruby-kafka/blob/2a73471b6a607a52dc85c79301ba522acb4566b5/lib/kafka/producer.rb#L360-L370
train
teamcapybara/capybara
lib/capybara/session.rb
Capybara.Session.open_new_window
def open_new_window(kind = :tab) window_opened_by do if driver.method(:open_new_window).arity.zero? driver.open_new_window else driver.open_new_window(kind) end end end
ruby
def open_new_window(kind = :tab) window_opened_by do if driver.method(:open_new_window).arity.zero? driver.open_new_window else driver.open_new_window(kind) end end end
[ "def", "open_new_window", "(", "kind", "=", ":tab", ")", "window_opened_by", "do", "if", "driver", ".", "method", "(", ":open_new_window", ")", ".", "arity", ".", "zero?", "driver", ".", "open_new_window", "else", "driver", ".", "open_new_window", "(", "kind",...
Open new window. Current window doesn't change as the result of this call. It should be switched to explicitly. @return [Capybara::Window] window that has been opened
[ "Open", "new", "window", ".", "Current", "window", "doesn", "t", "change", "as", "the", "result", "of", "this", "call", ".", "It", "should", "be", "switched", "to", "explicitly", "." ]
3819078c820c5cd3be6f0bc9e8b1b0cc1190bc41
https://github.com/teamcapybara/capybara/blob/3819078c820c5cd3be6f0bc9e8b1b0cc1190bc41/lib/capybara/session.rb#L461-L469
train
lostisland/faraday
lib/faraday/autoload.rb
Faraday.AutoloadHelper.autoload_all
def autoload_all(prefix, options) if prefix =~ %r{^faraday(/|$)}i prefix = File.join(Faraday.root_path, prefix) end options.each do |const_name, path| autoload const_name, File.join(prefix, path) end end
ruby
def autoload_all(prefix, options) if prefix =~ %r{^faraday(/|$)}i prefix = File.join(Faraday.root_path, prefix) end options.each do |const_name, path| autoload const_name, File.join(prefix, path) end end
[ "def", "autoload_all", "(", "prefix", ",", "options", ")", "if", "prefix", "=~", "%r{", "}i", "prefix", "=", "File", ".", "join", "(", "Faraday", ".", "root_path", ",", "prefix", ")", "end", "options", ".", "each", "do", "|", "const_name", ",", "path",...
Registers the constants to be auto loaded. @param prefix [String] The require prefix. If the path is inside Faraday, then it will be prefixed with the root path of this loaded Faraday version. @param options [{ Symbol => String }] library names. @example Faraday.autoload_all 'faraday/foo'...
[ "Registers", "the", "constants", "to", "be", "auto", "loaded", "." ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/autoload.rb#L25-L33
train
lostisland/faraday
lib/faraday/autoload.rb
Faraday.AutoloadHelper.all_loaded_constants
def all_loaded_constants constants .map { |c| const_get(c) } .select { |a| a.respond_to?(:loaded?) && a.loaded? } end
ruby
def all_loaded_constants constants .map { |c| const_get(c) } .select { |a| a.respond_to?(:loaded?) && a.loaded? } end
[ "def", "all_loaded_constants", "constants", ".", "map", "{", "|", "c", "|", "const_get", "(", "c", ")", "}", ".", "select", "{", "|", "a", "|", "a", ".", "respond_to?", "(", ":loaded?", ")", "&&", "a", ".", "loaded?", "}", "end" ]
Filters the module's contents with those that have been already autoloaded. @return [Array<Class, Module>]
[ "Filters", "the", "module", "s", "contents", "with", "those", "that", "have", "been", "already", "autoloaded", "." ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/autoload.rb#L49-L53
train
lostisland/faraday
spec/support/helper_methods.rb
Faraday.HelperMethods.parse_multipart
def parse_multipart(boundary, body) reader = MultipartParser::Reader.new(boundary) result = { errors: [], parts: [] } def result.part(name) hash = self[:parts].detect { |h| h[:part].name == name } [hash[:part], hash[:body].join] end reader.on_part do |part| result[...
ruby
def parse_multipart(boundary, body) reader = MultipartParser::Reader.new(boundary) result = { errors: [], parts: [] } def result.part(name) hash = self[:parts].detect { |h| h[:part].name == name } [hash[:part], hash[:body].join] end reader.on_part do |part| result[...
[ "def", "parse_multipart", "(", "boundary", ",", "body", ")", "reader", "=", "MultipartParser", "::", "Reader", ".", "new", "(", "boundary", ")", "result", "=", "{", "errors", ":", "[", "]", ",", "parts", ":", "[", "]", "}", "def", "result", ".", "par...
parse a multipart MIME message, returning a hash of any multipart errors
[ "parse", "a", "multipart", "MIME", "message", "returning", "a", "hash", "of", "any", "multipart", "errors" ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/spec/support/helper_methods.rb#L100-L122
train
lostisland/faraday
lib/faraday/dependency_loader.rb
Faraday.DependencyLoader.dependency
def dependency(lib = nil) lib ? require(lib) : yield rescue LoadError, NameError => e self.load_error = e end
ruby
def dependency(lib = nil) lib ? require(lib) : yield rescue LoadError, NameError => e self.load_error = e end
[ "def", "dependency", "(", "lib", "=", "nil", ")", "lib", "?", "require", "(", "lib", ")", ":", "yield", "rescue", "LoadError", ",", "NameError", "=>", "e", "self", ".", "load_error", "=", "e", "end" ]
Executes a block which should try to require and reference dependent libraries
[ "Executes", "a", "block", "which", "should", "try", "to", "require", "and", "reference", "dependent", "libraries" ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/dependency_loader.rb#L10-L14
train
lostisland/faraday
lib/faraday/connection.rb
Faraday.Connection.default_parallel_manager
def default_parallel_manager @default_parallel_manager ||= begin adapter = @builder.adapter.klass if @builder.adapter if support_parallel?(adapter) adapter.setup_parallel_manager elsif block_given? yield end end end
ruby
def default_parallel_manager @default_parallel_manager ||= begin adapter = @builder.adapter.klass if @builder.adapter if support_parallel?(adapter) adapter.setup_parallel_manager elsif block_given? yield end end end
[ "def", "default_parallel_manager", "@default_parallel_manager", "||=", "begin", "adapter", "=", "@builder", ".", "adapter", ".", "klass", "if", "@builder", ".", "adapter", "if", "support_parallel?", "(", "adapter", ")", "adapter", ".", "setup_parallel_manager", "elsif...
Check if the adapter is parallel-capable. @yield if the adapter isn't parallel-capable, or if no adapter is set yet. @return [Object, nil] a parallel manager or nil if yielded @api private
[ "Check", "if", "the", "adapter", "is", "parallel", "-", "capable", "." ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/connection.rb#L355-L365
train
lostisland/faraday
lib/faraday/connection.rb
Faraday.Connection.url_prefix=
def url_prefix=(url, encoder = nil) uri = @url_prefix = Utils.URI(url) self.path_prefix = uri.path params.merge_query(uri.query, encoder) uri.query = nil with_uri_credentials(uri) do |user, password| basic_auth user, password uri.user = uri.password = nil end en...
ruby
def url_prefix=(url, encoder = nil) uri = @url_prefix = Utils.URI(url) self.path_prefix = uri.path params.merge_query(uri.query, encoder) uri.query = nil with_uri_credentials(uri) do |user, password| basic_auth user, password uri.user = uri.password = nil end en...
[ "def", "url_prefix", "=", "(", "url", ",", "encoder", "=", "nil", ")", "uri", "=", "@url_prefix", "=", "Utils", ".", "URI", "(", "url", ")", "self", ".", "path_prefix", "=", "uri", ".", "path", "params", ".", "merge_query", "(", "uri", ".", "query", ...
Parses the given URL with URI and stores the individual components in this connection. These components serve as defaults for requests made by this connection. @param url [String, URI] @param encoder [Object] @example conn = Faraday::Connection.new { ... } conn.url_prefix = "https://sushi.com/api" conn...
[ "Parses", "the", "given", "URL", "with", "URI", "and", "stores", "the", "individual", "components", "in", "this", "connection", ".", "These", "components", "serve", "as", "defaults", "for", "requests", "made", "by", "this", "connection", "." ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/connection.rb#L420-L431
train
lostisland/faraday
lib/faraday/connection.rb
Faraday.Connection.build_url
def build_url(url = nil, extra_params = nil) uri = build_exclusive_url(url) query_values = params.dup.merge_query(uri.query, options.params_encoder) query_values.update(extra_params) if extra_params uri.query = if query_values.empty? nil else query_values.to_...
ruby
def build_url(url = nil, extra_params = nil) uri = build_exclusive_url(url) query_values = params.dup.merge_query(uri.query, options.params_encoder) query_values.update(extra_params) if extra_params uri.query = if query_values.empty? nil else query_values.to_...
[ "def", "build_url", "(", "url", "=", "nil", ",", "extra_params", "=", "nil", ")", "uri", "=", "build_exclusive_url", "(", "url", ")", "query_values", "=", "params", ".", "dup", ".", "merge_query", "(", "uri", ".", "query", ",", "options", ".", "params_en...
Takes a relative url for a request and combines it with the defaults set on the connection instance. @param url [String] @param extra_params [Hash] @example conn = Faraday::Connection.new { ... } conn.url_prefix = "https://sushi.com/api?token=abc" conn.scheme # => https conn.path_prefix # => "/ap...
[ "Takes", "a", "relative", "url", "for", "a", "request", "and", "combines", "it", "with", "the", "defaults", "set", "on", "the", "connection", "instance", "." ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/connection.rb#L464-L477
train
lostisland/faraday
lib/faraday/connection.rb
Faraday.Connection.build_request
def build_request(method) Request.create(method) do |req| req.params = params.dup req.headers = headers.dup req.options = options yield(req) if block_given? end end
ruby
def build_request(method) Request.create(method) do |req| req.params = params.dup req.headers = headers.dup req.options = options yield(req) if block_given? end end
[ "def", "build_request", "(", "method", ")", "Request", ".", "create", "(", "method", ")", "do", "|", "req", "|", "req", ".", "params", "=", "params", ".", "dup", "req", ".", "headers", "=", "headers", ".", "dup", "req", ".", "options", "=", "options"...
Creates and configures the request object. @param method [Symbol] @yield [Faraday::Request] if block given @return [Faraday::Request]
[ "Creates", "and", "configures", "the", "request", "object", "." ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/connection.rb#L513-L520
train
lostisland/faraday
lib/faraday/connection.rb
Faraday.Connection.build_exclusive_url
def build_exclusive_url(url = nil, params = nil, params_encoder = nil) url = nil if url.respond_to?(:empty?) && url.empty? base = url_prefix if url && base.path && base.path !~ %r{/$} base = base.dup base.path = base.path + '/' # ensure trailing slash end uri = url ? base +...
ruby
def build_exclusive_url(url = nil, params = nil, params_encoder = nil) url = nil if url.respond_to?(:empty?) && url.empty? base = url_prefix if url && base.path && base.path !~ %r{/$} base = base.dup base.path = base.path + '/' # ensure trailing slash end uri = url ? base +...
[ "def", "build_exclusive_url", "(", "url", "=", "nil", ",", "params", "=", "nil", ",", "params_encoder", "=", "nil", ")", "url", "=", "nil", "if", "url", ".", "respond_to?", "(", ":empty?", ")", "&&", "url", ".", "empty?", "base", "=", "url_prefix", "if...
Build an absolute URL based on url_prefix. @param url [String, URI] @param params [Faraday::Utils::ParamsHash] A Faraday::Utils::ParamsHash to replace the query values of the resulting url (default: nil). @return [URI]
[ "Build", "an", "absolute", "URL", "based", "on", "url_prefix", "." ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/connection.rb#L530-L545
train
lostisland/faraday
lib/faraday/utils.rb
Faraday.Utils.normalize_path
def normalize_path(url) url = URI(url) (url.path.start_with?('/') ? url.path : '/' + url.path) + (url.query ? "?#{sort_query_params(url.query)}" : '') end
ruby
def normalize_path(url) url = URI(url) (url.path.start_with?('/') ? url.path : '/' + url.path) + (url.query ? "?#{sort_query_params(url.query)}" : '') end
[ "def", "normalize_path", "(", "url", ")", "url", "=", "URI", "(", "url", ")", "(", "url", ".", "path", ".", "start_with?", "(", "'/'", ")", "?", "url", ".", "path", ":", "'/'", "+", "url", ".", "path", ")", "+", "(", "url", ".", "query", "?", ...
Receives a String or URI and returns just the path with the query string sorted.
[ "Receives", "a", "String", "or", "URI", "and", "returns", "just", "the", "path", "with", "the", "query", "string", "sorted", "." ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/utils.rb#L82-L86
train
lostisland/faraday
lib/faraday/utils.rb
Faraday.Utils.deep_merge!
def deep_merge!(target, hash) hash.each do |key, value| target[key] = if value.is_a?(Hash) && target[key].is_a?(Hash) deep_merge(target[key], value) else value end end target end
ruby
def deep_merge!(target, hash) hash.each do |key, value| target[key] = if value.is_a?(Hash) && target[key].is_a?(Hash) deep_merge(target[key], value) else value end end target end
[ "def", "deep_merge!", "(", "target", ",", "hash", ")", "hash", ".", "each", "do", "|", "key", ",", "value", "|", "target", "[", "key", "]", "=", "if", "value", ".", "is_a?", "(", "Hash", ")", "&&", "target", "[", "key", "]", ".", "is_a?", "(", ...
Recursive hash update
[ "Recursive", "hash", "update" ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/utils.rb#L89-L98
train
lostisland/faraday
lib/faraday/request.rb
Faraday.Request.url
def url(path, params = nil) if path.respond_to? :query if (query = path.query) path = path.dup path.query = nil end else anchor_index = path.index('#') path = path.slice(0, anchor_index) unless anchor_index.nil? path, query = path.split('?', 2) ...
ruby
def url(path, params = nil) if path.respond_to? :query if (query = path.query) path = path.dup path.query = nil end else anchor_index = path.index('#') path = path.slice(0, anchor_index) unless anchor_index.nil? path, query = path.split('?', 2) ...
[ "def", "url", "(", "path", ",", "params", "=", "nil", ")", "if", "path", ".", "respond_to?", ":query", "if", "(", "query", "=", "path", ".", "query", ")", "path", "=", "path", ".", "dup", "path", ".", "query", "=", "nil", "end", "else", "anchor_ind...
Update path and params. @param path [URI, String] @param params [Hash, nil] @return [void]
[ "Update", "path", "and", "params", "." ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/request.rb#L86-L100
train
lostisland/faraday
lib/faraday/request.rb
Faraday.Request.marshal_dump
def marshal_dump { method: method, body: body, headers: headers, path: path, params: params, options: options } end
ruby
def marshal_dump { method: method, body: body, headers: headers, path: path, params: params, options: options } end
[ "def", "marshal_dump", "{", "method", ":", "method", ",", "body", ":", "body", ",", "headers", ":", "headers", ",", "path", ":", "path", ",", "params", ":", "params", ",", "options", ":", "options", "}", "end" ]
Marshal serialization support. @return [Hash] the hash ready to be serialized in Marshal.
[ "Marshal", "serialization", "support", "." ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/request.rb#L117-L126
train
lostisland/faraday
lib/faraday/request.rb
Faraday.Request.marshal_load
def marshal_load(serialised) self.method = serialised[:method] self.body = serialised[:body] self.headers = serialised[:headers] self.path = serialised[:path] self.params = serialised[:params] self.options = serialised[:options] end
ruby
def marshal_load(serialised) self.method = serialised[:method] self.body = serialised[:body] self.headers = serialised[:headers] self.path = serialised[:path] self.params = serialised[:params] self.options = serialised[:options] end
[ "def", "marshal_load", "(", "serialised", ")", "self", ".", "method", "=", "serialised", "[", ":method", "]", "self", ".", "body", "=", "serialised", "[", ":body", "]", "self", ".", "headers", "=", "serialised", "[", ":headers", "]", "self", ".", "path",...
Marshal serialization support. Restores the instance variables according to the +serialised+. @param serialised [Hash] the serialised object.
[ "Marshal", "serialization", "support", ".", "Restores", "the", "instance", "variables", "according", "to", "the", "+", "serialised", "+", "." ]
3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70
https://github.com/lostisland/faraday/blob/3abe9d1eea4bdf61cdf7b76ff9f1ae7e09482e70/lib/faraday/request.rb#L131-L138
train
aws/aws-sdk-ruby
gems/aws-sdk-s3/lib/aws-sdk-s3/client.rb
Aws::S3.Client.get_bucket_policy
def get_bucket_policy(params = {}, options = {}, &block) req = build_request(:get_bucket_policy, params) req.send_request(options, &block) end
ruby
def get_bucket_policy(params = {}, options = {}, &block) req = build_request(:get_bucket_policy, params) req.send_request(options, &block) end
[ "def", "get_bucket_policy", "(", "params", "=", "{", "}", ",", "options", "=", "{", "}", ",", "&", "block", ")", "req", "=", "build_request", "(", ":get_bucket_policy", ",", "params", ")", "req", ".", "send_request", "(", "options", ",", "block", ")", ...
Returns the policy of a specified bucket. @option params [required, String] :bucket @return [Types::GetBucketPolicyOutput] Returns a {Seahorse::Client::Response response} object which responds to the following methods: * {Types::GetBucketPolicyOutput#policy #policy} => IO @example Example: To get bucket poli...
[ "Returns", "the", "policy", "of", "a", "specified", "bucket", "." ]
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-s3/lib/aws-sdk-s3/client.rb#L2337-L2340
train
aws/aws-sdk-ruby
gems/aws-sdk-s3/lib/aws-sdk-s3/client.rb
Aws::S3.Client.get_object
def get_object(params = {}, options = {}, &block) req = build_request(:get_object, params) req.send_request(options, &block) end
ruby
def get_object(params = {}, options = {}, &block) req = build_request(:get_object, params) req.send_request(options, &block) end
[ "def", "get_object", "(", "params", "=", "{", "}", ",", "options", "=", "{", "}", ",", "&", "block", ")", "req", "=", "build_request", "(", ":get_object", ",", "params", ")", "req", ".", "send_request", "(", "options", ",", "block", ")", "end" ]
Retrieves objects from Amazon S3. @option params [String, IO] :response_target Where to write response data, file path, or IO object. @option params [required, String] :bucket @option params [String] :if_match Return the object only if its entity tag (ETag) is the same as the one specified, otherwise ret...
[ "Retrieves", "objects", "from", "Amazon", "S3", "." ]
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-s3/lib/aws-sdk-s3/client.rb#L2900-L2903
train
aws/aws-sdk-ruby
gems/aws-sdk-s3/lib/aws-sdk-s3/client.rb
Aws::S3.Client.get_object_torrent
def get_object_torrent(params = {}, options = {}, &block) req = build_request(:get_object_torrent, params) req.send_request(options, &block) end
ruby
def get_object_torrent(params = {}, options = {}, &block) req = build_request(:get_object_torrent, params) req.send_request(options, &block) end
[ "def", "get_object_torrent", "(", "params", "=", "{", "}", ",", "options", "=", "{", "}", ",", "&", "block", ")", "req", "=", "build_request", "(", ":get_object_torrent", ",", "params", ")", "req", ".", "send_request", "(", "options", ",", "block", ")", ...
Return torrent files from a bucket. @option params [String, IO] :response_target Where to write response data, file path, or IO object. @option params [required, String] :bucket @option params [required, String] :key @option params [String] :request_payer Confirms that the requester knows that she or he w...
[ "Return", "torrent", "files", "from", "a", "bucket", "." ]
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-s3/lib/aws-sdk-s3/client.rb#L3273-L3276
train
aws/aws-sdk-ruby
gems/aws-sdk-s3/lib/aws-sdk-s3/client.rb
Aws::S3.Client.wait_until
def wait_until(waiter_name, params = {}, options = {}) w = waiter(waiter_name, options) yield(w.waiter) if block_given? # deprecated w.wait(params) end
ruby
def wait_until(waiter_name, params = {}, options = {}) w = waiter(waiter_name, options) yield(w.waiter) if block_given? # deprecated w.wait(params) end
[ "def", "wait_until", "(", "waiter_name", ",", "params", "=", "{", "}", ",", "options", "=", "{", "}", ")", "w", "=", "waiter", "(", "waiter_name", ",", "options", ")", "yield", "(", "w", ".", "waiter", ")", "if", "block_given?", "# deprecated", "w", ...
Polls an API operation until a resource enters a desired state. ## Basic Usage A waiter will call an API operation until: * It is successful * It enters a terminal state * It makes the maximum number of attempts In between attempts, the waiter will sleep. # polls in a loop, sleeping between attempts ...
[ "Polls", "an", "API", "operation", "until", "a", "resource", "enters", "a", "desired", "state", "." ]
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-s3/lib/aws-sdk-s3/client.rb#L7139-L7143
train
aws/aws-sdk-ruby
gems/aws-sdk-core/lib/aws-sdk-core/shared_config.rb
Aws.SharedConfig.fresh
def fresh(options = {}) @profile_name = nil @credentials_path = nil @config_path = nil @parsed_credentials = {} @parsed_config = nil @config_enabled = options[:config_enabled] ? true : false @profile_name = determine_profile(options) @credentials_path = options[:credentia...
ruby
def fresh(options = {}) @profile_name = nil @credentials_path = nil @config_path = nil @parsed_credentials = {} @parsed_config = nil @config_enabled = options[:config_enabled] ? true : false @profile_name = determine_profile(options) @credentials_path = options[:credentia...
[ "def", "fresh", "(", "options", "=", "{", "}", ")", "@profile_name", "=", "nil", "@credentials_path", "=", "nil", "@config_path", "=", "nil", "@parsed_credentials", "=", "{", "}", "@parsed_config", "=", "nil", "@config_enabled", "=", "options", "[", ":config_e...
Constructs a new SharedConfig provider object. This will load the shared credentials file, and optionally the shared configuration file, as ini files which support profiles. By default, the shared credential file (the default path for which is `~/.aws/credentials`) and the shared config file (the default path for ...
[ "Constructs", "a", "new", "SharedConfig", "provider", "object", ".", "This", "will", "load", "the", "shared", "credentials", "file", "and", "optionally", "the", "shared", "configuration", "file", "as", "ini", "files", "which", "support", "profiles", "." ]
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-core/lib/aws-sdk-core/shared_config.rb#L61-L76
train
aws/aws-sdk-ruby
gems/aws-sdk-core/lib/aws-sdk-core/shared_config.rb
Aws.SharedConfig.assume_role_credentials_from_config
def assume_role_credentials_from_config(opts = {}) p = opts.delete(:profile) || @profile_name chain_config = opts.delete(:chain_config) credentials = assume_role_from_profile(@parsed_credentials, p, opts, chain_config) if @parsed_config credentials ||= assume_role_from_profile(@parsed_co...
ruby
def assume_role_credentials_from_config(opts = {}) p = opts.delete(:profile) || @profile_name chain_config = opts.delete(:chain_config) credentials = assume_role_from_profile(@parsed_credentials, p, opts, chain_config) if @parsed_config credentials ||= assume_role_from_profile(@parsed_co...
[ "def", "assume_role_credentials_from_config", "(", "opts", "=", "{", "}", ")", "p", "=", "opts", ".", "delete", "(", ":profile", ")", "||", "@profile_name", "chain_config", "=", "opts", ".", "delete", "(", ":chain_config", ")", "credentials", "=", "assume_role...
Attempts to assume a role from shared config or shared credentials file. Will always attempt first to assume a role from the shared credentials file, if present.
[ "Attempts", "to", "assume", "a", "role", "from", "shared", "config", "or", "shared", "credentials", "file", ".", "Will", "always", "attempt", "first", "to", "assume", "a", "role", "from", "the", "shared", "credentials", "file", "if", "present", "." ]
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-core/lib/aws-sdk-core/shared_config.rb#L114-L122
train
aws/aws-sdk-ruby
gems/aws-sdk-core/lib/aws-sdk-core/structure.rb
Aws.Structure.to_h
def to_h(obj = self) case obj when Struct obj.members.each.with_object({}) do |member, hash| value = obj[member] hash[member] = to_hash(value) unless value.nil? end when Hash obj.each.with_object({}) do |(key, value), hash| hash[key] = to_hash(valu...
ruby
def to_h(obj = self) case obj when Struct obj.members.each.with_object({}) do |member, hash| value = obj[member] hash[member] = to_hash(value) unless value.nil? end when Hash obj.each.with_object({}) do |(key, value), hash| hash[key] = to_hash(valu...
[ "def", "to_h", "(", "obj", "=", "self", ")", "case", "obj", "when", "Struct", "obj", ".", "members", ".", "each", ".", "with_object", "(", "{", "}", ")", "do", "|", "member", ",", "hash", "|", "value", "=", "obj", "[", "member", "]", "hash", "[",...
Deeply converts the Structure into a hash. Structure members that are `nil` are omitted from the resultant hash. You can call #orig_to_h to get vanilla #to_h behavior as defined in stdlib Struct. @return [Hash]
[ "Deeply", "converts", "the", "Structure", "into", "a", "hash", ".", "Structure", "members", "that", "are", "nil", "are", "omitted", "from", "the", "resultant", "hash", "." ]
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-core/lib/aws-sdk-core/structure.rb#L29-L45
train
aws/aws-sdk-ruby
gems/aws-sdk-core/lib/aws-sdk-core/client_stubs.rb
Aws.ClientStubs.api_requests
def api_requests(options = {}) if config.stub_responses if options[:exclude_presign] @api_requests.reject {|req| req[:context][:presigned_url] } else @api_requests end else msg = 'This method is only implemented for stubbed clients, and is ' msg <<...
ruby
def api_requests(options = {}) if config.stub_responses if options[:exclude_presign] @api_requests.reject {|req| req[:context][:presigned_url] } else @api_requests end else msg = 'This method is only implemented for stubbed clients, and is ' msg <<...
[ "def", "api_requests", "(", "options", "=", "{", "}", ")", "if", "config", ".", "stub_responses", "if", "options", "[", ":exclude_presign", "]", "@api_requests", ".", "reject", "{", "|", "req", "|", "req", "[", ":context", "]", "[", ":presigned_url", "]", ...
Allows you to access all of the requests that the stubbed client has made @params [Boolean] exclude_presign Setting to true for filtering out not sent requests from generating presigned urls. Default to false. @return [Array] Returns an array of the api requests made, each request object contains th...
[ "Allows", "you", "to", "access", "all", "of", "the", "requests", "that", "the", "stubbed", "client", "has", "made" ]
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-core/lib/aws-sdk-core/client_stubs.rb#L192-L204
train
aws/aws-sdk-ruby
gems/aws-sdk-core/lib/aws-sdk-core/client_stubs.rb
Aws.ClientStubs.stub_data
def stub_data(operation_name, data = {}) Stubbing::StubData.new(config.api.operation(operation_name)).stub(data) end
ruby
def stub_data(operation_name, data = {}) Stubbing::StubData.new(config.api.operation(operation_name)).stub(data) end
[ "def", "stub_data", "(", "operation_name", ",", "data", "=", "{", "}", ")", "Stubbing", "::", "StubData", ".", "new", "(", "config", ".", "api", ".", "operation", "(", "operation_name", ")", ")", ".", "stub", "(", "data", ")", "end" ]
Generates and returns stubbed response data from the named operation. s3 = Aws::S3::Client.new s3.stub_data(:list_buckets) #=> #<struct Aws::S3::Types::ListBucketsOutput buckets=[], owner=#<struct Aws::S3::Types::Owner display_name="DisplayName", id="ID">> In addition to generating default stubs, you ...
[ "Generates", "and", "returns", "stubbed", "response", "data", "from", "the", "named", "operation", "." ]
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-core/lib/aws-sdk-core/client_stubs.rb#L224-L226
train
aws/aws-sdk-ruby
gems/aws-sdk-core/lib/aws-sdk-core/pageable_response.rb
Aws.PageableResponse.each
def each(&block) return enum_for(:each_page) unless block_given? response = self yield(response) until response.last_page? response = response.next_page yield(response) end end
ruby
def each(&block) return enum_for(:each_page) unless block_given? response = self yield(response) until response.last_page? response = response.next_page yield(response) end end
[ "def", "each", "(", "&", "block", ")", "return", "enum_for", "(", ":each_page", ")", "unless", "block_given?", "response", "=", "self", "yield", "(", "response", ")", "until", "response", ".", "last_page?", "response", "=", "response", ".", "next_page", "yie...
Yields the current and each following response to the given block. @yieldparam [Response] response @return [Enumerable,nil] Returns a new Enumerable if no block is given.
[ "Yields", "the", "current", "and", "each", "following", "response", "to", "the", "given", "block", "." ]
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-core/lib/aws-sdk-core/pageable_response.rb#L72-L80
train
aws/aws-sdk-ruby
gems/aws-sdk-glacier/lib/aws-sdk-glacier/client.rb
Aws::Glacier.Client.get_job_output
def get_job_output(params = {}, options = {}, &block) req = build_request(:get_job_output, params) req.send_request(options, &block) end
ruby
def get_job_output(params = {}, options = {}, &block) req = build_request(:get_job_output, params) req.send_request(options, &block) end
[ "def", "get_job_output", "(", "params", "=", "{", "}", ",", "options", "=", "{", "}", ",", "&", "block", ")", "req", "=", "build_request", "(", ":get_job_output", ",", "params", ")", "req", ".", "send_request", "(", "options", ",", "block", ")", "end" ...
This operation downloads the output of the job you initiated using InitiateJob. Depending on the job type you specified when you initiated the job, the output will be either the content of an archive or a vault inventory. You can download all the job output or download a portion of the output by specifying a byte...
[ "This", "operation", "downloads", "the", "output", "of", "the", "job", "you", "initiated", "using", "InitiateJob", ".", "Depending", "on", "the", "job", "type", "you", "specified", "when", "you", "initiated", "the", "job", "the", "output", "will", "be", "eit...
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-glacier/lib/aws-sdk-glacier/client.rb#L1448-L1451
train
aws/aws-sdk-ruby
gems/aws-sdk-core/lib/aws-sdk-core/endpoint_cache.rb
Aws.EndpointCache.key?
def key?(key) if @entries.key?(key) && (@entries[key].nil? || @entries[key].expired?) self.delete(key) end @entries.key?(key) end
ruby
def key?(key) if @entries.key?(key) && (@entries[key].nil? || @entries[key].expired?) self.delete(key) end @entries.key?(key) end
[ "def", "key?", "(", "key", ")", "if", "@entries", ".", "key?", "(", "key", ")", "&&", "(", "@entries", "[", "key", "]", ".", "nil?", "||", "@entries", "[", "key", "]", ".", "expired?", ")", "self", ".", "delete", "(", "key", ")", "end", "@entries...
checking whether an unexpired endpoint key exists in cache @param [String] key @return [Boolean]
[ "checking", "whether", "an", "unexpired", "endpoint", "key", "exists", "in", "cache" ]
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-core/lib/aws-sdk-core/endpoint_cache.rb#L62-L67
train
aws/aws-sdk-ruby
gems/aws-sdk-core/lib/aws-sdk-core/endpoint_cache.rb
Aws.EndpointCache.extract_key
def extract_key(ctx) parts = [] # fetching from cred provider directly gives warnings parts << ctx.config.credentials.credentials.access_key_id if _endpoint_operation_identifier(ctx) parts << ctx.operation_name ctx.operation.input.shape.members.inject(parts) do |p, (name, ref)| ...
ruby
def extract_key(ctx) parts = [] # fetching from cred provider directly gives warnings parts << ctx.config.credentials.credentials.access_key_id if _endpoint_operation_identifier(ctx) parts << ctx.operation_name ctx.operation.input.shape.members.inject(parts) do |p, (name, ref)| ...
[ "def", "extract_key", "(", "ctx", ")", "parts", "=", "[", "]", "# fetching from cred provider directly gives warnings", "parts", "<<", "ctx", ".", "config", ".", "credentials", ".", "credentials", ".", "access_key_id", "if", "_endpoint_operation_identifier", "(", "ctx...
extract the key to be used in the cache from request context @param [RequestContext] ctx @return [String]
[ "extract", "the", "key", "to", "be", "used", "in", "the", "cache", "from", "request", "context" ]
e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d
https://github.com/aws/aws-sdk-ruby/blob/e28b8d320ddf7b6ee0161bdd9d00fb786d99b63d/gems/aws-sdk-core/lib/aws-sdk-core/endpoint_cache.rb#L105-L117
train
primer/octicons
lib/octicons_jekyll/lib/jekyll-octicons.rb
Jekyll.Octicons.string_to_hash
def string_to_hash(markup) options = {} if match = markup.match(Syntax) markup.scan(TagAttributes) do |key, value| options[key.to_sym] = value.gsub(/\A"|"\z/, "") end end options end
ruby
def string_to_hash(markup) options = {} if match = markup.match(Syntax) markup.scan(TagAttributes) do |key, value| options[key.to_sym] = value.gsub(/\A"|"\z/, "") end end options end
[ "def", "string_to_hash", "(", "markup", ")", "options", "=", "{", "}", "if", "match", "=", "markup", ".", "match", "(", "Syntax", ")", "markup", ".", "scan", "(", "TagAttributes", ")", "do", "|", "key", ",", "value", "|", "options", "[", "key", ".", ...
Create a ruby hash from a string passed by the jekyll tag
[ "Create", "a", "ruby", "hash", "from", "a", "string", "passed", "by", "the", "jekyll", "tag" ]
6fe5475945d5633818b49ce55619ec039789b1c8
https://github.com/primer/octicons/blob/6fe5475945d5633818b49ce55619ec039789b1c8/lib/octicons_jekyll/lib/jekyll-octicons.rb#L58-L68
train
resque/resque
lib/resque/plugin.rb
Resque.Plugin.lint
def lint(plugin) hooks = before_hooks(plugin) + around_hooks(plugin) + after_hooks(plugin) hooks.each do |hook| if hook.to_s.end_with?("perform") raise LintError, "#{plugin}.#{hook} is not namespaced" end end failure_hooks(plugin).each do |hook| if hook.to_s.e...
ruby
def lint(plugin) hooks = before_hooks(plugin) + around_hooks(plugin) + after_hooks(plugin) hooks.each do |hook| if hook.to_s.end_with?("perform") raise LintError, "#{plugin}.#{hook} is not namespaced" end end failure_hooks(plugin).each do |hook| if hook.to_s.e...
[ "def", "lint", "(", "plugin", ")", "hooks", "=", "before_hooks", "(", "plugin", ")", "+", "around_hooks", "(", "plugin", ")", "+", "after_hooks", "(", "plugin", ")", "hooks", ".", "each", "do", "|", "hook", "|", "if", "hook", ".", "to_s", ".", "end_w...
Ensure that your plugin conforms to good hook naming conventions. Resque::Plugin.lint(MyResquePlugin)
[ "Ensure", "that", "your", "plugin", "conforms", "to", "good", "hook", "naming", "conventions", "." ]
adb633a0f6b98b1eb5a5a85bb36ebac9309978fd
https://github.com/resque/resque/blob/adb633a0f6b98b1eb5a5a85bb36ebac9309978fd/lib/resque/plugin.rb#L10-L24
train
resque/resque
lib/resque/worker.rb
Resque.Worker.process
def process(job = nil, &block) return unless job ||= reserve job.worker = self working_on job perform(job, &block) ensure done_working end
ruby
def process(job = nil, &block) return unless job ||= reserve job.worker = self working_on job perform(job, &block) ensure done_working end
[ "def", "process", "(", "job", "=", "nil", ",", "&", "block", ")", "return", "unless", "job", "||=", "reserve", "job", ".", "worker", "=", "self", "working_on", "job", "perform", "(", "job", ",", "block", ")", "ensure", "done_working", "end" ]
DEPRECATED. Processes a single job. If none is given, it will try to produce one. Usually run in the child.
[ "DEPRECATED", ".", "Processes", "a", "single", "job", ".", "If", "none", "is", "given", "it", "will", "try", "to", "produce", "one", ".", "Usually", "run", "in", "the", "child", "." ]
adb633a0f6b98b1eb5a5a85bb36ebac9309978fd
https://github.com/resque/resque/blob/adb633a0f6b98b1eb5a5a85bb36ebac9309978fd/lib/resque/worker.rb#L275-L283
train
resque/resque
lib/resque/worker.rb
Resque.Worker.report_failed_job
def report_failed_job(job,exception) log_with_severity :error, "#{job.inspect} failed: #{exception.inspect}" begin job.fail(exception) rescue Object => exception log_with_severity :error, "Received exception when reporting failure: #{exception.inspect}" end begin fa...
ruby
def report_failed_job(job,exception) log_with_severity :error, "#{job.inspect} failed: #{exception.inspect}" begin job.fail(exception) rescue Object => exception log_with_severity :error, "Received exception when reporting failure: #{exception.inspect}" end begin fa...
[ "def", "report_failed_job", "(", "job", ",", "exception", ")", "log_with_severity", ":error", ",", "\"#{job.inspect} failed: #{exception.inspect}\"", "begin", "job", ".", "fail", "(", "exception", ")", "rescue", "Object", "=>", "exception", "log_with_severity", ":error"...
Reports the exception and marks the job as failed
[ "Reports", "the", "exception", "and", "marks", "the", "job", "as", "failed" ]
adb633a0f6b98b1eb5a5a85bb36ebac9309978fd
https://github.com/resque/resque/blob/adb633a0f6b98b1eb5a5a85bb36ebac9309978fd/lib/resque/worker.rb#L286-L298
train
resque/resque
lib/resque/worker.rb
Resque.Worker.perform
def perform(job) begin if fork_per_job? reconnect run_hook :after_fork, job end job.perform rescue Object => e report_failed_job(job,e) else log_with_severity :info, "done: #{job.inspect}" ensure yield job if block_given? ...
ruby
def perform(job) begin if fork_per_job? reconnect run_hook :after_fork, job end job.perform rescue Object => e report_failed_job(job,e) else log_with_severity :info, "done: #{job.inspect}" ensure yield job if block_given? ...
[ "def", "perform", "(", "job", ")", "begin", "if", "fork_per_job?", "reconnect", "run_hook", ":after_fork", ",", "job", "end", "job", ".", "perform", "rescue", "Object", "=>", "e", "report_failed_job", "(", "job", ",", "e", ")", "else", "log_with_severity", "...
Processes a given job in the child.
[ "Processes", "a", "given", "job", "in", "the", "child", "." ]
adb633a0f6b98b1eb5a5a85bb36ebac9309978fd
https://github.com/resque/resque/blob/adb633a0f6b98b1eb5a5a85bb36ebac9309978fd/lib/resque/worker.rb#L302-L316
train
resque/resque
lib/resque/worker.rb
Resque.Worker.reserve
def reserve queues.each do |queue| log_with_severity :debug, "Checking #{queue}" if job = Resque.reserve(queue) log_with_severity :debug, "Found job on #{queue}" return job end end nil rescue Exception => e log_with_severity :error, "Error reservi...
ruby
def reserve queues.each do |queue| log_with_severity :debug, "Checking #{queue}" if job = Resque.reserve(queue) log_with_severity :debug, "Found job on #{queue}" return job end end nil rescue Exception => e log_with_severity :error, "Error reservi...
[ "def", "reserve", "queues", ".", "each", "do", "|", "queue", "|", "log_with_severity", ":debug", ",", "\"Checking #{queue}\"", "if", "job", "=", "Resque", ".", "reserve", "(", "queue", ")", "log_with_severity", ":debug", ",", "\"Found job on #{queue}\"", "return",...
Attempts to grab a job off one of the provided queues. Returns nil if no job can be found.
[ "Attempts", "to", "grab", "a", "job", "off", "one", "of", "the", "provided", "queues", ".", "Returns", "nil", "if", "no", "job", "can", "be", "found", "." ]
adb633a0f6b98b1eb5a5a85bb36ebac9309978fd
https://github.com/resque/resque/blob/adb633a0f6b98b1eb5a5a85bb36ebac9309978fd/lib/resque/worker.rb#L320-L334
train
resque/resque
lib/resque/worker.rb
Resque.Worker.reconnect
def reconnect tries = 0 begin data_store.reconnect rescue Redis::BaseConnectionError if (tries += 1) <= 3 log_with_severity :error, "Error reconnecting to Redis; retrying" sleep(tries) retry else log_with_severity :error, "Error reconnect...
ruby
def reconnect tries = 0 begin data_store.reconnect rescue Redis::BaseConnectionError if (tries += 1) <= 3 log_with_severity :error, "Error reconnecting to Redis; retrying" sleep(tries) retry else log_with_severity :error, "Error reconnect...
[ "def", "reconnect", "tries", "=", "0", "begin", "data_store", ".", "reconnect", "rescue", "Redis", "::", "BaseConnectionError", "if", "(", "tries", "+=", "1", ")", "<=", "3", "log_with_severity", ":error", ",", "\"Error reconnecting to Redis; retrying\"", "sleep", ...
Reconnect to Redis to avoid sharing a connection with the parent, retry up to 3 times with increasing delay before giving up.
[ "Reconnect", "to", "Redis", "to", "avoid", "sharing", "a", "connection", "with", "the", "parent", "retry", "up", "to", "3", "times", "with", "increasing", "delay", "before", "giving", "up", "." ]
adb633a0f6b98b1eb5a5a85bb36ebac9309978fd
https://github.com/resque/resque/blob/adb633a0f6b98b1eb5a5a85bb36ebac9309978fd/lib/resque/worker.rb#L338-L352
train
resque/resque
lib/resque/worker.rb
Resque.Worker.shutdown!
def shutdown! shutdown if term_child if fork_per_job? new_kill_child else # Raise TermException in the same process trap('TERM') do # ignore subsequent terms end raise TermException.new("SIGTERM") end else ki...
ruby
def shutdown! shutdown if term_child if fork_per_job? new_kill_child else # Raise TermException in the same process trap('TERM') do # ignore subsequent terms end raise TermException.new("SIGTERM") end else ki...
[ "def", "shutdown!", "shutdown", "if", "term_child", "if", "fork_per_job?", "new_kill_child", "else", "# Raise TermException in the same process", "trap", "(", "'TERM'", ")", "do", "# ignore subsequent terms", "end", "raise", "TermException", ".", "new", "(", "\"SIGTERM\""...
Kill the child and shutdown immediately. If not forking, abort this process.
[ "Kill", "the", "child", "and", "shutdown", "immediately", ".", "If", "not", "forking", "abort", "this", "process", "." ]
adb633a0f6b98b1eb5a5a85bb36ebac9309978fd
https://github.com/resque/resque/blob/adb633a0f6b98b1eb5a5a85bb36ebac9309978fd/lib/resque/worker.rb#L434-L449
train
resque/resque
lib/resque/worker.rb
Resque.Worker.run_hook
def run_hook(name, *args) hooks = Resque.send(name) return if hooks.empty? return if name == :before_first_fork && @before_first_fork_hook_ran msg = "Running #{name} hooks" msg << " with #{args.inspect}" if args.any? log_with_severity :info, msg hooks.each do |hook| ar...
ruby
def run_hook(name, *args) hooks = Resque.send(name) return if hooks.empty? return if name == :before_first_fork && @before_first_fork_hook_ran msg = "Running #{name} hooks" msg << " with #{args.inspect}" if args.any? log_with_severity :info, msg hooks.each do |hook| ar...
[ "def", "run_hook", "(", "name", ",", "*", "args", ")", "hooks", "=", "Resque", ".", "send", "(", "name", ")", "return", "if", "hooks", ".", "empty?", "return", "if", "name", "==", ":before_first_fork", "&&", "@before_first_fork_hook_ran", "msg", "=", "\"Ru...
Runs a named hook, passing along any arguments.
[ "Runs", "a", "named", "hook", "passing", "along", "any", "arguments", "." ]
adb633a0f6b98b1eb5a5a85bb36ebac9309978fd
https://github.com/resque/resque/blob/adb633a0f6b98b1eb5a5a85bb36ebac9309978fd/lib/resque/worker.rb#L645-L657
train
resque/resque
lib/resque/worker.rb
Resque.Worker.unregister_worker
def unregister_worker(exception = nil) # If we're still processing a job, make sure it gets logged as a # failure. if (hash = processing) && !hash.empty? job = Job.new(hash['queue'], hash['payload']) # Ensure the proper worker is attached to this job, even if # it's not the pre...
ruby
def unregister_worker(exception = nil) # If we're still processing a job, make sure it gets logged as a # failure. if (hash = processing) && !hash.empty? job = Job.new(hash['queue'], hash['payload']) # Ensure the proper worker is attached to this job, even if # it's not the pre...
[ "def", "unregister_worker", "(", "exception", "=", "nil", ")", "# If we're still processing a job, make sure it gets logged as a", "# failure.", "if", "(", "hash", "=", "processing", ")", "&&", "!", "hash", ".", "empty?", "job", "=", "Job", ".", "new", "(", "hash"...
Unregisters ourself as a worker. Useful when shutting down.
[ "Unregisters", "ourself", "as", "a", "worker", ".", "Useful", "when", "shutting", "down", "." ]
adb633a0f6b98b1eb5a5a85bb36ebac9309978fd
https://github.com/resque/resque/blob/adb633a0f6b98b1eb5a5a85bb36ebac9309978fd/lib/resque/worker.rb#L667-L697
train
resque/resque
lib/resque/worker.rb
Resque.Worker.working_on
def working_on(job) data = encode \ :queue => job.queue, :run_at => Time.now.utc.iso8601, :payload => job.payload data_store.set_worker_payload(self,data) end
ruby
def working_on(job) data = encode \ :queue => job.queue, :run_at => Time.now.utc.iso8601, :payload => job.payload data_store.set_worker_payload(self,data) end
[ "def", "working_on", "(", "job", ")", "data", "=", "encode", ":queue", "=>", "job", ".", "queue", ",", ":run_at", "=>", "Time", ".", "now", ".", "utc", ".", "iso8601", ",", ":payload", "=>", "job", ".", "payload", "data_store", ".", "set_worker_payload",...
Given a job, tells Redis we're working on it. Useful for seeing what workers are doing and when.
[ "Given", "a", "job", "tells", "Redis", "we", "re", "working", "on", "it", ".", "Useful", "for", "seeing", "what", "workers", "are", "doing", "and", "when", "." ]
adb633a0f6b98b1eb5a5a85bb36ebac9309978fd
https://github.com/resque/resque/blob/adb633a0f6b98b1eb5a5a85bb36ebac9309978fd/lib/resque/worker.rb#L701-L707
train
resque/resque
lib/resque/worker.rb
Resque.Worker.windows_worker_pids
def windows_worker_pids tasklist_output = `tasklist /FI "IMAGENAME eq ruby.exe" /FO list`.encode("UTF-8", Encoding.locale_charmap) tasklist_output.split($/).select { |line| line =~ /^PID:/ }.collect { |line| line.gsub(/PID:\s+/, '') } end
ruby
def windows_worker_pids tasklist_output = `tasklist /FI "IMAGENAME eq ruby.exe" /FO list`.encode("UTF-8", Encoding.locale_charmap) tasklist_output.split($/).select { |line| line =~ /^PID:/ }.collect { |line| line.gsub(/PID:\s+/, '') } end
[ "def", "windows_worker_pids", "tasklist_output", "=", "`", "`", ".", "encode", "(", "\"UTF-8\"", ",", "Encoding", ".", "locale_charmap", ")", "tasklist_output", ".", "split", "(", "$/", ")", ".", "select", "{", "|", "line", "|", "line", "=~", "/", "/", "...
Returns an Array of string pids of all the other workers on this machine. Useful when pruning dead workers on startup.
[ "Returns", "an", "Array", "of", "string", "pids", "of", "all", "the", "other", "workers", "on", "this", "machine", ".", "Useful", "when", "pruning", "dead", "workers", "on", "startup", "." ]
adb633a0f6b98b1eb5a5a85bb36ebac9309978fd
https://github.com/resque/resque/blob/adb633a0f6b98b1eb5a5a85bb36ebac9309978fd/lib/resque/worker.rb#L818-L821
train
resque/resque
lib/resque/job.rb
Resque.Job.fail
def fail(exception) begin run_failure_hooks(exception) rescue Exception => e raise e ensure Failure.create \ :payload => payload, :exception => exception, :worker => worker, :queue => queue end end
ruby
def fail(exception) begin run_failure_hooks(exception) rescue Exception => e raise e ensure Failure.create \ :payload => payload, :exception => exception, :worker => worker, :queue => queue end end
[ "def", "fail", "(", "exception", ")", "begin", "run_failure_hooks", "(", "exception", ")", "rescue", "Exception", "=>", "e", "raise", "e", "ensure", "Failure", ".", "create", ":payload", "=>", "payload", ",", ":exception", "=>", "exception", ",", ":worker", ...
Given an exception object, hands off the needed parameters to the Failure module.
[ "Given", "an", "exception", "object", "hands", "off", "the", "needed", "parameters", "to", "the", "Failure", "module", "." ]
adb633a0f6b98b1eb5a5a85bb36ebac9309978fd
https://github.com/resque/resque/blob/adb633a0f6b98b1eb5a5a85bb36ebac9309978fd/lib/resque/job.rb#L232-L244
train
ruby-grape/grape
lib/grape/endpoint.rb
Grape.Endpoint.inherit_settings
def inherit_settings(namespace_stackable) inheritable_setting.route[:saved_validations] += namespace_stackable[:validations] parent_declared_params = namespace_stackable[:declared_params] if parent_declared_params inheritable_setting.route[:declared_params] ||= [] inheritable_setting....
ruby
def inherit_settings(namespace_stackable) inheritable_setting.route[:saved_validations] += namespace_stackable[:validations] parent_declared_params = namespace_stackable[:declared_params] if parent_declared_params inheritable_setting.route[:declared_params] ||= [] inheritable_setting....
[ "def", "inherit_settings", "(", "namespace_stackable", ")", "inheritable_setting", ".", "route", "[", ":saved_validations", "]", "+=", "namespace_stackable", "[", ":validations", "]", "parent_declared_params", "=", "namespace_stackable", "[", ":declared_params", "]", "if"...
Create a new endpoint. @param new_settings [InheritableSetting] settings to determine the params, validations, and other properties from. @param options [Hash] attributes of this endpoint @option options path [String or Array] the path to this endpoint, within the current scope. @option options method [String...
[ "Create", "a", "new", "endpoint", "." ]
e26ae618b86920b19b1a98945ba7d6e953a9b989
https://github.com/ruby-grape/grape/blob/e26ae618b86920b19b1a98945ba7d6e953a9b989/lib/grape/endpoint.rb#L112-L122
train
ankane/blazer
app/helpers/blazer/base_helper.rb
Blazer.BaseHelper.blazer_json_escape
def blazer_json_escape(s) if Rails::VERSION::STRING < "4.1" result = s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE) s.html_safe? ? result.html_safe : result else json_escape(s) end end
ruby
def blazer_json_escape(s) if Rails::VERSION::STRING < "4.1" result = s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE) s.html_safe? ? result.html_safe : result else json_escape(s) end end
[ "def", "blazer_json_escape", "(", "s", ")", "if", "Rails", "::", "VERSION", "::", "STRING", "<", "\"4.1\"", "result", "=", "s", ".", "to_s", ".", "gsub", "(", "JSON_ESCAPE_REGEXP", ",", "JSON_ESCAPE", ")", "s", ".", "html_safe?", "?", "result", ".", "htm...
Prior to version 4.1 of rails double quotes were inadventently removed in json_escape. This adds the correct json_escape functionality to rails versions < 4.1
[ "Prior", "to", "version", "4", ".", "1", "of", "rails", "double", "quotes", "were", "inadventently", "removed", "in", "json_escape", ".", "This", "adds", "the", "correct", "json_escape", "functionality", "to", "rails", "versions", "<", "4", ".", "1" ]
c6c56314d47194b4b24aded4246835d036705bb3
https://github.com/ankane/blazer/blob/c6c56314d47194b4b24aded4246835d036705bb3/app/helpers/blazer/base_helper.rb#L44-L51
train
activeadmin/activeadmin
lib/active_admin/namespace.rb
ActiveAdmin.Namespace.register
def register(resource_class, options = {}, &block) config = find_or_build_resource(resource_class, options) # Register the resource register_resource_controller(config) parse_registration_block(config, &block) if block_given? reset_menu! # Dispatch a registration event Active...
ruby
def register(resource_class, options = {}, &block) config = find_or_build_resource(resource_class, options) # Register the resource register_resource_controller(config) parse_registration_block(config, &block) if block_given? reset_menu! # Dispatch a registration event Active...
[ "def", "register", "(", "resource_class", ",", "options", "=", "{", "}", ",", "&", "block", ")", "config", "=", "find_or_build_resource", "(", "resource_class", ",", "options", ")", "# Register the resource", "register_resource_controller", "(", "config", ")", "pa...
Register a resource into this namespace. The preffered method to access this is to use the global registration ActiveAdmin.register which delegates to the proper namespace instance.
[ "Register", "a", "resource", "into", "this", "namespace", ".", "The", "preffered", "method", "to", "access", "this", "is", "to", "use", "the", "global", "registration", "ActiveAdmin", ".", "register", "which", "delegates", "to", "the", "proper", "namespace", "...
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/namespace.rb#L65-L78
train
activeadmin/activeadmin
lib/active_admin/namespace.rb
ActiveAdmin.Namespace.build_menu
def build_menu(name = DEFAULT_MENU) @menus.before_build do |menus| menus.menu name do |menu| yield menu end end end
ruby
def build_menu(name = DEFAULT_MENU) @menus.before_build do |menus| menus.menu name do |menu| yield menu end end end
[ "def", "build_menu", "(", "name", "=", "DEFAULT_MENU", ")", "@menus", ".", "before_build", "do", "|", "menus", "|", "menus", ".", "menu", "name", "do", "|", "menu", "|", "yield", "menu", "end", "end", "end" ]
Add a callback to be ran when we build the menu @param [Symbol] name The name of the menu. Default: :default @yield [ActiveAdmin::Menu] The block to be ran when the menu is built @return [void]
[ "Add", "a", "callback", "to", "be", "ran", "when", "we", "build", "the", "menu" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/namespace.rb#L135-L141
train
activeadmin/activeadmin
lib/active_admin/namespace.rb
ActiveAdmin.Namespace.add_logout_button_to_menu
def add_logout_button_to_menu(menu, priority = 20, html_options = {}) if logout_link_path html_options = html_options.reverse_merge(method: logout_link_method || :get) menu.add id: 'logout', priority: priority, html_options: html_options, label: -> { I18n.t 'active_admin.logout' }, ...
ruby
def add_logout_button_to_menu(menu, priority = 20, html_options = {}) if logout_link_path html_options = html_options.reverse_merge(method: logout_link_method || :get) menu.add id: 'logout', priority: priority, html_options: html_options, label: -> { I18n.t 'active_admin.logout' }, ...
[ "def", "add_logout_button_to_menu", "(", "menu", ",", "priority", "=", "20", ",", "html_options", "=", "{", "}", ")", "if", "logout_link_path", "html_options", "=", "html_options", ".", "reverse_merge", "(", "method", ":", "logout_link_method", "||", ":get", ")"...
The default logout menu item @param [ActiveAdmin::MenuItem] menu The menu to add the logout link to @param [Fixnum] priority The numeric priority for the order in which it appears @param [Hash] html_options An options hash to pass along to link_to
[ "The", "default", "logout", "menu", "item" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/namespace.rb#L149-L157
train
activeadmin/activeadmin
lib/active_admin/namespace.rb
ActiveAdmin.Namespace.add_current_user_to_menu
def add_current_user_to_menu(menu, priority = 10, html_options = {}) if current_user_method menu.add id: 'current_user', priority: priority, html_options: html_options, label: -> { display_name current_active_admin_user }, url: -> { auto_url_for(current_active_admin_user) }, ...
ruby
def add_current_user_to_menu(menu, priority = 10, html_options = {}) if current_user_method menu.add id: 'current_user', priority: priority, html_options: html_options, label: -> { display_name current_active_admin_user }, url: -> { auto_url_for(current_active_admin_user) }, ...
[ "def", "add_current_user_to_menu", "(", "menu", ",", "priority", "=", "10", ",", "html_options", "=", "{", "}", ")", "if", "current_user_method", "menu", ".", "add", "id", ":", "'current_user'", ",", "priority", ":", "priority", ",", "html_options", ":", "ht...
The default user session menu item @param [ActiveAdmin::MenuItem] menu The menu to add the logout link to @param [Fixnum] priority The numeric priority for the order in which it appears @param [Hash] html_options An options hash to pass along to link_to
[ "The", "default", "user", "session", "menu", "item" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/namespace.rb#L165-L172
train
activeadmin/activeadmin
lib/active_admin/page_dsl.rb
ActiveAdmin.PageDSL.content
def content(options = {}, &block) config.set_page_presenter :index, ActiveAdmin::PagePresenter.new(options, &block) end
ruby
def content(options = {}, &block) config.set_page_presenter :index, ActiveAdmin::PagePresenter.new(options, &block) end
[ "def", "content", "(", "options", "=", "{", "}", ",", "&", "block", ")", "config", ".", "set_page_presenter", ":index", ",", "ActiveAdmin", "::", "PagePresenter", ".", "new", "(", "options", ",", "block", ")", "end" ]
Page content. The block should define the view using Arbre. Example: ActiveAdmin.register "My Page" do content do para "Sweet!" end end
[ "Page", "content", "." ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/page_dsl.rb#L17-L19
train
activeadmin/activeadmin
lib/active_admin/resource_collection.rb
ActiveAdmin.ResourceCollection.find_resource
def find_resource(obj) resources.detect do |r| r.resource_name.to_s == obj.to_s end || resources.detect do |r| r.resource_class.to_s == obj.to_s end || if obj.respond_to? :base_class resources.detect { |r| r.resource_class.to_s == obj.base_class.to_s } end end
ruby
def find_resource(obj) resources.detect do |r| r.resource_name.to_s == obj.to_s end || resources.detect do |r| r.resource_class.to_s == obj.to_s end || if obj.respond_to? :base_class resources.detect { |r| r.resource_class.to_s == obj.base_class.to_s } end end
[ "def", "find_resource", "(", "obj", ")", "resources", ".", "detect", "do", "|", "r", "|", "r", ".", "resource_name", ".", "to_s", "==", "obj", ".", "to_s", "end", "||", "resources", ".", "detect", "do", "|", "r", "|", "r", ".", "resource_class", ".",...
Finds a resource based on the resource name, resource class, or base class.
[ "Finds", "a", "resource", "based", "on", "the", "resource", "name", "resource", "class", "or", "base", "class", "." ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/resource_collection.rb#L34-L43
train
activeadmin/activeadmin
lib/active_admin/application.rb
ActiveAdmin.Application.register
def register(resource, options = {}, &block) ns = options.fetch(:namespace) { default_namespace } namespace(ns).register resource, options, &block end
ruby
def register(resource, options = {}, &block) ns = options.fetch(:namespace) { default_namespace } namespace(ns).register resource, options, &block end
[ "def", "register", "(", "resource", ",", "options", "=", "{", "}", ",", "&", "block", ")", "ns", "=", "options", ".", "fetch", "(", ":namespace", ")", "{", "default_namespace", "}", "namespace", "(", "ns", ")", ".", "register", "resource", ",", "option...
Registers a brand new configuration for the given resource.
[ "Registers", "a", "brand", "new", "configuration", "for", "the", "given", "resource", "." ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/application.rb#L63-L66
train
activeadmin/activeadmin
lib/active_admin/application.rb
ActiveAdmin.Application.namespace
def namespace(name) name ||= :root namespace = namespaces[name] ||= begin namespace = Namespace.new(self, name) ActiveSupport::Notifications.publish ActiveAdmin::Namespace::RegisterEvent, namespace namespace end yield(namespace) if block_given? namespace end
ruby
def namespace(name) name ||= :root namespace = namespaces[name] ||= begin namespace = Namespace.new(self, name) ActiveSupport::Notifications.publish ActiveAdmin::Namespace::RegisterEvent, namespace namespace end yield(namespace) if block_given? namespace end
[ "def", "namespace", "(", "name", ")", "name", "||=", ":root", "namespace", "=", "namespaces", "[", "name", "]", "||=", "begin", "namespace", "=", "Namespace", ".", "new", "(", "self", ",", "name", ")", "ActiveSupport", "::", "Notifications", ".", "publish"...
Creates a namespace for the given name Yields the namespace if a block is given @return [Namespace] the new or existing namespace
[ "Creates", "a", "namespace", "for", "the", "given", "name" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/application.rb#L73-L85
train
activeadmin/activeadmin
lib/active_admin/application.rb
ActiveAdmin.Application.register_page
def register_page(name, options = {}, &block) ns = options.fetch(:namespace) { default_namespace } namespace(ns).register_page name, options, &block end
ruby
def register_page(name, options = {}, &block) ns = options.fetch(:namespace) { default_namespace } namespace(ns).register_page name, options, &block end
[ "def", "register_page", "(", "name", ",", "options", "=", "{", "}", ",", "&", "block", ")", "ns", "=", "options", ".", "fetch", "(", ":namespace", ")", "{", "default_namespace", "}", "namespace", "(", "ns", ")", ".", "register_page", "name", ",", "opti...
Register a page @param name [String] The page name @option [Hash] Accepts option :namespace. @&block The registration block.
[ "Register", "a", "page" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/application.rb#L93-L96
train
activeadmin/activeadmin
lib/active_admin/application.rb
ActiveAdmin.Application.load!
def load! unless loaded? ActiveSupport::Notifications.publish BeforeLoadEvent, self # before_load hook files.each { |file| load file } # load files namespace(default_namespace) # init AA resources ActiveSupport::Notifications...
ruby
def load! unless loaded? ActiveSupport::Notifications.publish BeforeLoadEvent, self # before_load hook files.each { |file| load file } # load files namespace(default_namespace) # init AA resources ActiveSupport::Notifications...
[ "def", "load!", "unless", "loaded?", "ActiveSupport", "::", "Notifications", ".", "publish", "BeforeLoadEvent", ",", "self", "# before_load hook", "files", ".", "each", "{", "|", "file", "|", "load", "file", "}", "# load files", "namespace", "(", "default_namespac...
Loads all ruby files that are within the load_paths setting. To reload everything simply call `ActiveAdmin.unload!`
[ "Loads", "all", "ruby", "files", "that", "are", "within", "the", "load_paths", "setting", ".", "To", "reload", "everything", "simply", "call", "ActiveAdmin", ".", "unload!" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/application.rb#L112-L120
train
activeadmin/activeadmin
lib/active_admin/application.rb
ActiveAdmin.Application.routes
def routes(rails_router) load! Router.new(router: rails_router, namespaces: namespaces).apply end
ruby
def routes(rails_router) load! Router.new(router: rails_router, namespaces: namespaces).apply end
[ "def", "routes", "(", "rails_router", ")", "load!", "Router", ".", "new", "(", "router", ":", "rails_router", ",", "namespaces", ":", "namespaces", ")", ".", "apply", "end" ]
Creates all the necessary routes for the ActiveAdmin configurations Use this within the routes.rb file: Application.routes.draw do |map| ActiveAdmin.routes(self) end @param rails_router [ActionDispatch::Routing::Mapper]
[ "Creates", "all", "the", "necessary", "routes", "for", "the", "ActiveAdmin", "configurations" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/application.rb#L140-L143
train
activeadmin/activeadmin
lib/active_admin/application.rb
ActiveAdmin.Application.attach_reloader
def attach_reloader Rails.application.config.after_initialize do |app| ActiveSupport::Reloader.after_class_unload do ActiveAdmin.application.unload! end admin_dirs = {} load_paths.each do |path| admin_dirs[path] = [:rb] end routes_reloader = a...
ruby
def attach_reloader Rails.application.config.after_initialize do |app| ActiveSupport::Reloader.after_class_unload do ActiveAdmin.application.unload! end admin_dirs = {} load_paths.each do |path| admin_dirs[path] = [:rb] end routes_reloader = a...
[ "def", "attach_reloader", "Rails", ".", "application", ".", "config", ".", "after_initialize", "do", "|", "app", "|", "ActiveSupport", "::", "Reloader", ".", "after_class_unload", "do", "ActiveAdmin", ".", "application", ".", "unload!", "end", "admin_dirs", "=", ...
Hook into the Rails code reloading mechanism so that things are reloaded properly in development mode. If any of the app files (e.g. models) has changed, we need to reload all the admin files. If the admin files themselves has changed, we need to regenerate the routes as well.
[ "Hook", "into", "the", "Rails", "code", "reloading", "mechanism", "so", "that", "things", "are", "reloaded", "properly", "in", "development", "mode", "." ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/application.rb#L188-L223
train
activeadmin/activeadmin
lib/active_admin/form_builder.rb
ActiveAdmin.HasManyBuilder.extract_custom_settings!
def extract_custom_settings!(options) @heading = options.key?(:heading) ? options.delete(:heading) : default_heading @sortable_column = options.delete(:sortable) @sortable_start = options.delete(:sortable_start) || 0 @new_record = options.key?(:new_record) ? options.delete(:new_record) : true ...
ruby
def extract_custom_settings!(options) @heading = options.key?(:heading) ? options.delete(:heading) : default_heading @sortable_column = options.delete(:sortable) @sortable_start = options.delete(:sortable_start) || 0 @new_record = options.key?(:new_record) ? options.delete(:new_record) : true ...
[ "def", "extract_custom_settings!", "(", "options", ")", "@heading", "=", "options", ".", "key?", "(", ":heading", ")", "?", "options", ".", "delete", "(", ":heading", ")", ":", "default_heading", "@sortable_column", "=", "options", ".", "delete", "(", ":sortab...
remove options that should not render as attributes
[ "remove", "options", "that", "should", "not", "render", "as", "attributes" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/form_builder.rb#L69-L76
train
activeadmin/activeadmin
lib/active_admin/form_builder.rb
ActiveAdmin.HasManyBuilder.render_has_many_form
def render_has_many_form(form_builder, parent, &block) index = parent && form_builder.send(:parent_child_index, parent) template.concat template.capture { yield(form_builder, index) } template.concat has_many_actions(form_builder, "".html_safe) end
ruby
def render_has_many_form(form_builder, parent, &block) index = parent && form_builder.send(:parent_child_index, parent) template.concat template.capture { yield(form_builder, index) } template.concat has_many_actions(form_builder, "".html_safe) end
[ "def", "render_has_many_form", "(", "form_builder", ",", "parent", ",", "&", "block", ")", "index", "=", "parent", "&&", "form_builder", ".", "send", "(", ":parent_child_index", ",", "parent", ")", "template", ".", "concat", "template", ".", "capture", "{", ...
Renders the Formtastic inputs then appends ActiveAdmin delete and sort actions.
[ "Renders", "the", "Formtastic", "inputs", "then", "appends", "ActiveAdmin", "delete", "and", "sort", "actions", "." ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/form_builder.rb#L101-L105
train
activeadmin/activeadmin
lib/active_admin/form_builder.rb
ActiveAdmin.HasManyBuilder.js_for_has_many
def js_for_has_many(class_string, &form_block) assoc_name = assoc_klass.model_name placeholder = "NEW_#{assoc_name.to_s.underscore.upcase.gsub(/\//, '_')}_RECORD" opts = { for: [assoc, assoc_klass.new], class: class_string, for_options: { child_index: placeholder } ...
ruby
def js_for_has_many(class_string, &form_block) assoc_name = assoc_klass.model_name placeholder = "NEW_#{assoc_name.to_s.underscore.upcase.gsub(/\//, '_')}_RECORD" opts = { for: [assoc, assoc_klass.new], class: class_string, for_options: { child_index: placeholder } ...
[ "def", "js_for_has_many", "(", "class_string", ",", "&", "form_block", ")", "assoc_name", "=", "assoc_klass", ".", "model_name", "placeholder", "=", "\"NEW_#{assoc_name.to_s.underscore.upcase.gsub(/\\//, '_')}_RECORD\"", "opts", "=", "{", "for", ":", "[", "assoc", ",", ...
Capture the ADD JS
[ "Capture", "the", "ADD", "JS" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/form_builder.rb#L158-L172
train
activeadmin/activeadmin
lib/active_admin/router.rb
ActiveAdmin.Router.define_resources_routes
def define_resources_routes resources = namespaces.flat_map { |n| n.resources.values } resources.each do |config| define_resource_routes(config) end end
ruby
def define_resources_routes resources = namespaces.flat_map { |n| n.resources.values } resources.each do |config| define_resource_routes(config) end end
[ "def", "define_resources_routes", "resources", "=", "namespaces", ".", "flat_map", "{", "|", "n", "|", "n", ".", "resources", ".", "values", "}", "resources", ".", "each", "do", "|", "config", "|", "define_resource_routes", "(", "config", ")", "end", "end" ]
Defines the routes for each resource
[ "Defines", "the", "routes", "for", "each", "resource" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/router.rb#L30-L35
train
activeadmin/activeadmin
lib/active_admin/router.rb
ActiveAdmin.Router.define_actions
def define_actions(config) router.member do config.member_actions.each { |action| build_action(action) } end router.collection do config.collection_actions.each { |action| build_action(action) } router.post :batch_action if config.batch_actions_enabled? end end
ruby
def define_actions(config) router.member do config.member_actions.each { |action| build_action(action) } end router.collection do config.collection_actions.each { |action| build_action(action) } router.post :batch_action if config.batch_actions_enabled? end end
[ "def", "define_actions", "(", "config", ")", "router", ".", "member", "do", "config", ".", "member_actions", ".", "each", "{", "|", "action", "|", "build_action", "(", "action", ")", "}", "end", "router", ".", "collection", "do", "config", ".", "collection...
Defines member and collection actions
[ "Defines", "member", "and", "collection", "actions" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/router.rb#L75-L84
train
activeadmin/activeadmin
lib/active_admin/callbacks.rb
ActiveAdmin.Callbacks.run_callback
def run_callback(method, *args) case method when Symbol send(method, *args) when Proc instance_exec(*args, &method) else raise "Please register with callbacks using a symbol or a block/proc." end end
ruby
def run_callback(method, *args) case method when Symbol send(method, *args) when Proc instance_exec(*args, &method) else raise "Please register with callbacks using a symbol or a block/proc." end end
[ "def", "run_callback", "(", "method", ",", "*", "args", ")", "case", "method", "when", "Symbol", "send", "(", "method", ",", "args", ")", "when", "Proc", "instance_exec", "(", "args", ",", "method", ")", "else", "raise", "\"Please register with callbacks using...
Simple callback system. Implements before and after callbacks for use within the controllers. We didn't use the ActiveSupport callbacks because they do not support passing in any arbitrary object into the callback method (which we need to do)
[ "Simple", "callback", "system", ".", "Implements", "before", "and", "after", "callbacks", "for", "use", "within", "the", "controllers", "." ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/callbacks.rb#L14-L23
train
activeadmin/activeadmin
lib/active_admin/resource_dsl.rb
ActiveAdmin.ResourceDSL.permit_params
def permit_params(*args, &block) param_key = config.param_key.to_sym belongs_to_param = config.belongs_to_param create_another_param = :create_another if config.create_another controller do define_method :permitted_params do permitted_params = active_admin_namespac...
ruby
def permit_params(*args, &block) param_key = config.param_key.to_sym belongs_to_param = config.belongs_to_param create_another_param = :create_another if config.create_another controller do define_method :permitted_params do permitted_params = active_admin_namespac...
[ "def", "permit_params", "(", "*", "args", ",", "&", "block", ")", "param_key", "=", "config", ".", "param_key", ".", "to_sym", "belongs_to_param", "=", "config", ".", "belongs_to_param", "create_another_param", "=", ":create_another", "if", "config", ".", "creat...
Keys included in the `permitted_params` setting are automatically whitelisted. Either permit_params :title, :author, :body, tags: [] Or permit_params do defaults = [:title, :body] if current_user.admin? defaults + [:author] else defaults end end
[ "Keys", "included", "in", "the", "permitted_params", "setting", "are", "automatically", "whitelisted", "." ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/resource_dsl.rb#L63-L80
train
activeadmin/activeadmin
lib/active_admin/resource_dsl.rb
ActiveAdmin.ResourceDSL.index
def index(options = {}, &block) options[:as] ||= :table config.set_page_presenter :index, ActiveAdmin::PagePresenter.new(options, &block) end
ruby
def index(options = {}, &block) options[:as] ||= :table config.set_page_presenter :index, ActiveAdmin::PagePresenter.new(options, &block) end
[ "def", "index", "(", "options", "=", "{", "}", ",", "&", "block", ")", "options", "[", ":as", "]", "||=", ":table", "config", ".", "set_page_presenter", ":index", ",", "ActiveAdmin", "::", "PagePresenter", ".", "new", "(", "options", ",", "block", ")", ...
Configure the index page for the resource
[ "Configure", "the", "index", "page", "for", "the", "resource" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/resource_dsl.rb#L83-L86
train
activeadmin/activeadmin
lib/active_admin/resource_dsl.rb
ActiveAdmin.ResourceDSL.show
def show(options = {}, &block) config.set_page_presenter :show, ActiveAdmin::PagePresenter.new(options, &block) end
ruby
def show(options = {}, &block) config.set_page_presenter :show, ActiveAdmin::PagePresenter.new(options, &block) end
[ "def", "show", "(", "options", "=", "{", "}", ",", "&", "block", ")", "config", ".", "set_page_presenter", ":show", ",", "ActiveAdmin", "::", "PagePresenter", ".", "new", "(", "options", ",", "block", ")", "end" ]
Configure the show page for the resource
[ "Configure", "the", "show", "page", "for", "the", "resource" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/resource_dsl.rb#L89-L91
train
activeadmin/activeadmin
lib/active_admin/resource_dsl.rb
ActiveAdmin.ResourceDSL.csv
def csv(options = {}, &block) options[:resource] = config config.csv_builder = CSVBuilder.new(options, &block) end
ruby
def csv(options = {}, &block) options[:resource] = config config.csv_builder = CSVBuilder.new(options, &block) end
[ "def", "csv", "(", "options", "=", "{", "}", ",", "&", "block", ")", "options", "[", ":resource", "]", "=", "config", "config", ".", "csv_builder", "=", "CSVBuilder", ".", "new", "(", "options", ",", "block", ")", "end" ]
Configure the CSV format For example: csv do column :name column("Author") { |post| post.author.full_name } end csv col_sep: ";", force_quotes: true do column :name end
[ "Configure", "the", "CSV", "format" ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/resource_dsl.rb#L110-L114
train
activeadmin/activeadmin
lib/active_admin/resource_dsl.rb
ActiveAdmin.ResourceDSL.action
def action(set, name, options = {}, &block) warn "Warning: method `#{name}` already defined" if controller.method_defined?(name) set << ControllerAction.new(name, options) title = options.delete(:title) controller do before_action(only: [name]) { @page_title = title } if title ...
ruby
def action(set, name, options = {}, &block) warn "Warning: method `#{name}` already defined" if controller.method_defined?(name) set << ControllerAction.new(name, options) title = options.delete(:title) controller do before_action(only: [name]) { @page_title = title } if title ...
[ "def", "action", "(", "set", ",", "name", ",", "options", "=", "{", "}", ",", "&", "block", ")", "warn", "\"Warning: method `#{name}` already defined\"", "if", "controller", ".", "method_defined?", "(", "name", ")", "set", "<<", "ControllerAction", ".", "new",...
Member Actions give you the functionality of defining both the action and the route directly from your ActiveAdmin registration block. For example: ActiveAdmin.register Post do member_action :comments do @post = Post.find(params[:id]) @comments = @post.comments end end Will create a...
[ "Member", "Actions", "give", "you", "the", "functionality", "of", "defining", "both", "the", "action", "and", "the", "route", "directly", "from", "your", "ActiveAdmin", "registration", "block", "." ]
0759c8dcf97865748c9344459162ac3c7e65a6cd
https://github.com/activeadmin/activeadmin/blob/0759c8dcf97865748c9344459162ac3c7e65a6cd/lib/active_admin/resource_dsl.rb#L135-L145
train
Shopify/shopify_api
lib/shopify_api/resources/product.rb
ShopifyAPI.Product.price_range
def price_range prices = variants.collect(&:price).collect(&:to_f) format = "%0.2f" if prices.min != prices.max "#{format % prices.min} - #{format % prices.max}" else format % prices.min end end
ruby
def price_range prices = variants.collect(&:price).collect(&:to_f) format = "%0.2f" if prices.min != prices.max "#{format % prices.min} - #{format % prices.max}" else format % prices.min end end
[ "def", "price_range", "prices", "=", "variants", ".", "collect", "(", ":price", ")", ".", "collect", "(", ":to_f", ")", "format", "=", "\"%0.2f\"", "if", "prices", ".", "min", "!=", "prices", ".", "max", "\"#{format % prices.min} - #{format % prices.max}\"", "el...
compute the price range
[ "compute", "the", "price", "range" ]
2e069578fcaa93188c4f5a919a76df7b3e2e26ef
https://github.com/Shopify/shopify_api/blob/2e069578fcaa93188c4f5a919a76df7b3e2e26ef/lib/shopify_api/resources/product.rb#L7-L15
train
sds/overcommit
lib/overcommit/configuration_loader.rb
Overcommit.ConfigurationLoader.load_file
def load_file(file) config = self.class.load_from_file(file, default: false, logger: @log) config = self.class.default_configuration.merge(config) if @options.fetch(:verify) { config.verify_signatures? } verify_signatures(config) end config rescue Overcommit::Exceptions::Conf...
ruby
def load_file(file) config = self.class.load_from_file(file, default: false, logger: @log) config = self.class.default_configuration.merge(config) if @options.fetch(:verify) { config.verify_signatures? } verify_signatures(config) end config rescue Overcommit::Exceptions::Conf...
[ "def", "load_file", "(", "file", ")", "config", "=", "self", ".", "class", ".", "load_from_file", "(", "file", ",", "default", ":", "false", ",", "logger", ":", "@log", ")", "config", "=", "self", ".", "class", ".", "default_configuration", ".", "merge",...
Loads a configuration, ensuring it extends the default configuration.
[ "Loads", "a", "configuration", "ensuring", "it", "extends", "the", "default", "configuration", "." ]
35d60adb41da942178b789560968e3ad030b0ac7
https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/configuration_loader.rb#L64-L79
train
sds/overcommit
lib/overcommit/hook_context/base.rb
Overcommit::HookContext.Base.filter_directories
def filter_directories(modified_files) modified_files.reject do |file| File.directory?(file) && !Overcommit::Utils::FileUtils.symlink?(file) end end
ruby
def filter_directories(modified_files) modified_files.reject do |file| File.directory?(file) && !Overcommit::Utils::FileUtils.symlink?(file) end end
[ "def", "filter_directories", "(", "modified_files", ")", "modified_files", ".", "reject", "do", "|", "file", "|", "File", ".", "directory?", "(", "file", ")", "&&", "!", "Overcommit", "::", "Utils", "::", "FileUtils", ".", "symlink?", "(", "file", ")", "en...
Filter out directories. This could happen when changing a symlink to a directory as part of an amendment, since the symlink will still appear as a file, but the actual working tree will have a directory.
[ "Filter", "out", "directories", ".", "This", "could", "happen", "when", "changing", "a", "symlink", "to", "a", "directory", "as", "part", "of", "an", "amendment", "since", "the", "symlink", "will", "still", "appear", "as", "a", "file", "but", "the", "actua...
35d60adb41da942178b789560968e3ad030b0ac7
https://github.com/sds/overcommit/blob/35d60adb41da942178b789560968e3ad030b0ac7/lib/overcommit/hook_context/base.rb#L133-L137
train