_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3
values | text stringlengths 66 10.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q24600 | Rscons.Environment.wait_for_threaded_commands | train | def wait_for_threaded_commands(options = {})
options[:which] ||= @threaded_commands
threads = options[:which].map(&:thread)
if finished_thread = find_finished_thread(threads, options[:nonblock])
threaded_command = @threaded_commands.find do |tc|
tc.thread == finished_thread
e... | ruby | {
"resource": ""
} |
q24601 | Rscons.Environment.find_finished_thread | train | def find_finished_thread(threads, nonblock)
if nonblock
threads.find do |thread|
!thread.alive?
end
else
if threads.empty?
raise "No threads to wait for"
end
ThreadsWait.new(*threads).next_wait
end
end | ruby | {
"resource": ""
} |
q24602 | Rscons.Environment.find_builder_for | train | def find_builder_for(target, source, features)
@builders.values.find do |builder|
features_met?(builder, features) and builder.produces?(target, source, self)
end
end | ruby | {
"resource": ""
} |
q24603 | Rscons.Environment.features_met? | train | def features_met?(builder, features)
builder_features = builder.features
features.all? do |feature|
want_feature = true
if feature =~ /^-(.*)$/
want_feature = false
feature = $1
end
builder_has_feature = builder_features.include?(feature)
want_feat... | ruby | {
"resource": ""
} |
q24604 | BeakerAnswers.Answers.answer_for | train | def answer_for(options, q, default = nil)
case @format
when :bash
answer = DEFAULT_ANSWERS[q]
answers = options[:answers]
when :hiera
answer = DEFAULT_HIERA_ANSWERS[q]
answers = flatten_keys_to_joined_string(options[:answers]) if options[:answers]
else
rai... | ruby | {
"resource": ""
} |
q24605 | ChefWorkflow.KnifeSupport.build_knife_config | train | def build_knife_config
FileUtils.mkdir_p(chef_config_path)
File.binwrite(knife_config_path, ERB.new(knife_config_template).result(binding))
end | ruby | {
"resource": ""
} |
q24606 | Itrp.Attachments.upload_attachment | train | def upload_attachment(storage, attachment, raise_exceptions)
begin
# attachment is already a file or we need to open the file from disk
unless attachment.respond_to?(:path) && attachment.respond_to?(:read)
raise "file does not exist: #{attachment}" unless File.exists?(attachment)
... | ruby | {
"resource": ""
} |
q24607 | Itrp.Attachments.itrp_upload | train | def itrp_upload(itrp, key_template, key, attachment)
uri = itrp[:upload_uri] =~ /\/v1/ ? itrp[:upload_uri] : itrp[:upload_uri].gsub('/attachments', '/v1/attachments')
response = send_file(uri, {file: attachment, key: key_template}, @client.send(:expand_header))
raise "ITRP upload to #{itrp[:upload_uri... | ruby | {
"resource": ""
} |
q24608 | SanitizeAttributes.Macros.sanitize_attributes | train | def sanitize_attributes(*args, &block)
if (args.last && args.last.is_a?(Hash))
options = args.pop
end
options ||= {}
unless @sanitize_hook_already_defined
include InstanceMethods
extend ClassMethods
if options[:before_validation]
before_validation :sani... | ruby | {
"resource": ""
} |
q24609 | Atomy.EvalLocalState.search_local | train | def search_local(name)
if variable = variables[name]
return variable.nested_reference
end
if variable = search_scopes(name)
variables[name] = variable
return variable.nested_reference
end
end | ruby | {
"resource": ""
} |
q24610 | StripeInvoice.InvoicesHelper.format_currency | train | def format_currency(amount, currency)
currency = currency.upcase()
# assuming that all currencies are split into 100 parts is probably wrong
# on an i18n scale but it works for USD, EUR and LBP
# TODO fix this maybe?
amount = amount / 100.0
options = {
# use comma for ... | ruby | {
"resource": ""
} |
q24611 | RETerm.ColorPair.format | train | def format(win)
win.win.attron(nc)
yield
win.win.attroff(nc)
end | ruby | {
"resource": ""
} |
q24612 | ChefWorkflow.Scheduler.schedule_provision | train | def schedule_provision(group_name, provisioner, dependencies=[])
return nil if vm_groups[group_name]
provisioner = [provisioner] unless provisioner.kind_of?(Array)
provisioner.each { |x| x.name = group_name }
vm_groups[group_name] = provisioner
unless dependencies.all? { |x| vm_groups.has... | ruby | {
"resource": ""
} |
q24613 | ChefWorkflow.Scheduler.wait_for | train | def wait_for(*dependencies)
return nil if @serial
return nil if dependencies.empty?
dep_set = dependencies.to_set
until dep_set & solved == dep_set
sleep 1
@solver_thread.join unless @solver_thread.alive?
end
end | ruby | {
"resource": ""
} |
q24614 | ChefWorkflow.Scheduler.with_timeout | train | def with_timeout(do_loop=true)
Timeout.timeout(10) do
dead_working = @working.values.reject(&:alive?)
if dead_working.size > 0
dead_working.map(&:join)
end
yield
end
rescue TimeoutError
retry if do_loop
end | ruby | {
"resource": ""
} |
q24615 | ChefWorkflow.Scheduler.service_resolved_waiters | train | def service_resolved_waiters
@waiters_mutex.synchronize do
@waiters.replace(@waiters.to_set - (@working.keys.to_set + solved))
end
waiter_iteration = lambda do
@waiters.each do |group_name|
if (solved.to_set & vm_dependencies[group_name]).to_a == vm_dependencies[group_name]
... | ruby | {
"resource": ""
} |
q24616 | RETerm.Layout.layout_containing | train | def layout_containing(component)
return self if children.include?(component)
found = nil
children.each { |c|
next if found
if c.kind_of?(Layout)
found = c unless c.layout_containing(component).nil?
end
}
found
end | ruby | {
"resource": ""
} |
q24617 | RETerm.Layout.contains? | train | def contains?(child)
children.any? { |c|
(c.kind_of?(Layout) && c.contains?(child)) || c == child
}
end | ruby | {
"resource": ""
} |
q24618 | RETerm.Layout.add_child | train | def add_child(h={})
c = nil
if h.key?(:component)
c = h[:component]
h = {:rows => c.requested_rows + c.extra_padding,
:cols => c.requested_cols + c.extra_padding}.merge(h)
end
raise ArgumentError, "must specify x/y" unless h.key?(:x) &&
... | ruby | {
"resource": ""
} |
q24619 | Lazily.Enumerable.select | train | def select(&predicate)
filter("select") do |yielder|
each do |element|
yielder.call(element) if yield(element)
end
end
end | ruby | {
"resource": ""
} |
q24620 | Lazily.Enumerable.uniq | train | def uniq
filter("uniq") do |yielder|
seen = Set.new
each do |element|
key = if block_given?
yield element
else
element
end
yielder.call(element) if seen.add?(key)
end
end
end | ruby | {
"resource": ""
} |
q24621 | Lazily.Enumerable.take | train | def take(n)
filter("take") do |yielder, all_done|
if n > 0
each_with_index do |element, index|
yielder.call(element)
throw all_done if index + 1 == n
end
end
end
end | ruby | {
"resource": ""
} |
q24622 | Lazily.Enumerable.take_while | train | def take_while(&predicate)
filter("take_while") do |yielder, all_done|
each do |element|
throw all_done unless yield(element)
yielder.call(element)
end
end
end | ruby | {
"resource": ""
} |
q24623 | Lazily.Enumerable.drop | train | def drop(n)
filter("drop") do |yielder|
each_with_index do |element, index|
next if index < n
yielder.call(element)
end
end
end | ruby | {
"resource": ""
} |
q24624 | Lazily.Enumerable.drop_while | train | def drop_while(&predicate)
filter("drop_while") do |yielder|
take = false
each do |element|
take ||= !yield(element)
yielder.call(element) if take
end
end
end | ruby | {
"resource": ""
} |
q24625 | Lazily.Enumerable.grep | train | def grep(pattern)
filter("grep") do |yielder|
each do |element|
if pattern === element
result = if block_given?
yield element
else
element
end
yielder.call(result)
end
end
end
end | ruby | {
"resource": ""
} |
q24626 | Lazily.Enumerable.flatten | train | def flatten(level = 1)
filter("flatten") do |yielder|
each do |element|
if level > 0 && element.respond_to?(:each)
element.flatten(level - 1).each(&yielder)
else
yielder.call(element)
end
end
end
end | ruby | {
"resource": ""
} |
q24627 | Lazily.Enumerable.compact | train | def compact
filter("compact") do |yielder|
each do |element|
yielder.call(element) unless element.nil?
end
end
end | ruby | {
"resource": ""
} |
q24628 | RETerm.NavInput.handle_input | train | def handle_input(from_parent=false)
@focus ||= 0
# focus on first component
ch = handle_focused unless nav_select
# Repeat until quit
until quit_nav?(ch)
# Navigate to the specified component (nav_select)
if self.nav_select
# it is a descendent of this one
... | ruby | {
"resource": ""
} |
q24629 | RETerm.NavInput.handle_focused | train | def handle_focused
ch = nil
focused.dispatch :focused
update_focus
if focused.activate_focus?
focused.activate!
elsif focused.kind_of?(Layout)
ch = focused.handle_input(true)
elsif !deactivate? && !nav_select
ch = sync_getch
end
if self.ch_sel... | ruby | {
"resource": ""
} |
q24630 | RETerm.NavInput.nav_to_selected | train | def nav_to_selected
# clear nav_select
ns = self.nav_select
self.nav_select = nil
# specified component is a direct child
if self.children.include?(ns)
remove_focus
@focus = focusable.index(ns)
#handle_focused
#update_focus
#focused.activate!
... | ruby | {
"resource": ""
} |
q24631 | Interface.Helpers.must_implement | train | def must_implement(*args)
parsed_args(args).each do |method, arity|
raise_interface_error(method, arity) unless valid_method?(method, arity)
end
end | ruby | {
"resource": ""
} |
q24632 | Interface.Helpers.parsed_args | train | def parsed_args(args)
args.inject({}) do |memo, method|
memo.merge(method.is_a?(Hash) ? method : { method => nil })
end
end | ruby | {
"resource": ""
} |
q24633 | Apilayer.ConnectionHelper.get_request | train | def get_request(slug, params={})
# calls connection method on the extended module
connection.get do |req|
req.url "api/#{slug}"
params.each_pair do |k,v|
req.params[k] = v
end
end
end | ruby | {
"resource": ""
} |
q24634 | Infosimples::Data.Client.download_sites_urls | train | def download_sites_urls(response)
return [] if !response.is_a?(Hash) ||
(sites_urls = response.dig('receipt', 'sites_urls')).nil?
sites_urls.map do |url|
Infosimples::Data::HTTP.request(url: url, http_timeout: 30)
end
end | ruby | {
"resource": ""
} |
q24635 | Infosimples::Data.Client.request | train | def request(service, method = :get, payload = {})
res = Infosimples::Data::HTTP.request(
url: BASE_URL.gsub(':service', service),
http_timeout: timeout,
method: method,
payload: payload.merge(
token: token,
timeout: timeout,
max_age: max_age,
... | ruby | {
"resource": ""
} |
q24636 | StripeInvoice.Charge.source_country | train | def source_country
# source can only be accessed via Customer
cus = Stripe::Customer.retrieve self.indifferent_json[:customer]
# TODO this is wrong, because there might be multiple sources and I
# just randomly select the first one - also some source types might NOT even
# have a country ... | ruby | {
"resource": ""
} |
q24637 | BabelBridge.Shell.start | train | def start(options={},&block)
@stdout = options[:stdout] || $stdout
@stderr = options[:stdout] || @stdout
@stdin = options[:stdin] || $stdin
while line = @stdin == $stdin ? Readline.readline("> ", true) : @stdin.gets
line.strip!
next if line.length==0
parse_tree_node = parser.pars... | ruby | {
"resource": ""
} |
q24638 | Negroku::Modes.Env.set_vars_to_stage | train | def set_vars_to_stage(stage, variables)
# convert to array using VAR=value
vars_array = variables.map{|k,v| "#{k}=#{v}" }
Capistrano::Application.invoke(stage)
Capistrano::Application.invoke("rbenv:vars:set", *vars_array)
end | ruby | {
"resource": ""
} |
q24639 | Negroku::Modes.Env.get_variables | train | def get_variables
return unless File.exists?(ENV_FILE)
File.open(ENV_FILE).each do |line|
var_name = line.split("=").first
yield var_name unless line =~ /^\#/
end
end | ruby | {
"resource": ""
} |
q24640 | Negroku::Modes.Env.select_variables | train | def select_variables
selection = {}
puts I18n.t(:ask_variables_message, scope: :negroku)
get_variables do |var_name|
selection[var_name] = Ask.input(var_name)
end
selection.reject {|key, value| value.empty? }
end | ruby | {
"resource": ""
} |
q24641 | Rscons.VarSet.[] | train | def [](key)
if @my_vars.include?(key)
@my_vars[key]
else
@coa_vars.each do |coa_vars|
if coa_vars.include?(key)
@my_vars[key] = deep_dup(coa_vars[key])
return @my_vars[key]
end
end
nil
end
end | ruby | {
"resource": ""
} |
q24642 | Rscons.VarSet.include? | train | def include?(key)
if @my_vars.include?(key)
true
else
@coa_vars.find do |coa_vars|
coa_vars.include?(key)
end
end
end | ruby | {
"resource": ""
} |
q24643 | Rscons.VarSet.append | train | def append(values)
coa!
if values.is_a?(VarSet)
values.send(:coa!)
@coa_vars = values.instance_variable_get(:@coa_vars) + @coa_vars
else
@my_vars = deep_dup(values)
end
self
end | ruby | {
"resource": ""
} |
q24644 | Rscons.VarSet.merge | train | def merge(other = {})
coa!
varset = self.class.new
varset.instance_variable_set(:@coa_vars, @coa_vars.dup)
varset.append(other)
end | ruby | {
"resource": ""
} |
q24645 | Rscons.VarSet.to_h | train | def to_h
result = deep_dup(@my_vars)
@coa_vars.reduce(result) do |result, coa_vars|
coa_vars.each_pair do |key, value|
unless result.include?(key)
result[key] = deep_dup(value)
end
end
result
end
end | ruby | {
"resource": ""
} |
q24646 | Rscons.VarSet.deep_dup | train | def deep_dup(obj)
obj_class = obj.class
if obj_class == Hash
obj.reduce({}) do |result, (k, v)|
result[k] = deep_dup(v)
result
end
elsif obj_class == Array
obj.map { |v| deep_dup(v) }
elsif obj_class == String
obj.dup
else
obj
... | ruby | {
"resource": ""
} |
q24647 | Itrp.Client.import | train | def import(csv, type, block_until_completed = false)
csv = File.open(csv, 'rb') unless csv.respond_to?(:path) && csv.respond_to?(:read)
data, headers = Itrp::Multipart::Post.prepare_query(type: type, file: csv)
request = Net::HTTP::Post.new(expand_path('/import'), expand_header(headers))
request... | ruby | {
"resource": ""
} |
q24648 | Itrp.Client.export | train | def export(types, from = nil, block_until_completed = false, locale = nil)
data = {type: [types].flatten.join(',')}
data[:from] = from unless from.blank?
data[:locale] = locale unless locale.blank?
response = post('/export', data)
if response.valid?
if response.raw.code.to_s == '20... | ruby | {
"resource": ""
} |
q24649 | Itrp.Client.expand_header | train | def expand_header(header = {})
header = DEFAULT_HEADER.merge(header)
header['X-ITRP-Account'] = option(:account) if option(:account)
header['AUTHORIZATION'] = 'Basic ' + ["#{option(:api_token)}:x"].pack('m*').gsub(/\s/, '')
if option(:source)
header['X-ITRP-Source'] = option(:source)
... | ruby | {
"resource": ""
} |
q24650 | Itrp.Client.typecast | train | def typecast(value, escape = true)
case value.class.name.to_sym
when :NilClass then ''
when :String then escape ? uri_escape(value) : value
when :TrueClass then 'true'
when :FalseClass then 'false'
when :DateTime then datetime = value.new_offset(0).iso8601; es... | ruby | {
"resource": ""
} |
q24651 | RETerm.CDKComponent.component | train | def component
enable_cdk!
@component ||= begin
c = _component
c.setBackgroundColor("</#{@colors.id}>") if colored?
c.timeout(SYNC_TIMEOUT) if sync_enabled? # XXX
c.title_attrib = @title_attrib if @title_attrib
c
end
end | ruby | {
"resource": ""
} |
q24652 | RETerm.CDKComponent.activate! | train | def activate!(*input)
dispatch :activated
component.resetExitType
r = nil
while [:EARLY_EXIT, :NEVER_ACTIVATED, :TIMEOUT].include?(component.exit_type) &&
!shutdown?
r = component.activate(input)
run_sync! if sync_enabled?
end
dispatch :deactivated
... | ruby | {
"resource": ""
} |
q24653 | RETerm.CDKComponent.bind_key | train | def bind_key(key, kcb=nil, &bl)
kcb = bl if kcb.nil? && !bl.nil?
cb = lambda do |cdktype, widget, component, key|
kcb.call component, key
end
component.bind(:ENTRY, key, cb, self)
end | ruby | {
"resource": ""
} |
q24654 | Negroku::Modes.App.ask_name | train | def ask_name
question = I18n.t :application_name, scope: :negroku
Ask.input question, default: File.basename(Dir.getwd)
end | ruby | {
"resource": ""
} |
q24655 | Negroku::Modes.App.select_repo | train | def select_repo
remote_urls = %x(git remote -v 2> /dev/null | awk '{print $2}' | uniq).split("\n")
remote_urls << (I18n.t :other, scope: :negroku)
question = I18n.t :choose_repo_url, scope: :negroku
selected_idx = Ask.list question, remote_urls
if selected_idx == remote_urls.length - 1
... | ruby | {
"resource": ""
} |
q24656 | BabelBridge.RuleVariant.pattern_elements | train | def pattern_elements
@pattern_elements||=pattern.collect { |match| [PatternElement.new(match, :rule_variant => self, :pattern_element => true), delimiter_pattern] }.flatten[0..-2]
end | ruby | {
"resource": ""
} |
q24657 | BabelBridge.RuleVariant.parse | train | def parse(parent_node)
#return parse_nongreedy_optional(src,offset,parent_node) # nongreedy optionals break standard PEG
node = variant_node_class.new(parent_node, delimiter_pattern)
node.match parser.delimiter_pattern if root_rule?
pattern_elements.each do |pe|
return unless node.match(pe)
... | ruby | {
"resource": ""
} |
q24658 | Rscons.Cache.write | train | def write
@cache["version"] = VERSION
File.open(CACHE_FILE, "w") do |fh|
fh.puts(JSON.dump(@cache))
end
end | ruby | {
"resource": ""
} |
q24659 | Rscons.Cache.mkdir_p | train | def mkdir_p(path)
parts = path.split(/[\\\/]/)
parts.each_index do |i|
next if parts[i] == ""
subpath = File.join(*parts[0, i + 1])
unless File.exists?(subpath)
FileUtils.mkdir_p(subpath)
@cache["directories"][subpath] = true
end
end
end | ruby | {
"resource": ""
} |
q24660 | Rscons.Cache.calculate_checksum | train | def calculate_checksum(file)
@lookup_checksums[file] = Digest::MD5.hexdigest(File.read(file, mode: "rb")) rescue ""
end | ruby | {
"resource": ""
} |
q24661 | Chozo::Mixin.FromFile.from_file | train | def from_file(filename)
filename = filename.to_s
if File.exists?(filename) && File.readable?(filename)
self.instance_eval(IO.read(filename), filename, 1)
self
else
raise IOError, "Could not open or read: '#{filename}'"
end
end | ruby | {
"resource": ""
} |
q24662 | Chozo::Mixin.FromFile.class_from_file | train | def class_from_file(filename)
filename = filename.to_s
if File.exists?(filename) && File.readable?(filename)
self.class_eval(IO.read(filename), filename, 1)
self
else
raise IOError, "Could not open or read: '#{filename}'"
end
end | ruby | {
"resource": ""
} |
q24663 | BabelBridge.PatternElement.parse | train | def parse(parent_node)
# run element parser
begin
parent_node.parser.matching_negative if negative
match = parser.call(parent_node)
ensure
parent_node.parser.unmatching_negative if negative
end
# Negative patterns (PEG: !element)
match = match ? nil : EmptyNode.new(parent_nod... | ruby | {
"resource": ""
} |
q24664 | BabelBridge.PatternElement.init_rule | train | def init_rule(rule_name)
rule_name.to_s[/^([^?!]*)([?!])?$/]
rule_name = $1.to_sym
option = $2
match_rule = rules[rule_name]
raise "no rule for #{rule_name}" unless match_rule
self.parser = lambda {|parent_node| match_rule.parse(parent_node)}
self.name ||= rule_name
case option
when... | ruby | {
"resource": ""
} |
q24665 | BabelBridge.PatternElement.init_hash | train | def init_hash(hash)
if hash[:parser]
self.parser=hash[:parser]
elsif hash[:many]
init_many hash
elsif hash[:match]
init hash[:match]
elsif hash[:any]
init_any hash[:any]
else
raise "extended-options patterns (specified by a hash) must have either :parser=> or a :match=>... | ruby | {
"resource": ""
} |
q24666 | GoogleSpeech.ChunkFactory.each | train | def each
pos = 0
while(pos < @original_duration) do
chunk = nil
begin
chunk = Chunk.new(@original_file, @original_duration, pos, (@chunk_duration + @overlap), @rate)
yield chunk
pos = pos + [chunk.duration, @chunk_duration].min
ensure
chunk.clo... | ruby | {
"resource": ""
} |
q24667 | ChefWorkflow.SSHHelper.ssh_role_command | train | def ssh_role_command(role, command)
t = []
ChefWorkflow::IPSupport.get_role_ips(role).each do |ip|
t.push(
Thread.new do
ssh_command(ip, command)
end
)
end
t.each(&:join)
end | ruby | {
"resource": ""
} |
q24668 | ChefWorkflow.SSHHelper.ssh_command | train | def ssh_command(ip, command)
configure_ssh_command(ip, command) do |ch, success|
return 1 unless success
if_debug(2) do
ch.on_data do |ch, data|
$stderr.puts data
end
end
ch.on_request("exit-status") do |ch, data|
return data.read_long
... | ruby | {
"resource": ""
} |
q24669 | ChefWorkflow.SSHHelper.ssh_capture | train | def ssh_capture(ip, command)
retval = ""
configure_ssh_command(ip, command) do |ch, success|
return "" unless success
ch.on_data do |ch, data|
retval << data
end
ch.on_request("exit-status") do |ch, data|
return retval
end
end
return... | ruby | {
"resource": ""
} |
q24670 | ChefWorkflow.EC2Support.create_security_group | train | def create_security_group
aws_ec2 = ec2_obj
name = nil
loop do
name = 'chef-workflow-' + (0..rand(10).to_i).map { rand(0..9).to_s }.join("")
if_debug(3) do
$stderr.puts "Seeing if security group name #{name} is taken"
end
break unless aws_ec2.security_grou... | ruby | {
"resource": ""
} |
q24671 | ChefWorkflow.EC2Support.assert_security_groups | train | def assert_security_groups
aws_ec2 = ec2_obj
if security_groups == :auto
loaded_groups = load_security_group
# this will make it hit the second block everytime from now on (and
# bootstrap it recursively)
if loaded_groups
self.security_groups loaded_groups
... | ruby | {
"resource": ""
} |
q24672 | Itrp.Response.json | train | def json
return @json if defined?(@json)
# no content, no JSON
if @response.code.to_s == '204'
data = {}
elsif @response.body.blank?
# no body, no json
data = {message: @response.message.blank? ? 'empty body' : @response.message.strip}
end
begin
data |... | ruby | {
"resource": ""
} |
q24673 | Itrp.Response.[] | train | def[](*keys)
values = json.is_a?(Array) ? json : [json]
keys.each { |key| values = values.map{ |value| value.is_a?(Hash) ? value[key] : nil} }
json.is_a?(Array) ? values : values.first
end | ruby | {
"resource": ""
} |
q24674 | Mockingbird.Script.on_connection | train | def on_connection(selector=nil,&block)
if selector.nil? || selector == '*'
instance_eval(&block)
else
@current_connection = ConnectionScript.new
instance_eval(&block)
@connections << [selector,@current_connection]
@current_connection = nil
end
end | ruby | {
"resource": ""
} |
q24675 | Mockingbird.Script.add_command | train | def add_command(command=nil,&block)
command = Commands::Command.new(&block) if block_given?
current_connection.add_command(command)
end | ruby | {
"resource": ""
} |
q24676 | ActiveCucumber.ActiveRecordBuilder.create_record | train | def create_record attributes
creator = @creator_class.new attributes, @context
FactoryGirl.create @clazz.name.underscore.to_sym, creator.factorygirl_attributes
end | ruby | {
"resource": ""
} |
q24677 | Rscons.JobSet.get_next_job_to_run | train | def get_next_job_to_run(targets_still_building)
targets_not_built_yet = targets_still_building + @jobs.keys
side_effects = targets_not_built_yet.map do |target|
@side_effects[target] || []
end.flatten
targets_not_built_yet += side_effects
@jobs.keys.each do |target|
skip =... | ruby | {
"resource": ""
} |
q24678 | Negroku::Modes.Stage.ask_stage | train | def ask_stage
question = I18n.t :ask_stage_name, scope: :negroku
stage_name = Ask.input question
raise "Stage name required" if stage_name.empty?
stage_name
end | ruby | {
"resource": ""
} |
q24679 | ChefWorkflow.DebugSupport.if_debug | train | def if_debug(minimum=1, else_block=nil)
$CHEF_WORKFLOW_DEBUG ||=
ENV.has_key?("CHEF_WORKFLOW_DEBUG") ?
ENV["CHEF_WORKFLOW_DEBUG"].to_i :
CHEF_WORKFLOW_DEBUG_DEFAULT
if $CHEF_WORKFLOW_DEBUG >= minimum
yield if block_given?
elsif else_block
else_block.call... | ruby | {
"resource": ""
} |
q24680 | ZMachine.TcpMsgChannel.read_inbound_data | train | def read_inbound_data
ZMachine.logger.debug("zmachine:tcp_msg_channel:#{__method__}", channel: self) if ZMachine.debug
raise IOException.new("EOF") if @socket.read(@buffer) == -1
pos = @buffer.position
@buffer.flip
# validate magic
if @buffer.remaining >= 4
bytes = java.uti... | ruby | {
"resource": ""
} |
q24681 | Rxhp.AttributeValidator.validate_attributes! | train | def validate_attributes!
# Check for required attributes
self.class.required_attributes.each do |matcher|
matched = self.attributes.any? do |key, value|
key = key.to_s
Rxhp::AttributeValidator.match? matcher, key, value
end
if !matched
raise MissingRequi... | ruby | {
"resource": ""
} |
q24682 | Rxhp.HtmlElement.render | train | def render options = {}
validate!
options = fill_options(options)
open = render_open_tag(options)
inner = render_children(options)
close = render_close_tag(options)
if options[:pretty]
indent = ' ' * (options[:indent] * options[:depth])
out = indent.dup
out ... | ruby | {
"resource": ""
} |
q24683 | Rxhp.HtmlElement.render_string | train | def render_string string, options
escaped = html_escape(string)
if options[:pretty]
indent = ' ' * (options[:indent] * options[:depth])
indent + escaped + "\n"
else
escaped
end
end | ruby | {
"resource": ""
} |
q24684 | Rxhp.HtmlElement.render_open_tag | train | def render_open_tag options
out = '<' + tag_name
unless attributes.empty?
attributes.each do |name,value|
name = name.to_s.gsub('_', '-') if name.is_a? Symbol
value = value.to_s.gsub('_', '-') if value.is_a? Symbol
case value
when false
next
... | ruby | {
"resource": ""
} |
q24685 | Rxhp.Element.render_children | train | def render_children options = {}
return if children.empty?
flattened_children.map{ |child| render_child(child, options) }.join
end | ruby | {
"resource": ""
} |
q24686 | Rxhp.Element.fill_options | train | def fill_options options
{
:pretty => true,
:format => Rxhp::HTML_FORMAT,
:skip_doctype => false,
:doctype => Rxhp::HTML_5,
:depth => 0,
:indent => 2,
}.merge(options)
end | ruby | {
"resource": ""
} |
q24687 | Rxhp.Element.flattened_children | train | def flattened_children
no_frags = []
children.each do |node|
if node.is_a? Rxhp::Fragment
no_frags += node.children
else
no_frags.push node
end
end
previous = nil
no_consecutive_strings = []
no_frags.each do |node|
if node.is_a?(St... | ruby | {
"resource": ""
} |
q24688 | Rxhp.ComposableElement.render | train | def render options = {}
validate!
self.compose do
# Allow 'yield' to embed all children
self.children.each do |child|
fragment child
end
end.render(options)
end | ruby | {
"resource": ""
} |
q24689 | ZMachine.Connection.bind | train | def bind(address, port_or_type, &block)
ZMachine.logger.debug("zmachine:connection:#{__method__}", connection: self) if ZMachine.debug
klass = channel_class(address)
@channel = klass.new
@channel.bind(sanitize_adress(address, klass), port_or_type)
@block = block
@block.call(self) if ... | ruby | {
"resource": ""
} |
q24690 | DataSift.Account.usage | train | def usage(start_time, end_time, period = '')
params = { start: start_time, end: end_time }
params.merge!(period: period) unless period.empty?
DataSift.request(:GET, 'account/usage', @config, params)
end | ruby | {
"resource": ""
} |
q24691 | RWebSpec.WebBrowser.locate_input_element | train | def locate_input_element(how, what, types, value=nil)
@browser.locate_input_element(how, what, types, value)
end | ruby | {
"resource": ""
} |
q24692 | RWebSpec.WebBrowser.click_button_with_caption | train | def click_button_with_caption(caption, opts={})
all_buttons = button_elements
matching_buttons = all_buttons.select{|x| x.attribute('value') == caption}
if matching_buttons.size > 0
if opts && opts[:index]
the_index = opts[:index].to_i() - 1
puts "Call matchin... | ruby | {
"resource": ""
} |
q24693 | RWebSpec.WebBrowser.submit | train | def submit(buttonName = nil)
if (buttonName.nil?) then
buttons.each { |button|
next if button.type != 'submit'
button.click
return
}
else
click_button_with_name(buttonName)
end
end | ruby | {
"resource": ""
} |
q24694 | MediaWiki.Watch.watch_request | train | def watch_request(titles, unwatch = false)
titles = titles.is_a?(Array) ? titles : [titles]
params = {
action: 'watch',
titles: titles.shift(get_limited(titles.length, 50, 500)).join('|'),
token: get_token('watch')
}
success_key = 'watched'
if unwatch
params... | ruby | {
"resource": ""
} |
q24695 | RWebSpec.Core.failsafe | train | def failsafe(& block)
begin
yield
rescue RWebSpec::Assertion => e1
rescue ArgumentError => ae
rescue RSpec::Expectations::ExpectationNotMetError => ree
rescue =>e
end
end | ruby | {
"resource": ""
} |
q24696 | RWebSpec.Core.random_string_in | train | def random_string_in(arr)
return nil if arr.empty?
index = random_number(0, arr.length-1)
arr[index]
end | ruby | {
"resource": ""
} |
q24697 | RWebSpec.Core.interpret_value | train | def interpret_value(value)
case value
when Array then value.rand
when Range then value_in_range(value)
else value
end
end | ruby | {
"resource": ""
} |
q24698 | RWebSpec.Core.process_each_row_in_csv_file | train | def process_each_row_in_csv_file(csv_file, &block)
require 'faster_csv'
connect_to_testwise("CSV_START", csv_file) if $testwise_support
has_error = false
idx = 0
FasterCSV.foreach(csv_file, :headers => :first_row, :encoding => 'u') do |row|
connect_to_testwise("CSV_ON_ROW", idx.to_s) if ... | ruby | {
"resource": ""
} |
q24699 | Crep.CrashController.top_crashes | train | def top_crashes(version, build)
@version = version
@build = build
@crashes = @crash_source.crashes(@top, version, build, @show_only_unresolved)
@total_crashes = @crash_source.crash_count(version: @version, build: @build)
report
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.