_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3
values | text stringlengths 66 10.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q2700 | MongoidShortener.ShortenedUrlsController.translate | train | def translate
# pull the link out of the db
sl = ShortenedUrl.where(:unique_key => params[:unique_key][1..-1]).first
if sl
sl.inc(:use_count, 1)
# do a 301 redirect to the destination url
head :moved_permanently, :location => sl.url
else
# if we don't find the sh... | ruby | {
"resource": ""
} |
q2701 | ActsAsFerret.ActMethods.acts_as_ferret | train | def acts_as_ferret(options={})
extend ClassMethods
include InstanceMethods
include MoreLikeThis::InstanceMethods
if options[:rdig]
cattr_accessor :rdig_configuration
self.rdig_configuration = options[:rdig]
require 'rdig_adapter'
include ActsAsFerret::RdigAdapt... | ruby | {
"resource": ""
} |
q2702 | ActsAsFerret.ActMethods.define_to_field_method | train | def define_to_field_method(field, options = {})
method_name = "#{field}_to_ferret"
return if instance_methods.include?(method_name) # already defined
aaf_configuration[:defined_fields] ||= {}
aaf_configuration[:defined_fields][field] = options
dynamic_boost = options[:boost] if options[:bo... | ruby | {
"resource": ""
} |
q2703 | Minke.Command.create_dependencies | train | def create_dependencies task
project_name = "minke#{SecureRandom.urlsafe_base64(12)}".downcase.gsub(/[^0-9a-z ]/i, '')
network_name = ENV['DOCKER_NETWORK'] ||= "#{project_name}_default"
ENV['DOCKER_PROJECT'] = project_name
ENV['DOCKER_NETWORK'] = network_name
logger = Minke::Logging.creat... | ruby | {
"resource": ""
} |
q2704 | Rapinoe.Slide.write_preview_to_file | train | def write_preview_to_file(path)
FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'wb') do |out|
out.write(preview_data)
end
end | ruby | {
"resource": ""
} |
q2705 | Gemnasium.Configuration.is_valid? | train | def is_valid?
site_option_valid = !site.nil? && !site.empty?
api_key_option_valid = !api_key.nil? && !api_key.empty?
use_ssl_option_valid = !use_ssl.nil? && !!use_ssl == use_ssl # Check this is a boolean
api_version_option_valid = !api_version.nil? && !... | ruby | {
"resource": ""
} |
q2706 | GScraper.SponsoredLinks.ads_with_title | train | def ads_with_title(title)
return enum_for(:ads_with_title,title) unless block_given?
comparitor = if title.kind_of?(Regexp)
lambda { |ad| ad.title =~ title }
else
lambda { |ad| ad.title == title }
end
return ads_with do ... | ruby | {
"resource": ""
} |
q2707 | GScraper.SponsoredLinks.ads_with_url | train | def ads_with_url(url)
return enum_for(:ads_with_url,url) unless block_given?
comparitor = if url.kind_of?(Regexp)
lambda { |ad| ad.url =~ url }
else
lambda { |ad| ad.url == url }
end
return ads_with do |ad|
if co... | ruby | {
"resource": ""
} |
q2708 | GScraper.SponsoredLinks.ads_with_direct_url | train | def ads_with_direct_url(direct_url)
return enum_for(:ads_with_direct_url,direct_url) unless block_given?
comparitor = if direct_url.kind_of?(Regexp)
lambda { |ad| ad.direct_url =~ direct_url }
else
lambda { |ad| ad.direct_url == direct_url }
... | ruby | {
"resource": ""
} |
q2709 | Rapinoe.Keynote.aspect_ratio | train | def aspect_ratio
path = "/tmp/rapinoe-aspect"
write_preview_to_file(path)
dimensions = FastImage.size(path)
widescreen = (16/9.0)
if widescreen == (dimensions[0] / dimensions[1].to_f)
:widescreen
else
:standard
end
end | ruby | {
"resource": ""
} |
q2710 | Rapinoe.Keynote.colors | train | def colors
return @colors if @colors
path = "/tmp/rapinoe-aspect"
write_preview_to_file(path)
colors = Miro::DominantColors.new(path)
by_percentage = colors.by_percentage
hash = {}
colors.to_rgb.each_with_index do |hex, i|
hash[hex] = by_percentage[i]
end
... | ruby | {
"resource": ""
} |
q2711 | XCRes::XCAssets.ResourceImage.read | train | def read(hash)
self.scale = hash.delete('scale').sub(/x$/, '').to_i unless hash['scale'].nil?
KNOWN_KEYS.each do |key|
value = hash.delete(key.to_s.dasherize)
next if value.nil?
self.send "#{key}=".to_sym, value
end
self.attributes = hash
return self
end | ruby | {
"resource": ""
} |
q2712 | XCRes::XCAssets.ResourceImage.to_hash | train | def to_hash
hash = {}
hash['scale'] = "#{scale}x" unless scale.nil?
(KNOWN_KEYS - [:scale]).each do |key|
value = self.send(key)
hash[key.to_s.dasherize] = value.to_s unless value.nil?
end
attributes.each do |key, value|
hash[key.to_s] = value
end
ha... | ruby | {
"resource": ""
} |
q2713 | XCRes.AggregateAnalyzer.add_with_class | train | def add_with_class(analyzer_class, options={})
analyzer = analyzer_class.new(target, self.options.merge(options))
analyzer.exclude_file_patterns = exclude_file_patterns
analyzer.logger = logger
self.analyzers << analyzer
analyzer
end | ruby | {
"resource": ""
} |
q2714 | Lieu.Request.post | train | def post(path, options={})
response = request(:post, path, options)
response.delete(:status) if response.respond_to?(:status)
response
end | ruby | {
"resource": ""
} |
q2715 | MongoidShortener.ShortenedUrlsHelper.shortened_url | train | def shortened_url(url)
raise "Only String accepted: #{url}" unless url.class == String
short_url = MongoidShortener::ShortenedUrl.generate(url)
short_url
end | ruby | {
"resource": ""
} |
q2716 | ActsAsFerret.LocalIndex.ferret_index | train | def ferret_index
ensure_index_exists
(@ferret_index ||= Ferret::Index::Index.new(index_definition[:ferret])).tap do |idx|
idx.batch_size = index_definition[:reindex_batch_size]
idx.logger = logger
end
end | ruby | {
"resource": ""
} |
q2717 | ActsAsFerret.LocalIndex.rebuild_index | train | def rebuild_index
models = index_definition[:registered_models]
logger.debug "rebuild index with models: #{models.inspect}"
close
index = Ferret::Index::Index.new(index_definition[:ferret].dup.update(:auto_flush => false,
... | ruby | {
"resource": ""
} |
q2718 | ActsAsFerret.LocalIndex.process_query | train | def process_query(query, options = {})
return query unless String === query
ferret_index.synchronize do
if options[:analyzer]
# use per-query analyzer if present
qp = Ferret::QueryParser.new ferret_index.instance_variable_get('@options').merge(options)
reader = ferret_i... | ruby | {
"resource": ""
} |
q2719 | ActsAsFerret.LocalIndex.total_hits | train | def total_hits(query, options = {})
ferret_index.search(process_query(query, options), options).total_hits
end | ruby | {
"resource": ""
} |
q2720 | ActsAsFerret.LocalIndex.highlight | train | def highlight(key, query, options = {})
logger.debug("highlight: #{key} query: #{query}")
options.reverse_merge! :num_excerpts => 2, :pre_tag => '<em>', :post_tag => '</em>'
highlights = []
ferret_index.synchronize do
doc_num = document_number(key)
if options[:field]
h... | ruby | {
"resource": ""
} |
q2721 | ActsAsFerret.LocalIndex.document_number | train | def document_number(key)
docnum = ferret_index.doc_number(key)
# hits = ferret_index.search query_for_record(key)
# return hits.hits.first.doc if hits.total_hits == 1
raise "cannot determine document number for record #{key}" if docnum.nil?
docnum
end | ruby | {
"resource": ""
} |
q2722 | SocialMedia::Service.Facebook.get_app_access_token | train | def get_app_access_token
return connection_params[:app_access_token] if connection_params.has_key? :app_access_token
@oauth = Koala::Facebook::OAuth.new(connection_params[:app_id], connection_params[:app_secret], callback_url)
connection_params[:app_access_token] = @oauth.get_app_access_token
end | ruby | {
"resource": ""
} |
q2723 | ESP.Suppression.regions | train | def regions
# When regions come back in an include, the method still gets called, to return the object from the attributes.
return attributes['regions'] if attributes['regions'].present?
return [] unless respond_to? :region_ids
ESP::Region.where(id_in: region_ids)
end | ruby | {
"resource": ""
} |
q2724 | ESP.Suppression.external_accounts | train | def external_accounts
# When external_accounts come back in an include, the method still gets called, to return the object from the attributes.
return attributes['external_accounts'] if attributes['external_accounts'].present?
return [] unless respond_to? :external_account_ids
ESP::ExternalAccou... | ruby | {
"resource": ""
} |
q2725 | ESP.Suppression.signatures | train | def signatures
# When signatures come back in an include, the method still gets called, to return the object from the attributes.
return attributes['signatures'] if attributes['signatures'].present?
return [] unless respond_to? :signature_ids
ESP::Signature.where(id_in: signature_ids)
end | ruby | {
"resource": ""
} |
q2726 | ESP.Suppression.custom_signatures | train | def custom_signatures
# When custom_signatures come back in an include, the method still gets called, to return the object from the attributes.
return attributes['custom_signatures'] if attributes['custom_signatures'].present?
return [] unless respond_to? :custom_signature_ids
ESP::CustomSignatu... | ruby | {
"resource": ""
} |
q2727 | ESP.Region.suppress | train | def suppress(arguments = {})
arguments = arguments.with_indifferent_access
ESP::Suppression::Region.create(regions: [code], external_account_ids: Array(arguments[:external_account_ids]), reason: arguments[:reason])
end | ruby | {
"resource": ""
} |
q2728 | Tolaria.HelpLink.validate! | train | def validate!
if title.blank?
raise RuntimeError, "HelpLinks must provide a string title"
end
file_configured = (slug.present? && markdown_file.present?)
link_configured = link_to.present?
unless file_configured || link_configured
raise RuntimeError, "Incomplete HelpLink... | ruby | {
"resource": ""
} |
q2729 | Jabber.Bot.presence | train | def presence(presence=nil, status=nil, priority=nil)
@config[:presence] = presence
@config[:status] = status
@config[:priority] = priority
status_message = Presence.new(presence, status, priority)
@jabber.send!(status_message) if @jabber.connected?
end | ruby | {
"resource": ""
} |
q2730 | Jabber.Bot.add_command_alias | train | def add_command_alias(command_name, alias_command, callback) #:nodoc:
original_command = @commands[:meta][command_name]
original_command[:syntax] << alias_command[:syntax]
alias_name = command_name(alias_command[:syntax])
alias_command[:is_public] = original_command[:is_public]
add_comm... | ruby | {
"resource": ""
} |
q2731 | Jabber.Bot.add_command_meta | train | def add_command_meta(name, command, is_alias=false) #:nodoc:
syntax = command[:syntax]
@commands[:meta][name] = {
:syntax => syntax.is_a?(Array) ? syntax : [syntax],
:description => command[:description],
:is_public => command[:is_public] || false,
:is_alias => is_... | ruby | {
"resource": ""
} |
q2732 | Jabber.Bot.help_message | train | def help_message(sender, command_name) #:nodoc:
if command_name.nil? || command_name.length == 0
# Display help for all commands
help_message = "I understand the following commands:\n\n"
@commands[:meta].sort.each do |command|
# Thank you, Hash.sort
command = command[1... | ruby | {
"resource": ""
} |
q2733 | Jabber.Bot.start_listener_thread | train | def start_listener_thread #:nodoc:
listener_thread = Thread.new do
loop do
if @jabber.received_messages?
@jabber.received_messages do |message|
# Remove the Jabber resourse, if any
sender = message.from.to_s.sub(/\/.+$/, '')
if message.type ... | ruby | {
"resource": ""
} |
q2734 | EPP.Server.prepare_request | train | def prepare_request(command, extension = nil)
cmd = EPP::Requests::Command.new(req_tid, command, extension)
EPP::Request.new(cmd)
end | ruby | {
"resource": ""
} |
q2735 | EPP.Server.connection | train | def connection
@connection_errors = []
addrinfo.each do |_,port,_,addr,_,_,_|
retried = false
begin
@conn = TCPSocket.new(addr, port)
rescue Errno::EINVAL => e
if retried
message = e.message.split(" - ")[1]
@connection_errors << Errno::EINV... | ruby | {
"resource": ""
} |
q2736 | EPP.Server.send_frame | train | def send_frame(xml)
xml = xml.to_s if xml.kind_of?(Request)
@sock.write([xml.size + HEADER_LEN].pack("N") + xml)
end | ruby | {
"resource": ""
} |
q2737 | EPP.Server.recv_frame | train | def recv_frame
header = @sock.read(HEADER_LEN)
if header.nil? && @sock.eof?
raise ServerError, "Connection terminated by remote host"
elsif header.nil?
raise ServerError, "Failed to read header from remote host"
else
len = header.unpack('N')[0]
r... | ruby | {
"resource": ""
} |
q2738 | Tolaria.MarkdownRendererProxy.render | train | def render(document)
if Tolaria.config.markdown_renderer.nil?
return simple_format(document)
else
@markdown_renderer ||= Tolaria.config.markdown_renderer.constantize
return @markdown_renderer.render(document)
end
end | ruby | {
"resource": ""
} |
q2739 | ProblemChild.Helpers.base_sha | train | def base_sha
default_branch = client.repo(repo)[:default_branch]
branches.find { |branch| branch[:name] == default_branch }[:commit][:sha]
end | ruby | {
"resource": ""
} |
q2740 | ProblemChild.Helpers.patch_branch | train | def patch_branch
num = 1
branch_name = form_data['title'].parameterize
return branch_name unless branch_exists?(branch_name)
branch = "#{branch_name}-#{num}"
while branch_exists?(branch)
num += 1
branch = "#{branch_name}-#{num}"
end
branch
end | ruby | {
"resource": ""
} |
q2741 | ProblemChild.Helpers.create_pull_request | train | def create_pull_request
unless uploads.empty?
branch = patch_branch
create_branch(branch)
uploads.each do |key, upload|
client.create_contents(
repo,
upload[:filename],
"Create #{upload[:filename]}",
branch: branch,
file... | ruby | {
"resource": ""
} |
q2742 | Runfile.ExecHandler.run | train | def run(cmd)
cmd = @before_run_block.call(cmd) if @before_run_block
return false unless cmd
say "!txtgrn!> #{cmd}" unless Runfile.quiet
system cmd
@after_run_block.call(cmd) if @after_run_block
end | ruby | {
"resource": ""
} |
q2743 | Runfile.ExecHandler.run! | train | def run!(cmd)
cmd = @before_run_block.call(cmd) if @before_run_block
return false unless cmd
say "!txtgrn!> #{cmd}" unless Runfile.quiet
exec cmd
end | ruby | {
"resource": ""
} |
q2744 | Runfile.ExecHandler.run_bg | train | def run_bg(cmd, pid: nil, log: '/dev/null')
cmd = @before_run_block.call(cmd) if @before_run_block
return false unless cmd
full_cmd = "exec #{cmd} >#{log} 2>&1"
say "!txtgrn!> #{full_cmd}" unless Runfile.quiet
process = IO.popen "exec #{cmd} >#{log} 2>&1"
File.write pidfile(pid), pro... | ruby | {
"resource": ""
} |
q2745 | Runfile.ExecHandler.stop_bg | train | def stop_bg(pid)
file = pidfile(pid)
if File.exist? file
pid = File.read file
File.delete file
run "kill -s TERM #{pid}"
else
say "!txtred!PID file not found." unless Runfile.quiet
end
end | ruby | {
"resource": ""
} |
q2746 | ESP.Console.start | train | def start # rubocop:disable Metrics/MethodLength
ARGV.clear
IRB.setup nil
IRB.conf[:PROMPT] = {}
IRB.conf[:IRB_NAME] = 'espsdk'
IRB.conf[:PROMPT][:ESPSDK] = {
PROMPT_I: '%N:%03n:%i> ',
PROMPT_N: '%N:%03n:%i> ',
PROMPT_S: '%N:%03n:%i%l ',
PRO... | ruby | {
"resource": ""
} |
q2747 | EPP.XMLHelpers.epp_namespace | train | def epp_namespace(node, name = nil, namespaces = {})
return namespaces['epp'] if namespaces.has_key?('epp')
xml_namespace(node, name, 'urn:ietf:params:xml:ns:epp-1.0')
end | ruby | {
"resource": ""
} |
q2748 | EPP.XMLHelpers.epp_node | train | def epp_node(name, value = nil, namespaces = {})
value, namespaces = nil, value if value.kind_of?(Hash)
node = xml_node(name, value)
node.namespaces.namespace = epp_namespace(node, nil, namespaces)
node
end | ruby | {
"resource": ""
} |
q2749 | EPP.XMLHelpers.xml_namespace | train | def xml_namespace(node, name, uri, namespaces = {})
XML::Namespace.new(node, name, uri)
end | ruby | {
"resource": ""
} |
q2750 | EPP.XMLHelpers.xml_document | train | def xml_document(obj)
case obj
when XML::Document
XML::Document.document(obj)
else
XML::Document.new('1.0')
end
end | ruby | {
"resource": ""
} |
q2751 | Vanguard.DSL.method_missing | train | def method_missing(method_name, *arguments)
klass = REGISTRY.fetch(method_name) { super }
Evaluator.new(klass, arguments).rules.each do |rule|
add(rule)
end
self
end | ruby | {
"resource": ""
} |
q2752 | Cliqr.Interface.execute | train | def execute(args = [], **options)
execute_internal(args, options)
Executor::ExitCode.code(:success)
rescue Cliqr::Error::CliqrError => e
puts e.message
Executor::ExitCode.code(e)
end | ruby | {
"resource": ""
} |
q2753 | Cliqr.Interface.execute_internal | train | def execute_internal(args = [], **options)
options = {
output: :default,
environment: :cli
}.merge(options)
@runner.execute(args, options)
end | ruby | {
"resource": ""
} |
q2754 | Cliqr.InterfaceBuilder.build | train | def build
raise Cliqr::Error::ConfigNotFound, 'a valid config should be defined' if @config.nil?
unless @config.valid?
raise Cliqr::Error::ValidationError, \
"invalid Cliqr interface configuration - [#{@config.errors}]"
end
Interface.new(@config)
end | ruby | {
"resource": ""
} |
q2755 | Runfile.Runner.execute | train | def execute(argv, filename='Runfile')
@ignore_settings = !filename
argv = expand_shortcuts argv
filename and File.file?(filename) or handle_no_runfile argv
begin
load settings.helper if settings.helper
load filename
rescue => ex
abort "Runfile error:\n#{ex.message}... | ruby | {
"resource": ""
} |
q2756 | Runfile.Runner.add_action | train | def add_action(name, altname=nil, &block)
if @last_usage.nil?
@last_usage = altname ? "(#{name}|#{altname})" : name
end
[@namespace, @superspace].each do |prefix|
prefix or next
name = "#{prefix}_#{name}"
@last_usage = "#{prefix} #{last_usage}" unless @last_usage == fa... | ruby | {
"resource": ""
} |
q2757 | Runfile.Runner.add_option | train | def add_option(flag, text, scope=nil)
scope or scope = 'Options'
@options[scope] ||= {}
@options[scope][flag] = text
end | ruby | {
"resource": ""
} |
q2758 | Runfile.Runner.add_param | train | def add_param(name, text, scope=nil)
scope or scope = 'Parameters'
@params[scope] ||= {}
@params[scope][name] = text
end | ruby | {
"resource": ""
} |
q2759 | Runfile.Runner.run | train | def run(*argv)
begin
docopt_exec argv
rescue Docopt::Exit => ex
puts ex.message
exit 2
end
end | ruby | {
"resource": ""
} |
q2760 | ActiveResource.Validations.load_remote_errors | train | def load_remote_errors(remote_errors, save_cache = false)
if self.class.format == ActiveResource::Formats::JsonAPIFormat
errors.from_json_api(remote_errors.response.body, save_cache)
elsif self.class.format == ActiveResource::Formats[:json]
super
end
end | ruby | {
"resource": ""
} |
q2761 | Slugalicious.ClassMethods.find_from_slug_path | train | def find_from_slug_path(path)
slug = path.split('/').last
scope = path[0..(-(slug.size + 1))]
find_from_slug slug, scope
end | ruby | {
"resource": ""
} |
q2762 | Oxblood.Pipeline.sync | train | def sync
serialized_commands = @commands.map { |c| Protocol.build_command(*c) }
connection.socket.write(serialized_commands.join)
Array.new(@commands.size) { connection.read_response }
ensure
@commands.clear
end | ruby | {
"resource": ""
} |
q2763 | LonoCfn.Base.get_source_path | train | def get_source_path(path, type)
default_convention_path = convention_path(@stack_name, type)
return default_convention_path if path.nil?
# convention path based on the input from the user
convention_path(path, type)
end | ruby | {
"resource": ""
} |
q2764 | LonoCfn.Base.detect_format | train | def detect_format
formats = Dir.glob("#{@project_root}/output/**/*").map { |path| path }.
reject { |s| s =~ %r{/params/} }. # reject output/params folder
map { |path| File.extname(path) }.
reject { |s| s.empty? }. # reject ""
uniq
if fo... | ruby | {
"resource": ""
} |
q2765 | ActiveResource.PaginatedCollection.page | train | def page(page_number = nil)
fail ArgumentError, "You must supply a page number." unless page_number.present?
fail ArgumentError, "Page number cannot be less than 1." if page_number.to_i < 1
fail ArgumentError, "Page number cannot be greater than the last page number." if page_number.to_i > last_page_n... | ruby | {
"resource": ""
} |
q2766 | Runfile.RunfileHelper.make_runfile | train | def make_runfile(name=nil)
name = 'Runfile' if name.nil?
template = File.expand_path("../templates/Runfile", __FILE__)
name += ".runfile" unless name == 'Runfile'
dest = "#{Dir.pwd}/#{name}"
begin
File.write(dest, File.read(template))
puts "#{name} created."
rescue =>... | ruby | {
"resource": ""
} |
q2767 | Runfile.RunfileHelper.show_make_help | train | def show_make_help(runfiles, compact=false)
say "!txtpur!Runfile engine v#{Runfile::VERSION}" unless compact
if runfiles.size < 3 and !compact
say "\nTip: Type '!txtblu!run new!txtrst!' or '!txtblu!run new name!txtrst!' to create a runfile.\nFor global access, place !txtblu!named.runfiles!txtrst! in... | ruby | {
"resource": ""
} |
q2768 | Runfile.RunfileHelper.say_runfile_list | train | def say_runfile_list(runfiles)
runfile_paths = runfiles.map { |f| File.dirname f }
max = runfile_paths.max_by(&:length).size
width = detect_terminal_size[0]
runfiles.each do |f|
f[/([^\/]+).runfile$/]
command = "run #{$1}"
spacer_size = width - max - command.size - 6
... | ruby | {
"resource": ""
} |
q2769 | Runfile.RunfileHelper.say_runfile_usage | train | def say_runfile_usage(runfiles)
runfiles_as_columns = get_runfiles_as_columns runfiles
say "#{settings.intro}\n" if settings.intro
say "Usage: run <file>"
say runfiles_as_columns
show_shortcuts if settings.shortcuts
end | ruby | {
"resource": ""
} |
q2770 | Runfile.RunfileHelper.show_shortcuts | train | def show_shortcuts
say "\nShortcuts:"
max = settings.shortcuts.keys.max_by(&:length).length
settings.shortcuts.each_pair do |shortcut, command|
say " #{shortcut.rjust max} : #{command}"
end
end | ruby | {
"resource": ""
} |
q2771 | Runfile.RunfileHelper.get_runfiles_as_columns | train | def get_runfiles_as_columns(runfiles)
namelist = runfile_names runfiles
width = detect_terminal_size[0]
max = namelist.max_by(&:length).length
message = " " + namelist.map {|f| f.ljust max+1 }.join(' ')
word_wrap message, width
end | ruby | {
"resource": ""
} |
q2772 | ESP.Resource.serializable_hash | train | def serializable_hash(*)
h = attributes.extract!('included')
h['data'] = { 'type' => self.class.to_s.underscore.sub('esp/', '').pluralize,
'attributes' => changed_attributes.except('id', 'type', 'created_at', 'updated_at', 'relationships') }
h['data'... | ruby | {
"resource": ""
} |
q2773 | Oxblood.Pool.with | train | def with
conn = @pool.checkout
session = Session.new(conn)
yield(session)
ensure
if conn
session.discard if conn.in_transaction?
@pool.checkin
end
end | ruby | {
"resource": ""
} |
q2774 | Runfile.DocoptHelper.docopt_usage | train | def docopt_usage
doc = ["\nUsage:"];
@actions.each do |_name, action|
doc << " run #{action.usage}" unless action.usage == false
end
basic_flags = @version ? "(-h|--help|--version)" : "(-h|--help)"
if @superspace
doc << " run #{@superspace} #{basic_flags}\n"
else
... | ruby | {
"resource": ""
} |
q2775 | Runfile.DocoptHelper.docopt_commands | train | def docopt_commands(width)
doc = []
caption_printed = false
@actions.each do |_name, action|
action.help or next
doc << "Commands:" unless caption_printed
caption_printed = true
helpline = " #{action.help}"
wrapped = word_wrap helpline, width
doc <... | ruby | {
"resource": ""
} |
q2776 | Runfile.DocoptHelper.docopt_examples | train | def docopt_examples(width)
return [] if @examples.empty?
doc = ["Examples:"]
base_command = @superspace ? "run #{@superspace}" : "run"
@examples.each do |command|
helpline = " #{base_command} #{command}"
wrapped = word_wrap helpline, width
doc << "#{wrapped}"
end... | ruby | {
"resource": ""
} |
q2777 | Tolaria.FormBuildable.hint | train | def hint(hint_text, options = {})
css_class = "hint #{options.delete(:class)}"
content_tag(:p, content_tag(:span, hint_text.chomp), class:css_class, **options)
end | ruby | {
"resource": ""
} |
q2778 | Tolaria.FormBuildable.image_association_select | train | def image_association_select(method, collection, value_method, text_method, preview_url_method, options = {})
render(partial:"admin/shared/forms/image_association_select", locals: {
f: self,
method: method,
collection: collection,
value_method: value_method,
text_method: te... | ruby | {
"resource": ""
} |
q2779 | Tolaria.FormBuildable.markdown_composer | train | def markdown_composer(method, options = {})
render(partial:"admin/shared/forms/markdown_composer", locals: {
f: self,
method: method,
options: options,
})
end | ruby | {
"resource": ""
} |
q2780 | Tolaria.FormBuildable.attachment_field | train | def attachment_field(method, options = {})
render(partial:"admin/shared/forms/attachment_field", locals: {
f: self,
method: method,
options: options,
})
end | ruby | {
"resource": ""
} |
q2781 | Tolaria.FormBuildable.image_field | train | def image_field(method, options = {})
render(partial:"admin/shared/forms/image_field", locals: {
f: self,
method: method,
options: options,
preview_url: options[:preview_url]
})
end | ruby | {
"resource": ""
} |
q2782 | Tolaria.FormBuildable.timestamp_field | train | def timestamp_field(method, options = {})
render(partial:"admin/shared/forms/timestamp_field", locals: {
f: self,
method: method,
options: options,
})
end | ruby | {
"resource": ""
} |
q2783 | Tolaria.FormBuildable.slug_field | train | def slug_field(method, options = {})
pattern = options.delete(:pattern)
preview_value = self.object.send(method).try(:parameterize).presence || "*"
render(partial:"admin/shared/forms/slug_field", locals: {
f: self,
method: method,
options: options,
preview_value: previe... | ruby | {
"resource": ""
} |
q2784 | Tolaria.FormBuildable.swatch_field | train | def swatch_field(method, options = {})
render(partial:"admin/shared/forms/swatch_field", locals: {
f: self,
method: method,
options: options,
})
end | ruby | {
"resource": ""
} |
q2785 | Oxblood.RSocket.gets | train | def gets(separator, timeout = @timeout)
while (crlf = @buffer.index(separator)).nil?
@buffer << readpartial(1024, timeout)
end
@buffer.slice!(0, crlf + separator.bytesize)
end | ruby | {
"resource": ""
} |
q2786 | Oxblood.RSocket.write | train | def write(data, timeout = @timeout)
full_size = data.bytesize
while data.bytesize > 0
written = socket.write_nonblock(data, exception: false)
if written == :wait_writable
socket.wait_writable(timeout) or fail_with_timeout!
else
data = data.byteslice(written..-1)... | ruby | {
"resource": ""
} |
q2787 | Laundry.SOAPModel.instance_action_module | train | def instance_action_module
@instance_action_module ||= Module.new do
# Returns the <tt>Savon::Client</tt> from the class instance.
def client(&block)
self.class.client(&block)
end
private
def merged_default_body(body = {})
default = self.respond_to?(:... | ruby | {
"resource": ""
} |
q2788 | Vanguard.Result.violations | train | def violations
validator.rules.each_with_object(Set.new) do |rule, violations|
violations.merge(rule.violations(resource))
end
end | ruby | {
"resource": ""
} |
q2789 | RFuse.Fuse.run | train | def run(signals=Signal.list.keys)
if mounted?
begin
traps = trap_signals(*signals)
self.loop()
ensure
traps.each { |t| Signal.trap(t,"DEFAULT") }
unmount()
end
end
... | ruby | {
"resource": ""
} |
q2790 | RFuse.Fuse.loop | train | def loop()
raise RFuse::Error, "Already running!" if @running
raise RFuse::Error, "FUSE not mounted" unless mounted?
@running = true
while @running do
begin
ready, ignore, errors = IO.select([@fuse_io,@pr],[],[@fuse_io])
... | ruby | {
"resource": ""
} |
q2791 | RFuse.FuseDelegator.debug= | train | def debug=(value)
value = value ? true : false
if @debug && !value
$stderr.puts "=== #{ self }.debug=false"
elsif !@debug && value
$stderr.puts "=== #{ self }.debug=true"
end
@debug = value
end | ruby | {
"resource": ""
} |
q2792 | Watir.Element.dom_changed? | train | def dom_changed?(delay: 1.1)
element_call do
begin
driver.manage.timeouts.script_timeout = delay + 1
driver.execute_async_script(DOM_WAIT_JS, wd, delay)
rescue Selenium::WebDriver::Error::JavascriptError => error
# sometimes we start script execution before new page i... | ruby | {
"resource": ""
} |
q2793 | ESP.Signature.run! | train | def run!(arguments = {})
result = run(arguments)
return result if result.is_a?(ActiveResource::Collection)
result.message = result.errors.full_messages.join(' ')
fail(ActiveResource::ResourceInvalid.new(result)) # rubocop:disable Style/RaiseArgs
end | ruby | {
"resource": ""
} |
q2794 | ESP.Signature.run | train | def run(arguments = {})
arguments = arguments.with_indifferent_access
attributes['external_account_id'] ||= arguments[:external_account_id]
attributes['region'] ||= arguments[:region]
response = connection.post("#{self.class.prefix}signatures/#{id}/run.json", to_json)
ESP::Alert.send(:ins... | ruby | {
"resource": ""
} |
q2795 | ESP.Signature.suppress | train | def suppress(arguments = {})
arguments = arguments.with_indifferent_access
ESP::Suppression::Signature.create(signature_ids: [id], regions: Array(arguments[:regions]), external_account_ids: Array(arguments[:external_account_ids]), reason: arguments[:reason])
end | ruby | {
"resource": ""
} |
q2796 | TableSetter.Table.csv_data | train | def csv_data
case
when google_key || url then Curl::Easy.perform(uri).body_str
when file then File.open(uri).read
end
end | ruby | {
"resource": ""
} |
q2797 | TableSetter.Table.updated_at | train | def updated_at
csv_time = google_key.nil? ? modification_time(uri) : google_modification_time
(csv_time > yaml_time ? csv_time : yaml_time).to_s
end | ruby | {
"resource": ""
} |
q2798 | TableSetter.Table.paginate! | train | def paginate!(curr_page)
return if !hard_paginate?
@page = curr_page.to_i
raise ArgumentError if @page < 1 || @page > total_pages
adj_page = @page - 1 > 0 ? @page - 1 : 0
@prev_page = adj_page > 0 ? adj_page : nil
@next_page = page < total_pages ? (@page + 1) : nil
@data.only!(... | ruby | {
"resource": ""
} |
q2799 | TableSetter.Table.sort_array | train | def sort_array
if @data.sorted_by
@data.sorted_by.inject([]) do |memo, (key, value)|
memo << [@data.columns.index(key), value == 'descending' ? 1 : 0]
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.