_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3 values | text stringlengths 66 10.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q18200 | CukeModeler.Gherkin6Adapter.adapt_comment! | train | def adapt_comment!(parsed_comment)
# Saving off the original data
parsed_comment['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_comment))
parsed_comment['text'] = parsed_comment.delete(:text)
parsed_comment['line'] = parsed_comment.delete(:location)[:line]
end | ruby | {
"resource": ""
} |
q18201 | CukeModeler.Feature.to_s | train | def to_s
text = ''
text << tag_output_string + "\n" unless tags.empty?
text << "#{@keyword}:#{name_output_string}"
text << "\n" + description_output_string unless (description.nil? || description.empty?)
text << "\n\n" + background_output_string if background
text << "\n\n" + tests_output_string unless tests.empty?
text
end | ruby | {
"resource": ""
} |
q18202 | CukeModeler.Step.to_s | train | def to_s
text = "#{keyword} #{self.text}"
text << "\n" + block.to_s.split("\n").collect { |line| " #{line}" }.join("\n") if block
text
end | ruby | {
"resource": ""
} |
q18203 | CukeModeler.Gherkin3Adapter.adapt_doc_string! | train | def adapt_doc_string!(parsed_doc_string)
# Saving off the original data
parsed_doc_string['cuke_modeler_parsing_data'] = Marshal::load(Marshal.dump(parsed_doc_string))
parsed_doc_string['value'] = parsed_doc_string.delete(:content)
parsed_doc_string['content_type'] = parsed_doc_string.delete(:contentType)
parsed_doc_string['line'] = parsed_doc_string.delete(:location)[:line]
end | ruby | {
"resource": ""
} |
q18204 | CukeModeler.Outline.to_s | train | def to_s
text = ''
text << tag_output_string + "\n" unless tags.empty?
text << "#{@keyword}:#{name_output_string}"
text << "\n" + description_output_string unless (description.nil? || description.empty?)
text << "\n" unless (steps.empty? || description.nil? || description.empty?)
text << "\n" + steps_output_string unless steps.empty?
text << "\n\n" + examples_output_string unless examples.empty?
text
end | ruby | {
"resource": ""
} |
q18205 | CukeModeler.Containing.each_descendant | train | def each_descendant(&block)
children.each do |child_model|
block.call(child_model)
child_model.each_descendant(&block) if child_model.respond_to?(:each_descendant)
end
end | ruby | {
"resource": ""
} |
q18206 | CukeModeler.Nested.get_ancestor | train | def get_ancestor(ancestor_type)
target_type = {:directory => [Directory],
:feature_file => [FeatureFile],
:feature => [Feature],
:test => [Scenario, Outline, Background],
:background => [Background],
:scenario => [Scenario],
:outline => [Outline],
:step => [Step],
:table => [Table],
:example => [Example],
:row => [Row]
}[ancestor_type]
raise(ArgumentError, "Unknown ancestor type '#{ancestor_type}'.") if target_type.nil?
ancestor = self.parent_model
until target_type.include?(ancestor.class) || ancestor.nil?
ancestor = ancestor.parent_model
end
ancestor
end | ruby | {
"resource": ""
} |
q18207 | CukeModeler.Example.to_s | train | def to_s
text = ''
text << tag_output_string + "\n" unless tags.empty?
text << "#{@keyword}:#{name_output_string}"
text << "\n" + description_output_string unless (description.nil? || description.empty?)
text << "\n" unless (rows.empty? || description.nil? || description.empty?)
text << "\n" + parameters_output_string if parameter_row
text << "\n" + rows_output_string unless argument_rows.empty?
text
end | ruby | {
"resource": ""
} |
q18208 | Vines.Stanza.broadcast | train | def broadcast(recipients)
@node[FROM] = stream.user.jid.to_s
recipients.each do |recipient|
@node[TO] = recipient.user.jid.to_s
recipient.write(@node)
end
end | ruby | {
"resource": ""
} |
q18209 | Vines.Stanza.local? | train | def local?
return true unless ROUTABLE_STANZAS.include?(@node.name)
to = JID.new(@node[TO])
to.empty? || local_jid?(to)
end | ruby | {
"resource": ""
} |
q18210 | Vines.Stanza.send_unavailable | train | def send_unavailable(from, to)
available = router.available_resources(from, to)
stanzas = available.map {|stream| unavailable(stream.user.jid) }
broadcast_to_available_resources(stanzas, to)
end | ruby | {
"resource": ""
} |
q18211 | Vines.Stanza.unavailable | train | def unavailable(from)
doc = Document.new
doc.create_element('presence',
'from' => from.to_s,
'id' => Kit.uuid,
'type' => 'unavailable')
end | ruby | {
"resource": ""
} |
q18212 | Vines.Stanza.send_to_remote | train | def send_to_remote(stanzas, to)
return false if local_jid?(to)
to = JID.new(to)
stanzas.each do |el|
el[TO] = to.bare.to_s
router.route(el)
end
true
end | ruby | {
"resource": ""
} |
q18213 | Vines.Stanza.send_to_recipients | train | def send_to_recipients(stanzas, recipients)
recipients.each do |recipient|
stanzas.each do |el|
el[TO] = recipient.user.jid.to_s
recipient.write(el)
end
end
end | ruby | {
"resource": ""
} |
q18214 | Vines.User.update_from | train | def update_from(user)
@name = user.name
@password = user.password
@roster = user.roster.map {|c| c.clone }
end | ruby | {
"resource": ""
} |
q18215 | Vines.User.contact | train | def contact(jid)
bare = JID.new(jid).bare
@roster.find {|c| c.jid.bare == bare }
end | ruby | {
"resource": ""
} |
q18216 | Vines.User.remove_contact | train | def remove_contact(jid)
bare = JID.new(jid).bare
@roster.reject! {|c| c.jid.bare == bare }
end | ruby | {
"resource": ""
} |
q18217 | Vines.User.request_subscription | train | def request_subscription(jid)
unless contact = contact(jid)
contact = Contact.new(:jid => jid)
@roster << contact
end
contact.ask = 'subscribe' if %w[none from].include?(contact.subscription)
end | ruby | {
"resource": ""
} |
q18218 | Vines.User.add_subscription_from | train | def add_subscription_from(jid)
unless contact = contact(jid)
contact = Contact.new(:jid => jid)
@roster << contact
end
contact.subscribe_from
end | ruby | {
"resource": ""
} |
q18219 | Vines.User.to_roster_xml | train | def to_roster_xml(id)
doc = Nokogiri::XML::Document.new
doc.create_element('iq', 'id' => id, 'type' => 'result') do |el|
el << doc.create_element('query', 'xmlns' => 'jabber:iq:roster') do |query|
@roster.sort!.each do |contact|
query << contact.to_roster_xml
end
end
end
end | ruby | {
"resource": ""
} |
q18220 | Vines.Contact.send_roster_push | train | def send_roster_push(recipient)
doc = Nokogiri::XML::Document.new
node = doc.create_element('iq',
'id' => Kit.uuid,
'to' => recipient.user.jid.to_s,
'type' => 'set')
node << doc.create_element('query', 'xmlns' => NAMESPACES[:roster]) do |query|
query << to_roster_xml
end
recipient.write(node)
end | ruby | {
"resource": ""
} |
q18221 | Vines.CLI.start | train | def start
register_storage
opts = parse(ARGV)
check_config(opts)
command = Command.const_get(opts[:command].capitalize).new
begin
command.run(opts)
rescue SystemExit
# do nothing
rescue Exception => e
puts e.message
exit(1)
end
end | ruby | {
"resource": ""
} |
q18222 | Vines.CLI.check_config | train | def check_config(opts)
return if %w[bcrypt init].include?(opts[:command])
unless File.exists?(opts[:config])
puts "No config file found at #{opts[:config]}"
exit(1)
end
end | ruby | {
"resource": ""
} |
q18223 | Vines.Config.pubsub | train | def pubsub(domain)
host = @vhosts.values.find {|host| host.pubsub?(domain) }
host.pubsubs[domain.to_s] if host
end | ruby | {
"resource": ""
} |
q18224 | Vines.Config.component? | train | def component?(*jids)
!jids.flatten.index do |jid|
!component_password(JID.new(jid).domain)
end
end | ruby | {
"resource": ""
} |
q18225 | Vines.Config.component_password | train | def component_password(domain)
host = @vhosts.values.find {|host| host.component?(domain) }
host.password(domain) if host
end | ruby | {
"resource": ""
} |
q18226 | Vines.Config.local_jid? | train | def local_jid?(*jids)
!jids.flatten.index do |jid|
!vhost?(JID.new(jid).domain)
end
end | ruby | {
"resource": ""
} |
q18227 | Vines.Config.allowed? | train | def allowed?(to, from)
to, from = JID.new(to), JID.new(from)
return false if to.empty? || from.empty?
return true if to.domain == from.domain # same domain always allowed
return cross_domain?(to, from) if local_jid?(to, from) # both virtual hosted here
return check_subdomains(to, from) if subdomain?(to, from) # component/pubsub to component/pubsub
return check_subdomain(to, from) if subdomain?(to) # to component/pubsub
return check_subdomain(from, to) if subdomain?(from) # from component/pubsub
return cross_domain?(to) if local_jid?(to) # from is remote
return cross_domain?(from) if local_jid?(from) # to is remote
return false
end | ruby | {
"resource": ""
} |
q18228 | Vines.Config.strip_domain | train | def strip_domain(jid)
domain = jid.domain.split('.').drop(1).join('.')
JID.new(domain)
end | ruby | {
"resource": ""
} |
q18229 | Vines.Config.cross_domain? | train | def cross_domain?(*jids)
!jids.flatten.index do |jid|
!vhost(jid.domain).cross_domain_messages?
end
end | ruby | {
"resource": ""
} |
q18230 | Vines.Cluster.start | train | def start
@connection.connect
@publisher.broadcast(:online)
@subscriber.subscribe
EM.add_periodic_timer(1) { heartbeat }
at_exit do
@publisher.broadcast(:offline)
@sessions.delete_all(@id)
end
end | ruby | {
"resource": ""
} |
q18231 | Vines.Cluster.query | train | def query(name, *args)
fiber, yielding = Fiber.current, true
req = connection.send(name, *args)
req.errback { fiber.resume rescue yielding = false }
req.callback {|response| fiber.resume(response) }
Fiber.yield if yielding
end | ruby | {
"resource": ""
} |
q18232 | Vines.Storage.authenticate | train | def authenticate(username, password)
user = find_user(username)
hash = BCrypt::Password.new(user.password) rescue nil
(hash && hash == password) ? user : nil
end | ruby | {
"resource": ""
} |
q18233 | Vines.Storage.authenticate_with_ldap | train | def authenticate_with_ldap(username, password, &block)
op = operation { ldap.authenticate(username, password) }
cb = proc {|user| save_ldap_user(user, &block) }
EM.defer(op, cb)
end | ruby | {
"resource": ""
} |
q18234 | Vines.Storage.save_ldap_user | train | def save_ldap_user(user, &block)
Fiber.new do
if user.nil?
block.call
elsif found = find_user(user.jid)
block.call(found)
else
save_user(user)
block.call(user)
end
end.resume
end | ruby | {
"resource": ""
} |
q18235 | Vines.Router.connected_resources | train | def connected_resources(jid, from, proxies=true)
jid, from = JID.new(jid), JID.new(from)
return [] unless @config.allowed?(jid, from)
local = @clients[jid.bare] || EMPTY
local = local.select {|stream| stream.user.jid == jid } unless jid.bare?
remote = proxies ? proxies(jid) : EMPTY
[local, remote].flatten
end | ruby | {
"resource": ""
} |
q18236 | Vines.Router.delete | train | def delete(stream)
case stream_type(stream)
when :client then
return unless stream.connected?
jid = stream.user.jid.bare
streams = @clients[jid] || []
streams.delete(stream)
@clients.delete(jid) if streams.empty?
when :server then @servers.delete(stream)
when :component then @components.delete(stream)
end
end | ruby | {
"resource": ""
} |
q18237 | Vines.Router.route | train | def route(stanza)
to, from = %w[to from].map {|attr| JID.new(stanza[attr]) }
return unless @config.allowed?(to, from)
key = [to.domain, from.domain]
if stream = connection_to(to, from)
stream.write(stanza)
elsif @pending.key?(key)
@pending[key] << stanza
elsif @config.s2s?(to.domain)
@pending[key] << stanza
Vines::Stream::Server.start(@config, to.domain, from.domain) do |stream|
stream ? send_pending(key, stream) : return_pending(key)
@pending.delete(key)
end
else
raise StanzaErrors::RemoteServerNotFound.new(stanza, 'cancel')
end
end | ruby | {
"resource": ""
} |
q18238 | Vines.Router.size | train | def size
clients = @clients.values.inject(0) {|sum, arr| sum + arr.size }
clients + @servers.size + @components.size
end | ruby | {
"resource": ""
} |
q18239 | Vines.Router.return_pending | train | def return_pending(key)
@pending[key].each do |stanza|
to, from = JID.new(stanza['to']), JID.new(stanza['from'])
xml = StanzaErrors::RemoteServerNotFound.new(stanza, 'cancel').to_xml
if @config.component?(from)
connection_to(from, to).write(xml) rescue nil
else
connected_resources(from, to).each {|c| c.write(xml) }
end
end
end | ruby | {
"resource": ""
} |
q18240 | Vines.Router.clients | train | def clients(jids, from, &filter)
jids = filter_allowed(jids, from)
local = @clients.values_at(*jids).compact.flatten.select(&filter)
proxies = proxies(*jids).select(&filter)
[local, proxies].flatten
end | ruby | {
"resource": ""
} |
q18241 | Vines.Router.filter_allowed | train | def filter_allowed(jids, from)
from = JID.new(from)
jids.flatten.map {|jid| JID.new(jid).bare }
.select {|jid| @config.allowed?(jid, from) }
end | ruby | {
"resource": ""
} |
q18242 | Vines.Daemon.running? | train | def running?
begin
pid && Process.kill(0, pid)
rescue Errno::ESRCH
delete_pid
false
rescue Errno::EPERM
true
end
end | ruby | {
"resource": ""
} |
q18243 | Vines.Store.domain? | train | def domain?(pem, domain)
if cert = OpenSSL::X509::Certificate.new(pem) rescue nil
OpenSSL::SSL.verify_certificate_identity(cert, domain) rescue false
end
end | ruby | {
"resource": ""
} |
q18244 | Vines.Store.files_for_domain | train | def files_for_domain(domain)
crt = File.expand_path("#{domain}.crt", @dir)
key = File.expand_path("#{domain}.key", @dir)
return [crt, key] if File.exists?(crt) && File.exists?(key)
# Might be a wildcard cert file.
@@sources.each do |file, certs|
certs.each do |cert|
if OpenSSL::SSL.verify_certificate_identity(cert, domain)
key = file.chomp(File.extname(file)) + '.key'
return [file, key] if File.exists?(file) && File.exists?(key)
end
end
end
nil
end | ruby | {
"resource": ""
} |
q18245 | Vines.Stream.post_init | train | def post_init
@remote_addr, @local_addr = addresses
@user, @closed, @stanza_size = nil, false, 0
@bucket = TokenBucket.new(100, 10)
@store = Store.new(@config.certs)
@nodes = EM::Queue.new
process_node_queue
create_parser
log.info { "%s %21s -> %s" %
['Stream connected:'.ljust(PAD), @remote_addr, @local_addr] }
end | ruby | {
"resource": ""
} |
q18246 | Vines.Stream.receive_data | train | def receive_data(data)
return if @closed
@stanza_size += data.bytesize
if @stanza_size < max_stanza_size
@parser << data rescue error(StreamErrors::NotWellFormed.new)
else
error(StreamErrors::PolicyViolation.new('max stanza size reached'))
end
end | ruby | {
"resource": ""
} |
q18247 | Vines.Stream.write | train | def write(data)
log_node(data, :out)
if data.respond_to?(:to_xml)
data = data.to_xml(:indent => 0)
end
send_data(data)
end | ruby | {
"resource": ""
} |
q18248 | Vines.Stream.error | train | def error(e)
case e
when SaslError, StanzaError
write(e.to_xml)
when StreamError
send_stream_error(e)
close_stream
else
log.error(e)
send_stream_error(StreamErrors::InternalServerError.new)
close_stream
end
end | ruby | {
"resource": ""
} |
q18249 | Vines.Stream.addresses | train | def addresses
[get_peername, get_sockname].map do |addr|
addr ? Socket.unpack_sockaddr_in(addr)[0, 2].reverse.join(':') : 'unknown'
end
end | ruby | {
"resource": ""
} |
q18250 | Rosemary.Member.to_xml | train | def to_xml(options = {})
xml = options[:builder] ||= Builder::XmlMarkup.new
xml.instruct! unless options[:skip_instruct]
xml.member(:type => type, :ref => ref, :role => role)
end | ruby | {
"resource": ""
} |
q18251 | Rosemary.Api.destroy | train | def destroy(element, changeset)
element.changeset = changeset.id
response = delete("/#{element.type.downcase}/#{element.id}", :body => element.to_xml) unless element.id.nil?
response.to_i # New version number
end | ruby | {
"resource": ""
} |
q18252 | Rosemary.Api.save | train | def save(element, changeset)
response = if element.id.nil?
create(element, changeset)
else
update(element, changeset)
end
end | ruby | {
"resource": ""
} |
q18253 | Rosemary.Api.create | train | def create(element, changeset)
element.changeset = changeset.id
put("/#{element.type.downcase}/create", :body => element.to_xml)
end | ruby | {
"resource": ""
} |
q18254 | Rosemary.Api.update | train | def update(element, changeset)
element.changeset = changeset.id
response = put("/#{element.type.downcase}/#{element.id}", :body => element.to_xml)
response.to_i # New Version number
end | ruby | {
"resource": ""
} |
q18255 | Rosemary.Api.create_changeset | train | def create_changeset(comment = nil, tags = {})
tags.merge!(:comment => comment) { |key, v1, v2| v1 }
changeset = Changeset.new(:tags => tags)
changeset_id = put("/changeset/create", :body => changeset.to_xml).to_i
find_changeset(changeset_id) unless changeset_id == 0
end | ruby | {
"resource": ""
} |
q18256 | Rosemary.Api.do_request | train | def do_request(method, url, options = {})
begin
response = self.class.send(method, api_url(url), options)
check_response_codes(response)
response.parsed_response
rescue Timeout::Error
raise Unavailable.new('Service Unavailable')
end
end | ruby | {
"resource": ""
} |
q18257 | Rosemary.Api.do_authenticated_request | train | def do_authenticated_request(method, url, options = {})
begin
response = case client
when BasicAuthClient
self.class.send(method, api_url(url), options.merge(:basic_auth => client.credentials))
when OauthClient
# We have to wrap the result of the access_token request into an HTTParty::Response object
# to keep duck typing with HTTParty
result = client.send(method, api_url(url), options)
content_type = Parser.format_from_mimetype(result.content_type)
parsed_response = Parser.call(result.body, content_type)
HTTParty::Response.new(nil, result, lambda { parsed_response })
else
raise CredentialsMissing
end
check_response_codes(response)
response.parsed_response
rescue Timeout::Error
raise Unavailable.new('Service Unavailable')
end
end | ruby | {
"resource": ""
} |
q18258 | Rosemary.Way.<< | train | def <<(stuff)
case stuff
when Array # call this method recursively
stuff.each do |item|
self << item
end
when Rosemary::Node
nodes << stuff.id
when String
nodes << stuff.to_i
when Integer
nodes << stuff
else
tags.merge!(stuff)
end
self # return self to allow chaining
end | ruby | {
"resource": ""
} |
q18259 | Rosemary.Tags.to_xml | train | def to_xml(options = {})
xml = options[:builder] ||= Builder::XmlMarkup.new
xml.instruct! unless options[:skip_instruct]
each do |key, value|
# Remove leading and trailing whitespace from tag values
xml.tag(:k => key, :v => coder.decode(value.strip)) unless value.blank?
end unless empty?
end | ruby | {
"resource": ""
} |
q18260 | Rosemary.Changeset.to_xml | train | def to_xml(options = {})
xml = options[:builder] ||= Builder::XmlMarkup.new
xml.instruct! unless options[:skip_instruct]
xml.osm do
xml.changeset(attributes) do
tags.each do |k,v|
xml.tag(:k => k, :v => v)
end unless tags.empty?
end
end
end | ruby | {
"resource": ""
} |
q18261 | Rosemary.Relation.to_xml | train | def to_xml(options = {})
xml = options[:builder] ||= Builder::XmlMarkup.new
xml.instruct! unless options[:skip_instruct]
xml.osm(:generator => "rosemary v#{Rosemary::VERSION}", :version => Rosemary::Api::API_VERSION) do
xml.relation(attributes) do
members.each do |member|
member.to_xml(:builder => xml, :skip_instruct => true)
end
tags.to_xml(:builder => xml, :skip_instruct => true)
end
end
end | ruby | {
"resource": ""
} |
q18262 | Rosemary.Element.add_tags | train | def add_tags(new_tags)
case new_tags
when Array # Called with an array
# Call recursively for each entry
new_tags.each do |tag_hash|
add_tags(tag_hash)
end
when Hash # Called with a hash
#check if it is weird {'k' => 'key', 'v' => 'value'} syntax
if (new_tags.size == 2 && new_tags.keys.include?('k') && new_tags.keys.include?('v'))
# call recursively with values from k and v keys.
add_tags({new_tags['k'] => new_tags['v']})
else
# OK, this seems to be a proper ruby hash with a single entry
new_tags.each do |k,v|
self.tags[k] = v
end
end
end
self # return self so calls can be chained
end | ruby | {
"resource": ""
} |
q18263 | Rosemary.Element.get_relations_from_api | train | def get_relations_from_api(api=Rosemary::API.new)
api.get_relations_referring_to_object(type, self.id.to_i)
end | ruby | {
"resource": ""
} |
q18264 | Rosemary.Element.get_history_from_api | train | def get_history_from_api(api=Rosemary::API.new)
api.get_history(type, self.id.to_i)
end | ruby | {
"resource": ""
} |
q18265 | CowProxy.Struct.dig | train | def dig(key, *args)
value = send(key)
args.empty? ? value : value&.dig(*args)
end | ruby | {
"resource": ""
} |
q18266 | CowProxy.Array.map! | train | def map!
__copy_on_write__
return enum_for(:map!) unless block_given?
__getobj__.each.with_index do |_, i|
self[i] = yield(self[i])
end
end | ruby | {
"resource": ""
} |
q18267 | Bud.BudDbmTable.tick_deltas | train | def tick_deltas
unless @delta.empty?
merge_to_db(@delta)
@tick_delta.concat(@delta.values) if accumulate_tick_deltas
@delta.clear
end
unless @new_delta.empty?
# We allow @new_delta to contain duplicates but eliminate them here. We
# can't just allow duplicate delta tuples because that might cause
# spurious infinite delta processing loops.
@new_delta.reject! {|key, val| self[key] == val}
@delta = @new_delta
@new_delta = {}
end
return !(@delta.empty?)
end | ruby | {
"resource": ""
} |
q18268 | Bud.BudDbmTable.tick | train | def tick
deleted = nil
@to_delete.each do |tuple|
k = get_key_vals(tuple)
k_str = MessagePack.pack(k)
cols_str = @dbm[k_str]
unless cols_str.nil?
db_cols = MessagePack.unpack(cols_str)
delete_cols = val_cols.map{|c| tuple[cols.index(c)]}
if db_cols == delete_cols
deleted ||= @dbm.delete k_str
end
end
end
@to_delete = []
@invalidated = !deleted.nil?
unless @pending.empty?
@delta = @pending
@pending = {}
end
flush
end | ruby | {
"resource": ""
} |
q18269 | Bud.BudZkTable.start_watchers | train | def start_watchers
# Watcher callbacks are invoked in a separate Ruby thread. Note that there
# is a possible deadlock between invoking watcher callbacks and calling
# close(): if we get a watcher event and a close at around the same time,
# the close might fire first. Closing the Zk handle will block on
# dispatching outstanding watchers, but it does so holding the @zk_mutex,
# causing a deadlock. Hence, we just have the watcher callback spin on the
# @zk_mutex, aborting if the handle is ever closed.
@child_watcher = Zookeeper::Callbacks::WatcherCallback.new do
while true
break if @zk.closed?
if @zk_mutex.try_lock
get_and_watch unless @zk.closed?
@zk_mutex.unlock
break
end
end
end
@stat_watcher = Zookeeper::Callbacks::WatcherCallback.new do
while true
break if @zk.closed?
if @zk_mutex.try_lock
stat_and_watch unless @zk.closed?
@zk_mutex.unlock
break
end
end
end
stat_and_watch
end | ruby | {
"resource": ""
} |
q18270 | Bud.BudChannel.payloads | train | def payloads(&blk)
return self.pro(&blk) if @is_loopback
if @payload_struct.nil?
payload_cols = cols.dup
payload_cols.delete_at(@locspec_idx)
@payload_struct = Bud::TupleStruct.new(*payload_cols)
@payload_colnums = payload_cols.map {|k| cols.index(k)}
end
retval = self.pro do |t|
@payload_struct.new(*t.values_at(*@payload_colnums))
end
retval = retval.pro(&blk) unless blk.nil?
return retval
end | ruby | {
"resource": ""
} |
q18271 | Mobility.Util.camelize | train | def camelize(str)
call_or_yield str do
str.to_s.sub(/^[a-z\d]*/) { $&.capitalize }.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
end
end | ruby | {
"resource": ""
} |
q18272 | Mobility.Util.call_or_yield | train | def call_or_yield(object)
caller_method = caller_locations(1,1)[0].label
if object.respond_to?(caller_method)
object.public_send(caller_method)
else
yield
end
end | ruby | {
"resource": ""
} |
q18273 | Helpers.LazyDescribedClass.described_class | train | def described_class
klass = super
return klass if klass
# crawl up metadata tree looking for description that can be constantized
this_metadata = metadata
while this_metadata do
candidate = this_metadata[:description_args].first
begin
return candidate.constantize if String === candidate
rescue NameError, NoMethodError
end
this_metadata = this_metadata[:parent_example_group]
end
end | ruby | {
"resource": ""
} |
q18274 | PagSeguro.AuthorizationRequest.create | train | def create
request = Request.post_xml('authorizations/request', api_version, credentials, xml)
response = Response.new(request)
update_attributes(response.serialize)
response.success?
end | ruby | {
"resource": ""
} |
q18275 | PagSeguro.Items.<< | train | def <<(item)
item = ensure_type(Item, item)
original_item = find_item(item)
if original_item
original_item.quantity += (item.quantity || 1)
else
store << item
end
end | ruby | {
"resource": ""
} |
q18276 | PagSeguro.PaymentRequest.register | train | def register
request = if @receivers.empty?
Request.post('checkout', api_version, params)
else
Request.post_xml('checkouts', api_version, credentials, xml_params)
end
Response.new(request)
end | ruby | {
"resource": ""
} |
q18277 | PagSeguro.TransactionRequest.create | train | def create
request = if receivers.empty?
Request.post('transactions', api_version, params)
else
Request.post_xml('transactions/', nil, credentials, xml_params)
end
Response.new(request, self).serialize
end | ruby | {
"resource": ""
} |
q18278 | PagSeguro.Request.get | train | def get(path, api_version, data = {}, headers = {})
execute :get, path, api_version, data, headers
end | ruby | {
"resource": ""
} |
q18279 | PagSeguro.Request.post | train | def post(path, api_version, data = {}, headers = {})
execute :post, path, api_version, data, headers
end | ruby | {
"resource": ""
} |
q18280 | PagSeguro.Request.post_xml | train | def post_xml(path, api_version, credentials, data = '', options={})
credentials_params = credentials_to_params(credentials)
url_path = [api_version, path].reject(&:nil?).join('/')
request.post do
url PagSeguro.api_url("#{url_path}?#{credentials_params}")
headers "Content-Type" => "application/xml; charset=#{PagSeguro.encoding}"
headers.merge!(options[:headers]) if options[:headers]
body data
end
end | ruby | {
"resource": ""
} |
q18281 | PagSeguro.Request.put_xml | train | def put_xml(path, credentials, data)
full_url = PagSeguro.api_url("#{path}?#{credentials_to_params(credentials)}")
request.put do
url full_url
headers "Content-Type" => "application/xml; charset=#{PagSeguro.encoding}",
"Accept" => "application/vnd.pagseguro.com.br.v1+xml;charset=ISO-8859-1"
body data
end
end | ruby | {
"resource": ""
} |
q18282 | PagSeguro.Request.execute | train | def execute(request_method, path, api_version, data, headers) # :nodoc:
request.public_send(
request_method,
PagSeguro.api_url("#{api_version}/#{path}"),
extended_data(data),
extended_headers(request_method, headers)
)
end | ruby | {
"resource": ""
} |
q18283 | PagSeguro.PaymentReleases.include? | train | def include?(payment)
self.find do |included_payment|
included_payment.installment == ensure_type(PaymentRelease, payment).installment
end
end | ruby | {
"resource": ""
} |
q18284 | PagSeguro.SubscriptionDiscount.create | train | def create
request = Request.put_xml("pre-approvals/#{code}/discount", credentials, xml_params)
Response.new(request, self).serialize
self
end | ruby | {
"resource": ""
} |
q18285 | GiphyClient.DefaultApi.gifs_categories_category_get | train | def gifs_categories_category_get(api_key, category, opts = {})
data, _status_code, _headers = gifs_categories_category_get_with_http_info(api_key, category, opts)
return data
end | ruby | {
"resource": ""
} |
q18286 | GiphyClient.DefaultApi.gifs_categories_get | train | def gifs_categories_get(api_key, opts = {})
data, _status_code, _headers = gifs_categories_get_with_http_info(api_key, opts)
return data
end | ruby | {
"resource": ""
} |
q18287 | GiphyClient.DefaultApi.gifs_get | train | def gifs_get(api_key, ids, opts = {})
data, _status_code, _headers = gifs_get_with_http_info(api_key, ids, opts)
return data
end | ruby | {
"resource": ""
} |
q18288 | GiphyClient.DefaultApi.gifs_gif_id_get | train | def gifs_gif_id_get(api_key, gif_id, opts = {})
data, _status_code, _headers = gifs_gif_id_get_with_http_info(api_key, gif_id, opts)
return data
end | ruby | {
"resource": ""
} |
q18289 | GiphyClient.DefaultApi.gifs_random_get | train | def gifs_random_get(api_key, opts = {})
data, _status_code, _headers = gifs_random_get_with_http_info(api_key, opts)
return data
end | ruby | {
"resource": ""
} |
q18290 | GiphyClient.DefaultApi.gifs_search_get | train | def gifs_search_get(api_key, q, opts = {})
data, _status_code, _headers = gifs_search_get_with_http_info(api_key, q, opts)
return data
end | ruby | {
"resource": ""
} |
q18291 | GiphyClient.DefaultApi.gifs_translate_get | train | def gifs_translate_get(api_key, s, opts = {})
data, _status_code, _headers = gifs_translate_get_with_http_info(api_key, s, opts)
return data
end | ruby | {
"resource": ""
} |
q18292 | GiphyClient.DefaultApi.stickers_random_get | train | def stickers_random_get(api_key, opts = {})
data, _status_code, _headers = stickers_random_get_with_http_info(api_key, opts)
return data
end | ruby | {
"resource": ""
} |
q18293 | GiphyClient.DefaultApi.stickers_search_get | train | def stickers_search_get(api_key, q, opts = {})
data, _status_code, _headers = stickers_search_get_with_http_info(api_key, q, opts)
return data
end | ruby | {
"resource": ""
} |
q18294 | GiphyClient.DefaultApi.stickers_translate_get | train | def stickers_translate_get(api_key, s, opts = {})
data, _status_code, _headers = stickers_translate_get_with_http_info(api_key, s, opts)
return data
end | ruby | {
"resource": ""
} |
q18295 | Jekyll.Filters.date_to_html_string | train | def date_to_html_string(date)
result = '<span class="month">' + date.strftime('%b').upcase + '</span> '
result += date.strftime('<span class="day">%d</span> ')
result += date.strftime('<span class="year">%Y</span> ')
result
end | ruby | {
"resource": ""
} |
q18296 | Jekyll.Site.write_category_index | train | def write_category_index(category)
target_dir = GenerateCategories.category_dir(self.config['category_dir'], category)
index = CategoryIndex.new(self, self.source, target_dir, category)
if index.render?
index.render(self.layouts, site_payload)
index.write(self.dest)
# Record the fact that this pages has been added, otherwise Site::cleanup will remove it.
self.pages << index
end
# Create an Atom-feed for each index.
feed = CategoryFeed.new(self, self.source, target_dir, category)
if feed.render?
feed.render(self.layouts, site_payload)
feed.write(self.dest)
# Record the fact that this pages has been added, otherwise Site::cleanup will remove it.
self.pages << feed
end
end | ruby | {
"resource": ""
} |
q18297 | Jekyll.Site.write_category_indexes | train | def write_category_indexes
if self.layouts.key? 'category_index'
self.categories.keys.each do |category|
self.write_category_index(category)
end
# Throw an exception if the layout couldn't be found.
else
throw "No 'category_index' layout found."
end
end | ruby | {
"resource": ""
} |
q18298 | Invitation.UserRegistration.process_invite_token | train | def process_invite_token(new_user = nil)
new_user = user_instance_variable if new_user.nil?
token = params[:invite_token]
new_user.claim_invite token if !token.nil? && !new_user.nil?
end | ruby | {
"resource": ""
} |
q18299 | Invitation.Invitable.invitable | train | def invitable(options = {})
has_many :invites, as: :invitable
class_attribute :invitable_options
self.invitable_options = {}
case
when options[:named_by] then invitable_options[:named_by] = options[:named_by]
when options[:named] then invitable_options[:named] = options[:named]
else raise 'invitable requires options be set, either :name or :named_by. \
e.g.: `invitable named: "string"` or `invitable named_by: :method_name`'
end
include Invitation::Invitable::InstanceMethods
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.