_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
30
4.3k
language
stringclasses
1 value
meta_information
dict
q27100
Tabletastic.TableBuilder.action_link
test
def action_link(action, prefix) html_class = "actions #{action.to_s}_link" block = lambda do |resource| compound_resource = [prefix, resource].compact compound_resource.flatten! if prefix.kind_of?(Array) case action when :show @template.link_to(link_title(action), compound_resource) when :destroy @template.link_to(link_title(action), compound_resource, :method => :delete, :data => { :confirm => confirmation_message }) else # edit, other resource
ruby
{ "resource": "" }
q27101
Metro.Scenes.add
test
def add(scene) all_scenes_for(scene).each { |scene|
ruby
{ "resource": "" }
q27102
Metro.Scenes.apply_post_filters
test
def apply_post_filters(new_scene,options) post_filters.inject(new_scene)
ruby
{ "resource": "" }
q27103
Metro.Scenes.hash_with_missing_scene_default
test
def hash_with_missing_scene_default hash = HashWithIndifferentAccess.new do |hash,key| missing_scene = hash[:missing_scene].constantize missing_scene.missing_scene = key.to_sym
ruby
{ "resource": "" }
q27104
Metro.Scenes.all_scenes_for
test
def all_scenes_for(scenes) Array(scenes).map do |scene_class_name| scene
ruby
{ "resource": "" }
q27105
Metro.Scene.actor
test
def actor(actor_or_actor_name) if actor_or_actor_name.is_a? String or actor_or_actor_name.is_a? Symbol
ruby
{ "resource": "" }
q27106
Metro.Scene.notification
test
def notification(event,sender=nil) sender = sender
ruby
{ "resource": "" }
q27107
Metro.Scene.after
test
def after(ticks,&block) tick = OnUpdateOperation.new interval: ticks, context: self
ruby
{ "resource": "" }
q27108
Metro.Scene.add_actors_to_scene
test
def add_actors_to_scene self.class.actors.each do |scene_actor| actor_instance =
ruby
{ "resource": "" }
q27109
Metro.Scene.register_animations!
test
def register_animations! self.class.animations.each do |animation| animate
ruby
{ "resource": "" }
q27110
Metro.Scene.register_actor
test
def register_actor(actor_factory) registering_actor = actor(actor_factory.name) registering_actor.window = window
ruby
{ "resource": "" }
q27111
Metro.Scene.base_update
test
def base_update updaters.each { |updater| updater.update }
ruby
{ "resource": "" }
q27112
Metro.Scene.base_draw
test
def base_draw drawers.each { |drawer| drawer.draw }
ruby
{ "resource": "" }
q27113
Metro.Scene.transition_to
test
def transition_to(scene_or_scene_name,options = {}) new_scene = Scenes.generate(scene_or_scene_name,options)
ruby
{ "resource": "" }
q27114
Metro.Scene._prepare_transition
test
def _prepare_transition(new_scene) log.debug "Preparing to transition from scene #{self} to #{new_scene}" new_scene.class.actors.find_all {|actor_factory| actor_factory.load_from_previous_scene? }.each do |actor_factory| new_actor = new_scene.actor(actor_factory.name)
ruby
{ "resource": "" }
q27115
Metro.Scene.to_hash
test
def to_hash drawn = drawers.find_all{|draw| draw.saveable_to_view }.inject({}) do
ruby
{ "resource": "" }
q27116
Metro.Model.create
test
def create(model_name,options={}) # @TODO: this is another path that parallels the ModelFactory
ruby
{ "resource": "" }
q27117
Metro.Model._load
test
def _load(options = {}) # Clean up and symbolize all the keys then merge that with the existing properties options.keys.each do |key| property_name = key.to_s.underscore.to_sym if respond_to? "#{property_name}="
ruby
{ "resource": "" }
q27118
WithingsSDK.Client.activities
test
def activities(user_id, options = {}) perform_request(:get, '/v2/measure', WithingsSDK::Activity, 'activities', {
ruby
{ "resource": "" }
q27119
WithingsSDK.Client.body_measurements
test
def body_measurements(user_id, options = {}) perform_request(:get, '/measure', WithingsSDK::MeasurementGroup, 'measuregrps', {
ruby
{ "resource": "" }
q27120
WithingsSDK.Client.weight
test
def weight(user_id, options = {}) groups = body_measurements(user_id, options) groups.map do |group| group.measures.select {
ruby
{ "resource": "" }
q27121
WithingsSDK.Client.sleep_series
test
def sleep_series(user_id, options = {}) perform_request(:get, '/v2/sleep', WithingsSDK::SleepSeries, 'series', {
ruby
{ "resource": "" }
q27122
WithingsSDK.Client.perform_request
test
def perform_request(http_method, path, klass, key, options = {}) if @consumer_key.nil? || @consumer_secret.nil? raise WithingsSDK::Error::ClientConfigurationError, "Missing consumer_key or consumer_secret" end options = WithingsSDK::Utils.normalize_date_params(options) request = WithingsSDK::HTTP::Request.new(@access_token, { 'User-Agent' => user_agent }) response = request.send(http_method, path, options) if key.nil?
ruby
{ "resource": "" }
q27123
CarrierWave.Magic.set_magic_content_type
test
def set_magic_content_type(override=false) if override || file.content_type.blank? || generic_content_type?(file.content_type) new_content_type = ::FileMagic.new(::FileMagic::MAGIC_MIME).file( file.path ).split(';').first if file.respond_to?(:content_type=) file.content_type = new_content_type else file.instance_variable_set(:@content_type, new_content_type)
ruby
{ "resource": "" }
q27124
RabbitMQ.Client.send_request
test
def send_request(channel_id, method, properties={}) Util.error_check :"sending a request",
ruby
{ "resource": "" }
q27125
RabbitMQ.Client.fetch_response
test
def fetch_response(channel_id, method, timeout: protocol_timeout) methods = Array(method).map(&:to_sym)
ruby
{ "resource": "" }
q27126
RabbitMQ.Client.on_event
test
def on_event(channel_id, method, callable=nil, &block) handler = block || callable raise ArgumentError, "expected block or callable as the event handler" \ unless handler.respond_to?(:call)
ruby
{ "resource": "" }
q27127
GtfsReader.SourceUpdater.download_source
test
def download_source Log.debug { " Reading #{@source.url.green}" } zip = Tempfile.new('gtfs') zip.binmode zip << open(@source.url).read zip.rewind extract_to_tempfiles(zip)
ruby
{ "resource": "" }
q27128
GtfsReader.SourceUpdater.check_files
test
def check_files @found_files = [] check_required_files check_optional_files # Add feed files of zip to the list of files to be processed @source.feed_definition.files.each do
ruby
{ "resource": "" }
q27129
GtfsReader.SourceUpdater.check_columns
test
def check_columns @found_files.each do |file| @temp_files[file.filename].open do |data|
ruby
{ "resource": "" }
q27130
GtfsReader.SourceUpdater.fetch_http_fallback_identifier
test
def fetch_http_fallback_identifier(head_request) if head_request.key?('last-modified') head_request['last-modified']
ruby
{ "resource": "" }
q27131
GtfsReader.Configuration.parameter
test
def parameter(*names) names.each do |name| define_singleton_method(name) do |*values| if (value = values.first) instance_variable_set("@#{name}", value)
ruby
{ "resource": "" }
q27132
GtfsReader.FileReader.find_columns
test
def find_columns(validate) @found_columns = [] prefix = "#{filename.yellow}:" required = @definition.required_columns unless required.empty? Log.info { "#{prefix} #{'required columns'.magenta}" } if validate missing = check_columns(validate, prefix, required, :green, :red) raise RequiredColumnsMissing, missing if validate && missing.present? end optional = @definition.optional_columns unless optional.empty?
ruby
{ "resource": "" }
q27133
Nidyx.Mapper.map
test
def map(models, options) models = models.values case options[:platform].downcase
ruby
{ "resource": "" }
q27134
Nidyx.Parser.generate
test
def generate(path, name) object = get_object(path) type = object[TYPE_KEY] if type == OBJECT_TYPE generate_object(path, name) elsif type == ARRAY_TYPE generate_top_level_array(path) elsif type.is_a?(Array) if type.include?(OBJECT_TYPE) raise UnsupportedSchemaError if type.include?(ARRAY_TYPE) generate_object(path,
ruby
{ "resource": "" }
q27135
Nidyx.Parser.resolve_array_refs
test
def resolve_array_refs(obj) items = obj[ITEMS_KEY] case items when Array return resolve_items_array(items) when Hash # handle a nested any of key
ruby
{ "resource": "" }
q27136
Nidyx.Generator.run
test
def run(schema_path, options) schema = Nidyx::Reader.read(schema_path) raw_models = Nidyx::Parser.parse(schema, options) models =
ruby
{ "resource": "" }
q27137
Nidyx.Reader.read
test
def read(path) schema = nil begin # TODO: validate this is legitimate JSON Schema schema = JSON.parse(IO.read(path)) raise EmptySchemaError if empty_schema?(schema) rescue JSON::JSONError => e puts "Encountered an error reading JSON from #{path}" puts e.message
ruby
{ "resource": "" }
q27138
Wxpay.Sign.sign_package
test
def sign_package params params_str = create_sign_str params if params_str =~ /trade_type=APP/
ruby
{ "resource": "" }
q27139
Webspicy.Scope._each_resource_file
test
def _each_resource_file(config) folder = config.folder folder.glob("**/*.yml").select(&to_filter_proc
ruby
{ "resource": "" }
q27140
Webspicy.Scope.each_resource
test
def each_resource(&bl) return enum_for(:each_resource) unless block_given? each_resource_file do |file, folder|
ruby
{ "resource": "" }
q27141
Webspicy.Scope.to_real_url
test
def to_real_url(url, test_case = nil, &bl) case config.host when Proc config.host.call(url, test_case) when String url =~ /^http/ ? url : "#{config.host}#{url}" else return url if url =~ /^http/ return yield(url) if
ruby
{ "resource": "" }
q27142
Webspicy.Scope.to_filter_proc
test
def to_filter_proc(filter) case ff = filter when NilClass then ->(f){ true }
ruby
{ "resource": "" }
q27143
Webspicy.Configuration.folder
test
def folder(folder = nil, &bl) if folder.nil? @folder else folder = folder.is_a?(String) ? @folder/folder : Path(folder) raise "Folder `#{folder}` does not exists" unless folder.exists? && folder.directory? raise "Folder must be a descendant" unless folder.inside?(@folder) child = dup do |c|
ruby
{ "resource": "" }
q27144
Webspicy.Configuration.data_system
test
def data_system schema = self.folder/"schema.fio" if schema.file? Finitio::DEFAULT_SYSTEM.parse(schema.read)
ruby
{ "resource": "" }
q27145
Exodus.Migration.run
test
def run(direction) self.status.direction = direction # reset the status if the job is rerunnable and has already be completed
ruby
{ "resource": "" }
q27146
Exodus.Migration.failure=
test
def failure=(exception) self.status.error = MigrationError.new( :error_message => exception.message,
ruby
{ "resource": "" }
q27147
Exodus.Migration.is_runnable?
test
def is_runnable?(direction) self.class.rerunnable_safe? || (direction == UP && status.current_status < status_complete) ||
ruby
{ "resource": "" }
q27148
Exodus.Migration.completed?
test
def completed?(direction) return false if self.status.execution_time == 0 (direction
ruby
{ "resource": "" }
q27149
Exodus.Migration.step
test
def step(step_message = nil, step_status = 1) unless status.status_processed?(status.direction, step_status) self.status.message = step_message puts "\t #{step_message}"
ruby
{ "resource": "" }
q27150
Exodus.Migration.time_it
test
def time_it puts "Running #{self.class}[#{self.status.arguments}](#{self.status.direction})" start = Time.now
ruby
{ "resource": "" }
q27151
Exodus.TextFormatter.super_print
test
def super_print(paragraphes, space_number = 50, title = true) puts
ruby
{ "resource": "" }
q27152
Gridify.Grid.columns_hash
test
def columns_hash colModel.inject({})
ruby
{ "resource": "" }
q27153
Amber.Site.render
test
def render @page_list.each do |page| page.render_to_file(@config.dest_dir) putc '.'; $stdout.flush end @dir_list.each do |directory| src = File.join(@config.pages_dir, directory) dst = File.join(@config.dest_dir, directory) Render::Asset.render_dir(src, dst) putc '.'; $stdout.flush
ruby
{ "resource": "" }
q27154
Amber.Site.add_page
test
def add_page(page) @pages_by_name[page.name] ||= page @pages_by_path[page.path.join('/')] = page add_aliases(I18n.default_locale, page, @pages_by_path) page.locales.each do |locale|
ruby
{ "resource": "" }
q27155
Amber.Site.add_aliases
test
def add_aliases(locale, page, path_hash) page.aliases(locale).each do |alias_path| alias_path_str = alias_path.join('/') if path_hash[alias_path_str] Amber.logger.warn "WARNING: page `#{page.path.join('/')}` has alias `#{alias_path_str}`, but this path
ruby
{ "resource": "" }
q27156
Amber.StaticPage.parse_headers
test
def parse_headers(content_file) headers = [] para1 = [] para2 = [] file_type = type_from_path(content_file) File.open(content_file, :encoding => 'UTF-8') do |f| while (line = f.gets) =~ /^(- |)@\w/ if line !~ /^-/ line = '- ' + line end headers << line end # eat empty lines while line = f.gets break unless line =~ /^\s*$/ end # grab first two paragraphs para1 << line while line = f.gets break if line =~ /^\s*$/ para1 << line end while line = f.gets break if line =~ /^\s*$/ para2 << line end end headers = headers.join para1 = para1.join para2 = para2.join excerpt = "" # pick the first non-heading paragraph.
ruby
{ "resource": "" }
q27157
Amber.StaticPage.variable_files
test
def variable_files if @simple_page directory = File.dirname(@file_path) regexp = SIMPLE_VAR_MATCH_RE.call(@name) else directory = @file_path regexp = VAR_FILE_MATCH_RE end hsh = {} Dir.foreach(directory) do |file| if
ruby
{ "resource": "" }
q27158
Amber.Menu.last_menu_at_depth
test
def last_menu_at_depth(depth) menu = self depth.times { menu
ruby
{ "resource": "" }
q27159
Amber::Render.TableOfContents.nameize
test
def nameize(str) str = str.dup str.gsub!(/&(\w{2,6}?|#[0-9A-Fa-f]{2,6});/,'') # remove html entitities str.gsub!(/[^- [[:word:]]]/u, '') # remove non-word characters (using unicode definition of a word char) str.strip! str.downcase! # upper case characters in
ruby
{ "resource": "" }
q27160
Amber::Render.TableOfContents.strip_html_tags
test
def strip_html_tags(html) Nokogiri::HTML::DocumentFragment.parse(html,
ruby
{ "resource": "" }
q27161
Amber::Render.TocItem.populate_node
test
def populate_node(node, options) @children.each do |item| li = node.document.create_element("li") li.add_child(li.document.create_element("a", item.text, :href => "#{options[:href_base]}##{item.anchor}")) if item.children.any?
ruby
{ "resource": "" }
q27162
Amber::Render.TocItem.to_html
test
def to_html(options={}) html = [] tag = options[:tag] indent = options[:indent] || 0 str = options[:indent_str] || " " html << '%s<%s>' % [(str*indent), tag] @children.each do |item| html << '%s<li>' % (str*(indent+1)) html << '%s<a href="%s#%s">%s</a>' % [str*(indent+2), options[:href_base],
ruby
{ "resource": "" }
q27163
Amber::Render.TocItem.parent_for
test
def parent_for(heading) heading = heading[1].to_i if heading.is_a?(String) if children.any? && children.last.level < heading
ruby
{ "resource": "" }
q27164
Eve.JavascriptHelper.type_id
test
def type_id(which) which = which.to_s.humanize unless which.kind_of?(String) which.downcase! case which when 'alliance' then 16159 when 'character' then 1377 when 'corporation' then 2 when 'constellation' then 4 when 'region'
ruby
{ "resource": "" }
q27165
Eve.JavascriptHelper.link_to_info
test
def link_to_info(text, type_id, item_id = nil, *args) function = "CCPEVE.showInfo(#{type_id.inspect}"
ruby
{ "resource": "" }
q27166
Eve.JavascriptHelper.link_to_route
test
def link_to_route(text, destination_id, source_id = nil, *args) function = "CCPEVE.showRouteTo(#{destination_id.inspect}" function.concat ", #{source_id.inspect}"
ruby
{ "resource": "" }
q27167
Eve.JavascriptHelper.link_to_trust_request
test
def link_to_trust_request(text, trust_url = "http://#{request.host}/", *args) trust_url = url_for(trust_url.merge(:only_path => false)) if trust_url.kind_of?(Hash)
ruby
{ "resource": "" }
q27168
Eve.JavascriptHelper.request_trust
test
def request_trust(trust_url = "http://#{request.host}/", *args) trust_url = url_for(trust_url.merge(:only_path => false)) if trust_url.kind_of?(Hash)
ruby
{ "resource": "" }
q27169
Amber.StaticPage.render_to_file
test
def render_to_file(dest_dir, options={}) render_content_files(dest_dir, options) render_assets(dest_dir) @props.locales.each do |locale| if
ruby
{ "resource": "" }
q27170
Amber.StaticPage.symlink
test
def symlink(from_path, to_path) to_path = realpath(to_path) target = from_path.relative_path_from(to_path).to_s.sub(/^\.\.\//, '') if !to_path.dirname.directory? Amber.logger.warn { "On page `#{@file_path}`, the parent directories for alias name `#{to_path}` don't exist. Skipping alias." } return end if to_path.exist?
ruby
{ "resource": "" }
q27171
Amber.StaticPage.render_content_files
test
def render_content_files(dest_dir, options) view = Render::View.new(self, @config) @config.locales.each do |file_locale| content_file = content_file(file_locale) next unless content_file dest = destination_file(dest_dir, file_locale) unless Dir.exist?(File.dirname(dest)) FileUtils.mkdir_p(File.dirname(dest)) end if options[:force] ||
ruby
{ "resource": "" }
q27172
Snoo.User.friend
test
def friend name, friend_id, note = nil friend_wrapper(api_name = name, api_container =
ruby
{ "resource": "" }
q27173
Snoo.User.get_user_listing
test
def get_user_listing username, opts = {} opts[:type] = 'overview' if opts[:type].nil? url = "/user/%s%s.json" % [username, ('/' + opts[:type] if opts[:type] != 'overview')]
ruby
{ "resource": "" }
q27174
Snoo.LinksComments.comment
test
def comment text, id logged_in? post('/api/comment', body: { text: text,
ruby
{ "resource": "" }
q27175
Snoo.LinksComments.submit
test
def submit title, subreddit, opts = {} logged_in? post = { title: title, sr: subreddit,
ruby
{ "resource": "" }
q27176
Snoo.LinksComments.vote
test
def vote direction, id logged_in? post('/api/vote', body: {id: id, dir:
ruby
{ "resource": "" }
q27177
Gotcha.Base.correct?
test
def correct?(str) str = str.is_a?(String) ? str : str.to_s str == (@answer.is_a?(String)
ruby
{ "resource": "" }
q27178
Gotcha.FormHelpers.gotcha
test
def gotcha(options = {}) options[:label_options] ||= {} options[:text_field_options] ||= {} if gotcha = Gotcha.random field = "gotcha_response[#{gotcha.class.name.to_s}-#{Digest::MD5.hexdigest(gotcha.class.down_transform(gotcha.answer))}]" (label_tag
ruby
{ "resource": "" }
q27179
Snoo.Subreddit.delete_image
test
def delete_image subreddit, image_name logged_in? post('/api/delete_sr_image', body: {r: subreddit, img_name:
ruby
{ "resource": "" }
q27180
Snoo.Subreddit.set_stylesheet
test
def set_stylesheet stylesheet, subreddit logged_in? post('/api/subreddit_stylesheet', body: {op: 'save', r:
ruby
{ "resource": "" }
q27181
Snoo.Subreddit.subscribe
test
def subscribe subreddit, action = "sub" logged_in? post('/api/subscribe', body: {action: action, sr:
ruby
{ "resource": "" }
q27182
Snoo.Subreddit.my_reddits
test
def my_reddits opts = {} logged_in? url = "/reddits/mine/%s.json" % (opts[:condition] if opts[:condition]) opts.delete
ruby
{ "resource": "" }
q27183
Snoo.Subreddit.get_reddits
test
def get_reddits opts = {} url = "/reddits/%s.json" % (opts[:condition] if opts[:condition]) opts.delete
ruby
{ "resource": "" }
q27184
Snoo.Subreddit.add_moderator
test
def add_moderator container, user, subreddit friend_wrapper
ruby
{ "resource": "" }
q27185
Snoo.Subreddit.add_contributor
test
def add_contributor container, user, subreddit friend_wrapper
ruby
{ "resource": "" }
q27186
Snoo.Subreddit.ban_user
test
def ban_user container, user, subreddit friend_wrapper
ruby
{ "resource": "" }
q27187
Snoo.Subreddit.remove_moderator
test
def remove_moderator container, user, subreddit unfriend_wrapper
ruby
{ "resource": "" }
q27188
Snoo.Subreddit.remove_contributor
test
def remove_contributor container, user, subreddit unfriend_wrapper
ruby
{ "resource": "" }
q27189
Snoo.Subreddit.unban_user
test
def unban_user container, user, subreddit unfriend_wrapper
ruby
{ "resource": "" }
q27190
Snoo.Utilities.get
test
def get *args, &block response = self.class.get *args, &block raise
ruby
{ "resource": "" }
q27191
Snoo.Account.log_in
test
def log_in username, password login = post("/api/login", :body => {user: username, passwd: password, api_type: 'json'}) errors = login['json']['errors'] raise errors[0][1] unless errors.size == 0 set_cookies login.headers['set-cookie']
ruby
{ "resource": "" }
q27192
Snoo.Account.auth
test
def auth modhash, cookies set_cookies cookies @modhash = modhash meinfo = get("/api/me.json")
ruby
{ "resource": "" }
q27193
Snoo.Account.delete_user
test
def delete_user password, reason = "deleted by script command" logged_in? delete = post('/api/delete_user', body: { confirm: true, delete_message: reason, passwd: password,
ruby
{ "resource": "" }
q27194
Snoo.PM.get_messages
test
def get_messages where = "inbox", opts = {} query = { mark: false } query.merge! opts
ruby
{ "resource": "" }
q27195
Snoo.Flair.clear_flair_templates
test
def clear_flair_templates type, subreddit logged_in? post('/api/clearflairtemplates', body: { flair_type: type,
ruby
{ "resource": "" }
q27196
Snoo.Flair.delete_user_flair
test
def delete_user_flair user, subreddit logged_in? post('/api/deleteflair', body: {name: user, r:
ruby
{ "resource": "" }
q27197
Snoo.Flair.delete_flair_template
test
def delete_flair_template id, subreddit logged_in? post('/api/deleteflairtemplate',
ruby
{ "resource": "" }
q27198
Snoo.Flair.flair_config
test
def flair_config subreddit, opts = {} logged_in? options = { flair_enabled: true, flair_position: 'right', flair_self_assign_enabled: false, link_flair_position: 'right', link_flair_self_assign_enabled: false, uh: @modhash,
ruby
{ "resource": "" }
q27199
Snoo.Flair.flair_csv
test
def flair_csv csv, subreddit logged_in? post('/api/flaircsv.json', body: {flair_csv:
ruby
{ "resource": "" }