_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q22100
Moped.Node.refresh
train
def refresh if address.resolve(self) begin @refreshed_at = Time.now configure(command("admin", ismaster: 1)) if !primary? && executing?(:ensure_primary) raise Errors::ReplicaSetReconfigured.new("#{inspect} is no longer the primary node.", {}) elsif !mess...
ruby
{ "resource": "" }
q22101
Moped.Node.remove
train
def remove(database, collection, selector, concern, options = {}) write(Protocol::Delete.new(database, collection, selector, options), concern) end
ruby
{ "resource": "" }
q22102
Moped.Node.update
train
def update(database, collection, selector, change, concern, options = {}) write(Protocol::Update.new(database, collection, selector, change, options), concern) end
ruby
{ "resource": "" }
q22103
Moped.Node.connect
train
def connect(conn) start = Time.now conn.connect @latency = Time.now - start @down_at = nil true end
ruby
{ "resource": "" }
q22104
Moped.Node.discover
train
def discover(*nodes) nodes.flatten.compact.each do |peer| node = Node.new(peer, options) node.credentials.merge!(@credentials) peers.push(node) unless peers.include?(node) end end
ruby
{ "resource": "" }
q22105
Moped.Node.flush
train
def flush(ops = queue) operations, callbacks = ops.transpose logging(operations) do ensure_connected do |conn| conn.write(operations) replies = conn.receive_replies(operations) replies.zip(callbacks).map do |reply, callback| callback ? callback[reply] : rep...
ruby
{ "resource": "" }
q22106
Support.ReplicaSetSimulator.start
train
def start @nodes.each(&:start) @worker = Thread.start do Thread.abort_on_exception = true catch(:shutdown) do loop do Moped.logger.debug "replica_set: waiting for next client" server, client = @manager.next_client if server Moped.l...
ruby
{ "resource": "" }
q22107
Support.ReplicaSetSimulator.initiate
train
def initiate primary, *secondaries = @nodes.shuffle primary.promote secondaries.each(&:demote) return primary, secondaries end
ruby
{ "resource": "" }
q22108
Moped.Cluster.nodes
train
def nodes # Find the nodes that were down but are ready to be refreshed, or those # with stale connection information. needs_refresh, available = seeds.partition do |node| refreshable?(node) end # Refresh those nodes. available.concat(refresh(needs_refresh)) # Now ret...
ruby
{ "resource": "" }
q22109
Moped.Cluster.refresh
train
def refresh(nodes_to_refresh = seeds) refreshed_nodes = [] seen = {} # Set up a recursive lambda function for refreshing a node and it's peers. refresh_node = ->(node) do unless node.address.resolved begin node.refresh rescue Errors::ConnectionFailure ...
ruby
{ "resource": "" }
q22110
Moped.Cluster.with_primary
train
def with_primary(&block) if node = nodes.find(&:primary?) begin node.ensure_primary do return yield(node) end rescue Errors::ConnectionFailure, Errors::ReplicaSetReconfigured end end raise Errors::ConnectionFailure, "Could not connect to a primar...
ruby
{ "resource": "" }
q22111
Moped.Cluster.with_secondary
train
def with_secondary(&block) available_nodes = available_secondary_nodes while node = available_nodes.shift begin return yield(node) rescue Errors::ConnectionFailure, Errors::ReplicaSetReconfigured => e next end end raise Errors::ConnectionFailure, "Coul...
ruby
{ "resource": "" }
q22112
Moped.Cluster.refreshable?
train
def refreshable?(node) return false if node.arbiter? node.down? ? node.down_at < down_boundary : node.needs_refresh?(refresh_boundary) end
ruby
{ "resource": "" }
q22113
Moped.Cluster.refresh_peers
train
def refresh_peers(node, &block) node.peers.each do |node| if node.address.resolved block.call(node) unless seeds.include?(node) peers.push(node) unless peers.include?(node) end end end
ruby
{ "resource": "" }
q22114
Moped.Cursor.each
train
def each documents = load_docs documents.each { |doc| yield doc } while more? return kill if limited? && @limit <= 0 documents = get_more documents.each { |doc| yield doc } end end
ruby
{ "resource": "" }
q22115
Moped.Cursor.get_more
train
def get_more with_retry(session.cluster) do reply = @node.get_more @database, @collection, @cursor_id, request_limit @limit -= reply.count if limited? @cursor_id = reply.cursor_id reply.documents end end
ruby
{ "resource": "" }
q22116
Moped.Cursor.load_docs
train
def load_docs @options[:flags] |= [:no_cursor_timeout] if @options[:no_timeout] options = @options.clone options[:limit] = request_limit reply, @node = read_preference.with_node(session.cluster) do |node| [ node.query(@database, @collection, @selector, query_options(options)), node ] ...
ruby
{ "resource": "" }
q22117
Moped.Uri.options
train
def options options_string, options = match[10], { database: database } unless options_string.nil? options_string.split(/\&/).each do |option_string| key, value = option_string.split(/=/) if WRITE_OPTIONS.include?(key) options[:write] = { key.to_sym => cast(value) } ...
ruby
{ "resource": "" }
q22118
Moped.Uri.to_hash
train
def to_hash config = { database: database, hosts: hosts } if username && password config.merge!(username: username, password: password) end config end
ruby
{ "resource": "" }
q22119
Moped.Database.command
train
def command(command) read_preference.with_node(cluster) do |node| node.command(name, command, query_options({})) end end
ruby
{ "resource": "" }
q22120
Moped.Indexes.create
train
def create(key, options = {}) spec = options.merge(ns: namespace, key: key) spec[:name] ||= key.to_a.join("_") database.session.with(write: { w: 1 }) do |_s| _s[:"system.indexes"].insert(spec) end end
ruby
{ "resource": "" }
q22121
Moped.Indexes.drop
train
def drop(key = nil) if key index = self[key] or return false name = index["name"] else name = "*" end result = database.command deleteIndexes: collection_name, index: name result["ok"] == 1 end
ruby
{ "resource": "" }
q22122
Moped.Session.new
train
def new(options = {}) session = with(options) session.instance_variable_set(:@cluster, cluster.dup) if block_given? yield(session) else session end end
ruby
{ "resource": "" }
q22123
Moped.Session.with
train
def with(options = {}) session = dup session.options.update(options) if block_given? yield(session) else session end end
ruby
{ "resource": "" }
q22124
Moped.Address.resolve
train
def resolve(node) return @resolved if @resolved start = Time.now retries = 0 begin # This timeout should be very large since Timeout::timeout plays very badly with multithreaded code # TODO: Remove this Timeout entirely Timeout::timeout(@timeout * 10) do Resolv....
ruby
{ "resource": "" }
q22125
Moped.Authenticatable.apply_credentials
train
def apply_credentials(logins) unless credentials == logins logouts = credentials.keys - logins.keys logouts.each do |database| logout(database) end logins.each do |database, (username, password)| unless credentials[database] == [ username, password ] ...
ruby
{ "resource": "" }
q22126
Moped.Authenticatable.login
train
def login(database, username, password) getnonce = Protocol::Command.new(database, getnonce: 1) self.write([getnonce]) reply = self.receive_replies([getnonce]).first if getnonce.failure?(reply) return end result = getnonce.results(reply) authenticate = Protocol::Comman...
ruby
{ "resource": "" }
q22127
Moped.Authenticatable.logout
train
def logout(database) command = Protocol::Command.new(database, logout: 1) self.write([command]) reply = self.receive_replies([command]).first if command.failure?(reply) return end credentials.delete(database) end
ruby
{ "resource": "" }
q22128
Moped.Retryable.with_retry
train
def with_retry(cluster, retries = cluster.max_retries, &block) begin block.call rescue Errors::ConnectionFailure, Errors::PotentialReconfiguration => e raise e if e.is_a?(Errors::PotentialReconfiguration) && ! (e.message.include?("not master") || e.message.include?("Not primary")) ...
ruby
{ "resource": "" }
q22129
Moped.Collection.drop
train
def drop begin session.with(read: :primary).command(drop: name) rescue Moped::Errors::OperationFailure => e raise e unless e.ns_not_found? false end end
ruby
{ "resource": "" }
q22130
Moped.Collection.rename
train
def rename(to_name) begin session. with(database: "admin", read: :primary). command(renameCollection: "#{database.name}.#{name}", to: "#{database.name}.#{to_name}") rescue Moped::Errors::OperationFailure => e raise e unless e.ns_not_exists? false end end
ruby
{ "resource": "" }
q22131
Moped.Collection.insert
train
def insert(documents, flags = nil) with_retry(cluster) do docs = documents.is_a?(Array) ? documents : [ documents ] cluster.with_primary do |node| node.insert(database.name, name, docs, write_concern, flags: flags || []) end end end
ruby
{ "resource": "" }
q22132
Moped.Query.count
train
def count(limit = false) command = { count: collection.name, query: selector } command.merge!(skip: operation.skip, limit: operation.limit) if limit result = collection.database.command(command) result["n"].to_i end
ruby
{ "resource": "" }
q22133
Moped.Query.distinct
train
def distinct(key) result = collection.database.command( distinct: collection.name, key: key.to_s, query: selector ) result["values"] end
ruby
{ "resource": "" }
q22134
Moped.Query.explain
train
def explain explanation = operation.selector.dup hint = explanation["$hint"] sort = explanation["$orderby"] max_scan = explanation["$maxScan"] explanation = { "$query" => selector, "$explain" => true, } explanation["$orderby"] = sort if sort explanation["$...
ruby
{ "resource": "" }
q22135
Moped.Query.first
train
def first reply = read_preference.with_node(cluster) do |node| node.query( operation.database, operation.collection, operation.selector, query_options( fields: operation.fields, flags: operation.flags, skip: operation.skip, ...
ruby
{ "resource": "" }
q22136
Moped.Query.remove
train
def remove with_retry(cluster) do cluster.with_primary do |node| node.remove( operation.database, operation.collection, operation.basic_selector, write_concern, flags: [ :remove_first ] ) end end end
ruby
{ "resource": "" }
q22137
Moped.Query.update
train
def update(change, flags = nil) with_retry(cluster) do cluster.with_primary do |node| node.update( operation.database, operation.collection, operation.selector["$query"] || operation.selector, change, write_concern, flags: f...
ruby
{ "resource": "" }
q22138
Moped.WriteConcern.get
train
def get(value) propagate = value[:w] || value["w"] if propagate == 0 || propagate == -1 Unverified.new else Propagate.new(value) end end
ruby
{ "resource": "" }
q22139
ADB.Instrumentation.instrument
train
def instrument(runner, args = {}) with(the(args) << using_the(runner)) raise ADBError, last_stdout unless last_stdout.empty? end
ruby
{ "resource": "" }
q22140
ScopedSearch.QueryBuilder.build_find_params
train
def build_find_params(options) keyconditions = [] keyparameters = [] parameters = [] includes = [] joins = [] # Build SQL WHERE clause using the AST sql = @ast.to_sql(self, definition) do |notification, value| # Handle the notifications encountered during the SQL ...
ruby
{ "resource": "" }
q22141
ScopedSearch.QueryBuilder.sql_operator
train
def sql_operator(operator, field) raise ScopedSearch::QueryNotSupported, "the operator '#{operator}' is not supported for field type '#{field.type}'" if !field.virtual? and [:like, :unlike].include?(operator) and !field.textual? SQL_OPERATORS[operator] end
ruby
{ "resource": "" }
q22142
ScopedSearch.QueryBuilder.translate_value
train
def translate_value(field, value) translated_value = field.complete_value[value.to_sym] raise ScopedSearch::QueryNotSupported, "'#{field.field}' should be one of '#{field.complete_value.keys.join(', ')}', but the query was '#{value}'" if translated_value.nil? translated_value end
ruby
{ "resource": "" }
q22143
ScopedSearch.RailsHelper.sort
train
def sort(field, as: nil, default: "ASC", html_options: {}, url_options: params) unless as id = field.to_s.downcase == "id" as = id ? field.to_s.upcase : field.to_s.humanize end ascend = "#{field} ASC" descend = "#{field} DESC" selected_sort = [ascend, descend].find { |o|...
ruby
{ "resource": "" }
q22144
ScopedSearch.AutoCompleteBuilder.build_autocomplete_options
train
def build_autocomplete_options # First parse to find illegal syntax in the existing query, # this method will throw exception on bad syntax. is_query_valid # get the completion options node = last_node completion = complete_options(node) suggestions = [] suggestions += ...
ruby
{ "resource": "" }
q22145
ScopedSearch.AutoCompleteBuilder.complete_options
train
def complete_options(node) return [:keyword] + [:prefix_op] if tokens.empty? #prefix operator return [:keyword] if last_token_is(PREFIX_OPERATORS) # left hand if is_left_hand(node) if (tokens.size == 1 || last_token_is(PREFIX_OPERATORS + LOGICAL_INFIX_OPERATORS) || l...
ruby
{ "resource": "" }
q22146
ScopedSearch.AutoCompleteBuilder.complete_keyword
train
def complete_keyword keywords = [] definition.fields.each do|f| next unless f[1].complete_enabled if (f[1].key_field) keywords += complete_key(f[0], f[1], tokens.last) else keywords << f[0].to_s + ' ' end end keywords.sort end
ruby
{ "resource": "" }
q22147
ScopedSearch.AutoCompleteBuilder.complete_key
train
def complete_key(name, field, val) return ["#{name}."] if !val || !val.is_a?(String) || !(val.include?('.')) val = val.sub(/.*\./,'') connection = definition.klass.connection quoted_table = field.key_klass.connection.quote_table_name(field.key_klass.table_name) quoted_field = field.k...
ruby
{ "resource": "" }
q22148
ScopedSearch.AutoCompleteBuilder.complete_date_value
train
def complete_date_value options = [] options << '"30 minutes ago"' options << '"1 hour ago"' options << '"2 hours ago"' options << 'Today' options << 'Yesterday' options << 'Tomorrow' options << 2.days.ago.strftime('%A') options << 3.days.ago.strftime('%A') op...
ruby
{ "resource": "" }
q22149
ScopedSearch.AutoCompleteBuilder.complete_key_value
train
def complete_key_value(field, token, val) key_name = token.sub(/^.*\./,"") key_klass = field.key_klass.where(field.key_field => key_name).first raise ScopedSearch::QueryNotSupported, "Field '#{key_name}' not recognized for searching!" if key_klass.nil? query = completer_scope(field) if f...
ruby
{ "resource": "" }
q22150
ScopedSearch.AutoCompleteBuilder.complete_operator
train
def complete_operator(node) definition.operator_by_field_name(node.value).map { |o| o.end_with?(' ') ? o : "#{o} " } end
ruby
{ "resource": "" }
q22151
ScopedSearch.ClassMethods.scoped_search
train
def scoped_search(*definitions) self.scoped_search_definition ||= ScopedSearch::Definition.new(self) unless self.scoped_search_definition.klass == self # inheriting the parent self.scoped_search_definition = ScopedSearch::Definition.new(self) end definitions.each do |definition| ...
ruby
{ "resource": "" }
q22152
ScopedSearch.Definition.operator_by_field_name
train
def operator_by_field_name(name) field = field_by_name(name) return [] if field.nil? return field.operators if field.operators return ['=', '!=', '>', '<', '<=', '>=', '~', '!~', '^', '!^'] if field.virtual? return ['=', '!='] ...
ruby
{ "resource": "" }
q22153
ScopedSearch.Definition.default_fields_for
train
def default_fields_for(value, operator = nil) column_types = [:virtual] column_types += [:string, :text] if [nil, :like, :unlike, :ne, :eq].include?(operator) column_types += [:double, :float, :decimal] if value =~ NUMERICAL_REGXP column_types += [:integer] ...
ruby
{ "resource": "" }
q22154
ScopedSearch.Definition.parse_temporal
train
def parse_temporal(value) return Date.current if value =~ /\btoday\b/i return 1.day.ago.to_date if value =~ /\byesterday\b/i return 1.day.from_now.to_date if value =~ /\btomorrow\b/i return (eval($1.strip.gsub(/\s+/,'.').downcase)).to_datetime if value =~ /\A\s*(\d+\s+\b(?:hours?|minutes?)\b\s+\...
ruby
{ "resource": "" }
q22155
ScopedSearch.Definition.reflection_by_name
train
def reflection_by_name(klass, name) return if name.nil? klass.reflections[name.to_sym] || klass.reflections[name.to_s] end
ruby
{ "resource": "" }
q22156
ScopedSearch.Definition.register_named_scope!
train
def register_named_scope! # :nodoc @klass.define_singleton_method(:search_for) do |query = '', options = {}| # klass may be different to @klass if the scope is called on a subclass klass = self definition = klass.scoped_search_definition search_scope = klass.all find_optio...
ruby
{ "resource": "" }
q22157
OData.Service.method_missing
train
def method_missing(name, *args) # Queries if @collections.include?(name.to_s) @query = build_collection_query_object(name,@additional_params, *args) return @query # Adds elsif name.to_s =~ /^AddTo(.*)/ type = $1 if @collections.include?(type) @save_operations << Operation...
ruby
{ "resource": "" }
q22158
OData.Service.delete_object
train
def delete_object(obj) type = obj.class.to_s if obj.respond_to?(:__metadata) && !obj.send(:__metadata).nil? @save_operations << Operation.new("Delete", type, obj) else raise OData::NotSupportedError.new "You cannot delete a non-tracked entity" end end
ruby
{ "resource": "" }
q22159
OData.Service.respond_to?
train
def respond_to?(method) if @collections.include?(method.to_s) return true # Adds elsif method.to_s =~ /^AddTo(.*)/ type = $1 if @collections.include?(type) return true else super end # Function Imports elsif @function_imports.include?(method.to_s) ...
ruby
{ "resource": "" }
q22160
OData.Service.load_property
train
def load_property(obj, nav_prop) raise NotSupportedError, "You cannot load a property on an entity that isn't tracked" if obj.send(:__metadata).nil? raise ArgumentError, "'#{nav_prop}' is not a valid navigation property" unless obj.respond_to?(nav_prop.to_sym) raise ArgumentError, "'#{nav_prop}' is not a va...
ruby
{ "resource": "" }
q22161
OData.Service.add_link
train
def add_link(parent, nav_prop, child) raise NotSupportedError, "You cannot add a link on an entity that isn't tracked (#{parent.class})" if parent.send(:__metadata).nil? raise ArgumentError, "'#{nav_prop}' is not a valid navigation property for #{parent.class}" unless parent.respond_to?(nav_prop.to_sym) rai...
ruby
{ "resource": "" }
q22162
OData.Service.build_collection_query_object
train
def build_collection_query_object(name, additional_parameters, *args) root = "/#{name.to_s}" if args.empty? #nothing to add elsif args.size == 1 if args.first.to_s =~ /\d+/ id_metadata = find_id_metadata(name.to_s) root << build_id_path(args.first, id_metadata) else ...
ruby
{ "resource": "" }
q22163
OData.Service.build_collections_and_classes
train
def build_collections_and_classes @classes = Hash.new @class_metadata = Hash.new # This is used to store property information about a class # Build complex types first, these will be used for entities complex_types = @edmx.xpath("//edm:ComplexType", @ds_namespaces) || [] complex_types.each do |c| ...
ruby
{ "resource": "" }
q22164
OData.Service.build_function_imports
train
def build_function_imports # Fill in the function imports functions = @edmx.xpath("//edm:EntityContainer/edm:FunctionImport", @ds_namespaces) functions.each do |f| http_method_attribute = f.xpath("@m:HttpMethod", @ds_namespaces).first # HttpMethod is no longer required http://www.odata.org/2011/10/act...
ruby
{ "resource": "" }
q22165
OData.Service.convert_to_local_type
train
def convert_to_local_type(edmx_type) return edm_to_ruby_type(edmx_type) if edmx_type =~ /^Edm/ klass_name = qualify_class_name(edmx_type.split('.').last) klass_name.camelize.constantize end
ruby
{ "resource": "" }
q22166
OData.Service.build_property_metadata
train
def build_property_metadata(props, keys=[]) metadata = {} props.each do |property_element| prop_meta = PropertyMetadata.new(property_element) prop_meta.is_key = keys.include?(prop_meta.name) # If this is a navigation property, we need to add the association to the property metadata prop...
ruby
{ "resource": "" }
q22167
OData.Service.handle_collection_result
train
def handle_collection_result(result) results = build_classes_from_result(result) while partial? && @options[:eager_partial] results.concat handle_partial end results end
ruby
{ "resource": "" }
q22168
OData.Service.handle_exception
train
def handle_exception(e) raise e unless defined?(e.response) && e.response != nil code = e.response[:status] error = Nokogiri::XML(e.response[:body]) message = if error.xpath("m:error/m:message", @ds_namespaces).first error.xpath("m:error/m:message", @ds_namespaces).first.content ...
ruby
{ "resource": "" }
q22169
OData.Service.collect_navigation_properties
train
def collect_navigation_properties(klass_name, element, doc) nav_props = element.xpath(".//edm:NavigationProperty", @ds_namespaces) @class_metadata[klass_name].merge!(build_property_metadata(nav_props)) nav_props.collect { |p| p['Name'] } end
ruby
{ "resource": "" }
q22170
OData.Service.build_classes_from_result
train
def build_classes_from_result(result) doc = Nokogiri::XML(result) is_links = doc.at_xpath("/ds:links", @ds_namespaces) return parse_link_results(doc) if is_links entries = doc.xpath("//atom:entry[not(ancestor::atom:entry)]", @ds_namespaces) extract_partial(doc) results = [] entries.each ...
ruby
{ "resource": "" }
q22171
OData.Service.entry_to_class
train
def entry_to_class(entry) # Retrieve the class name from the fully qualified name (the last string after the last dot) klass_name = entry.xpath("./atom:category/@term", @ds_namespaces).to_s.split('.')[-1] # Is the category missing? See if there is a title that we can use to build the class if klass_nam...
ruby
{ "resource": "" }
q22172
OData.Service.extract_partial
train
def extract_partial(doc) next_links = doc.xpath('//atom:link[@rel="next"]', @ds_namespaces) @has_partial = next_links.any? if @has_partial uri = Addressable::URI.parse(next_links[0]['href']) uri.query_values = uri.query_values.merge @additional_params unless @additional_params.empty? @next...
ruby
{ "resource": "" }
q22173
OData.Service.parse_link_results
train
def parse_link_results(doc) uris = doc.xpath("/ds:links/ds:uri", @ds_namespaces) results = [] uris.each do |uri_el| link = uri_el.content results << URI.parse(link) end results end
ruby
{ "resource": "" }
q22174
OData.Service.link_child_to_parent
train
def link_child_to_parent(operation) child_collection = operation.klass.send("#{operation.klass_name}") || [] child_collection << operation.child_klass operation.klass.send("#{operation.klass_name}=", child_collection) # Attach the parent to the child parent_meta = @class_metadata[operation.klass.cl...
ruby
{ "resource": "" }
q22175
OData.Service.fill_complex_type_properties
train
def fill_complex_type_properties(complex_type_xml, klass) properties = complex_type_xml.xpath(".//*") properties.each do |prop| klass.send "#{prop.name}=", parse_value_xml(prop) end end
ruby
{ "resource": "" }
q22176
OData.Service.parse_date
train
def parse_date(sdate) # Assume this is UTC if no timezone is specified sdate = sdate + "Z" unless sdate.match(/Z|([+|-]\d{2}:\d{2})$/) # This is to handle older versions of Ruby (e.g. ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]) # See http://makandra.com/notes/1017-maximum-representable-value...
ruby
{ "resource": "" }
q22177
OData.Service.parse_value_xml
train
def parse_value_xml(property_xml) property_type = Helpers.get_namespaced_attribute(property_xml, 'type', 'm') property_null = Helpers.get_namespaced_attribute(property_xml, 'null', 'm') if property_type.nil? || (property_type && property_type.match(/^Edm/)) return parse_value(property_xml.content, pr...
ruby
{ "resource": "" }
q22178
OData.Service.parse_primative_type
train
def parse_primative_type(value, return_type) return value.to_i if return_type == Fixnum return value.to_d if return_type == Float return parse_date(value.to_s) if return_type == Time return value.to_s end
ruby
{ "resource": "" }
q22179
OData.Service.execute_import_function
train
def execute_import_function(name, *args) func = @function_imports[name] # Check the args making sure that more weren't passed in than the function needs param_count = func[:parameters].nil? ? 0 : func[:parameters].count arg_count = args.nil? ? 0 : args[0].count if arg_count > param_count rais...
ruby
{ "resource": "" }
q22180
Pickle.Session.model_with_associations
train
def model_with_associations(name) model = created_model(name) return nil unless model OData::PickleAdapter.get_model(model.class, model.id, true) end
ruby
{ "resource": "" }
q22181
OData.ClassBuilder.build
train
def build # return if already built return @klass unless @klass.nil? # need the class name to build class return nil if @klass_name.nil? # return if we can find constant corresponding to class name already_defined = eval("defined?(#{@klass_name}) == 'constant' and #{@klass_name}...
ruby
{ "resource": "" }
q22182
OData.QueryBuilder.links
train
def links(navigation_property) raise OData::NotSupportedError.new("You cannot call both the `links` method and the `count` method in the same query.") if @count raise OData::NotSupportedError.new("You cannot call both the `links` method and the `select` method in the same query.") unless @select.empty? ...
ruby
{ "resource": "" }
q22183
OData.QueryBuilder.count
train
def count raise OData::NotSupportedError.new("You cannot call both the `links` method and the `count` method in the same query.") if @links_navigation_property raise OData::NotSupportedError.new("You cannot call both the `select` method and the `count` method in the same query.") unless @select.empty? ...
ruby
{ "resource": "" }
q22184
OData.QueryBuilder.select
train
def select(*fields) raise OData::NotSupportedError.new("You cannot call both the `links` method and the `select` method in the same query.") if @links_navigation_property raise OData::NotSupportedError.new("You cannot call both the `count` method and the `select` method in the same query.") if @count ...
ruby
{ "resource": "" }
q22185
Strava::Api::V3.Common.sanitize_request_parameters
train
def sanitize_request_parameters(parameters) parameters.reduce({}) do |result, (key, value)| # if the parameter is an array that contains non-enumerable values, # turn it into a comma-separated list # in Ruby 1.8.7, strings are enumerable, but we don't care if value.is_a?(Array) && ...
ruby
{ "resource": "" }
q22186
Strava::Api::V3.ActivityExtras.list_activity_photos
train
def list_activity_photos(id, args = {}, options = {}, &block) args['photo_sources'] = 'true' # Fetches the connections for given object. api_call("activities/#{id}/photos", args, 'get', options, &block) end
ruby
{ "resource": "" }
q22187
Strava::Api::V3.Stream.retrieve_activity_streams
train
def retrieve_activity_streams(id, types, args = {}, options = {}, &block) # Fetches the connections for given object. api_call("activities/#{id}/streams/#{types}", args, 'get', options, &block) end
ruby
{ "resource": "" }
q22188
Strava::Api::V3.Stream.retrieve_effort_streams
train
def retrieve_effort_streams(id, types, args = {}, options = {}, &block) # Fetches the connections for given object. api_call("segment_efforts/#{id}/streams/#{types}", args, 'get', options, &block) end
ruby
{ "resource": "" }
q22189
Strava::Api::V3.Stream.retrieve_segment_streams
train
def retrieve_segment_streams(id, types, args = {}, options = {}, &block) # Fetches the connections for given object. api_call("segments/#{id}/streams/#{types}", args, 'get', options, &block) end
ruby
{ "resource": "" }
q22190
CFPropertyList.CFDate.set_value
train
def set_value(value,format=CFDate::TIMESTAMP_UNIX) if(format == CFDate::TIMESTAMP_UNIX) then @value = Time.at(value) else @value = Time.at(value + CFDate::DATE_DIFF_APPLE_UNIX) end end
ruby
{ "resource": "" }
q22191
CFPropertyList.CFDate.get_value
train
def get_value(format=CFDate::TIMESTAMP_UNIX) if(format == CFDate::TIMESTAMP_UNIX) then @value.to_i else @value.to_f - CFDate::DATE_DIFF_APPLE_UNIX end end
ruby
{ "resource": "" }
q22192
CFPropertyList.CFArray.to_xml
train
def to_xml(parser) n = parser.new_node('array') @value.each do |v| n = parser.append_node(n, v.to_xml(parser)) end n end
ruby
{ "resource": "" }
q22193
CFPropertyList.CFDictionary.to_xml
train
def to_xml(parser) n = parser.new_node('dict') @value.each_pair do |key, value| k = parser.append_node(parser.new_node('key'), parser.new_text(key.to_s)) n = parser.append_node(n, k) n = parser.append_node(n, value.to_xml(parser)) end n end
ruby
{ "resource": "" }
q22194
CFPropertyList.Binary.load
train
def load(opts) @unique_table = {} @count_objects = 0 @object_refs = 0 @written_object_count = 0 @object_table = [] @object_ref_size = 0 @offsets = [] fd = nil if(opts.has_key?(:file)) fd = File.open(opts[:file],"rb") file = opts[:file] else ...
ruby
{ "resource": "" }
q22195
CFPropertyList.Binary.to_str
train
def to_str(opts={}) @unique_table = {} @count_objects = 0 @object_refs = 0 @written_object_count = 0 @object_table = [] @offsets = [] binary_str = "bplist00" @object_refs = count_object_refs(opts[:root]) opts[:root].to_binary(self) next_offset = 8 ...
ruby
{ "resource": "" }
q22196
CFPropertyList.Binary.read_binary_int
train
def read_binary_int(fname,fd,length) if length > 4 raise CFFormatError.new("Integer greater than 16 bytes: #{length}") end nbytes = 1 << length buff = fd.read(nbytes) CFInteger.new( case length when 0 then buff.unpack("C")[0] when 1 then buff.unpack("n")[...
ruby
{ "resource": "" }
q22197
CFPropertyList.Binary.read_binary_real
train
def read_binary_real(fname,fd,length) raise CFFormatError.new("Real greater than 8 bytes: #{length}") if length > 3 nbytes = 1 << length buff = fd.read(nbytes) CFReal.new( case length when 0 # 1 byte float? must be an error raise CFFormatError.new("got #{length+1} byt...
ruby
{ "resource": "" }
q22198
CFPropertyList.Binary.read_binary_date
train
def read_binary_date(fname,fd,length) raise CFFormatError.new("Date greater than 8 bytes: #{length}") if length > 3 nbytes = 1 << length buff = fd.read(nbytes) CFDate.new( case length when 0 then # 1 byte CFDate is an error raise CFFormatError.new("#{length+1} byte CF...
ruby
{ "resource": "" }
q22199
CFPropertyList.Binary.read_binary_data
train
def read_binary_data(fname,fd,length) CFData.new(read_fd(fd, length), CFData::DATA_RAW) end
ruby
{ "resource": "" }