idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
17,900 | def create_hash ( response ) begin JSON . parse response rescue JSON :: ParserError response rescue StandardError response end end | Create a Hash from a JSON response |
17,901 | def standard_agency1 ( scope , prefix , mandate ) case scope when "national" ret = NATIONAL &. dig ( @lang , gb_mandate_suffix ( prefix , mandate ) . to_sym , :admin ) || nil ret = ret . join ( " " ) if ret && ret . is_a? ( Array ) ret when "sector" SECTOR &. dig ( @lang , prefix . to_sym , :admin ) || nil when "local"... | return agency name as single string |
17,902 | def standard_agency ( scope , prefix , mandate ) case scope when "national" NATIONAL &. dig ( @lang , gb_mandate_suffix ( prefix , mandate ) . to_sym , :admin ) || nil when "sector" SECTOR &. dig ( @lang , prefix . to_sym , :admin ) || nil when "local" "#{LOCAL&.dig(@lang, prefix.to_sym) || 'XXXX'}#{@labels["local_issu... | return agency name allowing arrays in output |
17,903 | def start_loop loop do begin queue = [ ] running_jobs = @job_class . running . entries schedulable_jobs = @job_class . queued . order_by ( scheduled_at : :asc ) . entries jobs_to_schedule = @max_concurrent_jobs - running_jobs . count jobs_to_schedule = 0 if jobs_to_schedule < 0 scheduled_jobs = [ ] schedulable_jobs . f... | Creates a MainProcess which keeps running and continuously checks if new jobs are queued . |
17,904 | def reschedule_running_jobs @job_class . running . each do | job | begin Process . kill :QUIT , job . pid if job . pid . present? rescue Errno :: ESRCH , Errno :: EPERM ensure job . schedule end end end | Reschedules currently running jobs . |
17,905 | def device_data JSON . parse ( ENV [ 'DEVICES' ] ) . find { | t | t [ 'thread' ] . eql? thread } unless ENV [ 'DEVICES' ] . nil? end | Get the device data from the DEVICES environment variable |
17,906 | def save_device_data ( dev_array ) dev_array . each do | device | device_hash = { } device . each do | key , value | device_hash [ key ] = value end ` ` ` ` device . each do | k , v | open ( "output/specs-#{device_hash[:udid]}.log" , 'a' ) do | file | file << "#{k}: #{v}\n" end end end end | Save device specifications to output directory |
17,907 | def get_devices ( platform ) ENV [ 'THREADS' ] = '1' if ENV [ 'THREADS' ] . nil? if platform == 'android' Android . new . devices elsif platform == 'ios' IOS . new . devices end end | Get the device information for the respective platform |
17,908 | def appium_server_start ( ** options ) command = + 'appium' command << " --nodeconfig #{options[:config]}" if options . key? ( :config ) command << " -p #{options[:port]}" if options . key? ( :port ) command << " -bp #{options[:bp]}" if options . key? ( :bp ) command << " --log #{Dir.pwd}/output/#{options[:log]}" if op... | Start the appium server with the specified options |
17,909 | def generate_node_config ( file_name , appium_port , device ) system 'mkdir node_configs >> /dev/null 2>&1' f = File . new ( "#{Dir.pwd}/node_configs/#{file_name}" , 'w' ) f . write ( JSON . generate ( capabilities : [ { browserName : device [ :udid ] , maxInstances : 5 , platform : device [ :platform ] } ] , configura... | Generate node config for sellenium grid |
17,910 | def start_single_appium ( platform , port ) puts 'Getting Device data' devices = get_devices ( platform ) [ 0 ] if devices . nil? puts "No devices for #{platform}, Exiting..." exit else udid = devices [ :udid ] save_device_data [ devices ] end ENV [ 'UDID' ] = udid appium_server_start udid : udid , log : "appium-#{udid... | Start an appium server or the platform on the specified port |
17,911 | def launch_hub_and_nodes ( platform ) start_hub unless port_open? ( 'localhost' , 4444 ) devices = get_devices ( platform ) if devices . nil? puts "No devices for #{platform}, Exiting...." exit else save_device_data [ devices ] end threads = ENV [ 'THREADS' ] . to_i if devices . size < threads puts "Not enough availabl... | Launch the Selenium grid hub and required appium instances |
17,912 | def build_request ( options = { } ) src_creds_name = SRC_CREDS options = options . dup final_opts = options . dup options . keys . each do | key | orig_key = key new_key = orig_key . to_s . gsub ( "_" , "" ) . downcase if ( new_key == src_creds_name . downcase ) final_opts [ src_creds_name ] = final_opts [ key ] final_... | Builds the inner XML of the Mindbody SOAP call |
17,913 | def get_service ( service_symbol , options , unwrap_bool ) raise "No SOAP client instantiated" unless @client request_options = build_request ( options ) raise "No SourceCredentials supplied" if ! @src_creds || ! request_options [ SRC_CREDS ] response = @client . request Mb :: Meta :: NS , service_symbol do soap . body... | Build a Mindbody SOAP request for the given service |
17,914 | def on_complete ( env ) env [ :body ] = Nori . new ( strip_namespaces : true , convert_tags_to : -> ( tag ) { tag . snakecase . to_sym } ) . parse ( env [ :body ] ) raise SOAPError , "Invalid SOAP response" if env [ :body ] . empty? env [ :body ] = env [ :body ] [ :envelope ] [ :body ] env [ :body ] = find_key_in_hash ... | Expects response XML to already be parsed |
17,915 | def find_key_in_hash ( hash , index ) hash . each do | key , val | if val . respond_to? :has_key? if val . has_key? index return val [ index ] else return find_key_in_hash val , index end else val end end end | Finds + index + in + hash + by searching recursively |
17,916 | def << ( item ) if item . kind_of? Zyps :: Location self . location = item elsif item . kind_of? Zyps :: Color self . color = item elsif item . kind_of? Zyps :: Vector self . vector = item else raise "Invalid item: #{item.class}" end self end | Overloads the << operator to put the new item into the correct list or assign it to the correct attribute . Assignment is done based on item s class or a parent class of item . |
17,917 | def << ( item ) if item . kind_of? Condition add_condition ( item ) elsif item . kind_of? Action add_action ( item ) else raise "Invalid item: #{item.class}" end self end | True if all attributes actions and conditions are the same . Overloads the << operator to put the new item into the correct list or assign it to the correct attribute . Assignment is done based on item s class or a parent class of item . |
17,918 | def + ( vector2 ) new_x = ( self . x + vector2 . x ) new_y = ( self . y + vector2 . y ) new_length_squared = new_x ** 2 + new_y ** 2 new_length = ( new_length_squared == 0 ? 0 : Math . sqrt ( new_length_squared ) ) new_angle = ( new_x == 0 ? 0 : Utility . to_degrees ( Math . atan2 ( new_y , new_x ) ) ) Vector . new ( n... | Add this Vector to vector2 returning a new Vector . This operation is useful when calculating the effect of wind or thrust on an object s current heading . |
17,919 | def method_missing ( * args ) if Conversions . conversions [ units . to_sym ] [ args . first ] to_f . send ( units . to_sym ) . to ( args . first ) else super end end | Handle conversion methods |
17,920 | def albums ( featuring = nil , extras = nil , start = nil , count = nil ) api . getAlbumsForArtist self , featuring , extras , start , count end | Get all the albums by this artist |
17,921 | def tracks ids = track_keys return [ ] if not ids return ids . map { | id | Track . get id } end | Returns an array of tracks |
17,922 | def create_func ( params = { } ) raise ArgumentError , 'Invalid arguments.' unless check_arguments ( params , 'name' ) path = '/funcs/create' body = { } body . merge! ( prepare_json ( params ) ) Hyperb :: Request . new ( self , path , { } , 'post' , body ) . perform end | create a func |
17,923 | def remove_func ( params = { } ) raise ArgumentError , 'Invalid arguments.' unless check_arguments ( params , 'name' ) path = '/funcs/' + params [ :name ] Hyperb :: Request . new ( self , path , { } , 'delete' ) . perform end | remove a func |
17,924 | def call_func ( params = { } ) raise ArgumentError , 'Invalid arguments.' unless check_arguments ( params , 'name' , 'uuid' ) path = "call/#{params[:name]}/#{params[:uuid]}" path . concat ( '/sync' ) if params . key? ( :sync ) && params [ :sync ] Hyperb :: FuncCallRequest . new ( self , path , { } , 'post' ) . perform ... | call a func |
17,925 | def wrap ( http_method , url , params ) params = params . merge ( :appid => @appid ) params [ :sig ] = Gateway . signature ( "#{@appkey}&" , Gateway . make_source ( http_method . to_s . upcase , url , params ) ) params end | wrap http_method url params together |
17,926 | def default_ip begin orig , Socket . do_not_reverse_lookup = Socket . do_not_reverse_lookup , true UDPSocket . open do | s | s . connect rand_routable_daddr . to_s , rand_port s . addr . last end ensure Socket . do_not_reverse_lookup = orig end end | Determine the default ip address taken from packetfu s utils . rb |
17,927 | def default_interface ip = default_ip Socket . getifaddrs . each do | ifaddr | next unless ifaddr . addr . ip? return ifaddr . name if ifaddr . addr . ip_address == ip end return Pcap . lookupdev end | Determine the default routeable interface taken from packetfu s utils . rb |
17,928 | def run ( config , operation_name = nil ) config = config . with_indifferent_access config . merge! ( load_config ( config [ :config ] ) ) if config [ :config ] operation_run = false gather_operations . each do | operation | if operation_name . nil? || operation_name == operation . name op = operation . new ( config ) ... | Run all operations or a specific operation |
17,929 | def find_sources_file_dir ( dir = @relative_path_from_project . dirname ) return nil if is_outside_project? file = File . join ( @project . root , dir , "sources.rb" ) if dir . root? or dir . to_s == "." return nil elsif File . exists? ( file ) return dir else return find_sources_file_dir ( dir . parent ) end end | def within_expected_folder? rel_design_path_list = |
17,930 | def select ( actor , targets ) targets . find_all { | target | Utility . find_distance ( actor . location , target . location ) <= @distance } end | Returns an array of targets that are at the given distance or closer . |
17,931 | def select ( actor , targets ) return [ ] unless targets . length > 0 max_size = targets . map { | t | t . size } . max max_diff = Math . sqrt ( actor . size / Math :: PI ) + Math . sqrt ( max_size / Math :: PI ) x_range = ( actor . location . x - max_diff .. actor . location . x + max_diff ) y_range = ( actor . locati... | Returns an array of targets that have collided with the actor . |
17,932 | def select ( actor , targets ) targets . find_all { | target | actor . size >= target . size } end | Returns an array of targets that are weaker than the actor . For now strength is based merely on size . |
17,933 | def logout ( session_ids = Hash . new ) result = SfBase . connection . binding . invalidateSessions ( session_ids ) if "invalidateSessionsResponse" == result . to_s return true else return false end end | Logs out of the Salesforce session |
17,934 | def as ( unit ) unit = UOM :: Unit . for ( unit . to_sym ) if String === unit or Symbol === unit return self if @unit == unit Measurement . new ( unit , @unit . as ( quantity , unit ) ) end | Returns a new Measurement which expresses this measurement as the given unit . |
17,935 | def apply_to_quantity ( method , other ) other = other . as ( unit ) . quantity if Measurement === other new_quantity = block_given? ? yield ( to_f , other ) : to_f . send ( method , other ) Measurement . new ( unit , new_quantity ) end | Returns a new Measurement whose unit is this Measurement s unit and quantity is the result of applying the given method to this Measurement s quantity and the other quantity . |
17,936 | def compose ( method , other ) return apply_to_quantity ( method , other ) unless Measurement === other other = other . as ( unit ) if other . unit . axis == unit . axis new_quantity = quantity . zero? ? 0.0 : quantity . to_f . send ( method , other . quantity ) Measurement . new ( unit . send ( method , other . unit )... | Returns the application of method to this measurement and the other measurement or Numeric . If other is a Measurement then the returned Measurement Unit is the composition of this Measurement s unit and the other Measurement s unit . |
17,937 | def continue return if self . finished? || ! self . valid? || ! self . paused? if @flow_data . decr ( :paused ) == 0 workers = Hash [ self . counters . select { | name , _ | ! self . class . terminal? ( name ) && name != :processing } ] workers . each { | worker , num_objects | create_jobs ( worker , num_objects ) } en... | for now assumes |
17,938 | def init_formatter @formatter = proc do | s , d , p , m | "#{@format}\n" % { severity : s , datetime : d , progname : p , msg : m } end end | Initializes the logger s formatter proc based on the value of format instance variable . This method should only be called inside the register method |
17,939 | def init_logger @logger = case @path when STDOUT_STREAM then Logger . new ( STDOUT ) when STDERR_STREAM then Logger . new ( STDERR ) else Logger . new ( File . open ( @path , 'a' ) ) end @logger . datetime_format = @datetime_format @logger . sev_threshold = @threshold unless @severities . any? @logger . formatter = @fo... | Initializes the logger object from the standard library . This method should only be called inside the register method |
17,940 | def log ( message , severity = DEFAULT_SEVERITY ) fail 'Logfile not registered' unless @registered return if message . nil? @logger . add ( severity , message , @name ) if should_log? ( severity ) end | Log a message to the configured logger using the severity and program name as specified |
17,941 | def set_up @start = Hoiio :: IVRBlock :: Start . new @client @middle = Hoiio :: IVRBlock :: Middle . new @client @end = Hoiio :: IVRBlock :: End . new @client end | Set up the sub resources using shared |
17,942 | def fips_ls ( params = { } ) path = '/fips' query = { } query [ :filters ] = params [ :filters ] if params . key? ( :filters ) downcase_symbolize ( JSON . parse ( Hyperb :: Request . new ( self , path , query , 'get' ) . perform ) ) end | list floating ips |
17,943 | def fip_release ( params = { } ) path = '/fips/release' query = { } query [ :ip ] = params [ :ip ] if params . key? ( :ip ) Hyperb :: Request . new ( self , path , query , 'post' ) . perform end | release a floating ip |
17,944 | def fip_allocate ( params = { } ) raise ArgumentError , 'Invalid Arguments' unless check_arguments ( params , 'count' ) path = '/fips/allocate' query = { } query [ :count ] = params [ :count ] if params . key? ( :count ) fips = JSON . parse ( Hyperb :: Request . new ( self , path , query , 'post' ) . perform ) fips end | allocate a new floating ip |
17,945 | def act ( environment ) environment . objects . each do | object | object . vector . speed = Utility . constrain_value ( object . vector . speed , @maximum ) end end | If object is over the speed reduce its speed . |
17,946 | def act ( environment ) elapsed_time = @clock . elapsed_time environment . objects . each do | object | object . vector += Vector . new ( @vector . speed * elapsed_time , @vector . pitch ) end end | Add the given vector to each object but limited by elapsed time . |
17,947 | def act ( environment ) elapsed_time = @clock . elapsed_time environment . objects . each do | object | acceleration = @force * elapsed_time speed = object . vector . speed if speed > 0 speed -= acceleration speed = 0 if speed < 0 elsif speed < 0 speed += acceleration speed = 0 if speed > 0 end object . vector . speed ... | Reduce each object s speed at the given rate . |
17,948 | def act ( environment ) excess = environment . object_count - @count if excess > 0 objects_for_removal = [ ] environment . objects . each do | object | objects_for_removal << object break if objects_for_removal . length >= excess end objects_for_removal . each { | object | environment . remove_object ( object . identif... | Remove objects if there are too many objects in environment . |
17,949 | def has ( name , options = { } , & blk ) name = name . to_sym self [ name ] = Characteristic . new ( name , options , & blk ) end | Define a characteristic . |
17,950 | def define_static_cache_key_finder return unless acts_as_static_record_options [ :find_by_attribute_support ] if ( ( key_column = acts_as_static_record_options [ :key ] ) && ( ! column_methods_hash . include? ( key_column . to_sym ) ) ) class_eval %{ def self.find_by_#{key_column}(arg) self.static_r... | Define a method find_by_KEY if the specified cache key is not an active record column |
17,951 | def static_record_lookup_key ( value ) if value . is_a? self static_record_lookup_key ( value . send ( acts_as_static_record_options [ :lookup_key ] || acts_as_static_record_options [ :key ] || primary_key ) ) else value . to_s . gsub ( ' ' , '_' ) . gsub ( / \W / , "" ) . underscore end end | Parse the lookup key |
17,952 | def find_in_static_record_cache ( finder , attributes ) list = static_record_cache [ :primary_key ] . values . inject ( [ ] ) do | list , record | unless attributes . select { | k , v | record . send ( k ) . to_s != v . to_s } . any? return record if finder == :first list << record end list end finder == :all ? list : ... | Search the cache for records with the specified attributes |
17,953 | def find_with_static_record ( * args ) if scope ( :find ) . nil? && args if args . first . is_a? ( Fixnum ) && ( ( args . length == 1 || ( args [ 1 ] . is_a? ( Hash ) && args [ 1 ] . values . delete ( nil ) . nil? ) ) ) return static_record_cache [ :primary_key ] [ args . first ] elsif args . first == :all && args . le... | Perform find by searching through the static record cache if only an id is specified |
17,954 | def calculate_with_static_record ( operation , column_name , options = { } ) if scope ( :find ) . nil? && ! options . any? { | k , v | k . to_s . downcase != 'distinct' } key = "#{operation}_#{column_name}_#{options.none?{|k,v| v.blank? }}" static_record_cache [ :calc ] [ key ] ||= case operation . to_s when 'count' th... | Override calculate to compute data in memory if possible Only processes results if there is no scope and the no keys other than distinct |
17,955 | def static_records_for_calculation ( column_name , options = { } , & block ) if columns_hash . has_key? ( column_name . to_s ) records = static_record_cache [ :primary_key ] . values . collect ( & ( column_name . to_sym ) ) . compact results = ( options [ :distinct ] || options [ 'distinct' ] ) ? records . uniq : recor... | Return the array of results to calculate if they are available |
17,956 | def initialize_static_record_cache return unless @static_record_cache . nil? records = self . find_without_static_record ( :all , acts_as_static_record_options [ :find ] || { } ) @static_record_cache = records . inject ( { :primary_key => { } , :key => { } , :calc => { } } ) do | cache , record | cache [ :primary_key ]... | Find all the record and initialize the cache |
17,957 | def static_record_finder_method_name ( finder , attributes ) method_to_call = "find_in_static_record_cache(#{finder.inspect}, #{attributes.inspect})" if attributes . length == 1 key_value = case attributes . keys . first . to_s when self . primary_key then [ :primary_key , attributes . values . first . to_i ] when acts... | Retrieve the method name to call based on the attributes Single attributes on primary key or the specified key call directly to the cache All other methods iterate through the cache |
17,958 | def define_static_record_finder_method ( method_id , finder , bang , attributes ) method_to_call = static_record_finder_method_name ( finder , attributes ) method_with_static_record = "#{method_id}_with_static_rc" class_eval %{ def self.#{method_with_static_record}(*args) if (args.dup.extract_options!).... | Define the finder method on the class and return the name of the method Ex . find_by_id will define find_by_id_with_static_rc |
17,959 | def method_missing ( method_id , * arguments , & block ) if ( ( match = method_id . to_s . match ( / / ) ) && ( base_method_id = match [ 1 ] ) ) begin return super ( base_method_id , * arguments , & block ) ensure define_static_rc_alias ( base_method_id ) end end if match = ActiveRecord :: DynamicFinderMatch . match ( ... | Method missing is overridden to use cache calls for finder methods |
17,960 | def generate! ( slip , path ) image = MiniMagick :: Image . open ( File . expand_path ( '../../../assets/slip.png' , __FILE__ ) ) Bollettino :: Renderer :: Slip . render ( image , slip ) image . write path end | Initializes the generator . |
17,961 | def compose_down ( params = { } ) raise ArgumentError , 'Invalid arguments.' unless check_arguments ( params , 'project' ) path = '/compose/down' query = { } query [ :project ] = params [ :project ] if params . key? ( :project ) query [ :vol ] = params [ :vol ] if params . key? ( :vol ) query [ :rmi ] = params [ :rmi ]... | stop and remove a compose project |
17,962 | def compose_create ( params = { } ) raise ArgumentError , 'Invalid arguments.' unless check_arguments ( params , 'project' ) path = '/compose/create' query = { } body = { } query [ :project ] = params [ :project ] if params . key? ( :project ) body [ :serviceconfigs ] = { 'M' : { } } body [ :serviceconfigs ] [ :M ] = p... | create a compose project |
17,963 | def write_to_string_io ( string_io ) java_proto . write_to ( org . jruby . util . IOOutputStream . new ( string_io ) ) nil end | Serialize the message to the given StringIO . |
17,964 | def write_to_string string_io = StringIO . new . set_encoding ( Encoding :: BINARY ) write_to_string_io ( string_io ) string_io . string end | Serialize the message to a String . |
17,965 | def do ( actor , targets ) return if targets . empty? actor . vector . pitch = Utility . find_angle ( actor . location , random_target ( targets ) . location ) end | Set the actor s heading to point directly at first target . |
17,966 | def do ( actor , targets ) return if targets . empty? actor . vector += Vector . new ( delta , Utility . find_angle ( actor . location , random_target ( targets ) . location ) ) end | Accelerate toward the first target but limited by rate . |
17,967 | def do ( actor , targets ) targets . each do | target | target . environment . remove_object ( target . identifier ) end end | Remove the target from the environment . |
17,968 | def do ( actor , targets ) targets . each do | target | target . tags << tag unless target . tags . include? ( tag ) end end | Apply the given tag to the targets . |
17,969 | def do ( actor , targets ) actor . color . red += ( @color . red - actor . color . red ) * delta actor . color . green += ( @color . green - actor . color . green ) * delta actor . color . blue += ( @color . blue - actor . color . blue ) * delta end | Blend the actor s color with the assigned color . |
17,970 | def do ( actor , targets ) push_force = delta targets . each do | target | push_angle = Utility . find_angle ( actor . location , target . location ) target . vector += Vector . new ( push_force , push_angle ) end end | Push the targets away from the actor with force limited by elapsed time . |
17,971 | def do ( actor , targets ) pull_force = delta targets . each do | target | pull_angle = Utility . find_angle ( target . location , actor . location ) target . vector += Vector . new ( pull_force , pull_angle ) end end | Pull the targets toward the actor with force limited by elapsed time . |
17,972 | def do ( actor , targets ) prototypes . each do | prototype | actor . environment . add_object ( generate_child ( actor , prototype ) ) end end | Add children to environment . |
17,973 | def generate_child ( actor , prototype ) child = prototype . copy child . location = actor . location . copy child end | Copy prototype to actor s location . |
17,974 | def generate_child ( actor , prototype ) child = super child . vector += actor . vector child . size = actor . size / prototypes . length child end | Calls super method . Also adds actor s vector to child s . Finally reduces child s size to actor s size divided by number of shrapnel pieces . |
17,975 | def do ( actor , targets ) return if targets . empty? if prototypes [ @prototype_index ] . respond_to? ( :each ) prototypes [ @prototype_index ] . each do | prototype | actor . environment . add_object ( generate_child ( actor , prototype , targets [ @target_index ] ) ) end else targets [ @target_index ] . environment ... | Copies next prototype into environment . |
17,976 | def generate_child ( actor , prototype , target ) child = super ( actor , prototype ) child . vector . pitch = Utility . find_angle ( actor . location , target . location ) + child . vector . pitch child end | Calls super method . Also adds angle to target to child s vector angle . |
17,977 | def find ( context , facet_name , * args ) facet = find_facet ( context , facet_name ) if ! facet return nil end case result = facet . find ( * args ) when Array result . map { | item | @entities [ item ] } when String @entities [ result ] when NilClass nil else raise "Bad facet return type #{result.class.name.dump}" e... | Finds an entity or entities . |
17,978 | def find_facet ( context , facet_name ) cache_key = [ context , facet_name ] if @facet_cache . include? ( cache_key ) facet = @facet_cache [ cache_key ] else begin require "percolate/facet/#{facet_name}_facet" rescue LoadError end if facet = @adapter . load_facet ( context , facet_name ) @facet_cache [ cache_key ] = fa... | Finds a facet . |
17,979 | def url_for params p = params . dup query = p . map { | key , value | value . to_query ( key ) } * '&' "#{h.url_for({})}?#{query}" end | dirty hack to avoid rails sorted query in url |
17,980 | def create_service ( params = { } ) valid = check_arguments ( params , 'name' , 'image' , 'replicas' , 'serviceport' , 'labels' ) raise ArgumentError , 'Invalid arguments.' unless valid path = '/services/create' body = { } body . merge! ( params ) downcase_symbolize ( JSON . parse ( Hyperb :: Request . new ( self , pat... | create a service |
17,981 | def symbolize ( hash ) { } . tap do | h | hash . each { | key , value | h [ key . to_sym ] = map_value_symbol ( value ) } end end | This method is called to convert all the keys of a hash into symbols to allow consistent usage of hashes within your Ruby application . |
17,982 | def stringify ( hash ) { } . tap do | h | hash . each { | key , value | h [ key . to_s ] = map_value_string ( value ) } end end | This method is called to convert all the keys of a hash into strings to allow consistent usage of hashes within your Ruby application . |
17,983 | def to_hash ( obj ) return nil unless obj return obj if obj . is_a? ( Hash ) hash = { } obj . instance_variables . each do | key | hash [ key [ 1 .. - 1 ] . to_sym ] = deeply_to_hash ( obj . instance_variable_get ( key ) ) end hash end | Convert an object to a hash representation of its instance variables . |
17,984 | def follow ( from_id , to_id , scope = Amico . default_scope_key ) return if from_id == to_id return if blocked? ( to_id , from_id , scope ) return if Amico . pending_follow && pending? ( from_id , to_id , scope ) if Amico . pending_follow Amico . redis . multi do | transaction | transaction . zadd ( "#{Amico.namespace... | Establish a follow relationship between two IDs . After adding the follow relationship it checks to see if the relationship is reciprocated and establishes that relationship if so . |
17,985 | def unfollow ( from_id , to_id , scope = Amico . default_scope_key ) return if from_id == to_id Amico . redis . multi do Amico . redis . zrem ( "#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}" , to_id ) Amico . redis . zrem ( "#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}" , from_id ) Amico... | Remove a follow relationship between two IDs . After removing the follow relationship if a reciprocated relationship was established it is also removed . |
17,986 | def block ( from_id , to_id , scope = Amico . default_scope_key ) return if from_id == to_id Amico . redis . multi do Amico . redis . zrem ( "#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}" , to_id ) Amico . redis . zrem ( "#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{to_id}" , from_id ) Amico . ... | Block a relationship between two IDs . This method also has the side effect of removing any follower or following relationship between the two IDs . |
17,987 | def accept ( from_id , to_id , scope = Amico . default_scope_key ) return if from_id == to_id add_following_followers_reciprocated ( from_id , to_id , scope ) end | Accept a relationship that is pending between two IDs . |
17,988 | def deny ( from_id , to_id , scope = Amico . default_scope_key ) return if from_id == to_id Amico . redis . multi do Amico . redis . zrem ( "#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}" , from_id ) Amico . redis . zrem ( "#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}" , to_id ) end end | Deny a relationship that is pending between two IDs . |
17,989 | def following? ( id , following_id , scope = Amico . default_scope_key ) ! Amico . redis . zscore ( "#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}" , following_id ) . nil? end | Check to see if one individual is following another individual . |
17,990 | def follower? ( id , follower_id , scope = Amico . default_scope_key ) ! Amico . redis . zscore ( "#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}" , follower_id ) . nil? end | Check to see if one individual is a follower of another individual . |
17,991 | def blocked? ( id , blocked_id , scope = Amico . default_scope_key ) ! Amico . redis . zscore ( "#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}" , blocked_id ) . nil? end | Check to see if one individual has blocked another individual . |
17,992 | def blocked_by? ( id , blocked_by_id , scope = Amico . default_scope_key ) ! Amico . redis . zscore ( "#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}" , blocked_by_id ) . nil? end | Check to see if one individual is blocked by another individual . |
17,993 | def reciprocated? ( from_id , to_id , scope = Amico . default_scope_key ) following? ( from_id , to_id , scope ) && following? ( to_id , from_id , scope ) end | Check to see if one individual has reciprocated in following another individual . |
17,994 | def pending_with? ( from_id , to_id , scope = Amico . default_scope_key ) ! Amico . redis . zscore ( "#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{to_id}" , from_id ) . nil? end | Check to see if one individual has a pending relationship with another . |
17,995 | def following_page_count ( id , page_size = Amico . page_size , scope = Amico . default_scope_key ) total_pages ( "#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}" , page_size ) end | Count the number of pages of following relationships for an individual . |
17,996 | def followers_page_count ( id , page_size = Amico . page_size , scope = Amico . default_scope_key ) total_pages ( "#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}" , page_size ) end | Count the number of pages of follower relationships for an individual . |
17,997 | def blocked_page_count ( id , page_size = Amico . page_size , scope = Amico . default_scope_key ) total_pages ( "#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}" , page_size ) end | Count the number of pages of blocked relationships for an individual . |
17,998 | def blocked_by_page_count ( id , page_size = Amico . page_size , scope = Amico . default_scope_key ) total_pages ( "#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}" , page_size ) end | Count the number of pages of blocked_by relationships for an individual . |
17,999 | def reciprocated_page_count ( id , page_size = Amico . page_size , scope = Amico . default_scope_key ) total_pages ( "#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{id}" , page_size ) end | Count the number of pages of reciprocated relationships for an individual . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.