_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
30
4.3k
language
stringclasses
1 value
meta_information
dict
q800
JOSE.JWE.key_encrypt
train
def key_encrypt(key, decrypted_key) encrypted_key, new_alg = alg.key_encrypt(key, enc, decrypted_key)
ruby
{ "resource": "" }
q801
JOSE.JWE.next_cek
train
def next_cek(key) decrypted_key, new_alg = alg.next_cek(key, enc) new_jwe = JOSE::JWE.from_map(to_map)
ruby
{ "resource": "" }
q802
Stove.Validator.run
train
def run(cookbook, options = {}) log.info("Running validations for `#{klass.id}.#{id}'") inside(cookbook) do instance = klass.new(cookbook, options) unless result = instance.instance_eval(&block) log.debug("Validation failed, result: #{result.inspect}") # Convert the class and id to their magical equivalents error =
ruby
{ "resource": "" }
q803
Stove.Packager.tar
train
def tar(root, slip) io = StringIO.new('', 'r+b') Gem::Package::TarWriter.new(io) do |tar| slip.each do |original_file, tarball_file| mode = File.stat(original_file).mode if File.directory?(original_file) tar.mkdir(tarball_file, mode) else
ruby
{ "resource": "" }
q804
Stove.Cli.option_parser
train
def option_parser @option_parser ||= OptionParser.new do |opts| opts.banner = 'Usage: stove [OPTIONS]' opts.separator '' opts.separator 'Plugins:' opts.on('--no-git', 'Do not use the git plugin. Skips tagging if specified.') do options[:no_git] = true end opts.separator '' opts.separator 'Upload Options:' opts.on('--endpoint [URL]', 'Supermarket endpoint') do |v| options[:endpoint] = v end opts.on('--username [USERNAME]', 'Username to authenticate with') do |v| options[:username] = v end opts.on('--key [PATH]', 'Path to the private key on disk') do |v| options[:key] = v end opts.on('--[no-]extended-metadata', 'Include non-backwards compatible metadata keys such as `issues_url`') do |v| options[:extended_metadata] = v end opts.on('--no-ssl-verify', 'Turn off ssl verify') do options[:ssl_verify] = false end
ruby
{ "resource": "" }
q805
Stove.Cli.options
train
def options @options ||= { # Upload options :endpoint => nil, :username => Config.username, :key => Config.key, :extended_metadata => true, :ssl_verify => true, # Git options :remote => 'origin', :branch => 'master', :sign => false, # Artifactory options
ruby
{ "resource": "" }
q806
Stove.Supermarket.upload
train
def upload(cookbook, extended_metadata = false) connection.post('cookbooks', { 'tarball' => cookbook.tarball(extended_metadata), # This is for legacy, backwards-compatability reasons. The new # Supermarket site does not require a category, but many of the testing # tools still assume
ruby
{ "resource": "" }
q807
Stove.Supermarket.connection
train
def connection @connection ||= ChefAPI::Connection.new do |conn| conn.endpoint = ENV['STOVE_ENDPOINT'] || Config.endpoint || DEFAULT_ENDPOINT conn.client = ENV['STOVE_USERNAME'] || Config.username conn.key
ruby
{ "resource": "" }
q808
Stove.Artifactory.upload
train
def upload(cookbook, extended_metadata = false) # Artifactory doesn't prevent uploading over an existing release in # some cases so let's check for that. Seriously never do this, go delete # and then re-upload if you have to. response = request(:get, "api/v1/cookbooks/#{cookbook.name}/versions/#{cookbook.version}") # Artifactory's version of the cookbook_version endpoint returns an
ruby
{ "resource": "" }
q809
Stove.Artifactory.connection
train
def connection @connection ||= begin uri = URI(Config.artifactory.strip) # Open the HTTP connection to artifactory. http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == 'https' http.use_ssl = true # Mimic the behavior of the Cookbook uploader for SSL verification.
ruby
{ "resource": "" }
q810
Stove.Artifactory.request
train
def request(method, path, &block) uri_string = Config.artifactory.strip # Make sure we end up with the right number of separators. uri_string << '/' unless uri_string.end_with?('/') uri_string << path uri = URI(uri_string)
ruby
{ "resource": "" }
q811
Stove.Cookbook.released?
train
def released? Supermarket.cookbook(name, version) true
ruby
{ "resource": "" }
q812
Stove.Filter.run
train
def run(cookbook, options = {}) log.info(message) instance = klass.new(cookbook, options) inside(cookbook)
ruby
{ "resource": "" }
q813
Erubis.RubyEvaluator.evaluate
train
def evaluate(_context=Context.new) _context = Context.new(_context) if _context.is_a?(Hash) #return _context.instance_eval(@src, @filename || '(erubis)') #@_proc ||= eval("proc { #{@src} }", Erubis::EMPTY_BINDING, @filename || '(erubis)')
ruby
{ "resource": "" }
q814
Erubis.RubyEvaluator.def_method
train
def def_method(object, method_name, filename=nil) m = object.is_a?(Module) ? :module_eval : :instance_eval object.__send__(m,
ruby
{ "resource": "" }
q815
Erubis.Converter.convert
train
def convert(input) codebuf = "" # or [] @preamble.nil? ? add_preamble(codebuf) : (@preamble && (codebuf << @preamble)) convert_input(codebuf, input)
ruby
{ "resource": "" }
q816
Erubis.Converter.detect_spaces_at_bol
train
def detect_spaces_at_bol(text, is_bol) lspace = nil if text.empty? lspace = "" if is_bol elsif text[-1] == ?\n lspace = "" else rindex = text.rindex(?\n) if rindex s = text[rindex+1..-1] if s =~ /\A[ \t]*\z/ lspace = s #text = text[0..rindex] text[rindex+1..-1] = '' end
ruby
{ "resource": "" }
q817
Erubis.Engine.process
train
def process(input, context=nil, filename=nil) code = convert(input) filename ||= '(erubis)' if context.is_a?(Binding) return eval(code, context, filename)
ruby
{ "resource": "" }
q818
Erubis.Engine.process_proc
train
def process_proc(proc_obj, context=nil, filename=nil) if context.is_a?(Binding) filename ||= '(erubis)' return eval(proc_obj, context, filename) else
ruby
{ "resource": "" }
q819
LIBUSB.Device.open
train
def open ppHandle = FFI::MemoryPointer.new :pointer res = Call.libusb_open(@pDev, ppHandle) LIBUSB.raise_error res, "in libusb_open" if res!=0 handle = DevHandle.new self, ppHandle.read_pointer
ruby
{ "resource": "" }
q820
LIBUSB.Device.max_packet_size
train
def max_packet_size(endpoint) endpoint = endpoint.bEndpointAddress if endpoint.respond_to? :bEndpointAddress
ruby
{ "resource": "" }
q821
LIBUSB.Device.max_iso_packet_size
train
def max_iso_packet_size(endpoint) endpoint = endpoint.bEndpointAddress if endpoint.respond_to? :bEndpointAddress
ruby
{ "resource": "" }
q822
LIBUSB.Device.config_descriptor
train
def config_descriptor(index) ppConfig = FFI::MemoryPointer.new :pointer res = Call.libusb_get_config_descriptor(@pDev, index, ppConfig) LIBUSB.raise_error res, "in libusb_get_config_descriptor" if res!=0
ruby
{ "resource": "" }
q823
LIBUSB.Device.configurations
train
def configurations configs = [] bNumConfigurations.times do |config_index| begin configs << config_descriptor(config_index) rescue RuntimeError
ruby
{ "resource": "" }
q824
LIBUSB.Context.eventmachine_register
train
def eventmachine_register @eventmachine_attached_fds = {} @eventmachine_timer = nil pollfds = self.pollfds if pollfds pollfds.each do |pollfd| eventmachine_add_pollfd(pollfd) end self.on_pollfd_added do |pollfd| eventmachine_add_pollfd(pollfd) end self.on_pollfd_removed do |pollfd| eventmachine_rm_pollfd(pollfd)
ruby
{ "resource": "" }
q825
LIBUSB.DevHandle.claim_interface
train
def claim_interface(interface) interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber res = Call.libusb_claim_interface(@pHandle, interface) LIBUSB.raise_error res, "in libusb_claim_interface" if res!=0
ruby
{ "resource": "" }
q826
LIBUSB.DevHandle.set_configuration
train
def set_configuration(configuration) configuration = configuration.bConfigurationValue if configuration.respond_to? :bConfigurationValue res =
ruby
{ "resource": "" }
q827
LIBUSB.DevHandle.set_interface_alt_setting
train
def set_interface_alt_setting(setting_or_interface_number, alternate_setting=nil) alternate_setting ||= setting_or_interface_number.bAlternateSetting if setting_or_interface_number.respond_to? :bAlternateSetting
ruby
{ "resource": "" }
q828
LIBUSB.DevHandle.kernel_driver_active?
train
def kernel_driver_active?(interface) interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber
ruby
{ "resource": "" }
q829
LIBUSB.DevHandle.detach_kernel_driver
train
def detach_kernel_driver(interface) interface = interface.bInterfaceNumber if interface.respond_to? :bInterfaceNumber res = Call.libusb_detach_kernel_driver(@pHandle,
ruby
{ "resource": "" }
q830
LIBUSB.DevHandle.bulk_transfer
train
def bulk_transfer(args={}, &block) timeout = args.delete(:timeout) || 1000 endpoint = args.delete(:endpoint) || raise(ArgumentError, "no endpoint given") endpoint = endpoint.bEndpointAddress if endpoint.respond_to? :bEndpointAddress if endpoint&ENDPOINT_IN != 0 dataIn = args.delete(:dataIn) || raise(ArgumentError, "no :dataIn given for bulk read")
ruby
{ "resource": "" }
q831
LIBUSB.DevHandle.control_transfer
train
def control_transfer(args={}, &block) bmRequestType = args.delete(:bmRequestType) || raise(ArgumentError, "param :bmRequestType not given") bRequest = args.delete(:bRequest) || raise(ArgumentError, "param :bRequest not given") wValue = args.delete(:wValue) || raise(ArgumentError, "param :wValue not given") wIndex = args.delete(:wIndex) || raise(ArgumentError, "param :wIndex not given") timeout = args.delete(:timeout) || 1000 if bmRequestType&ENDPOINT_IN != 0 dataIn = args.delete(:dataIn) || 0 dataOut = '' else dataOut = args.delete(:dataOut) || '' end raise ArgumentError, "invalid params #{args.inspect}" unless args.empty? # reuse transfer struct to speed up transfer
ruby
{ "resource": "" }
q832
LIBUSB.Bos.device_capabilities
train
def device_capabilities pp_ext = FFI::MemoryPointer.new :pointer caps = [] # Capabilities are appended to the bos header ptr = pointer + offset_of(:dev_capability) bNumDeviceCaps.times do cap = DeviceCapability.new self, ptr.read_pointer case cap.bDevCapabilityType when LIBUSB::BT_WIRELESS_USB_DEVICE_CAPABILITY # no struct defined in libusb -> use generic DeviceCapability when LIBUSB::BT_USB_2_0_EXTENSION
ruby
{ "resource": "" }
q833
LIBUSB.Transfer.submit!
train
def submit!(&block) self.callback = block if block_given? # puts "submit transfer #{@transfer.inspect} buffer: #{@transfer[:buffer].inspect} length: #{@transfer[:length].inspect} status: #{@transfer[:status].inspect} callback: #{@transfer[:callback].inspect}
ruby
{ "resource": "" }
q834
LIBUSB.Transfer.submit_and_wait
train
def submit_and_wait raise ArgumentError, "#{self.class}#dev_handle not set" unless @dev_handle @completion_flag.completed = false submit! do |tr2| @completion_flag.completed = true end until @completion_flag.completed?
ruby
{ "resource": "" }
q835
LIBUSB.Context.handle_events
train
def handle_events(timeout=nil, completion_flag=nil) if completion_flag && !completion_flag.is_a?(Context::CompletionFlag) raise ArgumentError, "completion_flag is not a CompletionFlag" end if timeout timeval = Call::Timeval.new timeval.in_ms = timeout res = if Call.respond_to?(:libusb_handle_events_timeout_completed) Call.libusb_handle_events_timeout_completed(@ctx, timeval, completion_flag) else Call.libusb_handle_events_timeout(@ctx, timeval)
ruby
{ "resource": "" }
q836
LIBUSB.Context.devices
train
def devices(filter_hash={}) device_list.select do |dev| ( !filter_hash[:bClass] || (dev.bDeviceClass==CLASS_PER_INTERFACE ? dev.settings.map(&:bInterfaceClass).&([filter_hash[:bClass]].flatten).any? : [filter_hash[:bClass]].flatten.include?(dev.bDeviceClass))) && ( !filter_hash[:bSubClass] || (dev.bDeviceClass==CLASS_PER_INTERFACE ? dev.settings.map(&:bInterfaceSubClass).&([filter_hash[:bSubClass]].flatten).any? : [filter_hash[:bSubClass]].flatten.include?(dev.bDeviceSubClass))) && ( !filter_hash[:bProtocol] || (dev.bDeviceClass==CLASS_PER_INTERFACE ? dev.settings.map(&:bInterfaceProtocol).&([filter_hash[:bProtocol]].flatten).any? :
ruby
{ "resource": "" }
q837
LIBUSB.Context.pollfds
train
def pollfds ppPollfds = Call.libusb_get_pollfds(@ctx) return nil if ppPollfds.null? offs = 0 pollfds = [] while !(pPollfd=ppPollfds.get_pointer(offs)).null? pollfd = Call::Pollfd.new pPollfd pollfds << Pollfd.new(pollfd[:fd], pollfd[:events]) offs += FFI.type_size :pointer end
ruby
{ "resource": "" }
q838
LIBUSB.Context.next_timeout
train
def next_timeout timeval = Call::Timeval.new res = Call.libusb_get_next_timeout @ctx, timeval LIBUSB.raise_error
ruby
{ "resource": "" }
q839
LIBUSB.Context.on_pollfd_added
train
def on_pollfd_added &block @on_pollfd_added = proc do |fd, events, _| pollfd = Pollfd.new fd, events block.call pollfd
ruby
{ "resource": "" }
q840
LIBUSB.Context.on_pollfd_removed
train
def on_pollfd_removed &block @on_pollfd_removed = proc do |fd, _| pollfd = Pollfd.new fd block.call pollfd end
ruby
{ "resource": "" }
q841
LIBUSB.Context.on_hotplug_event
train
def on_hotplug_event(args={}, &block) events = args.delete(:events) || (HOTPLUG_EVENT_DEVICE_ARRIVED | HOTPLUG_EVENT_DEVICE_LEFT) flags = args.delete(:flags) || 0 vendor_id = args.delete(:vendor_id) || HOTPLUG_MATCH_ANY product_id = args.delete(:product_id) || HOTPLUG_MATCH_ANY dev_class = args.delete(:dev_class) || HOTPLUG_MATCH_ANY raise ArgumentError, "invalid params #{args.inspect}" unless args.empty? handle = HotplugCallback.new self, @ctx, @hotplug_callbacks block2 = proc do |ctx, pDevice, event, _user_data|
ruby
{ "resource": "" }
q842
Telegrammer.Bot.send_message
train
def send_message(params) extra_params_validation = { text: { required: true, class: [String] }, parse_mode: { required: false,
ruby
{ "resource": "" }
q843
Telegrammer.Bot.forward_message
train
def forward_message(params) params_validation = { chat_id: { required: true, class: [Fixnum] }, from_chat_id: { required: true, class: [String] },
ruby
{ "resource": "" }
q844
Telegrammer.Bot.send_photo
train
def send_photo(params) extra_params_validation = { photo: { required: true, class: [File, String] }, caption: { required: false, class: [String] }
ruby
{ "resource": "" }
q845
Telegrammer.Bot.send_audio
train
def send_audio(params) extra_params_validation = { audio: { required: true, class: [File, String] }, duration: { required: false, class: [Integer] }, performer: { required: false, class: [String]
ruby
{ "resource": "" }
q846
Telegrammer.Bot.send_voice
train
def send_voice(params) extra_params_validation = { voice: { required: true, class: [File, String] }, duration: { required: false, class: [Integer] }
ruby
{ "resource": "" }
q847
Telegrammer.Bot.send_document
train
def send_document(params) extra_params_validation = { document: { required: true, class: [File, String] } }
ruby
{ "resource": "" }
q848
Telegrammer.Bot.send_sticker
train
def send_sticker(params) extra_params_validation = { sticker: { required: true, class: [File, String] } }
ruby
{ "resource": "" }
q849
Telegrammer.Bot.send_video
train
def send_video(params) extra_params_validation = { video: { required: true, class: [File, String] }, duration: { required: false, class: [Integer] }, caption: {
ruby
{ "resource": "" }
q850
Telegrammer.Bot.send_location
train
def send_location(params) extra_params_validation = { latitude: { required: true, class: [Float] }, longitude: { required: true, class: [Float] }
ruby
{ "resource": "" }
q851
Telegrammer.Bot.send_chat_action
train
def send_chat_action(params) params_validation = { chat_id: { required: true, class: [Fixnum, String] }, action: { required: true, class: [String] }
ruby
{ "resource": "" }
q852
Telegrammer.Bot.get_user_profile_photos
train
def get_user_profile_photos(params) params_validation = { user_id: { required: true, class: [Fixnum] }, offset: { required: false, class: [Fixnum] },
ruby
{ "resource": "" }
q853
Telegrammer.Bot.get_file
train
def get_file(params) params_validation = { file_id: { required: true, class: [String] } } response = api_request("getFile", params, params_validation) file_object
ruby
{ "resource": "" }
q854
Telegrammer.Bot.answer_inline_query
train
def answer_inline_query(params) params_validation = { inline_query_id: { required: true, class: [String] }, results: { required: true, class: [Array] }, cache_time: { required: false, class: [Fixnum] }, is_personal: { required: false,
ruby
{ "resource": "" }
q855
GoogleMapsService::Apis.DistanceMatrix.distance_matrix
train
def distance_matrix(origins, destinations, mode: nil, language: nil, avoid: nil, units: nil, departure_time: nil, arrival_time: nil, transit_mode: nil, transit_routing_preference: nil) params = { origins: GoogleMapsService::Convert.waypoints(origins), destinations: GoogleMapsService::Convert.waypoints(destinations) } params[:language] = language if language params[:mode] = GoogleMapsService::Validator.travel_mode(mode) if mode
ruby
{ "resource": "" }
q856
GoogleMapsService.Convert.components
train
def components(arg) if arg.kind_of?(Hash) arg = arg.sort.map { |k, v| "#{k}:#{v}" } return arg.join("|") end
ruby
{ "resource": "" }
q857
GoogleMapsService.Convert.waypoint
train
def waypoint(waypoint) if waypoint.kind_of?(String) return waypoint end
ruby
{ "resource": "" }
q858
GoogleMapsService::Apis.Geocoding.reverse_geocode
train
def reverse_geocode(latlng, location_type: nil, result_type: nil, language: nil) params = { latlng: GoogleMapsService::Convert.latlng(latlng) } params[:result_type] = GoogleMapsService::Convert.join_list('|', result_type) if result_type
ruby
{ "resource": "" }
q859
GoogleMapsService::Apis.TimeZone.timezone
train
def timezone(location, timestamp: Time.now, language: nil) location = GoogleMapsService::Convert.latlng(location) timestamp = GoogleMapsService::Convert.time(timestamp)
ruby
{ "resource": "" }
q860
GoogleMapsService.Url.sign_hmac
train
def sign_hmac(secret, payload) secret = secret.encode('ASCII') payload = payload.encode('ASCII') # Decode the private key raw_key = Base64.urlsafe_decode64(secret) # Create a signature using the private key and the URL digest = OpenSSL::Digest.new('sha1')
ruby
{ "resource": "" }
q861
GoogleMapsService.Url.unquote_unreserved
train
def unquote_unreserved(uri) parts = uri.split('%') (1..parts.length-1).each do |i| h = parts[i][0..1] if h =~ /^([\h]{2})(.*)/ and c = $1.to_i(16).chr and UNRESERVED_SET.include?(c)
ruby
{ "resource": "" }
q862
GoogleMapsService.Client.new_client
train
def new_client client = Hurley::Client.new client.request_options.query_class = Hurley::Query::Flat client.request_options.redirection_limit = 0 client.header[:user_agent] = user_agent client.connection = @connection if @connection
ruby
{ "resource": "" }
q863
GoogleMapsService.Client.get
train
def get(path, params, base_url: DEFAULT_BASE_URL, accepts_client_id: true, custom_response_decoder: nil) url = base_url + generate_auth_url(path, params, accepts_client_id) Retriable.retriable timeout: @retry_timeout, on: RETRIABLE_ERRORS do |try| begin request_query_ticket response =
ruby
{ "resource": "" }
q864
GoogleMapsService.Client.generate_auth_url
train
def generate_auth_url(path, params, accepts_client_id) # Deterministic ordering through sorting by key. # Useful for tests, and in the future, any caching. if params.kind_of?(Hash) params = params.sort else params = params.dup end if accepts_client_id and @client_id and @client_secret params << ["client", @client_id] path = [path, GoogleMapsService::Url.urlencode_params(params)].join("?") sig = GoogleMapsService::Url.sign_hmac(@client_secret,
ruby
{ "resource": "" }
q865
GoogleMapsService.Client.decode_response_body
train
def decode_response_body(response) check_response_status_code(response)
ruby
{ "resource": "" }
q866
GoogleMapsService.Client.check_response_status_code
train
def check_response_status_code(response) case response.status_code when 200..300 # Do-nothing when 301, 302, 303, 307 raise GoogleMapsService::Error::RedirectError.new(response), sprintf('Redirect to %s', response.header[:location]) when 401 raise GoogleMapsService::Error::ClientError.new(response), 'Unauthorized' when 304, 400, 402...500
ruby
{ "resource": "" }
q867
GoogleMapsService::Apis.Directions.directions
train
def directions(origin, destination, mode: nil, waypoints: nil, alternatives: false, avoid: nil, language: nil, units: nil, region: nil, departure_time: nil, arrival_time: nil, optimize_waypoints: false, transit_mode: nil, transit_routing_preference: nil) params = { origin: GoogleMapsService::Convert.waypoint(origin), destination: GoogleMapsService::Convert.waypoint(destination) } params[:mode] = GoogleMapsService::Validator.travel_mode(mode) if mode if waypoints = waypoints waypoints = GoogleMapsService::Convert.as_list(waypoints) waypoints = waypoints.map { |waypoint| GoogleMapsService::Convert.waypoint(waypoint) } waypoints = ['optimize:true'] + waypoints if optimize_waypoints params[:waypoints] = GoogleMapsService::Convert.join_list("|", waypoints) end params[:alternatives] = 'true' if alternatives params[:avoid] = GoogleMapsService::Convert.join_list('|', avoid) if avoid params[:language] = language if language
ruby
{ "resource": "" }
q868
GoogleMapsService::Apis.Elevation.elevation_along_path
train
def elevation_along_path(path, samples) if path.kind_of?(String) path = "enc:%s" % path else path = GoogleMapsService::Convert.waypoints(path)
ruby
{ "resource": "" }
q869
GoogleMapsService::Apis.Roads.snap_to_roads
train
def snap_to_roads(path, interpolate: false) path = GoogleMapsService::Convert.waypoints(path) params = { path: path } params[:interpolate] = 'true' if interpolate return get('/v1/snapToRoads', params, base_url: ROADS_BASE_URL,
ruby
{ "resource": "" }
q870
GoogleMapsService::Apis.Roads.nearest_roads
train
def nearest_roads(points) points = GoogleMapsService::Convert.waypoints(points) params = { points: points } return get('/v1/nearestRoads', params, base_url: ROADS_BASE_URL,
ruby
{ "resource": "" }
q871
GoogleMapsService::Apis.Roads.extract_roads_body
train
def extract_roads_body(response) begin body = MultiJson.load(response.body, :symbolize_keys => true) rescue unless response.status_code == 200 check_response_status_code(response) end raise GoogleMapsService::Error::ApiError.new(response), 'Received a malformed response.' end
ruby
{ "resource": "" }
q872
GoogleMapsService.Polyline.encode
train
def encode(points) last_lat = last_lng = 0 result = "" points.each do |point| ll = GoogleMapsService::Convert.normalize_latlng(point) lat = (ll[0] * 1e5).round.to_i lng = (ll[1] * 1e5).round.to_i d_lat = lat - last_lat d_lng = lng - last_lng [d_lat, d_lng].each do |v| v = (v < 0) ? ~(v << 1) : (v << 1) while v >= 0x20
ruby
{ "resource": "" }
q873
Mongoid::FullTextSearch.ClassMethods.map_query_filters
train
def map_query_filters(filters) Hash[filters.map do |key, value| case value when Hash then if value.key? :any then format_query_filter('$in', key, value[:any]) elsif value.key? :all then format_query_filter('$all', key, value[:all])
ruby
{ "resource": "" }
q874
Stickler.SpecLite.=~
train
def =~(other) other = coerce( other ) return (other and self.name == other.name and self.version.to_s ==
ruby
{ "resource": "" }
q875
::Stickler::Repository.RemoteMirror.mirror
train
def mirror( spec, upstream_host ) raise Stickler::Repository::Error, "gem #{spec.full_name} already exists in remote repository" if remote_gem_file_exist?( spec )
ruby
{ "resource": "" }
q876
Stickler::Middleware.Index.marshalled_specs
train
def marshalled_specs( spec_a ) a = spec_a.collect { |s| s.to_rubygems_a }
ruby
{ "resource": "" }
q877
Stickler.Client.parser
train
def parser me = self # scoping forces this @parser ||= Trollop::Parser.new do banner me.class.banner opt :server, "The gem or stickler server URL", :type => :string, :default => Client.config.server
ruby
{ "resource": "" }
q878
Flickr.Attribute.find_value
train
def find_value(context) locations.each do |location| begin value = context.instance_exec(&location) next if value.nil?
ruby
{ "resource": "" }
q879
Flickr.AttributeSet.add_locations
train
def add_locations(hash) hash.each do |attribute_name, locations|
ruby
{ "resource": "" }
q880
Helpers.ClassMethods.record_api_methods
train
def record_api_methods before do stub_const("Flickr::Client::Data", Class.new(Flickr::Client::Data) do def do_request(http_method, flickr_method, params = {}) VCR.use_cassette(flickr_method) { super } end end) stub_const("Flickr::Client::Upload", Class.new(Flickr::Client::Upload) do
ruby
{ "resource": "" }
q881
Flickr.Object.inspect
train
def inspect attribute_values = self.class.attributes .inject({}) { |hash, attribute| hash.update(attribute.name => send(attribute.name)) } .reject { |name, value| value.nil? or (value.respond_to?(:empty?) and value.empty?)
ruby
{ "resource": "" }
q882
Flickr.SanitizedFile.sanitize!
train
def sanitize! if rails_file? @file = @original @content_type = @original.content_type @path = @original.tempfile elsif sinatra_file? @file = @original[:tempfile] @content_type = @original[:type] @path = @original[:tempfile].path elsif io? @file = @original @content_type = @original.content_type if @original.respond_to?(:content_type)
ruby
{ "resource": "" }
q883
Jquery.Helpers.link_to_modal
train
def link_to_modal(*args, &block) if block_given? options = args.first || {} html_options = args.second block_result = capture(&block) link_to_modal(block_result, options, html_options) else name = args[0] options = args[1] || {} html_options = args[2] || {} # extend the html_options html_options[:rel] = "modal:open" if (html_options.has_key?(:remote)) if (html_options[:remote] == true) html_options[:rel] = "modal:open:ajaxpost" end # remove the remote tag
ruby
{ "resource": "" }
q884
JekyllData.Reader.read_theme_data
train
def read_theme_data if @theme.data_path # # show contents of "<theme>/_data/" dir being read while degugging. inspect_theme_data theme_data = ThemeDataReader.new(site).read(site.config["data_dir"]) @site.data = Jekyll::Utils.deep_merge_hashes(theme_data, @site.data) # # show contents of merged site.data hash
ruby
{ "resource": "" }
q885
JekyllData.Reader.inspect_inner_hash
train
def inspect_inner_hash(hash) hash.each do |key, value| if value.is_a? Array print_label key extract_hashes_and_print value elsif value.is_a? Hash
ruby
{ "resource": "" }
q886
JekyllData.Reader.print_subkey_and_value
train
def print_subkey_and_value(key, value) print_label key value.each do |subkey, val| if val.is_a? Hash print_inner_subkey subkey inspect_inner_hash val elsif val.is_a? Array print_inner_subkey subkey
ruby
{ "resource": "" }
q887
PahoMqtt.ConnectionHelper.should_send_ping?
train
def should_send_ping?(now, keep_alive, last_packet_received_at) last_pingreq_sent_at = @sender.last_pingreq_sent_at last_pingresp_received_at = @handler.last_pingresp_received_at if !last_pingreq_sent_at || (last_pingresp_received_at && (last_pingreq_sent_at <= last_pingresp_received_at))
ruby
{ "resource": "" }
q888
Picasa.Utils.array_wrap
train
def array_wrap(object) if object.nil? [] elsif object.respond_to?(:to_ary) object.to_ary
ruby
{ "resource": "" }
q889
RSpecCommand.MatchFixture.failure_message
train
def failure_message matching_files = @fixture.files & @local.files fixture_only_files = @fixture.files - @local.files local_only_files = @local.files - @fixture.files buf = "expected fixture #{@fixture.path} to match files:\n" (@fixture.files | @local.files).sort.each do |file| if matching_files.include?(file) local_file = @local.absolute(file) fixture_file = @fixture.absolute(file) if File.directory?(local_file) && File.directory?(fixture_file) # Do nothing elsif File.directory?(fixture_file) buf << " #{file} should be a directory\n" elsif File.directory?(local_file) buf << " #{file} should not be a directory" else actual = IO.read(local_file) expected = IO.read(fixture_file) if actual != expected # Show a diff
ruby
{ "resource": "" }
q890
RSpecCommand.MatchFixture.file_content_match?
train
def file_content_match? @fixture.full_files.zip(@local.full_files).all? do |fixture_file, local_file| if File.directory?(fixture_file) File.directory?(local_file)
ruby
{ "resource": "" }
q891
RSpecCommand.ClassMethods.file
train
def file(path, content=nil, &block) raise "file path should be relative the the temporary directory." if path == File.expand_path(path) before do content = instance_eval(&block) if
ruby
{ "resource": "" }
q892
RSpecCommand.ClassMethods.fixture_file
train
def fixture_file(path, dest=nil) raise "file path should be relative the the temporary directory." if path == File.expand_path(path) before do |example| fixture_path = find_fixture(example.file_path, path) dest_path = dest ? File.join(temp_path, dest) : temp_path FileUtils.mkdir_p(dest_path) file_list = MatchFixture::FileList.new(fixture_path) file_list.files.each do |file|
ruby
{ "resource": "" }
q893
RSpecCommand.ClassMethods.environment
train
def environment(variables) before do variables.each do |key, value| if value.nil? _environment.delete(key.to_s) else
ruby
{ "resource": "" }
q894
DataMagic.StandardTranslation.randomize
train
def randomize(value) case value when Array then value[rand(value.size)] when Range then
ruby
{ "resource": "" }
q895
DataMagic.StandardTranslation.sequential
train
def sequential(value) index = index_variable_for(value) index = (index ? index + 1 : 0) index = 0 if index ==
ruby
{ "resource": "" }
q896
ActionAccess.Keeper.let
train
def let(clearance_level, actions, resource, options = {}) clearance_level = clearance_level.to_s.singularize.to_sym actions = Array(actions).map(&:to_sym) controller = get_controller_name(resource, options) @rules[controller] ||= {}
ruby
{ "resource": "" }
q897
ActionAccess.Keeper.lets?
train
def lets?(clearance_level, action, resource, options = {}) clearance_level = clearance_level.to_s.singularize.to_sym action = action.to_sym controller = get_controller_name(resource, options) # Load the controller to ensure its rules are loaded (lazy loading rules). controller.constantize.new rules = @rules[controller] return false unless rules
ruby
{ "resource": "" }
q898
ActionAccess.ControllerAdditions.validate_access!
train
def validate_access! action = self.action_name clearance_levels = Array(current_clearance_levels) authorized
ruby
{ "resource": "" }
q899
ActionAccess.ControllerAdditions.not_authorized!
train
def not_authorized!(*args) options = args.extract_options! message = options[:message] || I18n.t('action_access.redirection_message', default: 'Not authorized.')
ruby
{ "resource": "" }