id
int32
0
24.9k
repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
sequence
docstring
stringlengths
8
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
94
266
24,900
emilsoman/cloudster
lib/cloudster/cloud.rb
Cloudster.Cloud.get_ec2_details
def get_ec2_details(options = {}) stack_resources = resources(options) ec2_resource_ids = get_resource_ids(stack_resources, "AWS::EC2::Instance") ec2 = Fog::Compute::AWS.new(:aws_access_key_id => @access_key_id, :aws_secret_access_key => @secret_access_key, :region => @region) ec2_details = {} ec2_resource_ids.each do |key, value| ec2_instance_details = ec2.describe_instances('instance-id' => value) ec2_details[key] = ec2_instance_details.body["reservationSet"][0]["instancesSet"][0] rescue nil end return ec2_details end
ruby
def get_ec2_details(options = {}) stack_resources = resources(options) ec2_resource_ids = get_resource_ids(stack_resources, "AWS::EC2::Instance") ec2 = Fog::Compute::AWS.new(:aws_access_key_id => @access_key_id, :aws_secret_access_key => @secret_access_key, :region => @region) ec2_details = {} ec2_resource_ids.each do |key, value| ec2_instance_details = ec2.describe_instances('instance-id' => value) ec2_details[key] = ec2_instance_details.body["reservationSet"][0]["instancesSet"][0] rescue nil end return ec2_details end
[ "def", "get_ec2_details", "(", "options", "=", "{", "}", ")", "stack_resources", "=", "resources", "(", "options", ")", "ec2_resource_ids", "=", "get_resource_ids", "(", "stack_resources", ",", "\"AWS::EC2::Instance\"", ")", "ec2", "=", "Fog", "::", "Compute", "::", "AWS", ".", "new", "(", ":aws_access_key_id", "=>", "@access_key_id", ",", ":aws_secret_access_key", "=>", "@secret_access_key", ",", ":region", "=>", "@region", ")", "ec2_details", "=", "{", "}", "ec2_resource_ids", ".", "each", "do", "|", "key", ",", "value", "|", "ec2_instance_details", "=", "ec2", ".", "describe_instances", "(", "'instance-id'", "=>", "value", ")", "ec2_details", "[", "key", "]", "=", "ec2_instance_details", ".", "body", "[", "\"reservationSet\"", "]", "[", "0", "]", "[", "\"instancesSet\"", "]", "[", "0", "]", "rescue", "nil", "end", "return", "ec2_details", "end" ]
Get details of all EC2 instances in a stack ==== Examples cloud = Cloudster::Cloud.new( :access_key_id => 'aws_access_key_id', :secret_access_key => 'aws_secret_access_key', :region => 'us-east-1' ) cloud.get_ec2_details(:stack_name => 'ShittyStack') ==== Parameters * options<~Hash> * :stack_name : A string which will contain the name of the stack ==== Returns * A hash of instance details where the key is the logical instance name and value is the instance detail
[ "Get", "details", "of", "all", "EC2", "instances", "in", "a", "stack" ]
fd0e03758c2c08c1621212b9daa28e0be9a812ff
https://github.com/emilsoman/cloudster/blob/fd0e03758c2c08c1621212b9daa28e0be9a812ff/lib/cloudster/cloud.rb#L256-L266
24,901
emilsoman/cloudster
lib/cloudster/cloud.rb
Cloudster.Cloud.get_elb_details
def get_elb_details(options = {}) stack_resources = resources(options) elb_resource_ids = get_resource_ids(stack_resources, "AWS::ElasticLoadBalancing::LoadBalancer") elb = Fog::AWS::ELB.new(:aws_access_key_id => @access_key_id, :aws_secret_access_key => @secret_access_key, :region => @region) elb_details = {} elb_resource_ids.each do |key, value| elb_instance_details = elb.describe_load_balancers("LoadBalancerNames" => [value]) elb_details[key] = elb_instance_details.body["DescribeLoadBalancersResult"]["LoadBalancerDescriptions"][0] rescue nil end return elb_details end
ruby
def get_elb_details(options = {}) stack_resources = resources(options) elb_resource_ids = get_resource_ids(stack_resources, "AWS::ElasticLoadBalancing::LoadBalancer") elb = Fog::AWS::ELB.new(:aws_access_key_id => @access_key_id, :aws_secret_access_key => @secret_access_key, :region => @region) elb_details = {} elb_resource_ids.each do |key, value| elb_instance_details = elb.describe_load_balancers("LoadBalancerNames" => [value]) elb_details[key] = elb_instance_details.body["DescribeLoadBalancersResult"]["LoadBalancerDescriptions"][0] rescue nil end return elb_details end
[ "def", "get_elb_details", "(", "options", "=", "{", "}", ")", "stack_resources", "=", "resources", "(", "options", ")", "elb_resource_ids", "=", "get_resource_ids", "(", "stack_resources", ",", "\"AWS::ElasticLoadBalancing::LoadBalancer\"", ")", "elb", "=", "Fog", "::", "AWS", "::", "ELB", ".", "new", "(", ":aws_access_key_id", "=>", "@access_key_id", ",", ":aws_secret_access_key", "=>", "@secret_access_key", ",", ":region", "=>", "@region", ")", "elb_details", "=", "{", "}", "elb_resource_ids", ".", "each", "do", "|", "key", ",", "value", "|", "elb_instance_details", "=", "elb", ".", "describe_load_balancers", "(", "\"LoadBalancerNames\"", "=>", "[", "value", "]", ")", "elb_details", "[", "key", "]", "=", "elb_instance_details", ".", "body", "[", "\"DescribeLoadBalancersResult\"", "]", "[", "\"LoadBalancerDescriptions\"", "]", "[", "0", "]", "rescue", "nil", "end", "return", "elb_details", "end" ]
Get details of all Elastic Load Balancers in the stack ==== Examples cloud = Cloudster::Cloud.new( :access_key_id => 'aws_access_key_id', :secret_access_key => 'aws_secret_access_key', :region => 'us-east-1' ) cloud.get_elb_details(:stack_name => 'ShittyStack') ==== Parameters * options<~Hash> * :stack_name : A string which will contain the name of the stack ==== Returns * A hash containing elb details where the key is the logical name and value contains the details
[ "Get", "details", "of", "all", "Elastic", "Load", "Balancers", "in", "the", "stack" ]
fd0e03758c2c08c1621212b9daa28e0be9a812ff
https://github.com/emilsoman/cloudster/blob/fd0e03758c2c08c1621212b9daa28e0be9a812ff/lib/cloudster/cloud.rb#L284-L294
24,902
emilsoman/cloudster
lib/cloudster/cloud.rb
Cloudster.Cloud.outputs
def outputs(options = {}) require_options(options, [:stack_name]) stack_description = describe(:stack_name => options[:stack_name]) outputs = stack_description["Outputs"] rescue [] outputs_hash = {} outputs.each do |output| outputs_hash[output["OutputKey"]] = parse_outputs(output["OutputValue"]) end return outputs_hash end
ruby
def outputs(options = {}) require_options(options, [:stack_name]) stack_description = describe(:stack_name => options[:stack_name]) outputs = stack_description["Outputs"] rescue [] outputs_hash = {} outputs.each do |output| outputs_hash[output["OutputKey"]] = parse_outputs(output["OutputValue"]) end return outputs_hash end
[ "def", "outputs", "(", "options", "=", "{", "}", ")", "require_options", "(", "options", ",", "[", ":stack_name", "]", ")", "stack_description", "=", "describe", "(", ":stack_name", "=>", "options", "[", ":stack_name", "]", ")", "outputs", "=", "stack_description", "[", "\"Outputs\"", "]", "rescue", "[", "]", "outputs_hash", "=", "{", "}", "outputs", ".", "each", "do", "|", "output", "|", "outputs_hash", "[", "output", "[", "\"OutputKey\"", "]", "]", "=", "parse_outputs", "(", "output", "[", "\"OutputValue\"", "]", ")", "end", "return", "outputs_hash", "end" ]
Returns a hash containing the output values of each resource in the Stack ==== Examples cloud = Cloudster::Cloud.new( :access_key_id => 'aws_access_key_id', :secret_access_key => 'aws_secret_access_key', :region => 'us-east-1' ) cloud.outputs(:stack_name => 'RDSStack') ==== Parameters * options<~Hash> * :stack_name : A string which will contain the name of the stack ==== Returns * Hash containing outputs of the stack
[ "Returns", "a", "hash", "containing", "the", "output", "values", "of", "each", "resource", "in", "the", "Stack" ]
fd0e03758c2c08c1621212b9daa28e0be9a812ff
https://github.com/emilsoman/cloudster/blob/fd0e03758c2c08c1621212b9daa28e0be9a812ff/lib/cloudster/cloud.rb#L354-L363
24,903
emilsoman/cloudster
lib/cloudster/cloud.rb
Cloudster.Cloud.is_s3_bucket_name_available?
def is_s3_bucket_name_available?(bucket_name) s3 = Fog::Storage::AWS.new(:aws_access_key_id => @access_key_id, :aws_secret_access_key => @secret_access_key) begin response = s3.get_bucket(bucket_name) rescue Exception => e response = e.response end not_found_status = 404 return response[:status] == not_found_status end
ruby
def is_s3_bucket_name_available?(bucket_name) s3 = Fog::Storage::AWS.new(:aws_access_key_id => @access_key_id, :aws_secret_access_key => @secret_access_key) begin response = s3.get_bucket(bucket_name) rescue Exception => e response = e.response end not_found_status = 404 return response[:status] == not_found_status end
[ "def", "is_s3_bucket_name_available?", "(", "bucket_name", ")", "s3", "=", "Fog", "::", "Storage", "::", "AWS", ".", "new", "(", ":aws_access_key_id", "=>", "@access_key_id", ",", ":aws_secret_access_key", "=>", "@secret_access_key", ")", "begin", "response", "=", "s3", ".", "get_bucket", "(", "bucket_name", ")", "rescue", "Exception", "=>", "e", "response", "=", "e", ".", "response", "end", "not_found_status", "=", "404", "return", "response", "[", ":status", "]", "==", "not_found_status", "end" ]
Returns true if S3 bucket name is available, else returns false ==== Examples cloud = Cloudster::Cloud.new( :access_key_id => 'aws_access_key_id', :secret_access_key => 'aws_secret_access_key', :region => 'us-east-1' ) cloud.is_s3_bucket_name_available?('test-bucket-name') ==== Parameter * String containing the bucket name ==== Returns * true - If bucket name is available * false - If bucket name is not available
[ "Returns", "true", "if", "S3", "bucket", "name", "is", "available", "else", "returns", "false" ]
fd0e03758c2c08c1621212b9daa28e0be9a812ff
https://github.com/emilsoman/cloudster/blob/fd0e03758c2c08c1621212b9daa28e0be9a812ff/lib/cloudster/cloud.rb#L451-L460
24,904
activenetwork/gattica
lib/gattica/convertible.rb
Gattica.Convertible.to_h
def to_h output = {} instance_variables.each do |var| output.merge!({ var[1..-1] => instance_variable_get(var) }) unless var == '@xml' # exclude the whole XML dump end output end
ruby
def to_h output = {} instance_variables.each do |var| output.merge!({ var[1..-1] => instance_variable_get(var) }) unless var == '@xml' # exclude the whole XML dump end output end
[ "def", "to_h", "output", "=", "{", "}", "instance_variables", ".", "each", "do", "|", "var", "|", "output", ".", "merge!", "(", "{", "var", "[", "1", "..", "-", "1", "]", "=>", "instance_variable_get", "(", "var", ")", "}", ")", "unless", "var", "==", "'@xml'", "# exclude the whole XML dump", "end", "output", "end" ]
output as hash
[ "output", "as", "hash" ]
359a5a70eba67e0f9ddd6081cb4defbf14d2e74b
https://github.com/activenetwork/gattica/blob/359a5a70eba67e0f9ddd6081cb4defbf14d2e74b/lib/gattica/convertible.rb#L8-L14
24,905
nicstrong/android-adb
lib/android-adb/Adb.rb
AndroidAdb.Adb.get_devices
def get_devices devices = [] run_adb("devices") do |pout| pout.each do |line| line = line.strip if (!line.empty? && line !~ /^List of devices/) parts = line.split device = AndroidAdb::Device.new(parts[0], parts[1]) devices << device end end end return devices end
ruby
def get_devices devices = [] run_adb("devices") do |pout| pout.each do |line| line = line.strip if (!line.empty? && line !~ /^List of devices/) parts = line.split device = AndroidAdb::Device.new(parts[0], parts[1]) devices << device end end end return devices end
[ "def", "get_devices", "devices", "=", "[", "]", "run_adb", "(", "\"devices\"", ")", "do", "|", "pout", "|", "pout", ".", "each", "do", "|", "line", "|", "line", "=", "line", ".", "strip", "if", "(", "!", "line", ".", "empty?", "&&", "line", "!~", "/", "/", ")", "parts", "=", "line", ".", "split", "device", "=", "AndroidAdb", "::", "Device", ".", "new", "(", "parts", "[", "0", "]", ",", "parts", "[", "1", "]", ")", "devices", "<<", "device", "end", "end", "end", "return", "devices", "end" ]
Contructs an Adb object for issuing commands to the connected device or emulator. If the adb path is not specified in the +opts+ hash it is determined in the following order: 1. Try and use the unix which command to locate the adb binary. 2. Use the ANDROID_HOME environment variable. 3. Default to adb (no path specified). @param [Hash] opts The options to create the Adb object with. @option opts [Logger] :log A log4r logger that debug information can be sent too. @option opts [Boolean] :dry_run Does not execute the *adb* command but will log the command and set last_command. @option opts [Boolean] :adb_path Manually set the path to the adb binary. Returns a list of all connected devices. The collection is returned as a hash containing the device name <tt>:name</tt> and the serial <tt>:serial</tt>. @return [Array<Device>] THe list of connected devices/emulators.
[ "Contructs", "an", "Adb", "object", "for", "issuing", "commands", "to", "the", "connected", "device", "or", "emulator", "." ]
3db27394074c82342fe397bf18912c7dc9bef413
https://github.com/nicstrong/android-adb/blob/3db27394074c82342fe397bf18912c7dc9bef413/lib/android-adb/Adb.rb#L40-L53
24,906
nicstrong/android-adb
lib/android-adb/Adb.rb
AndroidAdb.Adb.get_packages
def get_packages(adb_opts = {}) packages = [] run_adb_shell("pm list packages -f", adb_opts) do |pout| pout.each do |line| @log.debug("{stdout} #{line}") unless @log.nil? parts = line.split(":") if (parts.length > 1) info = parts[1].strip.split("=") package = AndroidAdb::Package.new(info[1], info[0]); packages << package; end end end return packages end
ruby
def get_packages(adb_opts = {}) packages = [] run_adb_shell("pm list packages -f", adb_opts) do |pout| pout.each do |line| @log.debug("{stdout} #{line}") unless @log.nil? parts = line.split(":") if (parts.length > 1) info = parts[1].strip.split("=") package = AndroidAdb::Package.new(info[1], info[0]); packages << package; end end end return packages end
[ "def", "get_packages", "(", "adb_opts", "=", "{", "}", ")", "packages", "=", "[", "]", "run_adb_shell", "(", "\"pm list packages -f\"", ",", "adb_opts", ")", "do", "|", "pout", "|", "pout", ".", "each", "do", "|", "line", "|", "@log", ".", "debug", "(", "\"{stdout} #{line}\"", ")", "unless", "@log", ".", "nil?", "parts", "=", "line", ".", "split", "(", "\":\"", ")", "if", "(", "parts", ".", "length", ">", "1", ")", "info", "=", "parts", "[", "1", "]", ".", "strip", ".", "split", "(", "\"=\"", ")", "package", "=", "AndroidAdb", "::", "Package", ".", "new", "(", "info", "[", "1", "]", ",", "info", "[", "0", "]", ")", ";", "packages", "<<", "package", ";", "end", "end", "end", "return", "packages", "end" ]
Returns a list of all installed packages on the device. @param [Hash] adb_opts Options for the adb command (@see #run_adb) @return [Hash] THe list of installed packages. The hash returned contains the apk file name <tt>:apk</tt> and the name of the package <tt>:name</tt>.
[ "Returns", "a", "list", "of", "all", "installed", "packages", "on", "the", "device", "." ]
3db27394074c82342fe397bf18912c7dc9bef413
https://github.com/nicstrong/android-adb/blob/3db27394074c82342fe397bf18912c7dc9bef413/lib/android-adb/Adb.rb#L58-L72
24,907
bogdanRada/celluloid_pubsub
lib/celluloid_pubsub/helper.rb
CelluloidPubsub.Helper.setup_celluloid_logger
def setup_celluloid_logger return if !debug_enabled? || (respond_to?(:log_file_path) && log_file_path.blank?) setup_log_file Celluloid.logger = ::Logger.new(log_file_path.present? ? log_file_path : STDOUT) setup_celluloid_exception_handler end
ruby
def setup_celluloid_logger return if !debug_enabled? || (respond_to?(:log_file_path) && log_file_path.blank?) setup_log_file Celluloid.logger = ::Logger.new(log_file_path.present? ? log_file_path : STDOUT) setup_celluloid_exception_handler end
[ "def", "setup_celluloid_logger", "return", "if", "!", "debug_enabled?", "||", "(", "respond_to?", "(", ":log_file_path", ")", "&&", "log_file_path", ".", "blank?", ")", "setup_log_file", "Celluloid", ".", "logger", "=", "::", "Logger", ".", "new", "(", "log_file_path", ".", "present?", "?", "log_file_path", ":", "STDOUT", ")", "setup_celluloid_exception_handler", "end" ]
sets the celluloid logger and the celluloid exception handler @return [void] @api private
[ "sets", "the", "celluloid", "logger", "and", "the", "celluloid", "exception", "handler" ]
e5558257c04e553b49e08ce27c130d572ada210d
https://github.com/bogdanRada/celluloid_pubsub/blob/e5558257c04e553b49e08ce27c130d572ada210d/lib/celluloid_pubsub/helper.rb#L94-L99
24,908
bogdanRada/celluloid_pubsub
lib/celluloid_pubsub/helper.rb
CelluloidPubsub.Helper.setup_celluloid_exception_handler
def setup_celluloid_exception_handler Celluloid.task_class = defined?(Celluloid::TaskThread) ? Celluloid::TaskThread : Celluloid::Task::Threaded Celluloid.exception_handler do |ex| puts ex unless filtered_error?(ex) end end
ruby
def setup_celluloid_exception_handler Celluloid.task_class = defined?(Celluloid::TaskThread) ? Celluloid::TaskThread : Celluloid::Task::Threaded Celluloid.exception_handler do |ex| puts ex unless filtered_error?(ex) end end
[ "def", "setup_celluloid_exception_handler", "Celluloid", ".", "task_class", "=", "defined?", "(", "Celluloid", "::", "TaskThread", ")", "?", "Celluloid", "::", "TaskThread", ":", "Celluloid", "::", "Task", "::", "Threaded", "Celluloid", ".", "exception_handler", "do", "|", "ex", "|", "puts", "ex", "unless", "filtered_error?", "(", "ex", ")", "end", "end" ]
sets the celluloid exception handler @return [void] @api private
[ "sets", "the", "celluloid", "exception", "handler" ]
e5558257c04e553b49e08ce27c130d572ada210d
https://github.com/bogdanRada/celluloid_pubsub/blob/e5558257c04e553b49e08ce27c130d572ada210d/lib/celluloid_pubsub/helper.rb#L106-L111
24,909
bogdanRada/celluloid_pubsub
lib/celluloid_pubsub/helper.rb
CelluloidPubsub.Helper.setup_log_file
def setup_log_file return if !debug_enabled? || (respond_to?(:log_file_path) && log_file_path.blank?) FileUtils.mkdir_p(File.dirname(log_file_path)) unless File.directory?(log_file_path) log_file = File.open(log_file_path, 'w') log_file.sync = true end
ruby
def setup_log_file return if !debug_enabled? || (respond_to?(:log_file_path) && log_file_path.blank?) FileUtils.mkdir_p(File.dirname(log_file_path)) unless File.directory?(log_file_path) log_file = File.open(log_file_path, 'w') log_file.sync = true end
[ "def", "setup_log_file", "return", "if", "!", "debug_enabled?", "||", "(", "respond_to?", "(", ":log_file_path", ")", "&&", "log_file_path", ".", "blank?", ")", "FileUtils", ".", "mkdir_p", "(", "File", ".", "dirname", "(", "log_file_path", ")", ")", "unless", "File", ".", "directory?", "(", "log_file_path", ")", "log_file", "=", "File", ".", "open", "(", "log_file_path", ",", "'w'", ")", "log_file", ".", "sync", "=", "true", "end" ]
creates the log file where the debug messages will be printed @return [void] @api private
[ "creates", "the", "log", "file", "where", "the", "debug", "messages", "will", "be", "printed" ]
e5558257c04e553b49e08ce27c130d572ada210d
https://github.com/bogdanRada/celluloid_pubsub/blob/e5558257c04e553b49e08ce27c130d572ada210d/lib/celluloid_pubsub/helper.rb#L118-L123
24,910
bogdanRada/celluloid_pubsub
lib/celluloid_pubsub/helper.rb
CelluloidPubsub.Helper.parse_options
def parse_options(options) options = options.is_a?(Array) ? options.first : options options = options.is_a?(Hash) ? options.stringify_keys : {} options end
ruby
def parse_options(options) options = options.is_a?(Array) ? options.first : options options = options.is_a?(Hash) ? options.stringify_keys : {} options end
[ "def", "parse_options", "(", "options", ")", "options", "=", "options", ".", "is_a?", "(", "Array", ")", "?", "options", ".", "first", ":", "options", "options", "=", "options", ".", "is_a?", "(", "Hash", ")", "?", "options", ".", "stringify_keys", ":", "{", "}", "options", "end" ]
receives a list of options that need to be parsed if it is an Array will return the first element , otherwise if it is an Hash will return the hash with string keys, otherwise an empty hash @param [Hash, Array] options the options that need to be parsed @return [Hash] @api private
[ "receives", "a", "list", "of", "options", "that", "need", "to", "be", "parsed", "if", "it", "is", "an", "Array", "will", "return", "the", "first", "element", "otherwise", "if", "it", "is", "an", "Hash", "will", "return", "the", "hash", "with", "string", "keys", "otherwise", "an", "empty", "hash" ]
e5558257c04e553b49e08ce27c130d572ada210d
https://github.com/bogdanRada/celluloid_pubsub/blob/e5558257c04e553b49e08ce27c130d572ada210d/lib/celluloid_pubsub/helper.rb#L145-L149
24,911
adjust/dumbo
lib/dumbo/dependency_resolver.rb
Dumbo.DependencyResolver.resolve
def resolve list = dependency_list.sort { |a, b| a.last.size <=> b.last.size } resolve_list(list) end
ruby
def resolve list = dependency_list.sort { |a, b| a.last.size <=> b.last.size } resolve_list(list) end
[ "def", "resolve", "list", "=", "dependency_list", ".", "sort", "{", "|", "a", ",", "b", "|", "a", ".", "last", ".", "size", "<=>", "b", ".", "last", ".", "size", "}", "resolve_list", "(", "list", ")", "end" ]
Constructor accepts an array of files
[ "Constructor", "accepts", "an", "array", "of", "files" ]
e4a4821e86f0be26be8eb07f692610ba1b4bad12
https://github.com/adjust/dumbo/blob/e4a4821e86f0be26be8eb07f692610ba1b4bad12/lib/dumbo/dependency_resolver.rb#L24-L27
24,912
jronallo/microdata
lib/microdata/itemprop.rb
Microdata.Itemprop.make_absolute_url
def make_absolute_url(url) return url unless URI.parse(url).relative? begin URI.parse(@page_url).merge(url).to_s rescue URI::Error url end end
ruby
def make_absolute_url(url) return url unless URI.parse(url).relative? begin URI.parse(@page_url).merge(url).to_s rescue URI::Error url end end
[ "def", "make_absolute_url", "(", "url", ")", "return", "url", "unless", "URI", ".", "parse", "(", "url", ")", ".", "relative?", "begin", "URI", ".", "parse", "(", "@page_url", ")", ".", "merge", "(", "url", ")", ".", "to_s", "rescue", "URI", "::", "Error", "url", "end", "end" ]
This returns an empty string if can't form a valid absolute url as per the Microdata spec.
[ "This", "returns", "an", "empty", "string", "if", "can", "t", "form", "a", "valid", "absolute", "url", "as", "per", "the", "Microdata", "spec", "." ]
9af0e41801a815b1d14d5bb56f35bdd6c35ab006
https://github.com/jronallo/microdata/blob/9af0e41801a815b1d14d5bb56f35bdd6c35ab006/lib/microdata/itemprop.rb#L49-L56
24,913
emmanuel/aequitas
lib/aequitas/support/ordered_hash.rb
Aequitas.OrderedHash.[]=
def []=(k, i=nil, v=nil) if v insert(i,k,v) else store(k,i) end end
ruby
def []=(k, i=nil, v=nil) if v insert(i,k,v) else store(k,i) end end
[ "def", "[]=", "(", "k", ",", "i", "=", "nil", ",", "v", "=", "nil", ")", "if", "v", "insert", "(", "i", ",", "k", ",", "v", ")", "else", "store", "(", "k", ",", "i", ")", "end", "end" ]
Store operator. h[key] = value Or with additional index. h[key,index] = value
[ "Store", "operator", "." ]
984f16a1db12e88c8e9a4a3605896b295e285a6b
https://github.com/emmanuel/aequitas/blob/984f16a1db12e88c8e9a4a3605896b295e285a6b/lib/aequitas/support/ordered_hash.rb#L232-L238
24,914
jonathanchrisp/fredapi
lib/fredapi/request.rb
FREDAPI.Request.request
def request method, path, opts={} conn_options = connection_options opts opts['api_key'] = api_key unless opts.has_key? 'api_key' opts['file_type'] = file_type unless opts.has_key? 'file_type' response = connection(conn_options).send(method) do |request| case method when :get request.url path, opts when :delete request.url path, opts when :patch, :post, :put if conn_options[:force_urlencoded] request.url path, opts else request.path = path request.body = MultiJson.dump(opts) unless opts.empty? end end end response end
ruby
def request method, path, opts={} conn_options = connection_options opts opts['api_key'] = api_key unless opts.has_key? 'api_key' opts['file_type'] = file_type unless opts.has_key? 'file_type' response = connection(conn_options).send(method) do |request| case method when :get request.url path, opts when :delete request.url path, opts when :patch, :post, :put if conn_options[:force_urlencoded] request.url path, opts else request.path = path request.body = MultiJson.dump(opts) unless opts.empty? end end end response end
[ "def", "request", "method", ",", "path", ",", "opts", "=", "{", "}", "conn_options", "=", "connection_options", "opts", "opts", "[", "'api_key'", "]", "=", "api_key", "unless", "opts", ".", "has_key?", "'api_key'", "opts", "[", "'file_type'", "]", "=", "file_type", "unless", "opts", ".", "has_key?", "'file_type'", "response", "=", "connection", "(", "conn_options", ")", ".", "send", "(", "method", ")", "do", "|", "request", "|", "case", "method", "when", ":get", "request", ".", "url", "path", ",", "opts", "when", ":delete", "request", ".", "url", "path", ",", "opts", "when", ":patch", ",", ":post", ",", ":put", "if", "conn_options", "[", ":force_urlencoded", "]", "request", ".", "url", "path", ",", "opts", "else", "request", ".", "path", "=", "path", "request", ".", "body", "=", "MultiJson", ".", "dump", "(", "opts", ")", "unless", "opts", ".", "empty?", "end", "end", "end", "response", "end" ]
Perform a request @param method [String] Type of request path @param path [String] URL path to send request @param opts [Hash] Request parameters @return [Hashie::Mash] Response
[ "Perform", "a", "request" ]
8eda87f0732d6c8b909c61fc0e260cd6848dbee3
https://github.com/jonathanchrisp/fredapi/blob/8eda87f0732d6c8b909c61fc0e260cd6848dbee3/lib/fredapi/request.rb#L74-L96
24,915
opyh/motion-state-machine
lib/motion-state-machine/state.rb
StateMachine.State.enter!
def enter! @state_machine.current_state = self @entry_actions.each do |entry_action| entry_action.call(@state_machine) end @transition_map.each do |type, events_to_transition_arrays| events_to_transition_arrays.each do |event, transitions| transitions.each(&:arm) end end end
ruby
def enter! @state_machine.current_state = self @entry_actions.each do |entry_action| entry_action.call(@state_machine) end @transition_map.each do |type, events_to_transition_arrays| events_to_transition_arrays.each do |event, transitions| transitions.each(&:arm) end end end
[ "def", "enter!", "@state_machine", ".", "current_state", "=", "self", "@entry_actions", ".", "each", "do", "|", "entry_action", "|", "entry_action", ".", "call", "(", "@state_machine", ")", "end", "@transition_map", ".", "each", "do", "|", "type", ",", "events_to_transition_arrays", "|", "events_to_transition_arrays", ".", "each", "do", "|", "event", ",", "transitions", "|", "transitions", ".", "each", "(", ":arm", ")", "end", "end", "end" ]
Sets the state machine's current_state to self, calls all entry actions and activates triggering mechanisms of all outgoing transitions.
[ "Sets", "the", "state", "machine", "s", "current_state", "to", "self", "calls", "all", "entry", "actions", "and", "activates", "triggering", "mechanisms", "of", "all", "outgoing", "transitions", "." ]
baafa93de4b05fe4ba91a3dbb944ab3d28b8913d
https://github.com/opyh/motion-state-machine/blob/baafa93de4b05fe4ba91a3dbb944ab3d28b8913d/lib/motion-state-machine/state.rb#L283-L294
24,916
opyh/motion-state-machine
lib/motion-state-machine/state.rb
StateMachine.State.exit!
def exit! map = @transition_map map.each do |type, events_to_transition_arrays| events_to_transition_arrays.each do |event, transitions| transitions.each(&:unarm) end end @exit_actions.each do |exit_action| exit_action.call(@state_machine) end @state_machine.current_state = nil end
ruby
def exit! map = @transition_map map.each do |type, events_to_transition_arrays| events_to_transition_arrays.each do |event, transitions| transitions.each(&:unarm) end end @exit_actions.each do |exit_action| exit_action.call(@state_machine) end @state_machine.current_state = nil end
[ "def", "exit!", "map", "=", "@transition_map", "map", ".", "each", "do", "|", "type", ",", "events_to_transition_arrays", "|", "events_to_transition_arrays", ".", "each", "do", "|", "event", ",", "transitions", "|", "transitions", ".", "each", "(", ":unarm", ")", "end", "end", "@exit_actions", ".", "each", "do", "|", "exit_action", "|", "exit_action", ".", "call", "(", "@state_machine", ")", "end", "@state_machine", ".", "current_state", "=", "nil", "end" ]
Sets the state machine's current_state to nil, calls all exit actions and deactivates triggering mechanisms of all outgoing transitions.
[ "Sets", "the", "state", "machine", "s", "current_state", "to", "nil", "calls", "all", "exit", "actions", "and", "deactivates", "triggering", "mechanisms", "of", "all", "outgoing", "transitions", "." ]
baafa93de4b05fe4ba91a3dbb944ab3d28b8913d
https://github.com/opyh/motion-state-machine/blob/baafa93de4b05fe4ba91a3dbb944ab3d28b8913d/lib/motion-state-machine/state.rb#L301-L313
24,917
opyh/motion-state-machine
lib/motion-state-machine/state.rb
StateMachine.State.cleanup
def cleanup @transition_map.each do |type, events_to_transition_arrays| events_to_transition_arrays.each do |event, transitions| transitions.clear end end @transition_map = nil @state_machine = nil @entry_actions = nil @exit_actions = nil end
ruby
def cleanup @transition_map.each do |type, events_to_transition_arrays| events_to_transition_arrays.each do |event, transitions| transitions.clear end end @transition_map = nil @state_machine = nil @entry_actions = nil @exit_actions = nil end
[ "def", "cleanup", "@transition_map", ".", "each", "do", "|", "type", ",", "events_to_transition_arrays", "|", "events_to_transition_arrays", ".", "each", "do", "|", "event", ",", "transitions", "|", "transitions", ".", "clear", "end", "end", "@transition_map", "=", "nil", "@state_machine", "=", "nil", "@entry_actions", "=", "nil", "@exit_actions", "=", "nil", "end" ]
Cleans up references to allow easier GC.
[ "Cleans", "up", "references", "to", "allow", "easier", "GC", "." ]
baafa93de4b05fe4ba91a3dbb944ab3d28b8913d
https://github.com/opyh/motion-state-machine/blob/baafa93de4b05fe4ba91a3dbb944ab3d28b8913d/lib/motion-state-machine/state.rb#L318-L329
24,918
opyh/motion-state-machine
lib/motion-state-machine/state.rb
StateMachine.State.guarded_execute
def guarded_execute(event_type, event_trigger_value) @state_machine.raise_outside_initial_queue return if terminating? if @transition_map[event_type].nil? || @transition_map[event_type][event_trigger_value].nil? raise ArgumentError, "No registered transition found "\ "for event #{event_type}:#{event_trigger_value}." end possible_transitions = @transition_map[event_type][event_trigger_value] return if possible_transitions.empty? allowed_transitions = possible_transitions.select(&:allowed?) if allowed_transitions.empty? @state_machine.log "All transitions are disallowed for "\ "#{event_type}:#{event_trigger_value}." elsif allowed_transitions.count > 1 list = allowed_transitions.collect do |t| "-> #{t.options[:to]}" end raise RuntimeError, "Not sure which transition to trigger "\ "when #{symbol} while #{self} (allowed: #{list}). "\ "Please make sure guard conditions exclude each other." else transition = allowed_transitions.first unless transition.nil? transition.send :unguarded_execute end end end
ruby
def guarded_execute(event_type, event_trigger_value) @state_machine.raise_outside_initial_queue return if terminating? if @transition_map[event_type].nil? || @transition_map[event_type][event_trigger_value].nil? raise ArgumentError, "No registered transition found "\ "for event #{event_type}:#{event_trigger_value}." end possible_transitions = @transition_map[event_type][event_trigger_value] return if possible_transitions.empty? allowed_transitions = possible_transitions.select(&:allowed?) if allowed_transitions.empty? @state_machine.log "All transitions are disallowed for "\ "#{event_type}:#{event_trigger_value}." elsif allowed_transitions.count > 1 list = allowed_transitions.collect do |t| "-> #{t.options[:to]}" end raise RuntimeError, "Not sure which transition to trigger "\ "when #{symbol} while #{self} (allowed: #{list}). "\ "Please make sure guard conditions exclude each other." else transition = allowed_transitions.first unless transition.nil? transition.send :unguarded_execute end end end
[ "def", "guarded_execute", "(", "event_type", ",", "event_trigger_value", ")", "@state_machine", ".", "raise_outside_initial_queue", "return", "if", "terminating?", "if", "@transition_map", "[", "event_type", "]", ".", "nil?", "||", "@transition_map", "[", "event_type", "]", "[", "event_trigger_value", "]", ".", "nil?", "raise", "ArgumentError", ",", "\"No registered transition found \"", "\"for event #{event_type}:#{event_trigger_value}.\"", "end", "possible_transitions", "=", "@transition_map", "[", "event_type", "]", "[", "event_trigger_value", "]", "return", "if", "possible_transitions", ".", "empty?", "allowed_transitions", "=", "possible_transitions", ".", "select", "(", ":allowed?", ")", "if", "allowed_transitions", ".", "empty?", "@state_machine", ".", "log", "\"All transitions are disallowed for \"", "\"#{event_type}:#{event_trigger_value}.\"", "elsif", "allowed_transitions", ".", "count", ">", "1", "list", "=", "allowed_transitions", ".", "collect", "do", "|", "t", "|", "\"-> #{t.options[:to]}\"", "end", "raise", "RuntimeError", ",", "\"Not sure which transition to trigger \"", "\"when #{symbol} while #{self} (allowed: #{list}). \"", "\"Please make sure guard conditions exclude each other.\"", "else", "transition", "=", "allowed_transitions", ".", "first", "unless", "transition", ".", "nil?", "transition", ".", "send", ":unguarded_execute", "end", "end", "end" ]
Executes the registered transition for the given event type and event trigger value, if such a transition exists and it is allowed. @raise [RuntimeError] if multiple transitions would be allowed at the same time.
[ "Executes", "the", "registered", "transition", "for", "the", "given", "event", "type", "and", "event", "trigger", "value", "if", "such", "a", "transition", "exists", "and", "it", "is", "allowed", "." ]
baafa93de4b05fe4ba91a3dbb944ab3d28b8913d
https://github.com/opyh/motion-state-machine/blob/baafa93de4b05fe4ba91a3dbb944ab3d28b8913d/lib/motion-state-machine/state.rb#L339-L375
24,919
activenetwork/gattica
lib/gattica/user.rb
Gattica.User.validate
def validate raise GatticaError::InvalidEmail, "The email address '#{@email}' is not valid" if not @email.match(/^(?:[_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-zA-Z0-9\-\.]+)*(\.[a-z]{2,4})$/i) raise GatticaError::InvalidPassword, "The password cannot be blank" if @password.empty? || @password.nil? end
ruby
def validate raise GatticaError::InvalidEmail, "The email address '#{@email}' is not valid" if not @email.match(/^(?:[_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-zA-Z0-9\-\.]+)*(\.[a-z]{2,4})$/i) raise GatticaError::InvalidPassword, "The password cannot be blank" if @password.empty? || @password.nil? end
[ "def", "validate", "raise", "GatticaError", "::", "InvalidEmail", ",", "\"The email address '#{@email}' is not valid\"", "if", "not", "@email", ".", "match", "(", "/", "\\.", "\\.", "\\-", "\\.", "\\.", "/i", ")", "raise", "GatticaError", "::", "InvalidPassword", ",", "\"The password cannot be blank\"", "if", "@password", ".", "empty?", "||", "@password", ".", "nil?", "end" ]
Determine whether or not this is a valid user
[ "Determine", "whether", "or", "not", "this", "is", "a", "valid", "user" ]
359a5a70eba67e0f9ddd6081cb4defbf14d2e74b
https://github.com/activenetwork/gattica/blob/359a5a70eba67e0f9ddd6081cb4defbf14d2e74b/lib/gattica/user.rb#L25-L28
24,920
jonathanchrisp/fredapi
lib/fredapi/configuration.rb
FREDAPI.Configuration.options
def options OPTION_KEYS.inject({}){|o,k|o.merge!(k => send(k))} end
ruby
def options OPTION_KEYS.inject({}){|o,k|o.merge!(k => send(k))} end
[ "def", "options", "OPTION_KEYS", ".", "inject", "(", "{", "}", ")", "{", "|", "o", ",", "k", "|", "o", ".", "merge!", "(", "k", "=>", "send", "(", "k", ")", ")", "}", "end" ]
Convert option_keys to hash and return
[ "Convert", "option_keys", "to", "hash", "and", "return" ]
8eda87f0732d6c8b909c61fc0e260cd6848dbee3
https://github.com/jonathanchrisp/fredapi/blob/8eda87f0732d6c8b909c61fc0e260cd6848dbee3/lib/fredapi/configuration.rb#L33-L35
24,921
TheArtificial/rails-wiki
app/models/wiki/wiki.rb
Wiki.Wiki.recent_updates
def recent_updates(options) default_options = { path: nil, limit: 10 } options = default_options.merge(options) limit = [options[:limit], 1].max paging_window = limit * 2 updates_hash = {} offset = 0 until updates_hash.count >= limit changes = recent_changes(options[:path], paging_window, offset) break if changes.nil? # we ran out of commits first group_changes_into_updates(changes, updates_hash) offset += paging_window end return updates_hash.values.take(limit) end
ruby
def recent_updates(options) default_options = { path: nil, limit: 10 } options = default_options.merge(options) limit = [options[:limit], 1].max paging_window = limit * 2 updates_hash = {} offset = 0 until updates_hash.count >= limit changes = recent_changes(options[:path], paging_window, offset) break if changes.nil? # we ran out of commits first group_changes_into_updates(changes, updates_hash) offset += paging_window end return updates_hash.values.take(limit) end
[ "def", "recent_updates", "(", "options", ")", "default_options", "=", "{", "path", ":", "nil", ",", "limit", ":", "10", "}", "options", "=", "default_options", ".", "merge", "(", "options", ")", "limit", "=", "[", "options", "[", ":limit", "]", ",", "1", "]", ".", "max", "paging_window", "=", "limit", "*", "2", "updates_hash", "=", "{", "}", "offset", "=", "0", "until", "updates_hash", ".", "count", ">=", "limit", "changes", "=", "recent_changes", "(", "options", "[", ":path", "]", ",", "paging_window", ",", "offset", ")", "break", "if", "changes", ".", "nil?", "# we ran out of commits first", "group_changes_into_updates", "(", "changes", ",", "updates_hash", ")", "offset", "+=", "paging_window", "end", "return", "updates_hash", ".", "values", ".", "take", "(", "limit", ")", "end" ]
one entry for each file
[ "one", "entry", "for", "each", "file" ]
234aafbd26ffaf57092cfe6a4cf834c9a18590e0
https://github.com/TheArtificial/rails-wiki/blob/234aafbd26ffaf57092cfe6a4cf834c9a18590e0/app/models/wiki/wiki.rb#L60-L78
24,922
bogdanRada/celluloid_pubsub
lib/celluloid_pubsub/client.rb
CelluloidPubsub.Client.supervise_actors
def supervise_actors current_actor = Actor.current @actor.link current_actor if @actor.respond_to?(:link) current_actor.link connection end
ruby
def supervise_actors current_actor = Actor.current @actor.link current_actor if @actor.respond_to?(:link) current_actor.link connection end
[ "def", "supervise_actors", "current_actor", "=", "Actor", ".", "current", "@actor", ".", "link", "current_actor", "if", "@actor", ".", "respond_to?", "(", ":link", ")", "current_actor", ".", "link", "connection", "end" ]
the method will link the current actor to the actor that is attached to, and the connection to the current actor @return [void] @api public
[ "the", "method", "will", "link", "the", "current", "actor", "to", "the", "actor", "that", "is", "attached", "to", "and", "the", "connection", "to", "the", "current", "actor" ]
e5558257c04e553b49e08ce27c130d572ada210d
https://github.com/bogdanRada/celluloid_pubsub/blob/e5558257c04e553b49e08ce27c130d572ada210d/lib/celluloid_pubsub/client.rb#L70-L74
24,923
bogdanRada/celluloid_pubsub
lib/celluloid_pubsub/client.rb
CelluloidPubsub.Client.on_message
def on_message(data) message = JSON.parse(data) log_debug("#{@actor.class} received JSON #{message}") if @actor.respond_to?(:async) @actor.async.on_message(message) else @actor.on_message(message) end end
ruby
def on_message(data) message = JSON.parse(data) log_debug("#{@actor.class} received JSON #{message}") if @actor.respond_to?(:async) @actor.async.on_message(message) else @actor.on_message(message) end end
[ "def", "on_message", "(", "data", ")", "message", "=", "JSON", ".", "parse", "(", "data", ")", "log_debug", "(", "\"#{@actor.class} received JSON #{message}\"", ")", "if", "@actor", ".", "respond_to?", "(", ":async", ")", "@actor", ".", "async", ".", "on_message", "(", "message", ")", "else", "@actor", ".", "on_message", "(", "message", ")", "end", "end" ]
callback executes when actor receives a message from a subscribed channel and parses the message using JSON.parse and dispatches the parsed message to the original actor that made the connection @param [JSON] data @return [void] @api public
[ "callback", "executes", "when", "actor", "receives", "a", "message", "from", "a", "subscribed", "channel", "and", "parses", "the", "message", "using", "JSON", ".", "parse", "and", "dispatches", "the", "parsed", "message", "to", "the", "original", "actor", "that", "made", "the", "connection" ]
e5558257c04e553b49e08ce27c130d572ada210d
https://github.com/bogdanRada/celluloid_pubsub/blob/e5558257c04e553b49e08ce27c130d572ada210d/lib/celluloid_pubsub/client.rb#L211-L219
24,924
bogdanRada/celluloid_pubsub
lib/celluloid_pubsub/client.rb
CelluloidPubsub.Client.on_close
def on_close(code, reason) connection.terminate terminate log_debug("#{@actor.class} dispatching on close #{code} #{reason}") if @actor.respond_to?(:async) @actor.async.on_close(code, reason) else @actor.on_close(code, reason) end end
ruby
def on_close(code, reason) connection.terminate terminate log_debug("#{@actor.class} dispatching on close #{code} #{reason}") if @actor.respond_to?(:async) @actor.async.on_close(code, reason) else @actor.on_close(code, reason) end end
[ "def", "on_close", "(", "code", ",", "reason", ")", "connection", ".", "terminate", "terminate", "log_debug", "(", "\"#{@actor.class} dispatching on close #{code} #{reason}\"", ")", "if", "@actor", ".", "respond_to?", "(", ":async", ")", "@actor", ".", "async", ".", "on_close", "(", "code", ",", "reason", ")", "else", "@actor", ".", "on_close", "(", "code", ",", "reason", ")", "end", "end" ]
callback executes when connection closes @param [String] code @param [String] reason @return [void] @api public
[ "callback", "executes", "when", "connection", "closes" ]
e5558257c04e553b49e08ce27c130d572ada210d
https://github.com/bogdanRada/celluloid_pubsub/blob/e5558257c04e553b49e08ce27c130d572ada210d/lib/celluloid_pubsub/client.rb#L230-L239
24,925
bogdanRada/celluloid_pubsub
lib/celluloid_pubsub/client.rb
CelluloidPubsub.Client.send_action
def send_action(action, channel = nil, data = {}) data = data.is_a?(Hash) ? data : {} publishing_data = { 'client_action' => action, 'channel' => channel, 'data' => data }.reject { |_key, value| value.blank? } async.chat(publishing_data) end
ruby
def send_action(action, channel = nil, data = {}) data = data.is_a?(Hash) ? data : {} publishing_data = { 'client_action' => action, 'channel' => channel, 'data' => data }.reject { |_key, value| value.blank? } async.chat(publishing_data) end
[ "def", "send_action", "(", "action", ",", "channel", "=", "nil", ",", "data", "=", "{", "}", ")", "data", "=", "data", ".", "is_a?", "(", "Hash", ")", "?", "data", ":", "{", "}", "publishing_data", "=", "{", "'client_action'", "=>", "action", ",", "'channel'", "=>", "channel", ",", "'data'", "=>", "data", "}", ".", "reject", "{", "|", "_key", ",", "value", "|", "value", ".", "blank?", "}", "async", ".", "chat", "(", "publishing_data", ")", "end" ]
method used to send an action to the webserver reactor , to a chanel and with data @param [String] action @param [String] channel @param [Hash] data @return [void] @api private
[ "method", "used", "to", "send", "an", "action", "to", "the", "webserver", "reactor", "to", "a", "chanel", "and", "with", "data" ]
e5558257c04e553b49e08ce27c130d572ada210d
https://github.com/bogdanRada/celluloid_pubsub/blob/e5558257c04e553b49e08ce27c130d572ada210d/lib/celluloid_pubsub/client.rb#L252-L256
24,926
bogdanRada/celluloid_pubsub
lib/celluloid_pubsub/client.rb
CelluloidPubsub.Client.chat
def chat(message) final_message = message.is_a?(Hash) ? message.to_json : JSON.dump(action: 'message', message: message) log_debug("#{@actor.class} sends JSON #{final_message}") connection.text final_message end
ruby
def chat(message) final_message = message.is_a?(Hash) ? message.to_json : JSON.dump(action: 'message', message: message) log_debug("#{@actor.class} sends JSON #{final_message}") connection.text final_message end
[ "def", "chat", "(", "message", ")", "final_message", "=", "message", ".", "is_a?", "(", "Hash", ")", "?", "message", ".", "to_json", ":", "JSON", ".", "dump", "(", "action", ":", "'message'", ",", "message", ":", "message", ")", "log_debug", "(", "\"#{@actor.class} sends JSON #{final_message}\"", ")", "connection", ".", "text", "final_message", "end" ]
method used to send messages to the webserver checks too see if the message is a hash and if it is it will transform it to JSON and send it to the webser otherwise will construct a JSON object that will have the key action with the value 'message" and the key message witth the parameter's value @param [Hash] message @return [void] @api private
[ "method", "used", "to", "send", "messages", "to", "the", "webserver", "checks", "too", "see", "if", "the", "message", "is", "a", "hash", "and", "if", "it", "is", "it", "will", "transform", "it", "to", "JSON", "and", "send", "it", "to", "the", "webser", "otherwise", "will", "construct", "a", "JSON", "object", "that", "will", "have", "the", "key", "action", "with", "the", "value", "message", "and", "the", "key", "message", "witth", "the", "parameter", "s", "value" ]
e5558257c04e553b49e08ce27c130d572ada210d
https://github.com/bogdanRada/celluloid_pubsub/blob/e5558257c04e553b49e08ce27c130d572ada210d/lib/celluloid_pubsub/client.rb#L267-L271