_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q8000
PuppetDBQuery.MongoDB.node_properties_update
train
def node_properties_update(new_node_properties) collection = connection[node_properties_collection] old_names = collection.find.batch_size(999).projection(_id: 1).map { |k| k[:_id] } delete = old_names - new_node_properties.keys data = new_node_properties.map do |k, v| { replac...
ruby
{ "resource": "" }
q8001
PuppetDBQuery.MongoDB.meta_fact_update
train
def meta_fact_update(method, ts_begin, ts_end) connection[meta_collection].find_one_and_update( {}, { '$set' => { last_fact_update: { ts_begin: ts_begin.iso8601, ts_end: ts_end.iso8601, method: method }, me...
ruby
{ "resource": "" }
q8002
PuppetDBQuery.MongoDB.meta_node_properties_update
train
def meta_node_properties_update(ts_begin, ts_end) connection[meta_collection].find_one_and_update( {}, { '$set' => { last_node_properties_update: { ts_begin: ts_begin.iso8601, ts_end: ts_end.iso8601 } } }, { ...
ruby
{ "resource": "" }
q8003
Idata.Detector.find_same_occurence
train
def find_same_occurence selected = @candidates.select { |delim, count| begin CSV.parse(@sample, col_sep: delim).select{|e| !e.empty? }.map{|e| e.count}.uniq.count == 1 rescue Exception => ex false end }.keys return selected.first if selected.count == 1 ...
ruby
{ "resource": "" }
q8004
DuckMap.Route.keys_required?
train
def keys_required? keys = self.segment_keys.dup keys.delete(:format) return keys.length > 0 ? true : false end
ruby
{ "resource": "" }
q8005
Ork.ResultSet.next_page
train
def next_page raise Ork::NoNextPage.new 'There is no next page' unless has_next_page? self.class.new(@model, @index, @query, @options.merge(continuation: keys.continuation)) end
ruby
{ "resource": "" }
q8006
Statixite.CloudSync.threaded_run!
train
def threaded_run!(files, change) return if files.empty? file_number = 0 total_files = files.length mutex = Mutex.new threads = [] 5.times do |i| threads[i] = Thread.new { until files.empty? mutex.synchronize do file_number += 1 ...
ruby
{ "resource": "" }
q8007
Rattler::Compiler.RubyGenerator.intersperse
train
def intersperse(enum, opts={}) sep = opts[:sep] newlines = opts[:newlines] || (opts[:newline] ? 1 : 0) enum.each_with_index do |_, i| if i > 0 self << sep if sep newlines.times { newline } end yield _ end self end
ruby
{ "resource": "" }
q8008
Clomp.Operation.get_status
train
def get_status @result['tracks'].collect {|track| track.name if track.failure?}.compact.count.zero? ? 'Success' : 'Failure' end
ruby
{ "resource": "" }
q8009
FixedWidthFileValidator.RecordFormatter.formatted_value
train
def formatted_value(value, format, width) value_str = value ? format(format, value) : ' ' * width # all space for nil value length = value_str.length if length > width value_str.slice(0..width - 1) elsif length < width ' ' * (width - length) + value_str else value_s...
ruby
{ "resource": "" }
q8010
JBLAS.MatrixEnumMixin.map!
train
def map!(&block) (0...length).each do |i| put(i, block.call(get(i))) end self end
ruby
{ "resource": "" }
q8011
Lanyon.Router.endpoint
train
def endpoint(path) normalized = normalize_path_info(path) fullpath = File.join(@root, normalized) endpoint = if FileTest.file?(fullpath) fullpath elsif needs_redirect_to_dir?(fullpath) :must_redirect elsif FileTest.file?(fullpath...
ruby
{ "resource": "" }
q8012
Lanyon.Router.custom_404_body
train
def custom_404_body filename = File.join(root, "404.html") File.exist?(filename) ? File.binread(filename) : nil end
ruby
{ "resource": "" }
q8013
GiantBomb.Search.filter
train
def filter(conditions) if conditions conditions.each do |key, value| if self.respond_to?(key) self.send(key, value) end end end end
ruby
{ "resource": "" }
q8014
NanocConrefFS.Ancestry.find_array_parents
train
def find_array_parents(toc, title) parents = '' toc.each do |item| if item.is_a?(Hash) parents = find_hash_parents(item, title) break unless parents.empty? end end parents end
ruby
{ "resource": "" }
q8015
NanocConrefFS.Ancestry.find_hash_parents
train
def find_hash_parents(toc, title) parents = '' toc.each_key do |key| next if toc[key].nil? toc[key].each do |item| if item.is_a?(Hash) if item.keys.include?(title) parents = key break else if item[item.keys.first].in...
ruby
{ "resource": "" }
q8016
NanocConrefFS.Ancestry.find_array_children
train
def find_array_children(toc, title) toc.each do |item| next unless item.is_a?(Hash) item.each_pair do |key, values| if key == title children = values.flatten return children end end end # Found no children Array.new end
ruby
{ "resource": "" }
q8017
NanocConrefFS.Ancestry.find_hash_children
train
def find_hash_children(toc, title) toc.each_key do |key| next if toc[key].nil? toc[key].each do |item| next unless item.is_a?(Hash) if item[title] children = item.values.flatten return children end end end # Found no childre...
ruby
{ "resource": "" }
q8018
Hatt.ApiClients.hatt_add_service
train
def hatt_add_service(name, url_or_svc_cfg_hash) svc_cfg = case url_or_svc_cfg_hash when String { 'url' => url_or_svc_cfg_hash } when Hash url_or_svc_cfg_hash else raise ArgumentError, "'#{url_or_svc_cfg_hash}' is...
ruby
{ "resource": "" }
q8019
ParcelApi.Address.details
train
def details(address_id) details_url = File.join(DOMESTIC_URL, address_id.to_s) response = @connection.get details_url OpenStruct.new(response.parsed['address']) end
ruby
{ "resource": "" }
q8020
ParcelApi.Address.australian_details
train
def australian_details(address_id) details_url = File.join(AUSTRALIAN_URL, address_id.to_s) response = @connection.get details_url RecursiveOpenStruct.new(response.parsed['address'], recurse_over_arrays: true) end
ruby
{ "resource": "" }
q8021
ParcelApi.Address.international_search
train
def international_search(query, count=5, country_code=nil) return [] if query.length < 4 response = @connection.get INTERNATIONAL_URL, params: { q: query.to_ascii, count: count, country_code: country_code } response.parsed['addresses'].map {|address| OpenStruct.new(address)} end
ruby
{ "resource": "" }
q8022
ParcelApi.Address.international_details
train
def international_details(address_id) details_url = File.join(INTERNATIONAL_URL, address_id.to_s) response = @connection.get details_url RecursiveOpenStruct.new(response.parsed['result'], recurse_over_arrays: true) end
ruby
{ "resource": "" }
q8023
ActionKitConnector.Connector.find_petition_pages
train
def find_petition_pages(name, limit: 10, offset: 0) target = "#{self.base_url}/petitionpage/" options = { basic_auth: self.auth, query: { _limit: limit, _offset: offset, name: name } } self.class.get(target, options) end
ruby
{ "resource": "" }
q8024
ActionKitConnector.Connector.create_petition_page
train
def create_petition_page(name, title, lang, canonical_url) target = "#{self.base_url}/petitionpage/" options = { basic_auth: self.auth, headers: { 'Content-type' => 'application/json; charset=UTF-8' }, :body => { :type => 'petitionpage', ...
ruby
{ "resource": "" }
q8025
ActionKitConnector.Connector.create_action
train
def create_action(page_name, email, options={}) target = "#{self.base_url}/action/" body = { page: page_name, email: email }.merge self.parse_action_options(options) options = { basic_auth: self.auth, body: body.to_json, format: :json, headers: {'Content-Type' =...
ruby
{ "resource": "" }
q8026
ActionKitConnector.Connector.create_donation_action
train
def create_donation_action(options={}) target = "#{self.base_url}/donationpush/" options = self.validate_donation_options(options) page_opts = { basic_auth: self.auth, body: options.to_json, headers: { 'Content-Type' => 'application/json; charset=UTF-8' ...
ruby
{ "resource": "" }
q8027
ActionKitConnector.Connector.list_users
train
def list_users(offset=0, limit=20) target = "#{self.base_url}/user/" options = { basic_auth: self.auth, query: { _limit: limit, _offset: offset } } self.class.get(target, options) end
ruby
{ "resource": "" }
q8028
Retrospec.Config.setup_config_file
train
def setup_config_file(file=nil) if file.nil? or ! File.exists?(file) # config does not exist setup_config_dir dst_file = File.join(default_retrospec_dir, 'config.yaml') src_file = File.join(gem_dir,'config.yaml.sample') safe_copy_file(src_file, dst_file) file = dst_...
ruby
{ "resource": "" }
q8029
SpeakyCsv.ConfigBuilder.field
train
def field(*fields, export_only: false) @config.fields += fields.map(&:to_sym) @config.fields.uniq! if export_only @config.export_only_fields += fields.map(&:to_sym) @config.export_only_fields.uniq! end nil end
ruby
{ "resource": "" }
q8030
SpeakyCsv.ConfigBuilder.has_one
train
def has_one(name) @config.root or raise NotImplementedError, "nested associations are not supported" @config.has_ones[name.to_sym] ||= Config.new yield self.class.new config: @config.has_ones[name.to_sym], root: false nil end
ruby
{ "resource": "" }
q8031
SpeakyCsv.ConfigBuilder.has_many
train
def has_many(name) @config.root or raise NotImplementedError, "nested associations are not supported" @config.has_manys[name.to_sym] ||= Config.new yield self.class.new config: @config.has_manys[name.to_sym], root: false nil end
ruby
{ "resource": "" }
q8032
IceCubeCron.RuleBuilder.build_rule
train
def build_rule(expression) rule = build_root_recurrence_rule(expression) rule = build_year_rules(rule, expression) rule = build_weekday_rule(rule, expression) rule = build_day_rules(rule, expression) rule = build_time_rules(rule, expression) rule = rule.until(expression.until) unless...
ruby
{ "resource": "" }
q8033
Hatt.JsonHelpers.jsonify
train
def jsonify(obj) case obj when String JSON.pretty_generate(JSON.parse(obj)) when Hash, Array JSON.pretty_generate(obj) else obj.to_s end rescue Exception obj.to_s end
ruby
{ "resource": "" }
q8034
Hatt.JsonHelpers.objectify
train
def objectify(json_string) return nil if json_string.nil? || json_string == '' case json_string when Hash, Array return json_string else JSON.parse(json_string.to_s) end rescue Exception json_string end
ruby
{ "resource": "" }
q8035
Podbay.Utils.count_values
train
def count_values(*values) values.inject(Hash.new(0)) { |h, v| h[v] += 1; h } end
ruby
{ "resource": "" }
q8036
Podbay.Utils.get_uid
train
def get_uid(username) Etc.passwd { |u| return u.uid if u.name == username } end
ruby
{ "resource": "" }
q8037
Podbay.Utils.get_gid
train
def get_gid(group_name) Etc.group { |g| return g.gid if g.name == group_name } end
ruby
{ "resource": "" }
q8038
Podbay.Utils.podbay_info
train
def podbay_info(ip_address, path, timeout = 5) JSON.parse( get_request( "http://#{ip_address}:#{Podbay::SERVER_INFO_PORT}/#{path}", timeout: timeout ).body, symbolize_names: true ) end
ruby
{ "resource": "" }
q8039
PuppetDBQuery.Updater.update2
train
def update2 update_node_properties logger.info "update2 started (full update)" tsb = Time.now source_nodes = source_node_properties.keys destination_nodes = destination.all_nodes delete_missing(destination_nodes, source_nodes) errors = false complete = source.facts ...
ruby
{ "resource": "" }
q8040
PuppetDBQuery.Updater.update_node_properties
train
def update_node_properties logger.info "update_node_properties started" tsb = Time.now @source_node_properties = source.node_properties destination.node_properties_update(source_node_properties) tse = Time.now logger.info "update_node_properties got #{source_node_properties.size} nod...
ruby
{ "resource": "" }
q8041
Rack::AcceptHeaders.Encoding.matches
train
def matches(encoding) values.select {|v| v == encoding || v == '*' }.sort {|a, b| # "*" gets least precedence, any others should be equal. a == '*' ? 1 : (b == '*' ? -1 : 0) } end
ruby
{ "resource": "" }
q8042
Selections.BelongsToSelection.belongs_to_selection
train
def belongs_to_selection(target, options={}) belongs_to target, options.merge(:class_name => "Selection") # The "selections" table may not exist during certain rake scenarios such as db:migrate or db:reset. if ActiveRecord::Base.connection.table_exists? Selection.table_name prefix = self.name...
ruby
{ "resource": "" }
q8043
HtmlGrid.Composite.full_colspan
train
def full_colspan raw_span = components.keys.collect{ |key| key.at(0) }.max.to_i (raw_span > 0) ? raw_span + 1 : nil end
ruby
{ "resource": "" }
q8044
EM::Xmpp.Entity.subscribe
train
def subscribe(&blk) pres = connection.presence_stanza('to'=>jid.bare, 'type' => 'subscribe') connection.send_stanza pres, &blk end
ruby
{ "resource": "" }
q8045
EM::Xmpp.Entity.accept_subscription
train
def accept_subscription(&blk) pres = connection.presence_stanza('to'=>jid.bare, 'type' => 'subscribed') connection.send_stanza pres, &blk end
ruby
{ "resource": "" }
q8046
EM::Xmpp.Entity.unsubscribe
train
def unsubscribe(&blk) pres = connection.presence_stanza('to'=>jid.bare, 'type' => 'unsubscribe') connection.send_stanza pres, &blk end
ruby
{ "resource": "" }
q8047
EM::Xmpp.Entity.pubsub
train
def pubsub(nid=nil) node_jid = if nid JID.new(jid.node, jid.domain, nid) else jid.to_s end PubSub.new(connection, node_jid) end
ruby
{ "resource": "" }
q8048
EM::Xmpp.Entity.muc
train
def muc(nick=nil) muc_jid = JID.new jid.node, jid.domain, nick Muc.new(connection, muc_jid) end
ruby
{ "resource": "" }
q8049
EstoreConventions.ArchivedOutliers.versions_average_for_attribute
train
def versions_average_for_attribute(att, opts={}) _use_delta = opts[:delta] || false if _use_delta return historical_rate_per_day(att, nil, nil) else data = versions_complete_data_for_attribute(att, opts) return data.e_mean end end
ruby
{ "resource": "" }
q8050
Jia.User.phone
train
def phone @phone ||= -> { mac = Jia::Utils.load_data('phone_mac').sample area_code = rand(9999).to_s.center(4, rand(9).to_s) user_identifier = rand(9999).to_s.center(4, rand(9).to_s) "#{mac}#{area_code}#{user_identifier}" }.call end
ruby
{ "resource": "" }
q8051
Cyclical.Rule.match?
train
def match?(time, base) aligned?(time, base) && @filters.all? { |f| f.match?(time) } end
ruby
{ "resource": "" }
q8052
Cyclical.Rule.potential_previous
train
def potential_previous(current, base) @filters.map { |f| f.previous(current) }.min || current end
ruby
{ "resource": "" }
q8053
Bixby.Hashify.to_hash
train
def to_hash self.instance_variables.inject({}) { |m,v| m[v[1,v.length].to_sym] = instance_variable_get(v); m } end
ruby
{ "resource": "" }
q8054
Coals.TaskTree.build_tasks
train
def build_tasks load_rakefile Rake.application.tasks.reject { |t| t.comment.nil? } end
ruby
{ "resource": "" }
q8055
LatoBlog.Post.check_lato_blog_post_parent
train
def check_lato_blog_post_parent post_parent = LatoBlog::PostParent.find_by(id: lato_blog_post_parent_id) if !post_parent errors.add('Post parent', 'not exist for the post') throw :abort return end same_language_post = post_parent.posts.find_by(meta_language: meta_languag...
ruby
{ "resource": "" }
q8056
LatoBlog.Post.add_to_default_category
train
def add_to_default_category default_category_parent = LatoBlog::CategoryParent.find_by(meta_default: true) return unless default_category_parent category = default_category_parent.categories.find_by(meta_language: meta_language) return unless category LatoBlog::CategoryPost.create(lato_b...
ruby
{ "resource": "" }
q8057
Scalaroid.JSONConnection.call
train
def call(function, params) start req = Net::HTTP::Post.new(DEFAULT_PATH) req.add_field('Content-Type', 'application/json; charset=utf-8') req.body = URI::encode({ :jsonrpc => :'2.0', :method => function, :params => params, :id => 0 }.to_json({:ascii_only => true})...
ruby
{ "resource": "" }
q8058
Caliph.CommandLine.string_format
train
def string_format (command_environment.map do |key, value| [key, value].join("=") end + [command]).join(" ") end
ruby
{ "resource": "" }
q8059
LittleLogFriend.Formatter.call
train
def call ( severity, time, progname, msg ) msg = Format % [format_datetime(time), severity, $$, progname, msg2str(msg)] msg = @@colors[severity] + msg + @@colors['DEFAULT'] if @@colorize msg << "\n" end
ruby
{ "resource": "" }
q8060
HailHydra.TPB.search
train
def search(query, pages=1, orderby=99) get = make_search_request(query, pages, orderby) raise "Invalid response: #{get.response.code}" unless get.response.code == "200" return parse_search_results(get.response.body) end
ruby
{ "resource": "" }
q8061
Skittles.Request.post
train
def post(path, options = {}, headers = {}, raw = false) request(:post, path, options, headers, raw) end
ruby
{ "resource": "" }
q8062
Skittles.Request.put
train
def put(path, options = {}, headers = {}, raw = false) request(:put, path, options, headers, raw) end
ruby
{ "resource": "" }
q8063
Skittles.Request.delete
train
def delete(path, options = {}, headers = {}, raw = false) request(:delete, path, options, headers, raw) end
ruby
{ "resource": "" }
q8064
Ablerc.Option.to_stub
train
def to_stub stub = "## #{name}\n" stub << "# #{description}\n" unless description.nil? stub << "#{entry_for_refuse_allow_behavior}\n" unless refuses.nil? and allows.nil? stub << "#{entry_for_key_value}\n" stub << "\n" end
ruby
{ "resource": "" }
q8065
Notifaction.Style.format
train
def format(message, colour = nil, style = nil) c = @map[:colour][colour.to_sym] unless colour.nil? if style.nil? t = 0 else t = @map[:style][style.to_sym] end "\e[#{t};#{c}m#{message}\e[0m" end
ruby
{ "resource": "" }
q8066
Vigilem::FFI.ArrayPointerSync.update
train
def update if (results = what_changed?)[:ary] update_ptr update_ary_cache true elsif results[:ptr] update_ary update_ptr_cache true else false end end
ruby
{ "resource": "" }
q8067
Vigilem::FFI.ArrayPointerSync.update_ptr
train
def update_ptr ptr.clear if (not (arry_type = self.class.ary_type).is_a?(Symbol)) if arry_type.respond_to? :to_native ary.each {|item| ptr.write_pointer(arry_type.to_native(item, nil)) } elsif arry_type.method_defined? :bytes ptr.write_bytes(ary.map {|item| item.respond....
ruby
{ "resource": "" }
q8068
ESS.Element.method_missing
train
def method_missing m, *args, &block if method_name_is_tag_name? m return assign_tag(m, args, &block) elsif method_name_is_tag_adder_method? m return extend_tag_list(m, args, &block) elsif method_name_is_tag_list_method? m return child_tags[m[0..-6].to_sym] ||= [] elsif m...
ruby
{ "resource": "" }
q8069
MediaWiki.Page.summary
train
def summary text_array = to_text.split("\n") text = text_array[0] i = 1 while text.length <= 140 && i < text_array.length text << "\n" + text_array[i] i += 1 end text end
ruby
{ "resource": "" }
q8070
OauthProviderEngine.RequestToken.upgrade!
train
def upgrade! access_token = nil transaction do access_token = OauthProviderEngine::AccessToken.create!({ :application_id => self.application_id, :user_id => self.user_id, }) self.destroy || raise(ActiveRecord::Rollback) end return access_token end
ruby
{ "resource": "" }
q8071
SortIndex.File.sorted_puts
train
def sorted_puts(line) if line == nil || line.size == 0 raise ArgumentError, 'Line cannot be blank!' end if line.index($/) raise ArgumentError, "Cannot `puts` a line with extra line endings. Make sure the line does not contain `#{$/.inspect}`" end matched, idx = binary_seek...
ruby
{ "resource": "" }
q8072
SortIndex.File.index_each_line
train
def index_each_line positions = [] size = 0 each_line do |line| positions << [size, line.size] size += line.size end rewind positions end
ruby
{ "resource": "" }
q8073
SortIndex.File.do_at_current_position
train
def do_at_current_position(&block) current_position = self.tell huge_buffer = self.read self.seek(current_position, IO::SEEK_SET) block.call ensure self.write huge_buffer end
ruby
{ "resource": "" }
q8074
TheBigDB.Request.prepare
train
def prepare(method, request_uri, params = {}) method = method.downcase.to_s if TheBigDB.api_key.is_a?(String) and !TheBigDB.api_key.empty? params.merge!("api_key" => TheBigDB.api_key) end # we add the API version to the URL, with a trailing slash and the rest of the request reque...
ruby
{ "resource": "" }
q8075
TheBigDB.Request.execute
train
def execute # Here is the order of operations: # -> setting @data_sent # -> executing before_request_execution callback # -> executing the HTTP request # -> setting @response # -> setting @data_received # -> executing after_request_execution callback # Setting @data_sent...
ruby
{ "resource": "" }
q8076
Aker.GroupMemberships.find
train
def find(group, *affiliate_ids) candidates = self.select { |gm| gm.group.include?(group) } return candidates if affiliate_ids.empty? candidates.select { |gm| affiliate_ids.detect { |id| gm.include_affiliate?(id) } } end
ruby
{ "resource": "" }
q8077
RailsKvsDriver.Session.session
train
def session(driver_config, &block) driver_config = validate_driver_config!(driver_config) driver_connection_pool(self, driver_config).with do |kvs_instance| block.call(self.new(kvs_instance, driver_config)) end end
ruby
{ "resource": "" }
q8078
RailsKvsDriver.Session.driver_connection_pool
train
def driver_connection_pool(driver_class, driver_config) pool = search_driver_connection_pool(driver_class, driver_config) return (pool.nil?) ? set_driver_connection_pool(driver_class, driver_config) : pool end
ruby
{ "resource": "" }
q8079
RailsKvsDriver.Session.set_driver_connection_pool
train
def set_driver_connection_pool(driver_class, driver_config) conf = { size: driver_config[:pool_size], timeout: driver_config[:timeout_sec] } pool = ConnectionPool.new(conf) { driver_class.connect(driver_config) } RailsKvsDriver::KVS_CONNECTION_POOL[driver_class.name] ||...
ruby
{ "resource": "" }
q8080
RailsKvsDriver.Session.search_driver_connection_pool
train
def search_driver_connection_pool(driver_class, driver_config) if RailsKvsDriver::KVS_CONNECTION_POOL.has_key?(driver_class.name) RailsKvsDriver::KVS_CONNECTION_POOL[driver_class.name].each do |pool_set| return pool_set[:pool] if equal_driver_config?(pool_set[:config], driver_config) end...
ruby
{ "resource": "" }
q8081
RailsKvsDriver.Session.equal_driver_config?
train
def equal_driver_config?(config1, config2) return false unless config1[:host] == config2[:host] return false unless config1[:port] == config2[:port] return false unless config1[:timeout_sec] == config2[:timeout_sec] return false unless config1[:pool_size] == config2[:pool_size] ...
ruby
{ "resource": "" }
q8082
Crisp.FunctionRunner.validate_args_count
train
def validate_args_count(expected, got) if (expected.is_a?(Numeric) and expected != got) or (expected.is_a?(Range) and !(expected === got)) raise ArgumentError, "wrong number of arguments for '#{name}' (#{got} for #{expected})" end end
ruby
{ "resource": "" }
q8083
Irie.ClassMethods.extensions!
train
def extensions!(*extension_syms) return extension_syms if extension_syms.length == 0 extension_syms = extension_syms.flatten.collect {|es| es.to_sym}.compact if extension_syms.include?(:all) ordered_extension_syms = self.extension_include_order.dup else extensions_without_defin...
ruby
{ "resource": "" }
q8084
Humpyard.ElementsController.new
train
def new @element = Humpyard::config.element_types[params[:type]].new( :page_id => params[:page_id], :container_id => params[:container_id].to_i > 0 ? params[:container_id].to_i : nil, :page_yield_name => params[:yield_name].blank? ? 'main' : params[:yield_name], :shared_state => 0...
ruby
{ "resource": "" }
q8085
Humpyard.ElementsController.create
train
def create @element = Humpyard::config.element_types[params[:type]].new params[:element] unless can? :create, @element.element render :json => { :status => :failed }, :status => 403 return end if @element.save @prev = Hump...
ruby
{ "resource": "" }
q8086
Humpyard.ElementsController.update
train
def update @element = Humpyard::Element.find(params[:id]) if @element unless can? :update, @element render :json => { :status => :failed }, :status => 403 return end if @element.content_data.update_attributes params[:element] ...
ruby
{ "resource": "" }
q8087
Humpyard.ElementsController.move
train
def move @element = Humpyard::Element.find(params[:id]) if @element unless can? :update, @element render :json => { :status => :failed }, :status => 403 return end @element.update_attributes( :container => Humpyard::...
ruby
{ "resource": "" }
q8088
Aker.Configuration.api_modes=
train
def api_modes=(*new_modes) new_modes = new_modes.first if new_modes.size == 1 && Array === new_modes.first @api_modes = new_modes.compact.collect(&:to_sym) end
ruby
{ "resource": "" }
q8089
Aker.Configuration.central
train
def central(filename) params = ::Aker::CentralParameters.new(filename) params.each { |k, v| add_parameters_for(k, v) } end
ruby
{ "resource": "" }
q8090
Adept.Core.configure
train
def configure(elf_file, target=@targets.keys.first) #Ensure the target is a string. target = target.to_s #Get the path to the bitfile and memory map which will be used to generate the new bitfile. memory_map = "#@base_path/#{@targets[target]['memory_map']}" bit_file = "#@base_path/...
ruby
{ "resource": "" }
q8091
Adept.Core.with_temporary_files
train
def with_temporary_files(file_contents='', dest_extension = '', source_extension = '', message=nil) #File mode for all of the created temporary files. #Create the files, and allow read/write, but do not lock for exclusive access. file_mode = File::CREAT | File::RDWR #Create a new file which co...
ruby
{ "resource": "" }
q8092
Cheers.Color.to_s
train
def to_s return '#' + r.to_s(16).rjust(2, '0') + g.to_s(16).rjust(2, '0') + b.to_s(16).rjust(2, '0') end
ruby
{ "resource": "" }
q8093
Plangrade.Client.request
train
def request(method, path, params={}) headers = @default_headers.merge({'Authorization' => "Bearer #{@access_token}"}) result = http_client.send_request(method, path, { :params => params, :headers => headers }) result end
ruby
{ "resource": "" }
q8094
VirtualMonkey.Application.app_servers
train
def app_servers ret = @servers.select { |s| s.nickname =~ /App Server/ } raise "No app servers in deployment" unless ret.length > 0 ret end
ruby
{ "resource": "" }
q8095
RVideo.Inspector.duration
train
def duration return nil unless valid? units = raw_duration.split(":") (units[0].to_i * 60 * 60 * 1000) + (units[1].to_i * 60 * 1000) + (units[2].to_f * 1000).to_i end
ruby
{ "resource": "" }
q8096
EmailChecker.Domain.valid?
train
def valid? return false unless @domain Timeout.timeout(SERVER_TIMEOUT) do return true if valid_mx_records? return true if a_records? end rescue Timeout::Error, Errno::ECONNREFUSED false end
ruby
{ "resource": "" }
q8097
EmailChecker.Domain.valid_mx_records?
train
def valid_mx_records? mx_servers.each do |server| exchange_a_records = dns.getresources(server[:address], Resolv::DNS::Resource::IN::A) return true if exchange_a_records.any? end false end
ruby
{ "resource": "" }
q8098
EmailChecker.Domain.mx_servers
train
def mx_servers return @mx_servers if @mx_servers @mx_servers = [] mx_records.each do |mx| @mx_servers.push(preference: mx.preference, address: mx.exchange.to_s) end @mx_servers end
ruby
{ "resource": "" }
q8099
BitMagic.BitsGenerator.bits_for
train
def bits_for(*field_names) bits = [] field_names.flatten.each do |i| if i.is_a?(Integer) bits << i next end if i.respond_to?(:to_sym) and @field_list[i.to_sym] bits << @field_list[i.to_sym] end end bits.flatten ...
ruby
{ "resource": "" }