_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3
values | text stringlengths 66 10.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q23600 | Moodle2CC::Moodle2Converter.Migrator.convert_question_banks | train | def convert_question_banks(question_categories)
bank_converter = Moodle2CC::Moodle2Converter::QuestionBankConverter.new
question_categories.map { |category| bank_converter.convert(category) }
end | ruby | {
"resource": ""
} |
q23601 | Packer.Client.build | train | def build(template, options = {})
args = ['build', '-machine-readable']
args << '-force' if options.key?(:force)
args << "-except=#{options[:except].join(',')}" if options.key?(:except)
args << "-only=#{options[:only].join(',')}" if options.key?(:only)
args << "-parallel=#{options[:paralle... | ruby | {
"resource": ""
} |
q23602 | Packer.Client.inspect_template | train | def inspect_template(template)
args = ['inspect', '-machine-readable', template]
Packer::Output::Inspect.new(command(args))
end | ruby | {
"resource": ""
} |
q23603 | Packer.Client.push | train | def push(template, options = {})
args = ['push']
args << "-message=#{options[:message]}" if options.key?(:message)
args << "-name=#{options[:name]}" if options.key?(:name)
args << "-token=#{options[:token]}" if options.key?(:token)
args << "-var-file=#{options[:var_file]}" if options.key?(... | ruby | {
"resource": ""
} |
q23604 | Packer.Client.validate | train | def validate(template, options = {})
args = ['validate']
args << '-syntax-only' if options.key?(:syntax_only)
args << "-except=#{options[:except].join(',')}" if options.key?(:except)
args << "-only=#{options[:only].join(',')}" if options.key?(:only)
args << "-var-file=#{options[:var_file]}... | ruby | {
"resource": ""
} |
q23605 | VCAP::Services::Base::SnapshotV2.SnapshotClient.update_name | train | def update_name(service_id, snapshot_id, name)
return unless service_id && snapshot_id && name
verify_input_name(name)
key = self.class.redis_key(service_id)
# NOTE: idealy should watch on combination of (service_id, snapshot_id)
# but current design doesn't support such fine-grained watc... | ruby | {
"resource": ""
} |
q23606 | Calyx.Modifiers.transform | train | def transform(name, value)
if respond_to?(name)
send(name, value)
elsif value.respond_to?(name)
value.send(name)
else
value
end
end | ruby | {
"resource": ""
} |
q23607 | Squirm.Procedure.load | train | def load
query = (arguments or self).info_sql
Squirm.exec(query, [name, schema]) do |result|
validate result
set_values_from result
end
self
end | ruby | {
"resource": ""
} |
q23608 | Squirm.Procedure.call | train | def call(*args, &block)
Squirm.exec query, arguments.format(*args) do |result|
if block_given?
yield result
elsif return_type =~ /\ASETOF/
result.to_a
else
result.getvalue(0,0)
end
end
end | ruby | {
"resource": ""
} |
q23609 | Squirm.Procedure.validate | train | def validate(result)
if result.ntuples == 0
raise NotFound
elsif result.ntuples > 1
raise TooManyChoices
end
end | ruby | {
"resource": ""
} |
q23610 | Interpolate.Points.merge! | train | def merge!(points = {})
# points must be a Hash
raise ArgumentError, "key points must be a Hash object" unless points.is_a? Hash
# ensure the points are all keyed Numeric-ally
points.each do |key, value|
raise ArgumentError, "found a point key that is not a Numeric object: #{key.inspect}... | ruby | {
"resource": ""
} |
q23611 | Interpolate.Points.at | train | def at(point, &block)
# obvious cases first
if @sorted.empty?
# no key points
return nil
elsif @sorted.size == 1
# one key point
return @sorted.first.last
end
# out-of-bounds cases next
if point <= @min_point
# lower than lowest key point
... | ruby | {
"resource": ""
} |
q23612 | Moodle2CC::CanvasCC::Models.QuestionBank.find_children_banks | train | def find_children_banks(all_banks, visited_banks=[])
visited_banks << self
children = []
sub_children = []
all_banks.each do |bank|
children << bank if bank.parent_id && bank.parent_id == self.original_id && !visited_banks.include?(bank)
end
children.each do |child|
s... | ruby | {
"resource": ""
} |
q23613 | Ore.Naming.module_of | train | def module_of(word)
if COMMON_NAMESPACES.has_key?(word)
COMMON_NAMESPACES[word]
elsif COMMON_ABBREVIATIONS.has_key?(word)
COMMON_ABBREVIATIONS[word]
else
word.capitalize
end
end | ruby | {
"resource": ""
} |
q23614 | Ore.Naming.modules_of | train | def modules_of(name)
names_in(name).map do |words|
words.split('_').map { |word| module_of(word) }.join
end
end | ruby | {
"resource": ""
} |
q23615 | JAPR.Pipeline.convert | train | def convert
@assets.each do |asset|
# Convert asset multiple times if more than one converter is found
finished = false
while finished == false
# Find a converter to use
klass = JAPR::Converter.klass(asset.filename)
# Convert asset if converter is found
... | ruby | {
"resource": ""
} |
q23616 | JAPR.Pipeline.bundle | train | def bundle
content = @assets.map(&:content).join("\n")
hash = JAPR::Pipeline.hash(@source, @manifest, @options)
@assets = [JAPR::Asset.new(content, "#{@prefix}-#{hash}#{@type}")]
end | ruby | {
"resource": ""
} |
q23617 | JAPR.Pipeline.write_asset_file | train | def write_asset_file(directory, asset)
FileUtils.mkpath(directory) unless File.directory?(directory)
begin
# Save file to disk
File.open(File.join(directory, asset.filename), 'w') do |file|
file.write(asset.content)
end
rescue StandardError => se
puts "Asset P... | ruby | {
"resource": ""
} |
q23618 | JAPR.Pipeline.markup | train | def markup
# Use display_path if defined, otherwise use output_path in url
display_path = @options['display_path'] || @options['output_path']
@html = @assets.map do |asset|
klass = JAPR::Template.klass(asset.filename)
html = klass.new(display_path, asset.filename).html unless klass.ni... | ruby | {
"resource": ""
} |
q23619 | SeventeenMon.IP.four_number | train | def four_number
@four_number ||= begin
fn = ip.split(".").map(&:to_i)
raise "ip is no valid" if fn.length != 4 || fn.any?{ |d| d < 0 || d > 255}
fn
end
end | ruby | {
"resource": ""
} |
q23620 | Moodle2CC::CC.Assignment.build_meta_fields | train | def build_meta_fields(mod)
fields = {}
%w{mod_type assignment_type}.each do |key|
fields[key] = mod.send(key) if mod.respond_to?(key)
end
if mod.grade_item
Moodle2CC::Moodle::GradeItem::PROPERTIES.each do |key|
fields[key] = mod.grade_item.send(key) if mod.grade_item.re... | ruby | {
"resource": ""
} |
q23621 | Squirm.Core.connect | train | def connect(options = {})
return @pool = options[:pool] if options[:pool]
options = options.dup
timeout = options.delete(:timeout) || 5
pool_size = options.delete(:pool_size) || 1
@pool = Squirm::Pool.new(timeout)
pool_size.times do
conn = PGconn.open(options)
... | ruby | {
"resource": ""
} |
q23622 | Squirm.Core.exec | train | def exec(*args, &block)
if current = Thread.current[:squirm_connection]
current.exec(*args, &block)
else
use {|conn| conn.exec(*args, &block)}
end
end | ruby | {
"resource": ""
} |
q23623 | Squirm.Core.use | train | def use(conn = nil)
conn_given = !!conn
conn = conn_given ? conn : @pool.checkout
begin
yield Thread.current[:squirm_connection] = conn
ensure
Thread.current[:squirm_connection] = nil
@pool.checkin conn unless conn_given
end
end | ruby | {
"resource": ""
} |
q23624 | VCAP::Services::Base::AsyncJob.Package.manifest= | train | def manifest=(hash)
return unless hash
raise "Input should be Hash" unless hash.is_a? Hash
@manifest.merge! VCAP.symbolize_keys(hash)
end | ruby | {
"resource": ""
} |
q23625 | VCAP::Services::Base::AsyncJob.Package.pack | train | def pack(force=nil)
if File.exists? @zipfile
if force
File.delete @zipfile
else
raise "File #{@zipfile} already exists."
end
end
dirname = File.dirname(@zipfile)
raise "Dir #{dirname} is not exists." unless File.exists? dirname
raise "Dir #{dirn... | ruby | {
"resource": ""
} |
q23626 | VCAP::Services::Base::AsyncJob.Package.unpack | train | def unpack path
raise "File #{@zipfile} not exists." unless File.exists? @zipfile
raise "unpack path: #{path} not found." unless Dir.exists? path
raise "unpack path: #{path} is not writable." unless File.writable? path
files = []
Zip::ZipFile.foreach(@zipfile) do |entry|
next if e... | ruby | {
"resource": ""
} |
q23627 | VCAP::Services::Base::AsyncJob.Package.load_manifest | train | def load_manifest
zf = Zip::ZipFile.open(@zipfile)
@manifest = VCAP.symbolize_keys(Yajl::Parser.parse(zf.read(MANIFEST_FILE)))
rescue Errno::ENOENT => e
raise ServiceError.new(ServiceError::BAD_SERIALIZED_DATAFILE, "request. Missing manifest.")
end | ruby | {
"resource": ""
} |
q23628 | Calyx.Registry.filter | train | def filter(name, callable=nil, &block)
if block_given?
transforms[name.to_sym] = block
else
transforms[name.to_sym] = callable
end
end | ruby | {
"resource": ""
} |
q23629 | Calyx.Registry.define_rule | train | def define_rule(name, trace, productions)
rules[name.to_sym] = Rule.new(name.to_sym, construct_rule(productions), trace)
end | ruby | {
"resource": ""
} |
q23630 | Calyx.Registry.define_context_rule | train | def define_context_rule(name, trace, productions)
productions = [productions] unless productions.is_a?(Enumerable)
context[name.to_sym] = Rule.new(name.to_sym, construct_rule(productions), trace)
end | ruby | {
"resource": ""
} |
q23631 | Calyx.Registry.expand | train | def expand(symbol)
expansion = rules[symbol] || context[symbol]
if expansion.nil?
if @options.strict?
raise Errors::UndefinedRule.new(@last_expansion, symbol)
else
expansion = Production::Terminal.new('')
end
end
@last_expansion = expansion
exp... | ruby | {
"resource": ""
} |
q23632 | Calyx.Registry.transform | train | def transform(name, value)
if transforms.key?(name)
transforms[name].call(value)
else
modifiers.transform(name, value)
end
end | ruby | {
"resource": ""
} |
q23633 | Calyx.Registry.unique_expansion | train | def unique_expansion(symbol)
pending = true
uniques[symbol] = [] if uniques[symbol].nil?
while pending
if uniques[symbol].size == expand(symbol).size
uniques[symbol] = []
pending = false
end
result = expand(symbol).evaluate(@options)
unless unique... | ruby | {
"resource": ""
} |
q23634 | Calyx.Registry.evaluate | train | def evaluate(start_symbol=:start, rules_map={})
reset_evaluation_context
rules_map.each do |key, value|
if rules.key?(key.to_sym)
raise Errors::DuplicateRule.new(key)
end
define_context_rule(key, caller_locations.last, value)
end
[start_symbol, expand(start_s... | ruby | {
"resource": ""
} |
q23635 | VCAP::Services::Base::AsyncJob.Lock.make_logger | train | def make_logger
logger = Logger.new(STDOUT)
logger.level = Logger::ERROR
logger
end | ruby | {
"resource": ""
} |
q23636 | VCAP::Services.AsynchronousServiceGateway.validate_incoming_request | train | def validate_incoming_request
unless request.media_type == Rack::Mime.mime_type('.json')
error_msg = ServiceError.new(ServiceError::INVALID_CONTENT).to_hash
logger.error("Validation failure: #{error_msg.inspect}, request media type: #{request.media_type} is not json")
abort_request(error_m... | ruby | {
"resource": ""
} |
q23637 | VCAP::Services::Base::SnapshotV2.BaseRollbackSnapshotJob.perform | train | def perform
begin
required_options :service_id, :snapshot_id
@name = options["service_id"]
@snapshot_id = options["snapshot_id"]
@logger.info("Launch job: #{self.class} for #{name}")
lock = create_lock
@snapshot_files = []
lock.lock do
... | ruby | {
"resource": ""
} |
q23638 | Before.ClassMethods.enhance_method | train | def enhance_method(method, callbacks)
_method = (PREFIX + method.to_s).to_sym
alias_method _method, method
self.send(:define_method, method) do |*args, &blk|
[callbacks, _method].flatten.each do |callback|
break unless self.send(callback, *args, &blk)
end
end
end | ruby | {
"resource": ""
} |
q23639 | Moodle2CC::Moodle2Converter.QuestionnaireConverter.convert_rating_question | train | def convert_rating_question(moodle_question, canvas_question)
choices = create_rating_choices(moodle_question)
canvas_question.responses = []
moodle_question.choices.each_with_index do |answer, answer_idx|
response = {:id => "response#{answer_idx + 1}", :choices => []}
# add dropdown... | ruby | {
"resource": ""
} |
q23640 | SPOT.Paginator.enumerator | train | def enumerator
Enumerator.new do |yielder|
response = get_initial_response
loop do
items = response.records
# If there are no records, we're done
break if items.empty?
# Otherwise, iterate through the records...
items.each { |item| yielder << it... | ruby | {
"resource": ""
} |
q23641 | Troles::Common::Api.Write.static_role! | train | def static_role! role_name
raise ArgumentError, "Take a single role name, was: #{role_name}" if !role_name || !role_name.kind_of_label?
troles_config.add_valid_roles role_name
if set_roles role_name
define_method :static_roles? do
true
end
end
end | ruby | {
"resource": ""
} |
q23642 | Troles::Common::Api.Write.set_roles | train | def set_roles *roles
roles_to_set = make_valid_roles(*roles).flat_uniq
return false if !roles_to_set || roles_to_set.empty?
store.set_roles(roles_to_set)
end | ruby | {
"resource": ""
} |
q23643 | PoParser.Entry.untranslated? | train | def untranslated?
return false if obsolete? || fuzzy?
return @msgstr.map(&:str).join.empty? if @msgstr.is_a? Array
@msgstr.nil? || @msgstr.str.empty?
end | ruby | {
"resource": ""
} |
q23644 | PoParser.Entry.to_h | train | def to_h
instance_variables.each_with_object({}) do |label, hash|
object = instance_variable_get(label)
# If it's a plural msgstr
if object.is_a?(Array)
object.each do |entry|
hash[entry.type] = entry.to_s unless entry.nil?
end
else
hash[ob... | ruby | {
"resource": ""
} |
q23645 | PoParser.Entry.to_s | train | def to_s
LABELS.each_with_object([]) do |label, arr|
object = instance_variable_get("@#{label}".to_sym)
# If it's a plural msgstr
if object.is_a?(Array)
arr.push(*object.map { |entry| entry.to_s(true) }.compact)
else
arr << object.to_s(true) unless object.nil?
... | ruby | {
"resource": ""
} |
q23646 | QiwiPay.PaymentOperation.params_hash | train | def params_hash
%i[opcode].push(*ATTRIBUTES)
.map { |a| [a, send(a).to_s] }
.to_h
.reject { |_k, v| v.nil? || v.empty? }
end | ruby | {
"resource": ""
} |
q23647 | QiwiPay.PaymentOperation.request_params | train | def request_params
params_hash.tap do |params|
params[:sign] = Signature.new(params, credentials.secret).sign
end
end | ruby | {
"resource": ""
} |
q23648 | Trole::Storage.BaseOne.set_roles | train | def set_roles *roles
raise ArgumentError, "A single role strategy can only allow setting a single role, was: #{roles}" if (roles.size > 1)
set_role roles.flat_uniq.first
end | ruby | {
"resource": ""
} |
q23649 | Trole::Storage.BitOne.set_role | train | def set_role role
num = bitmask.write role
set_ds_field(num == 1 ? false : true) # boolean field in Data store
end | ruby | {
"resource": ""
} |
q23650 | QiwiPay.Confirmation.to_h | train | def to_h
{}.tap do |h|
ALLOWED_PARAMS.each { |p| h[p] = send(p) }
h[:txn_status_message] = txn_status_message
h[:txn_type_message] = txn_type_message
end
end | ruby | {
"resource": ""
} |
q23651 | QiwiPay.Confirmation.calculated_sign | train | def calculated_sign
params = SIGN_PARAMS.each_with_object({}) do |p, h|
h[p] = send(p).tap { |v| v ? v.to_s : nil }
end
Signature.new(params, @secret).sign.upcase
end | ruby | {
"resource": ""
} |
q23652 | Trole::Api.Write.set_role | train | def set_role new_role
value = make_valid_role new_role
return false if !value
store.set_role(value)
end | ruby | {
"resource": ""
} |
q23653 | Flt.Bytes.to_hex | train | def to_hex(sep_bytes=false)
hx = @bytes.unpack('H*')[0].upcase
if sep_bytes
sep = ""
(0...hx.size).step(2) do |i|
sep << " " unless i==0
sep << hx[i,2]
end
hx = sep
end
hx
end | ruby | {
"resource": ""
} |
q23654 | Flt.Bytes.reverse_byte_nibbles! | train | def reverse_byte_nibbles!
w = ""
w.force_encoding("BINARY") if w.respond_to?(:force_encoding)
@bytes.each_byte do |b|
w << ((b >> 4)|((b&0xF)<<4))
end
@bytes = w
__setobj__ @bytes
self
end | ruby | {
"resource": ""
} |
q23655 | Flt.Bytes.reverse_byte_pairs! | train | def reverse_byte_pairs!
w = ""
w.force_encoding("BINARY") if w.respond_to?(:force_encoding)
(0...@bytes.size).step(2) do |i|
w << @bytes[i+1]
w << @bytes[i]
end
@bytes = w
__setobj__ @bytes
self
end | ruby | {
"resource": ""
} |
q23656 | Flt.Bytes.to_bitfields | train | def to_bitfields(lens,byte_endianness=:little_endian, bits_little_endian=false)
fields = []
i = to_i(byte_endianness,bits_little_endian)
for len in lens
mask = (1<<len)-1
fields << (i&mask)
i >>= len
end
fields
end | ruby | {
"resource": ""
} |
q23657 | ActiveRecord.PostgreSQLCursor.each | train | def each
@model.transaction do
begin
declare_cursor
if @join_dependency
rows = Array.new
last_id = nil
while row = fetch_forward
instantiated_row = @join_dependency.instantiate([row], @join_dependency.aliases).first
curr... | ruby | {
"resource": ""
} |
q23658 | QiwiPay.Signature.map_sorted | train | def map_sorted(hash)
hash.keys
.sort_by(&:to_sym)
.map { |k| yield k, hash[k] }
end | ruby | {
"resource": ""
} |
q23659 | PoParser.Header.merge_to_previous_string | train | def merge_to_previous_string(array)
array.each_with_index do |key, index|
next unless key.length == 1
array[index - 1][1] += key[0]
array.delete_at(index)
end
end | ruby | {
"resource": ""
} |
q23660 | SPOT.ApiService.get | train | def get(path:, params: {})
params ||= {}
if feed_password && !feed_password.empty?
params = params.merge(feedPassword: feed_password)
end
response = make_request(:get, path, params)
SPOT::ApiResponse.new(response)
end | ruby | {
"resource": ""
} |
q23661 | Troles::Common.Config.auto_config? | train | def auto_config? name
return auto_config[name] if !auto_config[name].nil?
Troles::Config.auto_config?(name)
end | ruby | {
"resource": ""
} |
q23662 | Troles::Common.Config.main_field= | train | def main_field= field_name
name = field_name.to_s.alpha_numeric.to_sym
raise ArgumentException, "Not a valid field name: #{field_name}" if !valid_field_name?(name)
@main_field ||= name
end | ruby | {
"resource": ""
} |
q23663 | Troles::Mongoid.Config.configure_relation | train | def configure_relation
case strategy
when :ref_many
has_many_for subject_class, :role, :through => join_key
belongs_to_for join_model, subject_class
belongs_to_for join_model, object_model
has_many_for role, subject_class, :through => join_key
... | ruby | {
"resource": ""
} |
q23664 | TroleGroups::Api.Write.set_rolegroups | train | def set_rolegroups *rolegroups
rolegroups_to_set = make_valid_rolegroups(*rolegroups).flat_uniq
return false if !rolegroups_to_set || rolegroups_to_set.empty?
group_store.set_rolegroups(rolegroups_to_set)
end | ruby | {
"resource": ""
} |
q23665 | PoParser.Po.add | train | def add(entry)
return import_hash(entry) if entry.is_a?(Hash)
return import_array(entry) if entry.is_a?(Array)
raise ArgumentError, 'Must be a hash or an array of hashes'
end | ruby | {
"resource": ""
} |
q23666 | PoParser.Po.delete | train | def delete(entry)
raise(ArgumentError, 'Must be an Entry') unless entry.is_a?(PoParser::Entry)
@entries.delete(entry)
end | ruby | {
"resource": ""
} |
q23667 | PoParser.Po.stats | train | def stats
untranslated_size = untranslated.size
translated_size = translated.size
fuzzy_size = fuzzy.size
{
translated: percentage(translated_size),
untranslated: percentage(untranslated_size),
fuzzy: percentage(fuzzy_size),
}
end | ruby | {
"resource": ""
} |
q23668 | PoParser.Po.save_file | train | def save_file
raise ArgumentError, 'Need a Path to save the file' if @path.nil?
File.open(@path, 'w') { |file| file.write(to_s) }
end | ruby | {
"resource": ""
} |
q23669 | DineroMailIpn.NotificationParser.xsd_file | train | def xsd_file(filename)
xsd_file_location = File.join(DineroMailIpn.resources_path, "/validation/xsd/#{filename}")
xsd_file = File.read(xsd_file_location)
xsd_file
end | ruby | {
"resource": ""
} |
q23670 | RightGit::Shell.Default.execute | train | def execute(cmd, options = {})
options = {
:directory => nil,
:outstream => nil,
:raise_on_failure => true,
:set_env_vars => nil,
:clear_env_vars => nil,
:logger => default_logger,
:timeout => nil,
:keep_alive_interval => nil,
:keep_alive_tim... | ruby | {
"resource": ""
} |
q23671 | RightGit::Shell.Default.output_for | train | def output_for(cmd, options = {})
output = StringIO.new
execute(cmd, options.merge(:outstream => output))
output.string
end | ruby | {
"resource": ""
} |
q23672 | RightGit::Shell.Default.configure_executioner | train | def configure_executioner(executioner, options)
# set specific environment variables, if requested.
sev = options[:set_env_vars]
if (sev && !sev.empty?)
executioner = lambda do |e|
lambda { set_env_vars(sev) { e.call } }
end.call(executioner)
end
# clear specific... | ruby | {
"resource": ""
} |
q23673 | RightGit::Shell.Default.set_env_vars | train | def set_env_vars(variables)
save_vars = {}
variables.each do |k, v|
k = k.to_s
save_vars[k] = ENV[k]
ENV[k] = v.nil? ? v : v.to_s
end
begin
yield
ensure
variables.each_key do |k|
k = k.to_s
ENV[k] = save_vars[k]
end
... | ruby | {
"resource": ""
} |
q23674 | Vic.Highlight.bg= | train | def bg=(color)
color = Color.new(color)
@ctermbg, @guibg = color.to_cterm, color.to_gui
self
end | ruby | {
"resource": ""
} |
q23675 | Vic.Highlight.fg= | train | def fg=(color)
color = Color.new(color)
@ctermfg, @guifg = color.to_cterm, color.to_gui
self
end | ruby | {
"resource": ""
} |
q23676 | Vic.Highlight.select_styles | train | def select_styles(*styles)
styles.tap(&:compact).flatten!
if styles.empty? or styles.length == 1 && /\Anone\z/io.match(styles[0])
return :NONE
end
styles.select { |s| FONT_STYLE.match(s) }
end | ruby | {
"resource": ""
} |
q23677 | BioTCM::Databases::HGNC.Parser.parse | train | def parse(fin)
# Headline
names = fin.gets.chomp.split("\t")
index2identifier = {}
index_hgncid = nil
BioTCM::Databases::HGNC::IDENTIFIERS.each do |identifer, name|
if identifer == :hgncid
index_hgncid = names.index(name)
elsif name.is_a?(String)
index2i... | ruby | {
"resource": ""
} |
q23678 | RightScraper::Retrievers.Git.retrieve | train | def retrieve
raise RetrieverError.new("git retriever is unavailable") unless available?
private_key = @repository.first_credential
private_key = nil if private_key && private_key.empty?
if is_windows?
if private_key
with_private_key_windows(private_key) { super }
else
... | ruby | {
"resource": ""
} |
q23679 | RightScraper::Retrievers.Git.do_clean_all | train | def do_clean_all(git_repo)
old_initial_directory = git_repo.repo_dir
clean_all_options = {
:directories => true,
:gitignored => true,
:submodules => true
}
relative_paths = [
'.',
git_repo.submodule_paths(:recursive => true)
].flatten
relativ... | ruby | {
"resource": ""
} |
q23680 | RightScraper::Retrievers.Git.validate_revision | train | def validate_revision(git_repo, revision)
branches = git_repo.branches(:all => true)
local_branches = branches.local
remote_branches = branches.remote
by_name = lambda { |item| item.name == revision }
# determine if revision is a tag.
remote_name = nil
if git_repo.tags.any?(&b... | ruby | {
"resource": ""
} |
q23681 | RightScraper::Retrievers.Git.without_size_limit | train | def without_size_limit(git_repo)
old_max_bytes = git_repo.shell.max_bytes
begin
git_repo.shell.max_bytes = nil
yield
ensure
git_repo.shell.max_bytes = old_max_bytes
end
end | ruby | {
"resource": ""
} |
q23682 | RightScraper::Retrievers.Git.without_host_key_checking_linux | train | def without_host_key_checking_linux
tmpdir = ::Dir.mktmpdir
ssh_cmd = ::File.join(tmpdir, 'ssh')
::File.open(ssh_cmd, 'w') do |cmd|
cmd.puts "#!/bin/bash"
cmd.puts "exec ssh -o StrictHostKeyChecking=no ${@}"
end
::FileUtils.chmod(0700, ssh_cmd)
old_env = ::ENV['GIT_... | ruby | {
"resource": ""
} |
q23683 | RightScraper::Retrievers.Git.with_replaced_file | train | def with_replaced_file(filepath, contents)
::Dir.mktmpdir do |temp_dir|
begin
temp_path = ::File.join(temp_dir, ::File.basename(filepath))
::FileUtils.mkdir_p(::File.dirname(filepath))
if ::File.file?(filepath)
::FileUtils.mv(filepath, temp_path, :force => true)
... | ruby | {
"resource": ""
} |
q23684 | RightGit::Git.Repository.fetch_all | train | def fetch_all(options = {})
options = { :prune => false }.merge(options)
git_args = ['--all']
git_args << '--prune' if options[:prune]
fetch(git_args)
fetch('--tags') # need a separate call for tags or else you don't get all the tags
true
end | ruby | {
"resource": ""
} |
q23685 | RightGit::Git.Repository.log | train | def log(revision, options = {})
options = {
:skip => nil,
:tail => 10_000,
:merges => false,
:no_merges => false,
:full_hashes => false,
}.merge(options)
skip = options[:skip]
git_args = [
'log',
"-n#{options[:tail]}",
... | ruby | {
"resource": ""
} |
q23686 | RightGit::Git.Repository.clean_all | train | def clean_all(options = {})
options = {
:directories => false,
:gitignored => false,
:submodules => false,
}.merge(options)
git_args = ['-f'] # force is required or else -n only lists files.
git_args << '-f' if options[:submodules] # double-tap -f to kill untracked su... | ruby | {
"resource": ""
} |
q23687 | RightGit::Git.Repository.submodule_paths | train | def submodule_paths(options = {})
options = {
:recursive => false
}.merge(options)
git_args = ['submodule', 'status']
git_args << '--recursive' if options[:recursive]
git_output(git_args).lines.map do |line|
data = line.chomp
if matched = SUBMODULE_STATUS_REGEX.matc... | ruby | {
"resource": ""
} |
q23688 | RightGit::Git.Repository.update_submodules | train | def update_submodules(options = {})
options = {
:recursive => false
}.merge(options)
git_args = ['submodule', 'update', '--init']
git_args << '--recursive' if options[:recursive]
spit_output(git_args)
true
end | ruby | {
"resource": ""
} |
q23689 | RightGit::Git.Repository.sha_for | train | def sha_for(revision)
# note that 'git show-ref' produces easier-to-parse output but it matches
# both local and remote branch to a simple branch name whereas 'git show'
# matches at-most-one and requires origin/ for remote branches.
git_args = ['show', revision].compact
result = nil
... | ruby | {
"resource": ""
} |
q23690 | RightGit::Git.Repository.vet_output | train | def vet_output(*args)
last_output = git_output(*args).strip
logger.info(last_output) unless last_output.empty?
if last_output.downcase =~ /^(error|fatal):/
raise GitError, "Git exited zero but an error was detected in output."
end
true
end | ruby | {
"resource": ""
} |
q23691 | RightScraper::Scanners.CookbookMetadata.end | train | def end(resource)
@logger.operation(:metadata_parsing) do
if @read_blk
metadata = ::JSON.parse(@read_blk.call)
resource.metadata = metadata
# check for undefined cookbook name.
#
# note that many specs in right_scraper use badly formed metadata
... | ruby | {
"resource": ""
} |
q23692 | RightScraper::Scanners.CookbookMetadata.finish | train | def finish
begin
::FileUtils.remove_entry_secure(tls[:tmpdir]) if tls[:tmpdir]
rescue ::Exception => e
@logger.note_warning(e.message)
end
ensure
# Cleanup thread-local storage
tls.clear
end | ruby | {
"resource": ""
} |
q23693 | RightScraper::Scanners.CookbookMetadata.generate_metadata_json | train | def generate_metadata_json
@logger.operation(:metadata_generation) do
# note we will use the same tmpdir path inside and outside the
# container only because it is non-trivial to invoke mktmpdir inside
# the container.
tmpdir, created = create_tmpdir
# path constants
... | ruby | {
"resource": ""
} |
q23694 | RightScraper::Scanners.CookbookMetadata.do_copy_in | train | def do_copy_in(path_map)
path_map.each do |src_path, dst_path|
if src_path != dst_path
::FileUtils.mkdir_p(::File.dirname(dst_path))
::FileUtils.cp(src_path, dst_path)
end
end
true
end | ruby | {
"resource": ""
} |
q23695 | RightScraper::Scanners.CookbookMetadata.do_copy_out | train | def do_copy_out(path_map)
path_map.each do |src_path, dst_path|
# constraining the generated 'metadata.json' size is debatable, but
# our UI attempts to load metadata JSON into memory far too often to
# be blasé about generating multi-megabyte JSON files.
unless ::File.file?(src_pa... | ruby | {
"resource": ""
} |
q23696 | RightScraper::Scanners.CookbookMetadata.generate_copy_in | train | def generate_copy_in(src_base_path, dst_base_path)
src_base_path = ::File.expand_path(src_base_path)
dst_base_path = ::File.expand_path(dst_base_path)
copy_in = []
recursive_generate_copy_in(copy_in, src_base_path)
src_base_path += '/'
src_base_path_len = src_base_path.length
... | ruby | {
"resource": ""
} |
q23697 | RightScraper::Scanners.CookbookMetadata.recursive_generate_copy_in | train | def recursive_generate_copy_in(copy_in, current_path)
limited_files_of(current_path) { |file| copy_in << file }
directories_of(current_path) do |dir|
recursive_generate_copy_in(copy_in, ::File.join(dir))
end
true
end | ruby | {
"resource": ""
} |
q23698 | RightScraper::Scanners.CookbookMetadata.limited_files_of | train | def limited_files_of(parent)
::Dir["#{parent}/*"].each do |item|
if ::File.file?(item)
if ::File.stat(item).size <= JAILED_FILE_SIZE_CONSTRAINT
yield item
else
if ::File.basename(item) == RUBY_METADATA
raise MetadataError,
'Meta... | ruby | {
"resource": ""
} |
q23699 | RightScraper::Scanners.CookbookMetadata.directories_of | train | def directories_of(parent)
::Dir["#{parent}/*"].each do |item|
case item
when '.', '..'
# do nothing
else
yield item if ::File.directory?(item)
end
end
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.