_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3
values | text stringlengths 66 10.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q7100 | Jinx.Inverse.detect_inverse_attribute | train | def detect_inverse_attribute(klass)
# The candidate attributes return the referencing type and don't already have an inverse.
candidates = domain_attributes.compose { |prop| klass <= prop.type and prop.inverse.nil? }
pa = detect_inverse_attribute_from_candidates(klass, candidates)
if pa then
... | ruby | {
"resource": ""
} |
q7101 | Jinx.Inverse.delegate_writer_to_inverse | train | def delegate_writer_to_inverse(attribute, inverse)
prop = property(attribute)
# nothing to do if no inverse
inv_prop = prop.inverse_property || return
logger.debug { "Delegating #{qp}.#{attribute} update to the inverse #{prop.type.qp}.#{inv_prop}..." }
# redefine the write to set the depen... | ruby | {
"resource": ""
} |
q7102 | Jinx.Inverse.restrict_attribute_inverse | train | def restrict_attribute_inverse(prop, inverse)
logger.debug { "Restricting #{prop.declarer.qp}.#{prop} to #{qp} with inverse #{inverse}..." }
rst_prop = prop.restrict(self, :inverse => inverse)
logger.debug { "Restricted #{prop.declarer.qp}.#{prop} to #{qp} with inverse #{inverse}." }
rst_prop
... | ruby | {
"resource": ""
} |
q7103 | Jinx.Inverse.add_inverse_updater | train | def add_inverse_updater(attribute)
prop = property(attribute)
# the reader and writer methods
rdr, wtr = prop.accessors
# the inverse attribute metadata
inv_prop = prop.inverse_property
# the inverse attribute reader and writer
inv_rdr, inv_wtr = inv_accessors = inv_prop.access... | ruby | {
"resource": ""
} |
q7104 | Epicmix.Client.login | train | def login
url = 'https://www.epicmix.com/vailresorts/sites/epicmix/api/mobile/authenticate.ashx'
options = { :query => { :loginID => username, :password => password }}
response = HTTParty.post(url, options)
token_from(response) # if response.instance_of? Net::HTTPOK
end | ruby | {
"resource": ""
} |
q7105 | Epicmix.Client.season_stats | train | def season_stats
url = 'https://www.epicmix.com/vailresorts/sites/epicmix/api/mobile/userstats.ashx'
options = { :timetype => 'season', :token => token }
response = HTTParty.get(url, :query => options, :headers => headers)
JSON.parse(response.body)['seasonStats']
end | ruby | {
"resource": ""
} |
q7106 | Mousevc.Validation.min_length? | train | def min_length?(value, length)
has_min_length = coerce_bool (value.length >= length)
unless has_min_length
@error = "Error, expected value to have at least #{length} characters, got: #{value.length}"
end
has_min_length
end | ruby | {
"resource": ""
} |
q7107 | Mousevc.Validation.max_length? | train | def max_length?(value, length)
has_max_length = coerce_bool (value.length <= length)
unless has_max_length
@error = "Error, expected value to have at most #{length} characters, got: #{value.length}"
end
has_max_length
end | ruby | {
"resource": ""
} |
q7108 | Mousevc.Validation.exact_length? | train | def exact_length?(value, length)
has_exact_length = coerce_bool (value.length == length)
unless has_exact_length
@error = "Error, expected value to have exactly #{length} characters, got: #{value.length}"
end
has_exact_length
end | ruby | {
"resource": ""
} |
q7109 | BetaInvite.BetaInvitesController.create | train | def create
email = params[:beta_invite][:email]
beta_invite = BetaInvite.new( email: email, token: SecureRandom.hex(10) )
if beta_invite.save
flash[:success] = "#{email} has been registered for beta invite"
# send an email if configured
if BetaInviteSetup.send_email_to_admins... | ruby | {
"resource": ""
} |
q7110 | Spockets.Watcher.stop | train | def stop
if(@runner.nil? && @stop)
raise NotRunning.new
elsif(@runner.nil? || !@runner.alive?)
@stop = true
@runner = nil
else
@stop = true
if(@runner)
@runner.raise Resync.new if @runner.alive? && @runner.stop?
@runner.join(0.05) if @runner
... | ruby | {
"resource": ""
} |
q7111 | Spockets.Watcher.watch | train | def watch
until(@stop)
begin
resultset = Kernel.select(@sockets.keys, nil, nil, nil)
for sock in resultset[0]
string = sock.gets
if(sock.closed? || string.nil?)
if(@sockets[sock][:closed])
@sockets[sock][:closed].each do |pr|
... | ruby | {
"resource": ""
} |
q7112 | Hoodie.FileHelper.command_in_path? | train | def command_in_path?(command)
found = ENV['PATH'].split(File::PATH_SEPARATOR).map do |p|
File.exist?(File.join(p, command))
end
found.include?(true)
end | ruby | {
"resource": ""
} |
q7113 | Ducktrap.PrettyDump.pretty_inspect | train | def pretty_inspect
io = StringIO.new
formatter = Formatter.new(io)
pretty_dump(formatter)
io.rewind
io.read
end | ruby | {
"resource": ""
} |
q7114 | Fixer.Response.method_missing | train | def method_missing(method_name, *args, &block)
if self.has_key?(method_name.to_s)
self.[](method_name, &block)
elsif self.body.respond_to?(method_name)
self.body.send(method_name, *args, &block)
elsif self.request[:api].respond_to?(method_name)
self.request[:api].send(method_na... | ruby | {
"resource": ""
} |
q7115 | SK::SDK.Sync.update | train | def update(side, flds=nil)
raise ArgumentError, 'The side to update must be :l or :r' unless [:l, :r].include?(side)
target, source = (side==:l) ? [:l, :r] : [:r, :l]
# use set field/s or update all
flds ||= fields
target_obj = self.send("#{target}_obj")
source_obj = self.send("#{sou... | ruby | {
"resource": ""
} |
q7116 | Pith.Input.ignorable? | train | def ignorable?
@ignorable ||= path.each_filename do |path_component|
project.config.ignore_patterns.each do |pattern|
return true if File.fnmatch(pattern, path_component)
end
end
end | ruby | {
"resource": ""
} |
q7117 | Pith.Input.render | train | def render(context, locals = {}, &block)
return file.read if !template?
ensure_loaded
pipeline.inject(@template_text) do |text, processor|
template = processor.new(file.to_s, @template_start_line) { text }
template.render(context, locals, &block)
end
end | ruby | {
"resource": ""
} |
q7118 | Pith.Input.load | train | def load
@load_time = Time.now
@meta = {}
if template?
logger.debug "loading #{path}"
file.open do |io|
read_meta(io)
@template_start_line = io.lineno + 1
@template_text = io.read
end
end
end | ruby | {
"resource": ""
} |
q7119 | Utf8Sanitizer.UTF.process_hash_row | train | def process_hash_row(hsh)
if @headers.any?
keys_or_values = hsh.values
@row_id = hsh[:row_id]
else
keys_or_values = hsh.keys.map(&:to_s)
end
file_line = keys_or_values.join(',')
validated_line = utf_filter(check_utf(file_line))
res = line_parse(validated_line... | ruby | {
"resource": ""
} |
q7120 | Utf8Sanitizer.UTF.line_parse | train | def line_parse(validated_line)
return unless validated_line
row = validated_line.split(',')
return unless row.any?
if @headers.empty?
@headers = row
else
@data_hash.merge!(row_to_hsh(row))
@valid_rows << @data_hash
end
end | ruby | {
"resource": ""
} |
q7121 | Shells.ShellBase.wait_for_prompt | train | def wait_for_prompt(silence_timeout = nil, command_timeout = nil, timeout_error = true) #:doc:
raise Shells::NotRunning unless running?
silence_timeout ||= options[:silence_timeout]
command_timeout ||= options[:command_timeout]
# when did we send a NL and how many have we sent while wait... | ruby | {
"resource": ""
} |
q7122 | Shells.ShellBase.temporary_prompt | train | def temporary_prompt(prompt) #:doc:
raise Shells::NotRunning unless running?
old_prompt = prompt_match
begin
self.prompt_match = prompt
yield if block_given?
ensure
self.prompt_match = old_prompt
end
end | ruby | {
"resource": ""
} |
q7123 | Rails::Generator::Commands.Base.next_migration_string | train | def next_migration_string(padding = 3)
@s = (!@s.nil?)? @s.to_i + 1 : if ActiveRecord::Base.timestamped_migrations
Time.now.utc.strftime("%Y%m%d%H%M%S")
else
"%.#{padding}d" % next_migration_number
end
end | ruby | {
"resource": ""
} |
q7124 | Rozi.Shared.interpret_color | train | def interpret_color(color)
if color.is_a? String
# Turns RRGGBB into BBGGRR for hex conversion.
color = color[-2..-1] << color[2..3] << color[0..1]
color = color.to_i(16)
end
color
end | ruby | {
"resource": ""
} |
q7125 | Mousevc.App.listen | train | def listen
begin
clear_view
@router.route unless Input.quit?
reset if Input.reset?
end until Input.quit?
end | ruby | {
"resource": ""
} |
q7126 | Jinx.MultilineLogger.format_message | train | def format_message(severity, datetime, progname, msg)
if String === msg then
msg.inject('') { |s, line| s << super(severity, datetime, progname, line.chomp) }
else
super
end
end | ruby | {
"resource": ""
} |
q7127 | UserInput.TypeSafeHash.each_pair | train | def each_pair(type, default = nil)
real_hash.each_key() { |key|
value = fetch(key, type, default)
if (!value.nil?)
yield(key, value)
end
}
end | ruby | {
"resource": ""
} |
q7128 | UserInput.TypeSafeHash.each_match | train | def each_match(regex, type, default = nil)
real_hash.each_key() { |key|
if (matchinfo = regex.match(key))
value = fetch(key, type, default)
if (!value.nil?)
yield(matchinfo, value)
end
end
}
end | ruby | {
"resource": ""
} |
q7129 | ScopedSerializer.Serializer.attributes_hash | train | def attributes_hash
attributes = @scope.attributes.collect do |attr|
value = fetch_property(attr)
if value.kind_of?(BigDecimal)
value = value.to_f
end
[attr, value]
end
Hash[attributes]
end | ruby | {
"resource": ""
} |
q7130 | ScopedSerializer.Serializer.associations_hash | train | def associations_hash
hash = {}
@scope.associations.each do |association, options|
hash.merge!(render_association(association, options))
end
hash
end | ruby | {
"resource": ""
} |
q7131 | ScopedSerializer.Serializer.render_association | train | def render_association(association_data, options={})
hash = {}
if association_data.is_a?(Hash)
association_data.each do |association, association_options|
data = render_association(association, options.merge(:include => association_options))
hash.merge!(data) if data
end... | ruby | {
"resource": ""
} |
q7132 | ScopedSerializer.Serializer.fetch_property | train | def fetch_property(property)
return nil unless property
unless respond_to?(property)
object = @resource.send(property)
else
object = send(property)
end
end | ruby | {
"resource": ""
} |
q7133 | ScopedSerializer.Serializer.fetch_association | train | def fetch_association(name, includes=nil)
association = fetch_property(name)
if includes.present? && ! @resource.association(name).loaded?
association.includes(includes)
else
association
end
end | ruby | {
"resource": ""
} |
q7134 | Remi.Job.execute | train | def execute(*components)
execute_transforms if components.empty? || components.include?(:transforms)
execute_sub_jobs if components.empty? || components.include?(:sub_jobs)
execute_load_targets if components.empty? || components.include?(:load_targets)
self
end | ruby | {
"resource": ""
} |
q7135 | KeytechKit.User.load | train | def load(username)
options = {}
options[:basic_auth] = @auth
response = self.class.get("/user/#{username}", options)
if response.success?
self.response = response
parse_response
self
else
raise response.response
end
end | ruby | {
"resource": ""
} |
q7136 | Jinx.Dependency.add_dependent_property | train | def add_dependent_property(property, *flags)
logger.debug { "Marking #{qp}.#{property} as a dependent attribute of type #{property.type.qp}..." }
flags << :dependent unless flags.include?(:dependent)
property.qualify(*flags)
inv = property.inverse
inv_type = property.type
# example: ... | ruby | {
"resource": ""
} |
q7137 | Jinx.Dependency.add_owner | train | def add_owner(klass, inverse, attribute=nil)
if inverse.nil? then
raise ValidationError.new("Owner #{klass.qp} missing dependent attribute for dependent #{qp}")
end
logger.debug { "Adding #{qp} owner #{klass.qp}#{' attribute ' + attribute.to_s if attribute} with inverse #{inverse}..." }
... | ruby | {
"resource": ""
} |
q7138 | Jinx.Dependency.add_owner_attribute | train | def add_owner_attribute(attribute)
prop = property(attribute)
otype = prop.type
hash = local_owner_property_hash
if hash.include?(otype) then
oa = hash[otype]
unless oa.nil? then
raise MetadataError.new("Cannot set #{qp} owner attribute to #{attribute} since it is alrea... | ruby | {
"resource": ""
} |
q7139 | NRSER.AbstractMethodError.method_instance | train | def method_instance
lazy_var :@method_instance do
# Just drop a warning if we can't get the method object
logger.catch.warn(
"Failed to get method",
instance: instance,
method_name: method_name,
) do
instance.method method_name
end
end
end | ruby | {
"resource": ""
} |
q7140 | GHULS.Lib.get_user_and_check | train | def get_user_and_check(user)
user_full = @octokit.user(user)
{
username: user_full[:login],
avatar: user_full[:avatar_url]
}
rescue Octokit::NotFound
return false
end | ruby | {
"resource": ""
} |
q7141 | GHULS.Lib.get_forks_stars_watchers | train | def get_forks_stars_watchers(repository)
{
forks: @octokit.forks(repository).length,
stars: @octokit.stargazers(repository).length,
watchers: @octokit.subscribers(repository).length
}
end | ruby | {
"resource": ""
} |
q7142 | GHULS.Lib.get_followers_following | train | def get_followers_following(username)
{
following: @octokit.following(username).length,
followers: @octokit.followers(username).length
}
end | ruby | {
"resource": ""
} |
q7143 | GHULS.Lib.get_user_langs | train | def get_user_langs(username)
repos = get_user_repos(username)
langs = {}
repos[:public].each do |r|
next if repos[:forks].include? r
repo_langs = @octokit.languages(r)
repo_langs.each do |l, b|
if langs[l].nil?
langs[l] = b
else
langs... | ruby | {
"resource": ""
} |
q7144 | GHULS.Lib.get_org_langs | train | def get_org_langs(username)
org_repos = get_org_repos(username)
langs = {}
org_repos[:public].each do |r|
next if org_repos[:forks].include? r
repo_langs = @octokit.languages(r)
repo_langs.each do |l, b|
if langs[l].nil?
langs[l] = b
else
... | ruby | {
"resource": ""
} |
q7145 | GHULS.Lib.get_color_for_language | train | def get_color_for_language(lang)
color_lang = @colors[lang]
color = color_lang['color']
if color_lang.nil? || color.nil?
return StringUtility.random_color_six
else
return color
end
end | ruby | {
"resource": ""
} |
q7146 | GHULS.Lib.get_language_percentages | train | def get_language_percentages(langs)
total = 0
langs.each { |_, b| total += b }
lang_percents = {}
langs.each do |l, b|
percent = self.class.calculate_percent(b, total.to_f)
lang_percents[l] = percent.round(2)
end
lang_percents
end | ruby | {
"resource": ""
} |
q7147 | YumRepo.Repomd.filelists | train | def filelists
fl = []
@repomd.xpath("/xmlns:repomd/xmlns:data[@type=\"filelists\"]/xmlns:location").each do |f|
fl << File.join(@url, f['href'])
end
fl
end | ruby | {
"resource": ""
} |
q7148 | Xpay.Payment.rewrite_request_block | train | def rewrite_request_block(auth_type="ST3DAUTH")
# set the required AUTH type
REXML::XPath.first(@request_xml, "//Request").attributes["Type"] = auth_type
# delete term url and merchant name
ops = REXML::XPath.first(@request_xml, "//Operation")
["TermUrl", "MerchantName"].each { |e| ops.d... | ruby | {
"resource": ""
} |
q7149 | Skeletor.CLI.clean | train | def clean
print 'Are you sure you want to clean this project directory? (Y|n): '
confirm = $stdin.gets.chomp
if confirm != 'Y' && confirm != 'n'
puts 'Please enter Y or n'
elsif confirm == 'Y'
path = options[:directory] || Dir.pwd
Builder.clean path
end
e... | ruby | {
"resource": ""
} |
q7150 | Layabout.FileUpload.wrap | train | def wrap(http_response)
OpenStruct.new.tap do |obj|
obj.code = http_response.code.to_i
obj.body = http_response.body
obj.headers = {}
http_response.each_header{|k,v| obj.headers[k] = v }
end
end | ruby | {
"resource": ""
} |
q7151 | Montage.OrderParser.clause_valid? | train | def clause_valid?
if @clause.is_a?(Hash)
@clause.flatten.find do |e|
return true unless (/\basc\b|\bdesc\b/).match(e).nil?
end
else
return true unless @clause.split.empty?
end
end | ruby | {
"resource": ""
} |
q7152 | Montage.OrderParser.parse_hash | train | def parse_hash
direction = clause.values.first
field = clause.keys.first.to_s
["$order_by", ["$#{direction}", field]]
end | ruby | {
"resource": ""
} |
q7153 | Montage.OrderParser.parse_string | train | def parse_string
direction = clause.split[1]
field = clause.split[0]
direction = "asc" unless %w(asc desc).include?(direction)
["$order_by", ["$#{direction}", field]]
end | ruby | {
"resource": ""
} |
q7154 | ZendeskTools.CleanSuspended.run | train | def run
@client.suspended_tickets.each do |suspended_ticket|
if should_delete?(suspended_ticket)
log.info "Deleting: #{suspended_ticket.subject}"
suspended_ticket.destroy
else
log.info "Keeping: #{suspended_ticket.subject}"
end
end
end | ruby | {
"resource": ""
} |
q7155 | SimpleCLI.Command.summary | train | def summary
if @summary.nil?
match = Command::SummaryMatcher.match documentation
match.captures.first.strip if match
else
@summary
end
end | ruby | {
"resource": ""
} |
q7156 | HueBridge.LightBulb.set_color | train | def set_color(opts = {})
color = Color.new(opts)
response = put('state', color.to_h)
response_successful?(response)
end | ruby | {
"resource": ""
} |
q7157 | HueBridge.LightBulb.store_state | train | def store_state
response = get
success = !!(response.body =~ %r(state))
data = JSON.parse(response.body) if success
@state = data.fetch('state')
delete_forbidden_stats
success
end | ruby | {
"resource": ""
} |
q7158 | CruLib.Async.perform | train | def perform(id, method, *args)
if id
begin
self.class.find(id).send(method, *args)
rescue ActiveRecord::RecordNotFound
# If the record was deleted after the job was created, swallow it
end
else
self.class.send(method, *args)
end
end | ruby | {
"resource": ""
} |
q7159 | Gitolite.Utils.is_subset? | train | def is_subset?(array1, array2)
result = array1 & array2
(array2.length == result.length)
end | ruby | {
"resource": ""
} |
q7160 | Gitolite.Utils.gitolite_friendly | train | def gitolite_friendly(permission)
if permission.empty?
return nil
elsif permission.match(/^RWDP?/)
return "RW+"
elsif permission.match(/^RW/)
return "RW+"
elsif permission.match(/^R/)
return 'R'
else
return nil
end
end | ruby | {
"resource": ""
} |
q7161 | Bebox.EnvironmentWizard.create_new_environment | train | def create_new_environment(project_root, environment_name)
# Check if the environment exist
return error(_('wizard.environment.name_exist')%{environment: environment_name}) if Bebox::Environment.environment_exists?(project_root, environment_name)
# Environment creation
environment = Bebox::Envir... | ruby | {
"resource": ""
} |
q7162 | Bebox.EnvironmentWizard.remove_environment | train | def remove_environment(project_root, environment_name)
# Check if the environment exist
return error(_('wizard.environment.name_not_exist')%{environment: environment_name}) unless Bebox::Environment.environment_exists?(project_root, environment_name)
# Confirm deletion
return warn(_('wizard.no_c... | ruby | {
"resource": ""
} |
q7163 | Asset.Item.write_cache | train | def write_cache
compressed.tap{|c| File.atomic_write(cache_path){|f| f.write(c)}}
end | ruby | {
"resource": ""
} |
q7164 | Asset.Item.compressed | train | def compressed
@compressed ||= case @type
when 'css'
Sass::Engine.new(joined, :syntax => :scss, :cache => false, :style => :compressed).render rescue joined
when 'js'
Uglifier.compile(joined, :mangle => false, :comments => :none) rescue joined
end
end | ruby | {
"resource": ""
} |
q7165 | Asset.Item.joined | train | def joined
@joined ||= files.map{|f| File.read(File.join(::Asset.path, @type, f))}.join
end | ruby | {
"resource": ""
} |
q7166 | Zomato2.Zomato.locations | train | def locations(params={})
args = [ :query, :lat, :lon, :count ]
params.each do |k,v|
if !args.include?(k)
raise ArgumentError.new 'Search term not allowed: ' + k.to_s
end
end
if !params.include?(:query)
raise ArgumentError.new '"query" term with location name is... | ruby | {
"resource": ""
} |
q7167 | Zomato2.Zomato.restaurants | train | def restaurants(params={})
args = [ :entity_id, :entity_type, # location
:q, :start, :count, :lat, :lon,
:radius, :cuisines, :establishment_type,
:collection_id, :category, :sort, :order,
:start, :count ]
params.each do |k,v|
if !args.incl... | ruby | {
"resource": ""
} |
q7168 | Resumator.Client.get | train | def get(object, options = {})
if options[:all_pages]
options.delete(:all_pages)
options[:page] = 1
out = []
begin
data = get(object, options)
out = out | data
options[:page] += 1
end while data.count >= 100
return out
else
... | ruby | {
"resource": ""
} |
q7169 | IRCSupport.Masks.matches_mask_array | train | def matches_mask_array(masks, strings, casemapping = :rfc1459)
results = {}
masks.each do |mask|
strings.each do |string|
if matches_mask(mask, string, casemapping)
results[mask] ||= []
results[mask] << string
end
end
end
return results... | ruby | {
"resource": ""
} |
q7170 | ScopedSerializer.Scope.merge! | train | def merge!(scope)
@options.merge!(scope.options)
@attributes += scope.attributes
@associations.merge!(scope.associations)
@attributes.uniq!
self
end | ruby | {
"resource": ""
} |
q7171 | ScopedSerializer.Scope._association | train | def _association(args, default_options={})
return if options.nil?
options = args.first
if options.is_a?(Hash)
options = {}.merge(options)
name = options.keys.first
properties = options.delete(name)
@associations[name] = default_options.merge({ :include =>... | ruby | {
"resource": ""
} |
q7172 | Pocus.Resource.get | train | def get(request_path, klass)
response = session.send_request('GET', path + request_path)
data = response.fetch(klass.tag)
resource = klass.new(data.merge(parent: self))
resource.assign_errors(response)
resource
end | ruby | {
"resource": ""
} |
q7173 | Pocus.Resource.reload | train | def reload
response = session.send_request('GET', path)
assign_attributes(response.fetch(self.class.tag))
assign_errors(response)
self
end | ruby | {
"resource": ""
} |
q7174 | MMETools.Enumerable.compose | train | def compose(*enumerables)
res=[]
enumerables.map(&:size).max.times do
tupla=[]
for enumerable in enumerables
tupla << enumerable.shift
end
res << (block_given? ? yield(tupla) : tupla)
end
res
end | ruby | {
"resource": ""
} |
q7175 | SpiderCore.FieldDSL.field | train | def field(display, pattern, opts = {}, &block)
actions << lambda {
action_for(:field, {display: display, pattern: pattern}, opts, &block)
}
end | ruby | {
"resource": ""
} |
q7176 | Encruby.Message.encrypt | train | def encrypt(message)
raise Error, "data must not be empty" if message.to_s.strip.empty?
# 1
@cipher.reset
@cipher.encrypt
aes_key = @cipher.random_key
aes_iv = @cipher.random_iv
encrypted = @cipher.update(message) + @cipher.final
# 2
rsa_encrypted_aes_key = @r... | ruby | {
"resource": ""
} |
q7177 | Encruby.Message.decrypt | train | def decrypt(message, hash: nil)
# 0
message = Base64.decode64(message)
hmac = message[0..63] # 64 bits of hmac signature
case
when hash && hmac != hash
raise Error, "Provided hash mismatch for encrypted file!"
when hmac != hmac_signature(message[64..-1])
raise Error,... | ruby | {
"resource": ""
} |
q7178 | RefBiblio.Referencia.titulo | train | def titulo (titulo)
tit = titulo.split(' ')
tit.each do |word|
if word.length > 3
word.capitalize!
else
word.downcase!
end
if word == tit[0]
word.capitalize!
end
@titulo = tit.join(' ')
end
# Metodo para guardar el editorial de la referencia
# @param [editorial] editorial E... | ruby | {
"resource": ""
} |
q7179 | RefBiblio.ArtPeriodico.to_s | train | def to_s
string = ""
string << @autor << " (" << Date::MONTHNAMES[get_publicacion.month] << " " << get_publicacion.day.to_s << ", " << get_publicacion.year.to_s << "). " << @titulo << ". " << @editorial << ", pp. " << @formato << ", " << @paginas.to_s << " paginas" << "."
end | ruby | {
"resource": ""
} |
q7180 | RefBiblio.DocElectronico.to_s | train | def to_s
string = ""
string << @autor << " (" << Date::MONTHNAMES[get_publicacion.month] << " " << get_publicacion.day.to_s << ", " << get_publicacion.year.to_s << "). " << @titulo << @formato << ". " << @editorial << ": " << @edicion << ". Disponible en: " << @url << " (" << Date::MONTHNAMES[get_fechacceso.month... | ruby | {
"resource": ""
} |
q7181 | Evvnt.PathHelpers.nest_path_within_parent | train | def nest_path_within_parent(path, params)
return path unless params_include_parent_resource_id?(params)
params.symbolize_keys!
parent_resource = parent_resource_name(params)
parent_id = params.delete(parent_resource_param(params)).try(:to_s)
File.join(*[parent_resource, parent_id, pa... | ruby | {
"resource": ""
} |
q7182 | DynamicRegistrar.Registrar.dispatch | train | def dispatch name, namespace = nil
responses = Hash.new
namespaces_to_search = namespace ? [namespace] : namespaces
namespaces_to_search.each do |namespace|
responses[namespace] ||= Hash.new
responses[namespace][name] = @registered_callbacks[namespace][name].call if @registered_callbac... | ruby | {
"resource": ""
} |
q7183 | DynamicRegistrar.Registrar.registered? | train | def registered? name
registration_map = namespaces.map do |namespace|
registered_in_namespace? name, namespace
end
registration_map.any?
end | ruby | {
"resource": ""
} |
q7184 | EasyTag.MP3AttributeAccessors.read_all_tags | train | def read_all_tags(taglib, id3v2_frames, id3v1_tag = nil, **opts)
frames = []
id3v2_frames.each { |frame_id| frames += id3v2_frames(taglib, frame_id) }
data = []
# only check id3v1 if no id3v2 frames found
if frames.empty?
data << id3v1_tag(taglib, id3v1_tag) unless id3v1_tag.nil?
... | ruby | {
"resource": ""
} |
q7185 | RComp.Runner.run | train | def run(suite, type, options={})
@conf = Conf.instance
reporter = Reporter.new(type)
reporter.header
suite.each do |test|
case type
when :test
run_test(test) if expected_exists?(test)
when :generate
if expected_exists?(test)
run_test(tes... | ruby | {
"resource": ""
} |
q7186 | RComp.Runner.cmp_output | train | def cmp_output(test)
# test out and err
if test.expected_out_exists? && test.expected_err_exists?
cmp_out(test)
cmp_err(test)
return :success if (test.out_result && test.err_result)
# test only out
elsif test.expected_out_exists?
cmp_out(test)
return :suc... | ruby | {
"resource": ""
} |
q7187 | RComp.Runner.cmp_out | train | def cmp_out(test)
test.out_result = FileUtils.cmp(test.expected_out_path,
test.result_out_path)
end | ruby | {
"resource": ""
} |
q7188 | RComp.Runner.cmp_err | train | def cmp_err(test)
test.err_result = FileUtils.cmp(test.expected_err_path,
test.result_err_path)
end | ruby | {
"resource": ""
} |
q7189 | ScopedSerializer.BaseSerializer.default_root_key | train | def default_root_key(object_class)
if (serializer = ScopedSerializer.find_serializer_by_class(object_class))
root_key = serializer.find_scope(:default).options[:root]
end
if root_key
root_key.to_s
elsif object_class.respond_to?(:model_name)
object_class.model_name.elemen... | ruby | {
"resource": ""
} |
q7190 | Garcon.TimerSet.post | train | def post(delay, *args, &task)
raise ArgumentError, 'no block given' unless block_given?
delay = TimerSet.calculate_delay!(delay)
mutex.synchronize do
return false unless running?
if (delay) <= 0.01
@task_executor.post(*args, &task)
else
@queue.push(Task.ne... | ruby | {
"resource": ""
} |
q7191 | Garcon.TimerSet.process_tasks | train | def process_tasks
loop do
task = mutex.synchronize { @queue.peek }
break unless task
now = Garcon.monotonic_time
diff = task.time - now
if diff <= 0
# We need to remove the task from the queue before passing it to the
# executor, to avoid race conditio... | ruby | {
"resource": ""
} |
q7192 | Roroacms.Admin::AdministratorsController.create | train | def create
@admin = Admin.new(administrator_params)
respond_to do |format|
if @admin.save
profile_images(params, @admin)
Emailer.profile(@admin).deliver
format.html { redirect_to admin_administrators_path, notice: I18n.t("controllers.admin.administrators.create.flash... | ruby | {
"resource": ""
} |
q7193 | Roroacms.Admin::AdministratorsController.edit | train | def edit
@admin = current_admin.id == params[:id].to_i ? @current_admin : Admin.find(params[:id])
# add breadcrumb and set title
set_title(I18n.t("controllers.admin.administrators.edit.title", username: @admin.username))
add_breadcrumb I18n.t("controllers.admin.administrators.edit.breadcrumb")
... | ruby | {
"resource": ""
} |
q7194 | Roroacms.Admin::AdministratorsController.update | train | def update
@admin = Admin.find(params[:id])
@admin.deal_with_cover params
respond_to do |format|
admin_passed =
if params[:admin][:password].blank?
@admin.update_without_password(administrator_params)
else
@admin.update_attributes(administrator... | ruby | {
"resource": ""
} |
q7195 | Roroacms.Admin::AdministratorsController.destroy | train | def destroy
@admin = Admin.find(params[:id])
@admin.destroy if @admin.overlord == 'N'
respond_to do |format|
format.html { redirect_to admin_administrators_path, notice: I18n.t("controllers.admin.administrators.destroy.flash.success") }
end
end | ruby | {
"resource": ""
} |
q7196 | Shells.PfShellWrapper.exec | train | def exec(*commands)
ret = ''
commands.each { |cmd| ret += shell.exec(cmd) }
ret + shell.exec('exec')
end | ruby | {
"resource": ""
} |
q7197 | Shells.PfShellWrapper.set_config_section | train | def set_config_section(section_name, values, message = '')
current_values = get_config_section(section_name)
changes = generate_config_changes("$config[#{section_name.to_s.inspect}]", current_values, values)
if changes&.any?
if message.to_s.strip == ''
message = "Updating #{sect... | ruby | {
"resource": ""
} |
q7198 | Shells.PfShellWrapper.enable_cert_auth | train | def enable_cert_auth(public_key = '~/.ssh/id_rsa.pub')
cert_regex = /^ssh-[rd]sa (?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)? \S*$/m
# get our cert unless the user provided a full cert for us.
unless public_key =~ cert_regex
public_key = File.expand_path(public_key)
... | ruby | {
"resource": ""
} |
q7199 | BarkestCore.HtmlHelper.glyph | train | def glyph(name, size = nil)
size = size.to_s.downcase
if %w(small smaller big bigger).include?(size)
size = ' glyph-' + size
else
size = ''
end
"<i class=\"glyphicon glyphicon-#{h name}#{size}\"></i>".html_safe
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.