idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
15,100 | def exception_handling ( exception_handler , control ) begin yield rescue => exception if exception_handler exception_handler . call ( exception , control ) else raise end end end | Defines how the server handles exception . |
15,101 | def save_with_provenance ( activity_uri ) predicate = exists? ? REVISED_URI : GENERATED_URI self << RDF :: Statement ( self , predicate , activity_uri ) save end | Adds an appropritate provenance statement with the given URI and saves the resource . |
15,102 | def assign_generator_activity! ( opts ) if opts . include? ( :generator_uri ) generator_uri = opts . delete ( :generator_uri ) @entity_source = @generator_activity = Krikri :: Activity . from_uri ( generator_uri ) end end | Store this agent s generator activity which is the activity that produced the target entities upon which the current agent will operate . |
15,103 | def deep_vars instance_variables . select do | var | value = instance_variable_get ( var ) value . kind_of? ( Array ) or value . kind_of? ( Hash ) or value . kind_of? ( DeepClonable :: InstanceMethods ) end end | You can override deep_vars in your class to specify which instance_variables should be deep cloned . As it is all Arrays and Hashes are deep cloned . |
15,104 | def post_request ( url , args ) uri = URI . parse ( url ) req = Net :: HTTP :: Post . new ( uri . path ) req . set_form_data ( args ) request ( uri , req ) end | url as a string the post data as a hash |
15,105 | def swap ( a , b ) temp = at ( a ) put a , at ( b ) put b , temp end | Swap elements of the two indexes . |
15,106 | def system_call ( * args ) result = SystemCall . call ( * args ) return result . success_result if result . success? return yield ( result . error_result ) if block_given? result . error_result end | Initiates a system call with the given arguments . |
15,107 | def signal synchronize do while ( t = @threads . shift ) if ( t && t . alive? && t . stop? ) t . wakeup break else next end end end end | Wake up earliest thread |
15,108 | def broadcast synchronize do @threads . dup . each do | t | t . wakeup if t . alive? && t . stop? end end end | Wake up all threads |
15,109 | def try_lock locked = false Thread . exclusive do clean unless ( locked? ( false ) ) do_lock locked = true else locked = owner? ( Thread . current ) end end locked end | Attempt to lock . Returns true if lock is aquired and false if not . |
15,110 | def clean @locks . delete_if { | t | ! t . alive? } if ( @lock_owner && ! @lock_owner . alive? ) @lock_owner = @locks . empty? ? nil : @locks . shift @lock_owner . wakeup if @lock_owner && ! owner? ( Thread . current ) end end | This is a simple helper method to help keep threads from ending up stuck waiting for a lock when a thread locks the monitor and then decides to die without unlocking . It is only called when new locks are attempted or a check is made if the monitor is currently locked . |
15,111 | def do_unlock unless ( owner? ( Thread . current ) ) raise ThreadError . new ( "Thread #{Thread.current} is not the current owner: #{@lock_owner}" ) end Thread . exclusive do @locks . delete_if { | t | ! t . alive? } unless ( @locks . empty? ) old_owner = @lock_owner @lock_owner = @locks . shift @lock_owner . wakeup un... | Unlock the monitor |
15,112 | def start_timer @timer = Thread . new do begin until ( @stop ) do cur = [ ] t = 0.0 Thread . exclusive do t = @timers . values . min cur = @timers . dup end t = 0.0 if ! t . nil? && t < 0.0 a = 0.0 begin a = Splib . sleep ( t ) rescue Wakeup ensure next if t . nil? Thread . exclusive do cur . each_pair do | thread , va... | Starts the timer for waiting threads with a timeout |
15,113 | def attributes_for_request ( attrs = filled_attributes ) return attrs if self . class :: ORIGIN_TRANSACTION_VARIABLES . empty? attrs . each_with_object ( { } ) do | ( attr , value ) , request_attrs | request_attrs [ self . class :: ORIGIN_TRANSACTION_VARIABLES . fetch ( attr , attr ) ] = value end end | Returns only filled attributes with the original Alpha Card Services transaction variables names . |
15,114 | def validate_required_attributes! unless required_attributes? blank_attribute = required_attributes . detect { | attr | self [ attr ] . nil? || self [ attr ] . empty? } raise ValidationError , "#{blank_attribute} can't be blank" end end | Validate required attributes to be filled . Raises an exception if one of the attribute is not specified . |
15,115 | def dump_one ( * vars ) refresh_index ( * vars ) document = search_by_id ( { :params => { :_source => '*' } } , * vars ) document . delete ( '_score' ) document end | refresh and pull the full document from the index |
15,116 | def post_bulk_collection ( collection , options = { } ) raise ArgumentError , "Array expected as :collection, got #{collection.inspect}" unless collection . is_a? ( Array ) bulk_string = '' collection . each do | d | bulk_string << build_bulk_string ( d , options ) end post_bulk_string ( :bulk_string => bulk_string ) u... | You should use Elastics . post_bulk_string if you have an already formatted bulk data - string |
15,117 | def examples @doc ||= Nokogiri :: HTML ( open ( PREFIX + CGI :: escape ( @word ) ) ) @example_results ||= @doc . css ( '.exsentences' ) . map { | x | x . text . strip } . reject ( & :empty? ) . flatten @example_results end | Fetches and gives the examples for the word |
15,118 | def similar_words @doc ||= Nokogiri :: HTML ( open ( PREFIX + CGI :: escape ( @word ) ) ) @similar_words = @doc . css ( "#relatedwords .fla a" ) . map ( & :text ) . reject ( & :empty? ) @similar_words end | Fetches and gives synonyms for the word |
15,119 | def query_params params = { :id => '*:*' , :sort => "random_#{rand(9999)} desc" , :rows => 1 } return params unless provider_id . present? provider = RDF :: URI ( Krikri :: Provider . base_uri ) / provider_id params [ :fq ] = "provider_id:\"#{provider}\"" params end | Parameters for the Solr request . Limits search by |
15,120 | def random_record_id ( provider_id ) doc = Krikri :: RandomSearchIndexDocumentBuilder . new do self . provider_id = provider_id end . document doc . present? ? local_name ( doc . id ) : nil end | Return the id of a document randomly selected from the search index . |
15,121 | def find ( location , kind = :file ) location = File . join ( absolute_location , location ) File . send ( "#{kind}?" , location ) ? Pathname . new ( environment , location ) : nil end | Returns a Pathname for the location relative to this pathname s absolute location . |
15,122 | def render_enriched_record ( document ) agg = document . aggregation return error_msg ( 'Aggregation not found.' ) unless agg . present? JSON . pretty_generate ( agg . to_jsonld [ '@graph' ] ) end | Render enriched record for view |
15,123 | def render_original_record ( document ) agg = document . aggregation return error_msg ( 'Aggregation not found.' ) unless agg . present? begin original_record = agg . original_record rescue StandardError => e logger . error e . message return error_msg ( e . message ) end return error_msg ( 'Original record not found.'... | Render original record for view |
15,124 | def cookie_accepted visitor_current_url = begin cookies . signed [ CookieAlert . config . cookie_name . to_sym ] . split ( CookieAlert . config . cookie_value_text_separator ) [ 1 ] rescue main_app . root_path end if CookieAlert . config . cookie_type == 'permanent' cookies . permanent . signed [ CookieAlert . config .... | Implement cookie acceptance when a visitor click the accept button |
15,125 | def check? ( color , proposed_manifest = @piece_locations , recurse_for_checkmate = false ) enemy_attack_vectors = { } player_attack_vectors = { } king_loc = [ ] enemy_color = opposing_color ( color ) proposed_manifest . each do | piece , details | if details [ :color ] == enemy_color enemy_attack_vectors [ piece ] = p... | Return whether the player of a specified color has their king currently in check by checking the attack vectors of all the opponents players against the king location Also check whether king currently in check has all of their valid moves within their opponents attack vectors and therefore are in checkmate ( |
15,126 | def transactions ( options = { } ) agent . transactions ( self [ 'id' ] , options ) do | data , resp | yield ( data , resp ) if block_given? end end | List of transactions |
15,127 | def transactions_by_address ( address , options = { } ) agent . transactions_by_address ( self [ 'id' ] , address , options ) do | data , resp | yield ( data , resp ) if block_given? end end | List of transactions by address |
15,128 | def [] ( id ) interfaces_hash . fetch ( id . to_s ) do raise UnknownInterface . new ( id . to_s ) , "Unknown interface: #{id}" end end | Returns traffic information for a certain interface . |
15,129 | def gen_subject subject_name = "/C=#{EasyRSA::Config.country}" subject_name += "/ST=#{EasyRSA::Config.state}" unless ! EasyRSA :: Config . state || EasyRSA :: Config . state . empty? subject_name += "/L=#{EasyRSA::Config.city}" subject_name += "/O=#{EasyRSA::Config.company}" subject_name += "/OU=#{EasyRSA::Config.orgun... | Cert subject for End - User |
15,130 | def nick = ( nick ) success = Utils . call_executable_returning_status ( '-i' , id , '--nick' , nick , '--update' ) unless success raise Error , "Unable to set nickname for interface (#{id}). " 'Please make sure the vnstat daemon is not running while ' 'performing this operation.' end @nick = nick end | Sets the alias name for the interface . |
15,131 | def open self . thread = Thread . new do EM . tick_loop do unless self . cmd_queue . empty? command = self . cmd_queue . pop self . _execute_command ( command ) end end self . wamp . open end end | Constructor for creating a client . Options are |
15,132 | def add_procedure ( procedure , klass , options = nil ) options ||= { } raise WampRails :: Error . new ( '"add_procedure" must be called BEFORE "open"' ) if self . thread self . registrations << WampRails :: Command :: Register . new ( procedure , klass , options , self ) end | Adds a procedure to the client |
15,133 | def add_subscription ( topic , klass , options = nil ) options ||= { } raise WampRails :: Error . new ( '"add_subscription" must be called BEFORE "open"' ) if self . thread self . subscriptions << WampRails :: Command :: Subscribe . new ( topic , klass , options , self ) end | Adds a subscription to the client |
15,134 | def call ( procedure , args = nil , kwargs = nil , options = { } , & callback ) command = WampRails :: Command :: Call . new ( procedure , args , kwargs , options , self ) self . _queue_command ( command , callback ) end | endregion region WAMP Methods Performs a WAMP call |
15,135 | def publish ( topic , args = nil , kwargs = nil , options = { } , & callback ) command = WampRails :: Command :: Publish . new ( topic , args , kwargs , options , self ) self . _queue_command ( command , callback ) end | Performs a WAMP publish |
15,136 | def register ( procedure , klass , options = { } , & callback ) command = WampRails :: Command :: Register . new ( procedure , klass , options , self ) self . _queue_command ( command , callback ) end | Performs a WAMP register |
15,137 | def subscribe ( topic , klass , options = { } , & callback ) command = WampRails :: Command :: Subscribe . new ( topic , klass , options , self ) self . _queue_command ( command , callback ) end | Performs a WAMP subscribe |
15,138 | def _queue_command ( command , callback = nil ) if self . thread == Thread . current self . _execute_command ( command ) else self . cmd_queue . push ( command ) end if callback callback_args = command . queue . pop callback . call ( callback_args . result , callback_args . error , callback_args . details ) end end | endregion region Private Methods Queues the command and blocks it the callback is not nil |
15,139 | def track_external_change ( app_id , action , document ) return unless Conf . redis Conf . redis . rpush ( "#{KEYS[:changes]}-#{app_id}" , MultiJson . encode ( [ action , document ] ) ) end | use this method when you are tracking the change of another app you must pass the app_id of the app being affected by the change |
15,140 | def report data return nil if data . nil? || data . empty? result = '' data . each do | file_name , analysis | rel_path = File . join ( '.' , File . expand_path ( file_name ) . sub ( Dir . pwd , '' ) ) result += "\n#{rel_path}\n" analysis . each do | line_number , warning | result += " #{line_number}: #{warning.join('... | Format data into a report |
15,141 | def blankish? ( value ) case value when nil , false true when Dux [ :nan? ] true when String , Symbol value . empty? || value =~ WHITESPACE_ONLY when Dux [ :blank? ] value . blank? when Hash value . empty? when Array , Enumerable Dux . attempt ( value , :empty? ) || value . all? { | val | blankish? ( val ) } when Dux [... | Check if a provided object is semantically empty . |
15,142 | def build_optional_patterns ( predicates ) return [ [ TYPE , predicates , VALUE ] ] unless predicates . is_a? Enumerable var1 = TYPE patterns = predicates . each_with_object ( [ ] ) do | predicate , ps | var2 = ( ps . count == predicates . size - 1 ) ? VALUE : "obj#{ps.count}" . to_sym ps << [ var1 , predicate , var2 ]... | Builds patterns matching a predicate or chain of predicates given assigning an unbound variable to each set of matches and passing it to the next pattern . |
15,143 | def possible_moves ( p1 , manifest , castling = false ) return [ ] if manifest [ p1 ] [ :type ] . nil? allowed = [ ] type = manifest [ p1 ] [ :type ] my_color = manifest [ p1 ] [ :color ] constants ( manifest , my_color , type ) return [ ] if unoccupied? ( p1 ) if type == :king allowed += [ move_lateral ( p1 , 1 ) ] . ... | Calls methods below to return a list of positions which are valid moves for piece at index p1 given the current board layout as defined in manifest |
15,144 | def move_pawn ( p1 ) col = get_col_from_index ( p1 ) valid = [ ] if Move . color == :red valid << ( p1 - 8 ) if unoccupied? ( p1 - 8 ) valid << ( p1 - 7 ) if piece_color ( p1 - 7 ) == Move . enemy_color && col < 8 valid << ( p1 - 9 ) if piece_color ( p1 - 9 ) == Move . enemy_color && col > 1 valid << ( p1 - 16 ) if ! M... | Returns all valid positions a pawn at index p1 can move to |
15,145 | def move_knight ( p1 ) row = get_row_from_index ( p1 ) col = get_col_from_index ( p1 ) valid = [ ] valid_moves_no_friendly_fire = [ ] valid << ( p1 + 17 ) if row < 7 && col < 8 valid << ( p1 + 15 ) if row < 7 && col > 1 valid << ( p1 + 10 ) if row < 8 && col < 7 valid << ( p1 + 6 ) if row < 8 && col > 2 valid << ( p1 -... | Returns valid positions a knight at index p1 can move to |
15,146 | def find_by_identity ( identity , at_date = nil ) if at_date . nil? q = current else q = at ( at_date ) end q = q . where ( IDENTITY_COLUMN => identity ) q . first end | Note that find_by_identity will return nil if there s not a current iteration of the identity |
15,147 | def create_identity ( attributes , start = nil ) start ||= START_OF_TIME create ( attributes . merge ( START_COLUMN => start || START_OF_TIME ) ) end | The first iteration can be defined with a specific start date but that is in general a bad idea since it complicates obtaining the first iteration |
15,148 | def gen_issuer name = "/C=#{EasyRSA::Config.country}" name += "/ST=#{EasyRSA::Config.state}" unless ! EasyRSA :: Config . state || EasyRSA :: Config . state . empty? name += "/L=#{EasyRSA::Config.city}" name += "/O=#{EasyRSA::Config.company}" name += "/OU=#{EasyRSA::Config.orgunit}" name += "/CN=#{EasyRSA::Config.serve... | Cert issuer details |
15,149 | def add_extensions ef = OpenSSL :: X509 :: ExtensionFactory . new ef . subject_certificate = @ca_cert ef . issuer_certificate = @ca_cert @ca_cert . add_extension ef . create_extension ( 'subjectKeyIdentifier' , 'hash' ) @ca_cert . add_extension ef . create_extension ( 'basicConstraints' , 'CA:TRUE' , true ) @ca_cert . ... | Add Extensions needed |
15,150 | def render_tbody if @lines and @lines . size > 0 return Tools :: html_safe ( content_tag ( :tbody , render_total_entries + Tools :: html_safe ( @lines . collect { | line | line . render_line } . join ) ) ) return Tools :: html_safe ( content_tag ( :tr , content_tag ( :td , I18n . t ( :total_entries , :scope => :sorting... | Return the balise tbody and its content |
15,151 | def render_total_entries if self . show_total_entries total_entries = @collection . total_entries rescue @collection . size header_total_cells = @header_line ? @header_line . total_cells : 0 max_cells = ( @lines . first . total_cells > header_total_cells ) ? @lines . first . total_cells : header_total_cells return Tool... | Calculate the total entries Return a tr and td with a colspan of total entries |
15,152 | def bulk_update_from_activity ( activity ) all_aggs = entities_as_json_hashes ( activity ) agg_batches = bulk_update_batches ( all_aggs ) agg_batches . each do | batch | index_with_error_handling ( activity ) { bulk_add ( batch ) } end end | Given an activity use the bulk - update method to load its revised entities into the search index . |
15,153 | def bulk_update_batches ( aggregations ) en = Enumerator . new do | e | i = 1 batch = [ ] aggregations . each do | agg | batch << agg if i % @bulk_update_size == 0 e . yield batch batch = [ ] end i += 1 end e . yield batch if batch . count > 0 end en . lazy end | Enumerate arrays of JSON strings one array per batch that is supposed to be loaded into the search index . |
15,154 | def incremental_update_from_activity ( activity ) entities_as_json_hashes ( activity ) . each do | h | index_with_error_handling ( activity ) { add ( h ) } end end | Given an activity load its revised entities into the search index one at a time . |
15,155 | def schema_keys schema_file = File . join ( Rails . root , 'solr_conf' , 'schema.xml' ) file = File . open ( schema_file ) doc = Nokogiri :: XML ( file ) file . close doc . xpath ( '//fields/field' ) . map { | f | f . attr ( 'name' ) } end | Get field names from Solr schema in host application . Will raise exception if file not found . |
15,156 | def flat_hash ( hash , keys = [ ] ) new_hash = { } hash . each do | key , val | new_hash [ format_key ( keys + [ key ] ) ] = val unless val . is_a? ( Array ) || val . is_a? ( Hash ) new_hash . merge! ( flat_hash ( val , keys + [ key ] ) ) if val . is_a? Hash if val . is_a? Array val . each do | v | if v . is_a? Hash ne... | Flattens a nested hash Joins keys with _ and removes |
15,157 | def dependencies ( names ) names . each do | name | calculation = fetch ( name , nil ) next unless calculation calculation . dependencies . each do | dependency | names << dependency unless names . include? ( dependency ) end end end | Add any missing names required for calculations that are named |
15,158 | def count ( opts = { } ) view = opts [ :view ] || @opts [ :view ] v = client . view ( view , include_docs : false , stream : false , startkey : '_design' , endkey : '_design0' ) total = v . total_rows design_doc_count = v . keys . size total - design_doc_count end | Return the total number of documents reported by a CouchDB view . |
15,159 | def records ( opts = { } ) view = opts [ :view ] || @opts [ :view ] limit = opts [ :limit ] || @opts [ :limit ] record_rows ( view , limit ) . map do | row | @record_class . build ( mint_id ( row [ 'doc' ] [ '_id' ] ) , row [ 'doc' ] . to_json , 'application/json' ) end end | Makes requests to a CouchDB view to yield documents . |
15,160 | def record_rows ( view , limit ) en = Enumerator . new do | e | view_opts = { include_docs : true , stream : false , limit : limit } rows_retrieved = 0 total_rows = nil loop do v = client . view ( view , view_opts ) total_rows ||= v . total_rows rows_retrieved += v . rows . size v . rows . each do | row | next if row [... | Return an enumerator that provides individual records from batched view requests . |
15,161 | def get_record ( identifier ) doc = client . get! ( CGI . escape ( identifier ) ) . body . to_json @record_class . build ( mint_id ( identifier ) , doc , 'application/json' ) end | Retrieves a specific document from CouchDB . |
15,162 | def open_receiver_class [ receivers_class ( @@options [ :receivers ] ) ] . flatten . each do | base | base . class_eval do has_many :deliveries , class_name : 'SimpleNotifications::Delivery' , as : :receiver has_many :received_notifications , through : :deliveries , source : :simple_notification end end end | Opening the classes which are defined as receivers . |
15,163 | def sender_class ( sender ) if sender . kind_of? Symbol reflections [ sender . to_s ] . klass elsif sender . kind_of? ActiveRecord :: Base sender . class else raise 'SimpleNotifications::SenderTypeError' end end | Provides the class of Sender |
15,164 | def receivers_class ( receivers ) if receivers . kind_of? Symbol reflections [ receivers . to_s ] . klass else if receivers . kind_of? ActiveRecord :: Base receivers . class elsif receivers . kind_of? ActiveRecord :: Relation receivers . klass elsif receivers . kind_of? Array receivers . flatten . collect { | receiver ... | Provides the classes of Receivers |
15,165 | def next_options ( opts , record_count ) old_start = opts [ 'params' ] . fetch ( 'start' , 0 ) opts [ 'params' ] [ 'start' ] = old_start . to_i + record_count opts end | Given a current set of options and a number of records from the last request generate the options for the next request . |
15,166 | def do_before_validation prim_slug , i = slug , 0 prim_slug , i = $1 , $2 . to_i if slug =~ / / return unless prim_slug . present? attempts = 0 conditions = new_record? ? [ 'slug = ?' , slug ] : [ 'slug = ? AND id != ?' , slug , id ] conditions [ 1 ] = "#{prim_slug}_#{i+=1}" while Page . where ( conditions ) . first &&... | auto increment slug until it is unique |
15,167 | def create_parameters { record . id_attribute => record . id } . tap do | params | custom_attrs = attribute_names . inject ( { } ) do | memo , attr | value = record . send ( attr ) memo [ attr . to_s ] = value if value memo end params . merge! custom_attrs params [ "ownerid" ] = record . owner . roleid if record . owne... | Each record is assumed to have an id attribute required for creation . In addition other create parameters can be specified by the + custom_attribute_names + method on the record . |
15,168 | def fill_rack_env ( env = { } ) env [ "rack.input" ] = @body || StringIO . new env [ "REQUEST_METHOD" ] = @method env [ "SCRIPT_NAME" ] = "" env [ "REQUEST_URI" ] = @path env [ "PATH_INFO" ] , query = @path . split ( "?" , 2 ) env [ "QUERY_STRING" ] = query || "" if ( @headers [ "HOST" ] && ! env [ "SERVER_NAME" ] ) en... | Given a basic rack environment will properly fill it in with the information gleaned from the parsed request . Note that this only fills the subset that can be determined by the parser library . Namely the only rack . variable set is rack . input . You should also have defaults in place for SERVER_NAME and SERVER_PORT ... |
15,169 | def make_new ( server ) begin conn = @db . connect ( server ) if ac = @after_connect case ac . arity when 3 ac . call ( conn , server , @db ) when 2 ac . call ( conn , server ) else ac . call ( conn ) end end rescue Exception => exception raise Sequel . convert_exception_class ( exception , Sequel :: DatabaseConnection... | Return a new connection by calling the connection proc with the given server name and checking for connection errors . |
15,170 | def add_request ( uri : nil , headers : { } , opts : { } ) fail ArgumentError , "uri must be a URI; got: #{uri}" unless uri . is_a? ( URI ) Request . new ( uri , headers , @default_opts . merge ( opts ) ) end | Create a new asynchronous URL fetcher . |
15,171 | def get_export_options ( model , options ) default_options = { only : model . attribute_names . map ( & :to_sym ) , except : [ ] , methods : [ ] , header : true } options = default_options . merge ( options ) unless options [ :only ] . is_a? ( Array ) && options [ :except ] . is_a? ( Array ) && options [ :methods ] . i... | Compute exportable options after overriding preferences |
15,172 | def get ( provider_name , node_type_name ) name = "#{provider_name}/#{node_type_name}/" response = http_get ( resource_url ( name ) ) format_object ( response , TYPE ) end | Returns the details of a specific NodeType |
15,173 | def get ( params = { } ) params = Utils . symbolize_hash_keys ( params ) query_params = { _actions : false , _links : true , _embedded : true } headers = { } body = nil raise ArgumentError . new ( "applicationId is required" ) unless params . has_key? ( :applicationId ) query_params [ :sortField ] = params [ :sortField... | Returns the applicationKeys for an application |
15,174 | def post ( params = { } ) params = Utils . symbolize_hash_keys ( params ) query_params = { _actions : false , _links : true , _embedded : true } headers = { } body = nil raise ArgumentError . new ( "applicationId is required" ) unless params . has_key? ( :applicationId ) raise ArgumentError . new ( "applicationKey is r... | Create a new applicationKey for an application |
15,175 | def class_of ( object ) case object when ActiveRecord :: Base object . class when ActiveRecord :: Relation object . klass when String object . constantize else object end end | Returns the class for the given class scope or record |
15,176 | def delegate_event ( event ) @message = event . deep_symbolize_keys @subject = message [ :subject ] @action = message [ :action ] if [ message , subject , action ] . any? { | a | a . nil? } raise "Message, subject, and action are not all specified for '#{event.inspect}'" end if respond_to? ( delegate_method ) public_se... | For use in adapters to delegate to method named receive_subject_action |
15,177 | def load! ( path ) settings = YAML . load ( ERB . new ( File . new ( path ) . read ) . result ) if settings . present? from_hash ( settings ) end end | Load the settings from a compliant easyrsa . yml file . This can be used for easy setup with frameworks other than Rails . |
15,178 | def records_by_provider ( solr_params , user_params ) if @provider_id . present? rdf_subject = Krikri :: Provider . base_uri + @provider_id solr_params [ :fq ] ||= [ ] solr_params [ :fq ] << "provider_id:\"#{rdf_subject}\"" end end | Limit the records returned by a Solr request to those belonging to the current provider . |
15,179 | def post_list models , params = { } , default_params = { } model = models . sub / / , '' params = default_params . merge params post ( model + '/list' , params ) [ models ] . map do | data | Geotrigger . const_get ( model . capitalize ) . from_api data , @session end end | Create an instance and from given options + Hash + . |
15,180 | def method_missing meth , * args meth_s = meth . to_s if meth_s =~ / / and args . length == 1 key = meth_s . sub ( / / , '' ) . camelcase if @data and @data . key? key @data [ key ] = args [ 0 ] else super meth , * args end else key = meth_s . camelcase if @data and @data . key? key @data [ key ] else super meth , * ar... | Allows snake_case accessor to top - level data values keyed by their camelCase counterparts . An attempt to be moar Rubyish . |
15,181 | def request_body_from ( req , body ) req . body . nil? || req . body . size == 0 ? body : req . body end | A bit convoluted because post_form uses form_data = to assign the data so in that case req . body will be empty |
15,182 | def enrich_value ( value ) return enrich_node ( value ) if value . is_a? ( ActiveTriples :: Resource ) && value . node? return value if value . is_a? ( DPLA :: MAP :: Controlled :: Language ) return nil if value . is_a? ( ActiveTriples :: Resource ) enrich_literal ( value ) end | Runs the enrichment against a node . Can match literal values and Language values with a provided label . |
15,183 | def enrich_literal ( label ) node = DPLA :: MAP :: Controlled :: Language . new ( ) node . providedLabel = label match = match_iso ( label . to_s ) match = match_label ( label . to_s ) if match . node? return node if match . node? node . exactMatch = match node . prefLabel = RDF :: ISO_639_3 [ match . rdf_subject . qna... | Runs the enrichment over a string . |
15,184 | def move_above ( other ) if position > other . position new_position = other . position other . lower_siblings . where ( :position . lt => self . position ) . each { | s | s . inc ( :position , 1 ) } other . inc ( :position , 1 ) self . position = new_position save! else new_position = other . position - 1 other . high... | Move this node above the specified node |
15,185 | def whitespace_token if md = WHITESPACE . match ( @chunk ) input = md . to_a [ 0 ] input . length else did_not_match end end | Matches and consumes non - meaningful whitespace . |
15,186 | def string_token if %w( ' " ) . include? ( @chunk [ 0 ] ) result = process_string @chunk [ 0 .. - 1 ] , @chunk [ 0 ] if @looking_for_args token :Argument , result . str , attrs : { quoted_by : @chunk [ 0 ] } else token :Command , result . str end result . consumed_length else did_not_match end end | Matches single and double quoted strings |
15,187 | def generate_field_report! report = field_queries . inject ( { } ) do | report_hash , ( k , v ) | report_hash [ k ] = solutions_to_hash ( v . execute ) report_hash end update ( field_report : report ) end | Generates and saves the field report for the provider sending SPARQL queries as necessary . |
15,188 | def generate_count_report! report = count_queries . inject ( { } ) do | report_hash , ( k , v ) | report_hash [ k ] = solutions_to_counts ( v . execute ) report_hash end update ( count_report : report ) end | Generates and saves the coun treport for the provider sending SPARQL queries as necessary . |
15,189 | def connection opts = options . to_hash extensions = options . extensions conn = if url = ( opts . delete ( :uri ) || opts . delete ( :url ) ) Sequel . connect ( url , opts ) else realm = opts [ :realm ] host_fqdn = opts [ :host_fqdn ] || opts [ :host ] principal = opts [ :principal ] adapter = opts [ :adapter ] if ada... | Accepts an optional set of database options |
15,190 | def register ( subject , schema , ** params ) lookup_subject_schema ( subject , schema ) rescue Excon :: Errors :: NotFound register_without_lookup ( subject , schema , params ) end | Override register to first check if a schema is registered by fingerprint Also allow additional params to be passed to register . |
15,191 | def compatible? ( subject , schema , version = 'latest' , ** params ) data = post ( "/compatibility/subjects/#{subject}/versions/#{version}" , expects : [ 200 , 404 ] , body : { schema : schema . to_s } . merge! ( params ) . to_json ) data . fetch ( 'is_compatible' , false ) unless data . key? ( 'error_code' ) end | Override to add support for additional params |
15,192 | def call_api_tsv ( http_method , path , opts = { } ) request = build_request ( http_method , path , opts ) response = request . run if @config . debugging @config . logger . debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" end unless response . success? if response . timed_out? fail ApiError . new ( 'Conne... | Call an API with given options and parse the TSV response . |
15,193 | def render_cell_tbody if @type == :action cell_value = action_link_to ( @ask ) elsif @ask cell_value = ( @ask . is_a? ( Symbol ) ) ? format_cell_value ( @object [ @ask ] , @ask ) : format_cell_value ( @ask ) else cell_value = @block end cell_value = action_link_to ( @options [ :action ] , cell_value ) if @type != :acti... | Return a td with the formated value or action for columns |
15,194 | def render_cell_thead if @ask cell_value = ( @ask . is_a? ( Symbol ) ) ? I18n . t ( @ask , { } , :header ) : @ask else cell_value = @block end if @can_sort sort_on = @options [ :sort_as ] || @ask @html_options . merge! ( :class => "#{@html_options[:class]} #{sorting_html_class(sort_on)}" . strip ) content_tag ( :th , s... | Return a td with the formated value or action for headers |
15,195 | def action_link_to ( action , block = nil ) object_or_array = @@object_or_array . clone object_or_array . push @object return case action . to_sym when :delete create_link_to ( block || I18n . t ( :delete ) , object_or_array , @@options [ :link_remote ] , :delete , I18n . t ( :confirm_delete ) ) when :show create_link_... | Create the link for actions Set the I18n translation or the given block for the link s name |
15,196 | def create_link_to ( block , url , remote , method = nil , confirm = nil ) if remote return link_to ( block , url , :method => method , :confirm => confirm , :remote => true ) end link_to ( block , url , :method => method , :confirm => confirm ) end | Create the link based on object Set an ajax link if option link_remote is set to true |
15,197 | def format_cell_value ( value , attribute = nil ) unless ( ret_value = format_cell_value_as_ask ( value ) ) . nil? return ret_value end format_cell_value_as_type ( value , attribute ) end | Return the formated cell s value |
15,198 | def format_cell_value_as_type ( value , attribute ) if value . is_a? ( Time ) or value . is_a? ( Date ) return :: I18n . l ( value , :format => @options [ :format ] || TableBuilder . i18n_default_format_date ) elsif TableBuilder . currency_columns . include? ( attribute ) return number_to_currency ( value ) elsif value... | Format the value based on value s type |
15,199 | def show @report = Krikri :: QAReport . find ( params [ :id ] ) @type = params [ :type ] == 'count' ? :count : :field respond_to do | format | format . html format . csv { render text : @report . send ( "#{@type}_csv" . to_sym ) . to_csv } end end | Rendering the report as either a full field report or a count report . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.