_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3 values | text stringlengths 66 10.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q3300 | ActsAsStaticRecord.SingletonMethods.find_with_static_record | train | def find_with_static_record(*args)#:nodoc:
if scope(:find).nil? && args
if args.first.is_a?(Fixnum) &&
((args.length == 1 ||
(args[1].is_a?(Hash) && args[1].values.delete(nil).nil?)))
return static_record_cache[:primary_key][args.first]
elsif args.first == :all && args.length == 1
return static_record_cache[:primary_key].values
end
end
find_without_static_record(*args)
end | ruby | {
"resource": ""
} |
q3301 | ActsAsStaticRecord.SingletonMethods.calculate_with_static_record | train | def calculate_with_static_record(operation, column_name, options={})#:nodoc:
if scope(:find).nil? && !options.any?{ |k,v| k.to_s.downcase != 'distinct' }
key = "#{operation}_#{column_name}_#{options.none?{|k,v| v.blank? }}"
static_record_cache[:calc][key]||=
case operation.to_s
when 'count' then
#count the cache if we want all or the unique primary key
if ['all', '', '*', primary_key].include?(column_name.to_s)
static_record_cache[:primary_key].length
#otherwise compute the length of the output
else
static_records_for_calculation(column_name, options) {|records| records.length }
end
#compute the method directly on the result array
when 'sum', 'max', 'min' then
if columns_hash[column_name.to_s].try(:type) == :integer
static_records_for_calculation(column_name, options) {|records| records.send(operation).to_i }
end
end
return static_record_cache[:calc][key] if static_record_cache[:calc][key]
end
calculate_without_static_record(operation, column_name, options)
end | ruby | {
"resource": ""
} |
q3302 | ActsAsStaticRecord.SingletonMethods.static_records_for_calculation | train | def static_records_for_calculation(column_name, options={}, &block)#:nodoc:
if columns_hash.has_key?(column_name.to_s)
records = static_record_cache[:primary_key].values.collect(&(column_name.to_sym)).compact
results = (options[:distinct]||options['distinct']) ? records.uniq : records
block ? yield(results) : results
else
nil
end
end | ruby | {
"resource": ""
} |
q3303 | ActsAsStaticRecord.SingletonMethods.initialize_static_record_cache | train | def initialize_static_record_cache#:nodoc:
return unless @static_record_cache.nil?
records = self.find_without_static_record(:all, acts_as_static_record_options[:find]||{})
@static_record_cache = records.inject({:primary_key => {}, :key => {}, :calc => {}}) do |cache, record|
cache[:primary_key][record.send(self.primary_key)] = record
if acts_as_static_record_options[:key]
cache[:key][record.send(acts_as_static_record_options[:key])] = record
end
cache
end
end | ruby | {
"resource": ""
} |
q3304 | ActsAsStaticRecord.DefineFinderMethods.static_record_finder_method_name | train | def static_record_finder_method_name(finder, attributes)#:nodoc:
method_to_call = "find_in_static_record_cache(#{finder.inspect}, #{attributes.inspect})"
if attributes.length == 1
key_value = case attributes.keys.first.to_s
when self.primary_key then [:primary_key, attributes.values.first.to_i]
when acts_as_static_record_options[:key] then [:key, attributes.values.first.to_s]
end
method_to_call = "static_record_cache[#{key_value[0].inspect}][#{key_value[1].inspect}]" if key_value
end
method_to_call
end | ruby | {
"resource": ""
} |
q3305 | ActsAsStaticRecord.DefineFinderMethods.define_static_record_finder_method | train | def define_static_record_finder_method(method_id, finder, bang, attributes)#:nodoc:
method_to_call = static_record_finder_method_name(finder, attributes)
method_with_static_record = "#{method_id}_with_static_rc"
#override the method to search memory if there are no args
class_eval %{
def self.#{method_with_static_record}(*args)
if (args.dup.extract_options!).any?
#{method_id}_without_static_rc(*args)
else
result = #{method_to_call}
#{'result || raise(RecordNotFound, "Couldn\'t find #{name} with #{attributes.to_a.collect {|pair| "#{pair.first} = #{pair.second}"}.join(\', \')}")' if bang}
end
end
}, __FILE__, __LINE__
method_with_static_record
end | ruby | {
"resource": ""
} |
q3306 | ActsAsStaticRecord.DefineFinderMethods.method_missing | train | def method_missing(method_id, *arguments, &block)#:nodoc:
# If the missing method is XXX_without_static_rc, define XXX
# using the superclass ActiveRecord::Base method_missing then
# Finally, alias chain it to XXX_with_static_rc
if ((match = method_id.to_s.match(/(.*)_without_static_rc$/)) &&
(base_method_id = match[1]))
begin
return super(base_method_id, *arguments, &block)
ensure
define_static_rc_alias(base_method_id)
end
end
# If the missing method is a finder like find_by_name
# Define on the class then invoke find_by_name_with_static_rc
if match = ActiveRecord::DynamicFinderMatch.match(method_id)
attribute_names = match.attribute_names
if all_attributes_exists?(attribute_names) && match.finder?
attributes = construct_attributes_from_arguments(attribute_names, arguments)
method_name = define_static_record_finder_method(method_id, match.finder, match.bang?, attributes)
return self.send method_name, *arguments
end
end
#If nothing matches, invoke the super
super(method_id, *arguments, &block)
end | ruby | {
"resource": ""
} |
q3307 | Bollettino.Generator.generate! | train | def generate!(slip, path)
image = MiniMagick::Image.open(File.expand_path('../../../assets/slip.png', __FILE__))
Bollettino::Renderer::Slip.render(image, slip)
image.write path
end | ruby | {
"resource": ""
} |
q3308 | Hyperb.Compose.compose_down | train | def compose_down(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'project')
path = '/compose/down'
query = {}
query[:project] = params[:project] if params.key?(:project)
query[:vol] = params[:vol] if params.key?(:vol)
query[:rmi] = params[:rmi] if params.key?(:rmi)
query[:rmorphans] = params[:rmorphans] if params.key?(:rmorphans)
Hyperb::Request.new(self, path, query, 'post').perform
end | ruby | {
"resource": ""
} |
q3309 | Hyperb.Compose.compose_create | train | def compose_create(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'project')
path = '/compose/create'
query = {}
body = {}
query[:project] = params[:project] if params.key?(:project)
body[:serviceconfigs] = { 'M': {} } # inherited from libcompose
body[:serviceconfigs][:M] = params[:serviceconfigs]
params.delete(:serviceconfigs)
body.merge!(params)
Hyperb::Request.new(self, path, query, 'post', body).perform
end | ruby | {
"resource": ""
} |
q3310 | JProtobuf.Message.write_to_string_io | train | def write_to_string_io(string_io)
java_proto.write_to(org.jruby.util.IOOutputStream.new(string_io))
nil
end | ruby | {
"resource": ""
} |
q3311 | JProtobuf.Message.write_to_string | train | def write_to_string
string_io = StringIO.new.set_encoding(Encoding::BINARY)
write_to_string_io(string_io)
string_io.string
end | ruby | {
"resource": ""
} |
q3312 | Zyps.FaceAction.do | train | def do(actor, targets)
return if targets.empty?
actor.vector.pitch = Utility.find_angle(actor.location, random_target(targets).location)
end | ruby | {
"resource": ""
} |
q3313 | Zyps.ApproachAction.do | train | def do(actor, targets)
return if targets.empty?
#Apply thrust to the creature's movement vector, adjusted by elapsed time.
actor.vector += Vector.new(
delta,
Utility.find_angle(actor.location, random_target(targets).location)
)
end | ruby | {
"resource": ""
} |
q3314 | Zyps.DestroyAction.do | train | def do(actor, targets)
targets.each do |target|
target.environment.remove_object(target.identifier)
end
end | ruby | {
"resource": ""
} |
q3315 | Zyps.TagAction.do | train | def do(actor, targets)
targets.each do |target|
target.tags << tag unless target.tags.include?(tag)
end
end | ruby | {
"resource": ""
} |
q3316 | Zyps.BlendAction.do | train | def do(actor, targets)
actor.color.red += (@color.red - actor.color.red) * delta
actor.color.green += (@color.green - actor.color.green) * delta
actor.color.blue += (@color.blue - actor.color.blue) * delta
end | ruby | {
"resource": ""
} |
q3317 | Zyps.PushAction.do | train | def do(actor, targets)
#Acceleration will be limited by elapsed time.
push_force = delta
targets.each do |target|
#Angle to target is also angle of push force.
push_angle = Utility.find_angle(actor.location, target.location)
#Apply the force to the creature's movement vector.
target.vector += Vector.new(push_force, push_angle)
end
end | ruby | {
"resource": ""
} |
q3318 | Zyps.PullAction.do | train | def do(actor, targets)
#Acceleration will be limited by elapsed time.
pull_force = delta
targets.each do |target|
#Angle from target to actor is also angle of pull force (opposite of that for push).
pull_angle = Utility.find_angle(target.location, actor.location)
#Apply the force to the creature's movement vector.
target.vector += Vector.new(pull_force, pull_angle)
end
end | ruby | {
"resource": ""
} |
q3319 | Zyps.SpawnAction.do | train | def do(actor, targets)
prototypes.each do |prototype|
actor.environment.add_object(generate_child(actor, prototype))
end
end | ruby | {
"resource": ""
} |
q3320 | Zyps.SpawnAction.generate_child | train | def generate_child(actor, prototype)
#Copy prototype so it can be spawned repeatedly if need be.
child = prototype.copy
child.location = actor.location.copy
child
end | ruby | {
"resource": ""
} |
q3321 | Zyps.ExplodeAction.generate_child | train | def generate_child(actor, prototype)
child = super
child.vector += actor.vector
child.size = actor.size / prototypes.length
child
end | ruby | {
"resource": ""
} |
q3322 | Zyps.ShootAction.do | train | def do(actor, targets)
return if targets.empty?
#If next item is a collection of prototypes, copy them all in at once.
if prototypes[@prototype_index].respond_to?(:each)
prototypes[@prototype_index].each do |prototype|
actor.environment.add_object(generate_child(actor, prototype, targets[@target_index]))
end
#Otherwise copy the single prototype.
else
targets[@target_index].environment.add_object(generate_child(actor, prototypes[@prototype_index], targets[@target_index]))
end
#Move to next target and prototype group, wrapping to start of array if need be.
@target_index = (@target_index + 1) % targets.length
@prototype_index = (@prototype_index + 1) % prototypes.length
end | ruby | {
"resource": ""
} |
q3323 | Zyps.ShootAction.generate_child | train | def generate_child(actor, prototype, target)
child = super(actor, prototype)
child.vector.pitch = Utility.find_angle(actor.location, target.location) + child.vector.pitch
child
end | ruby | {
"resource": ""
} |
q3324 | Percolate.Percolator.find | train | def find(context, facet_name, *args)
facet = find_facet(context, facet_name)
if !facet
return nil
end
case result = facet.find(*args)
when Array
result.map { |item| @entities[item] }
when String
@entities[result]
when NilClass
nil
else
raise "Bad facet return type #{result.class.name.dump}"
end
end | ruby | {
"resource": ""
} |
q3325 | Percolate.Percolator.find_facet | train | def find_facet(context, facet_name)
cache_key = [context, facet_name]
if @facet_cache.include?(cache_key)
facet = @facet_cache[cache_key]
else
begin
require "percolate/facet/#{facet_name}_facet"
rescue LoadError
# Do nothing. Give the benefit of the doubt if the file doesn't exist.
end
if facet = @adapter.load_facet(context, facet_name)
@facet_cache[cache_key] = facet
end
end
facet
end | ruby | {
"resource": ""
} |
q3326 | Gitter.Utils.url_for | train | def url_for params
p = params.dup
query = p.map{|key, value| value.to_query(key) } * '&'
"#{h.url_for({})}?#{query}"
end | ruby | {
"resource": ""
} |
q3327 | Hyperb.Services.create_service | train | def create_service(params = {})
valid = check_arguments(params, 'name', 'image', 'replicas', 'serviceport', 'labels')
raise ArgumentError, 'Invalid arguments.' unless valid
path = '/services/create'
body = {}
body.merge!(params)
downcase_symbolize(JSON.parse(Hyperb::Request.new(self, path, {}, 'post', body).perform))
end | ruby | {
"resource": ""
} |
q3328 | HashKit.Helper.symbolize | train | def symbolize(hash)
{}.tap do |h|
hash.each { |key, value| h[key.to_sym] = map_value_symbol(value) }
end
end | ruby | {
"resource": ""
} |
q3329 | HashKit.Helper.stringify | train | def stringify(hash)
{}.tap do |h|
hash.each { |key, value| h[key.to_s] = map_value_string(value) }
end
end | ruby | {
"resource": ""
} |
q3330 | HashKit.Helper.to_hash | train | def to_hash(obj)
return nil unless obj
return obj if obj.is_a?(Hash)
hash = {}
obj.instance_variables.each do |key|
hash[key[1..-1].to_sym] = deeply_to_hash(obj.instance_variable_get(key))
end
hash
end | ruby | {
"resource": ""
} |
q3331 | Amico.Relationships.follow | train | def follow(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
return if blocked?(to_id, from_id, scope)
return if Amico.pending_follow && pending?(from_id, to_id, scope)
if Amico.pending_follow
Amico.redis.multi do |transaction|
transaction.zadd("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
transaction.zadd("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
end
else
add_following_followers_reciprocated(from_id, to_id, scope)
end
end | ruby | {
"resource": ""
} |
q3332 | Amico.Relationships.unfollow | train | def unfollow(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
Amico.redis.multi do
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", to_id)
end
end | ruby | {
"resource": ""
} |
q3333 | Amico.Relationships.block | train | def block(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
Amico.redis.multi do
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{from_id}", to_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zadd("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
Amico.redis.zadd("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
end
end | ruby | {
"resource": ""
} |
q3334 | Amico.Relationships.accept | train | def accept(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
add_following_followers_reciprocated(from_id, to_id, scope)
end | ruby | {
"resource": ""
} |
q3335 | Amico.Relationships.deny | train | def deny(from_id, to_id, scope = Amico.default_scope_key)
return if from_id == to_id
Amico.redis.multi do
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", to_id)
end
end | ruby | {
"resource": ""
} |
q3336 | Amico.Relationships.following? | train | def following?(id, following_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}", following_id).nil?
end | ruby | {
"resource": ""
} |
q3337 | Amico.Relationships.follower? | train | def follower?(id, follower_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}", follower_id).nil?
end | ruby | {
"resource": ""
} |
q3338 | Amico.Relationships.blocked? | train | def blocked?(id, blocked_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", blocked_id).nil?
end | ruby | {
"resource": ""
} |
q3339 | Amico.Relationships.blocked_by? | train | def blocked_by?(id, blocked_by_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}", blocked_by_id).nil?
end | ruby | {
"resource": ""
} |
q3340 | Amico.Relationships.reciprocated? | train | def reciprocated?(from_id, to_id, scope = Amico.default_scope_key)
following?(from_id, to_id, scope) && following?(to_id, from_id, scope)
end | ruby | {
"resource": ""
} |
q3341 | Amico.Relationships.pending_with? | train | def pending_with?(from_id, to_id, scope = Amico.default_scope_key)
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{to_id}", from_id).nil?
end | ruby | {
"resource": ""
} |
q3342 | Amico.Relationships.following_page_count | train | def following_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}", page_size)
end | ruby | {
"resource": ""
} |
q3343 | Amico.Relationships.followers_page_count | train | def followers_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}", page_size)
end | ruby | {
"resource": ""
} |
q3344 | Amico.Relationships.blocked_page_count | train | def blocked_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", page_size)
end | ruby | {
"resource": ""
} |
q3345 | Amico.Relationships.blocked_by_page_count | train | def blocked_by_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}", page_size)
end | ruby | {
"resource": ""
} |
q3346 | Amico.Relationships.reciprocated_page_count | train | def reciprocated_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{id}", page_size)
end | ruby | {
"resource": ""
} |
q3347 | Amico.Relationships.pending_page_count | train | def pending_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{id}", page_size)
end | ruby | {
"resource": ""
} |
q3348 | Amico.Relationships.pending_with_page_count | train | def pending_with_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
total_pages("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{id}", page_size)
end | ruby | {
"resource": ""
} |
q3349 | Amico.Relationships.count | train | def count(id, type, scope = Amico.default_scope_key)
validate_relationship_type(type)
self.send("#{type.to_s}_count".to_sym, id, scope)
end | ruby | {
"resource": ""
} |
q3350 | Amico.Relationships.page_count | train | def page_count(id, type, page_size = Amico.page_size, scope = Amico.default_scope_key)
validate_relationship_type(type)
self.send("#{type.to_s}_page_count".to_sym, id, page_size, scope)
end | ruby | {
"resource": ""
} |
q3351 | Amico.Relationships.add_following_followers_reciprocated | train | def add_following_followers_reciprocated(from_id, to_id, scope)
Amico.redis.multi do
Amico.redis.zadd("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
Amico.redis.zadd("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id)
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", to_id)
end
if reciprocated?(from_id, to_id, scope)
Amico.redis.multi do
Amico.redis.zadd("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
Amico.redis.zadd("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
end
end
end | ruby | {
"resource": ""
} |
q3352 | Amico.Relationships.total_pages | train | def total_pages(key, page_size)
(Amico.redis.zcard(key) / page_size.to_f).ceil
end | ruby | {
"resource": ""
} |
q3353 | Amico.Relationships.members | train | def members(key, options = default_paging_options)
options = default_paging_options.dup.merge!(options)
if options[:page] < 1
options[:page] = 1
end
if options[:page] > total_pages(key, options[:page_size])
options[:page] = total_pages(key, options[:page_size])
end
index_for_redis = options[:page] - 1
starting_offset = (index_for_redis * options[:page_size])
if starting_offset < 0
starting_offset = 0
end
ending_offset = (starting_offset + options[:page_size]) - 1
Amico.redis.zrevrange(key, starting_offset, ending_offset, :with_scores => false)
end | ruby | {
"resource": ""
} |
q3354 | GAAPI.Response.csv | train | def csv
@csv ||= CSV.generate do |csv|
reports.each(&:report).each do |report|
# If there are no dimensions, but totals, we need to put an extra
# column at the start for the word "Total".
# I don't see how totals will be different than the metrics if you
# don't specify dimensions, but whatever.
totals_column = report.totals? && !report.dimensions? ? [nil] : []
csv << totals_column + report.headers
report.rows.each { |row| csv << totals_column + row.to_a }
next unless report.totals? # Rubocop did this. Not sure I like it.
csv << ["Totals"] + if !report.dimensions?
report.totals
else
report.totals[1..-1]
end
end
end
end | ruby | {
"resource": ""
} |
q3355 | Hyperb.Containers.containers | train | def containers(params = {})
path = '/containers/json'
query = {}
query.merge!(params)
response = JSON.parse(Hyperb::Request.new(self, path, query, 'get').perform)
response.map { |container| Hyperb::Container.new(container) }
end | ruby | {
"resource": ""
} |
q3356 | Hyperb.Containers.remove_container | train | def remove_container(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'id')
path = '/containers/' + params[:id]
query = {}
query[:v] = params[:v] if params.key?(:v)
query[:force] = params[:force] if params.key?(:force)
response = JSON.parse(Hyperb::Request.new(self, path, query, 'delete').perform)
downcase_symbolize(response)
end | ruby | {
"resource": ""
} |
q3357 | Hyperb.Containers.create_container | train | def create_container(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'image')
path = '/containers/create'
query = {}
# set default size, otherwise container can't be started
body = { labels: { sh_hyper_instancetype: 's1' } }
# parse host_config options
if params.key?(:host_config)
body[camelize(:host_config)] = setup_host_config(params)
params.delete(:host_config)
end
query[:name] = params[:name] if params.key?(:name)
params.delete(:name)
body.merge!(params)
downcase_symbolize(JSON.parse(Hyperb::Request.new(self, path, query, 'post', body).perform))
end | ruby | {
"resource": ""
} |
q3358 | Hyperb.Containers.rename_container | train | def rename_container(params = {})
raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name', 'id')
path = '/containers/' + params[:id] + '/rename'
query = {}
query[:name] = params[:name] if params.key?(:name)
Hyperb::Request.new(self, path, query, 'post').perform
end | ruby | {
"resource": ""
} |
q3359 | Logmsg.LogMsg.load | train | def load
close if @loaded
@path.each do |file|
next unless File.exist?(file)
@settings = Psych.load_file(file)
next unless @settings.include?(@namespace)
parse(@settings[@namespace])
@loaded = true
break
end
fail unless @loaded
end | ruby | {
"resource": ""
} |
q3360 | Logmsg.LogMsg.parse | train | def parse(settings, logfile = nil)
settings.each do |key, value|
if value.is_a?(Hash)
logfile = Logmsg::LogFile.new(key)
logfiles[key.to_sym] = logfile
parse(value, logfile)
logfile.register
else
logfile.public_send("#{key}=", value)
end
end
end | ruby | {
"resource": ""
} |
q3361 | Rdio.Api.addFriend | train | def addFriend(user)
method = 'addFriend'
type = true
args = {:user=>user}
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3362 | Rdio.Api.addToCollection | train | def addToCollection(objs)
method = 'addToCollection'
type = true
args = {:keys=>Rdio::keys(objs)}
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3363 | Rdio.Api.addToPlaylist | train | def addToPlaylist(playlist,tracks)
method = 'addToPlaylist'
type = true
args = {:playlist=>playlist, :tracks=>Rdio::keys(tracks)}
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3364 | Rdio.Api.createPlaylist | train | def createPlaylist(name,description,tracks,extras=nil)
method = 'createPlaylist'
type = Playlist
args = {:name=>name,:description=>description,
:tracks=>Rdio::keys(tracks)}
args[:extras] = extras if extras
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3365 | Rdio.Api.currentUser | train | def currentUser(extras=nil)
method = 'currentUser'
type = User
args = {}
args[:extras] = extras if extras
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3366 | Rdio.Api.deletePlaylist | train | def deletePlaylist(playlist)
method = 'deletePlaylist'
type = Boolean
args = {:playlist=>playlist}
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3367 | Rdio.Api.getActivityStream | train | def getActivityStream(user,scope,last_id=nil)
method = 'getActivityStream'
type = ActivityStream
args = {:user=>user,:scope=>scope}
args[:last_id] = last_id if last_id
auth = user
return_object type,method,args,auth
end | ruby | {
"resource": ""
} |
q3368 | Rdio.Api.getAlbumsForArtistInCollection | train | def getAlbumsForArtistInCollection(artist,user=nil,extras=nil)
method = 'getAlbumsForArtistInCollection'
type = Album
args = {:artist=>artist}
args[:user] = user if user
args[:extras] = extras if extras
auth = !!user
return_object type,method,args,auth
end | ruby | {
"resource": ""
} |
q3369 | Rdio.Api.getHeavyRotation | train | def getHeavyRotation(user=nil,type=nil,friends=nil,limit=nil,extras=nil)
method = 'getHeavyRotation'
cls = TODO
if type == 'artist'
cls = Artist
elsif type == 'album'
cls = Album
end
args = {}
args[:user] = user if user
args[:type] = type if type
args[:friends] = friends if friends
args[:limit] = limit if limit
args[:extras] = extras if extras
return_object cls,method,args
end | ruby | {
"resource": ""
} |
q3370 | Rdio.Api.getNewReleases | train | def getNewReleases(time=nil,start=nil,count=nil,extras=nil)
method = 'getNewReleases'
type = Album
args = {}
args[:time] = time if time
args[:start] = start if start
args[:count] = count if count
args[:extras] = extras if extras
return_object type,method,args
end | ruby | {
"resource": ""
} |
q3371 | Rdio.Api.getObjectFromShortCode | train | def getObjectFromShortCode(short_code,type=nil)
method = 'getObjectFromShortCode'
type = BaseObj if not type
args = {:short_code=>short_code}
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3372 | Rdio.Api.getObjectFromUrl | train | def getObjectFromUrl(url,type=nil)
method = 'getObjectFromUrl'
type = BaseObj if not type
args = {:url=>url}
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3373 | Rdio.Api.getPlaybackToken | train | def getPlaybackToken(domain=nil)
method = 'getPlaybackToken'
type = String
args = {}
args[:domain] = domain if domain
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3374 | Rdio.Api.getPlaylists | train | def getPlaylists(extras=nil)
method = 'getPlaylists'
type = Playlist
args = {}
args[:extras] = extras if extras
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3375 | Rdio.Api.getTopCharts | train | def getTopCharts(type,start=nil,count=nil,extras=nil)
method = 'getTopCharts'
cls = TODO
case type
when 'Artist'
cls = Artist
when 'Album'
cls = Album
when 'Track'
cls = Track
when 'Playlist'
cls = Playlist
end
args = {:type=>type}
return_object cls,method,args
end | ruby | {
"resource": ""
} |
q3376 | Rdio.Api.getTracksForAlbumInCollection | train | def getTracksForAlbumInCollection(album,user=nil,extras=nil)
method = 'getTracksForAlbumInCollection'
type = Track
args = {:album=>album}
args[:user] = user if user
args[:extras] = extras if extras
return_object type,method,args
end | ruby | {
"resource": ""
} |
q3377 | Rdio.Api.getTracksForArtistInCollection | train | def getTracksForArtistInCollection(artist,user=nil,extras=nil)
method = 'getTracksForArtistInCollection'
type = Track
args = {:artist=>artist}
args[:user] = user if user
args[:extras] = extras if extras
return_object type,method,args
end | ruby | {
"resource": ""
} |
q3378 | Rdio.Api.removeFriend | train | def removeFriend(user)
method = 'removeFriend'
type = Boolean
args = {:user=>user}
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3379 | Rdio.Api.removeFromCollection | train | def removeFromCollection(objs)
method = 'removeFromCollection'
type = Boolean
args = {:keys=>Rdio::keys(objs)}
return_object type,method,args
end | ruby | {
"resource": ""
} |
q3380 | Rdio.Api.removeFromPlaylist | train | def removeFromPlaylist(playlist,index,count,tracks)
method = 'removeFromPlaylist'
type = TODO
args = {:playlist=>playlist,:index=>index,
:count=>count,:tracks=>Rdio::keys(tracks)}
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3381 | Rdio.Api.setPlaylistFields | train | def setPlaylistFields(playlist,name,description)
method = 'setPlaylistFields'
type = Boolean
args = {:playlist=>playlist,:name=>name,:description=>description}
return_object type,method,args,true
end | ruby | {
"resource": ""
} |
q3382 | Rdio.Api.searchSuggestions | train | def searchSuggestions(query,extras)
method = 'searchSuggestions'
type = TODO
args = {:query=>query}
args[:extras] = extras if extras
return_object type,method,args
end | ruby | {
"resource": ""
} |
q3383 | Linkshare.Strategy.get_token | train | def get_token(username, password, sid, params = {}, opts = {})
request_body = opts.delete('auth_scheme') == 'request_body'
params = {'grant_type' => 'password',
'username' => username,
'password' => password,
'scope' => sid
}.merge(client_params).merge(params)
params.merge!('client_params' => {
:headers => {
'Authorization' => authorization(client_params['client_id'], client_params['client_secret']),
'Accept' => 'application/xml'}
})
# params.merge(:parse => :xml)
@client.get_token(params, opts)
end | ruby | {
"resource": ""
} |
q3384 | Socialcast.Gitx.run_cmd | train | def run_cmd(cmd)
raise "Unstubbed git command #{cmd}" if ENV['SCGITX_TEST'] == 'true'
say "\n$ "
say cmd.gsub("'", ''), :red
raise "#{cmd} failed" unless system cmd
end | ruby | {
"resource": ""
} |
q3385 | GoogleAuthentication.ActsAsGoogleUser.acts_as_google_user | train | def acts_as_google_user *modules
# assign devise modules to module variable
if modules.empty?
self.devise_modules_to_include = [:omniauthable]
else
# restrict modules given to devise
self.devise_modules_to_include = (modules + [:omniauthable] - FORBIDDEN_MODULES) & ALLOWED_MODULES
end
# include model methods
include ActsAsGoogleUser::Model
end | ruby | {
"resource": ""
} |
q3386 | Hoiio.Client.set_up_resources | train | def set_up_resources
@user = Hoiio::User.new self
@sms = Hoiio::SMS.new self
@voice = Hoiio::Voice.new self
@fax = Hoiio::Fax.new self
@number = Hoiio::Number.new self
@ivr = Hoiio::IVR.new self
end | ruby | {
"resource": ""
} |
q3387 | OmekaClient.Client.put_item | train | def put_item(omeka_item)
self.put("items", omeka_item.data.id, omeka_item.data.to_h.to_json)
end | ruby | {
"resource": ""
} |
q3388 | OmekaClient.Client.build_request | train | def build_request(method, resource = nil, id = nil, body =nil, query = {})
url = self.endpoint
url += "/" + resource unless resource.nil?
url += "/" + id.to_s unless id.nil?
query[:key] = self.api_key unless self.api_key.nil?
case method
when "get"
self.connection.get(url, :params => query)
when "post"
self.connection.post(url, :body => body, :params => query)
when "put"
self.connection.put(url, :body => body, :params => query)
when "delete"
begin
self.connection.delete(url, :params => query)
rescue TypeError
# Not putting the error to stdout
end
end
end | ruby | {
"resource": ""
} |
q3389 | Markascend.LineUnit.parse_inline_code | train | def parse_inline_code
if s = @src.scan(/
(`{1,})(\ ?)
.*?
\2\1
/x)
s =~ /^
(`{1,})(\ ?)
(.*?)
\2\1
$/x
@out << (::Markascend.hilite $3, env.hi, true)
true
end
end | ruby | {
"resource": ""
} |
q3390 | Phonology.Sound.<< | train | def <<(*args)
args.to_a.flatten.each do |feature|
features.subtract Features.set(feature).to_a
add! feature
end
self
end | ruby | {
"resource": ""
} |
q3391 | Phonology.Sound.>> | train | def >>(*args)
args.to_a.flatten.each do |feature|
features.delete feature.to_sym
end
self
end | ruby | {
"resource": ""
} |
q3392 | Unified.Chunk.each_line | train | def each_line
original_line_number = @original_line_number
modified_line_number = @modified_line_number
@lines.each do |line|
if line.addition?
yield line, nil, modified_line_number
modified_line_number += 1
elsif line.deletion?
yield line, original_line_number, nil
original_line_number += 1
elsif line.unchanged?
yield line, original_line_number, modified_line_number
original_line_number += 1
modified_line_number += 1
else
yield line
end
end
end | ruby | {
"resource": ""
} |
q3393 | Sys::Proc::Concern::StaticInstance.ClassMethods.method_missing | train | def method_missing(method, *args, &block)
if respond_to_missing?(method)
new.public_send(method, *args, &block)
else
super
end
end | ruby | {
"resource": ""
} |
q3394 | Manageable.ApplicationHelper.manageable_content_box | train | def manageable_content_box(options = {}, &block)
box_buffer = Helpers::BoxBuilder.new(self)
box_content = capture(box_buffer, &block)
options = {
:id => nil,
:class => []
}.merge(options)
block_class = ([ "block" ] + [ options[:class] ].flatten).join(" ")
content_tag(:div, :class => block_class, :id => options[:id]) do
block_out = box_buffer.buffers[:block_header].html_safe
block_out << content_tag(:div, :class => "content") do
content_out = ''.html_safe
content_out = content_tag(:h2, options[:headline]) if options[:headline]
content_out << content_tag(:div, box_content, :class => 'inner')
end
block_out << box_buffer.buffers[:block_footer].html_safe
end
end | ruby | {
"resource": ""
} |
q3395 | Manageable.ApplicationHelper.manageable_icon | train | def manageable_icon(name, size = :small, options = {})
return "" if name.nil?
dimension = ( (size == :small) ? "16" : "32" ).html_safe
options[:alt] ||= name.capitalize.gsub("_", " ")
image_tag(asset_path("manageable/icons/#{dimension}x#{dimension}/#{name}.png"), {
:alt => options[:alt]
})
end | ruby | {
"resource": ""
} |
q3396 | Manageable.ApplicationHelper.manageable_controls | train | def manageable_controls(options = {})
options[:class] ||= ""
options[:class] << " control"
options[:class].strip!
items = Helpers::NavigationBuilder.new
yield items if block_given?
content_tag("div", options) do
items.collect { |item|
manageable_button(item[:label], item[:href], item[:link_options].merge(:icon => item[:icon]))
}.join("").html_safe
end
end | ruby | {
"resource": ""
} |
q3397 | Manageable.ApplicationHelper.manageable_breadcrumbs | train | def manageable_breadcrumbs(options = {})
items = Helpers::NavigationBuilder.new
yield items if block_given?
options[:class] ||= ""
options[:class] << " breadcrumb"
options[:class].strip!
content_tag("div", options) do
content_tag("ul") do
items.collect { |item|
content_tag("li", :class => item[:class]) do
if item[:active]
item[:label]
else
link_to(item[:label], item[:href])
end
end
}.join("").html_safe
end
end
end | ruby | {
"resource": ""
} |
q3398 | Manageable.ApplicationHelper.manageable_button | train | def manageable_button(body, url, html_options = {})
html_options[:class] = [html_options[:class], "button"].compact.join(" ")
icon = manageable_icon(html_options.delete(:icon), :small, :alt => body) if html_options[:icon]
link_to url, html_options do
[icon, body].compact.join(" ").html_safe
end
end | ruby | {
"resource": ""
} |
q3399 | Manageable.ApplicationHelper.manageable_attributes | train | def manageable_attributes(record, options = {}, &block)
options[:html] ||= {}
html_class = [ "attrtastic", record.class.to_s.underscore, options[:html][:class] ].compact.join(" ")
output = tag(:div, { :class => html_class}, true)
if block_given?
output << capture(Helpers::AttributesBuilder.new(record, self), &block)
else
output << capture(Helpers::AttributesBuilder.new(record, self)) do |attr|
attr.attributes
end
end
output.safe_concat("</div>")
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.