idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
19,800
def run_analysis @filesPathProject = get_project_file ( @configurationInfo [ :source ] ) unless @filesPathProject message = "Problem on source path: #{@configurationInfo[:source]}" Util :: LoggerKuniri . error ( message ) return - 1 end @parser = Parser :: Parser . new ( @filesPathProject , @configurationInfo [ :langua...
Start Kuniri tasks based on configuration file . After read configuration file find all files in source directory .
19,801
def run! story = @configuration . story fail ( "Could not find story associated with branch" ) unless story Git . clean_working_tree? Git . push ( story . branch_name , set_upstream : true ) unless story . release? print "Creating pull-request on Github... " pull_request_params = story . params_for_pull_request . merge...
Publishes the branch and opens the pull request
19,802
def check_payment_transaction_status ( payment_transaction ) unless payment_transaction . finished? raise ValidationError , 'Only finished payment transaction can be used for create-card-ref-id' end unless payment_transaction . payment . paid? raise ValidationError , "Can not use new payment for create-card-ref-id. Exe...
Check if payment transaction is finished and payment is not new .
19,803
def current_tenant = ( val ) key = :" " unless Thread . current [ key ] . try ( :url_identifier ) == val . try ( :url_identifier ) Thread . current [ key ] = val ensure_tenant_model_reset end Thread . current [ key ] end
Sets current tenant from ApplicationController into a Thread local variable . Works only with thread - safe Rails as long as it gets set on every request
19,804
def with_tenant ( tenant , & blk ) orig = self . current_tenant begin self . current_tenant = tenant return blk . call ( tenant ) ensure self . current_tenant = orig end end
Replace current_tenant with
19,805
def convert ( val ) return nil if val . blank? and val != false if @type == String return val . to_s elsif @type == Integer return Kernel . Integer ( val ) rescue val elsif @type == Float return Kernel . Float ( val ) rescue val elsif @type == Boolean v = BOOLEAN_MAPPING [ val ] v = val . to_s . downcase == 'true' if v...
Convert a value to the proper class for storing it in the field . If the value can t be converted the original value will be returned . Blank values are always translated to nil . Hashes will be converted to EmbeddedDocument objects if the field type extends from EmbeddedDocument .
19,806
def method_missing ( method_name , * args , & block ) if level = ValidMethods [ method_name . to_s ] or level = ValidMethods [ "gritter_#{method_name}" ] options = args . extract_options! options [ :level ] = level args << options gritter_notice * args else super ( method_name , * args , & block ) end end
notice_success notice_error notice_warning notice_progress notice_notice - default . An alias for notice
19,807
def get_human_readable_attrs @zone = Dictionary . zone_from_command ( @command ) @command_name = Dictionary . command_to_name ( @command ) @command_description = Dictionary . description_from_command ( @command ) @value_name = Dictionary . command_value_to_value_name ( @command , @value ) @value_description = Dictionar...
Retrieves human readable attributes from the yaml file via Dictionary
19,808
def installed? ( package ) fail LookupFailed , 'No supported package tool found.' if tool . nil? cmd = tools [ tool ] fail LookupFailed , "Package tool '#{cmd}' not found." if command? ( cmd ) . nil? send tool , package end
Checks if package is installed .
19,809
def dpkg ( package ) cmd = command? 'dpkg' Open3 . popen3 cmd , '-s' , package do | _ , _ , _ , wait_thr | wait_thr . value . to_i == 0 end end
Tool specific package lookup methods below .
19,810
def check return @checked if @checked raise MissingFixtureError , "No fixture has been loaded, nothing to check" unless @data raise MissingConnectionError , "No connection has been provided, impossible to check" unless @connection @data . each_key do | collection | raise CollectionsNotEmptyError , "The collection '#{co...
Assures that the collections are empty before proceeding
19,811
def rollback begin check @data . each_key do | collection | @connection [ collection ] . drop end rescue CollectionsNotEmptyError => e raise RollbackIllegalError , "The collections weren't empty to begin with, rollback aborted." end end
Empties the collections only if they were empty to begin with
19,812
def scheduled? [ :min , :hour , :day , :month , :wday ] . all? do | key | send ( key ) . nil? || send ( key ) == now . send ( key ) end end
Takes a schedule as a String .
19,813
def close_tags ( text ) if @settings [ :strip_html ] && @settings [ :allowed_tags ] . empty? tagstoclose = nil else tagstoclose = "" tags = [ ] opentags = text . scan ( OPENING_TAG ) . transpose [ 0 ] || [ ] opentags . reverse! closedtags = text . scan ( CLOSING_TAG ) . transpose [ 0 ] || [ ] opentags . each do | ot | ...
close html tags
19,814
def paragraphs return non_excerpted_text if @pghcount < @settings [ :paragraphs ] text = @body . split ( "</p>" ) . slice ( @settings [ :skip_paragraphs ] , @settings [ :paragraphs ] ) @settings [ :ending ] = nil text = text . join ( "</p>" ) close_tags ( text ) end
limit by paragraphs
19,815
def strip_html ( html ) return @stripped_html if @stripped_html allowed = @settings [ :allowed_tags ] reg = if allowed . any? Regexp . new ( %(<(?!(\\s|\\/)*(#{ allowed.map {|tag| Regexp.escape( tag )}.join( "|" ) })( |>|\\/|'|"|<|\\s*\\z))[^>]*(>+|\\s*\\z)) , Regexp :: IGNORECASE | Regexp :: MULTIL...
Removes HTML tags from a string . Allows you to specify some tags to be kept .
19,816
def determinant_by_elimination_old m = dup inv , k = m . left_eliminate! s = ground . unity ( 0 ... size ) . each do | i | s *= m [ i , i ] end s / k end
def inverse_euclidian ; left_inverse_euclidian ; end
19,817
def determinant_by_elimination m = dup det = ground . unity each_j do | d | if i = ( d ... size ) . find { | i | ! m [ i , d ] . zero? } if i != d m . sswap_r! ( d , i ) det = - det end c = m [ d , d ] det *= c ( d + 1 ... size ) . each do | i0 | r = m . row! ( i0 ) q = ground . unity * m [ i0 , d ] / c ( d + 1 ... siz...
ground ring must be a field
19,818
def update_blurb ( state , locale , key , value , overwrite = false ) id = key key = "projects:#{api_key}:#{state}_blurbs:#{key}" current_value = redis . sismember ( "projects:#{api_key}:#{state}_blurb_keys" , id ) ? JSON . parse ( redis . get ( key ) ) : { } phrase = Phrase . new ( self , current_value ) if overwrite ...
Set the overwrite option to true to force overwriting existing translations .
19,819
def get_query_params out = { } search_attributes . each do | val | out [ val . field ] = self . send ( val . field ) unless self . send ( val . field ) . blank? end out end
Restituisce un hash con tutti i parametri da implementare sulla ricerca
19,820
def update_attributes ( datas ) search_attributes . each do | val | self . send ( "#{val.field}=" , val . cast_value ( datas [ val . field ] ) ) end end
Si occupa di aggiornare i valori interni di ricerca
19,821
def fuse ( criteria_conditions = { } ) criteria_conditions . inject ( self ) do | criteria , ( key , value ) | criteria . send ( key , value ) end end
Merges the supplied argument hash into a single criteria
19,822
def merge ( other ) @selector . update ( other . selector ) @options . update ( other . options ) @documents = other . documents end
Create the new + Criteria + object . This will initialize the selector and options hashes as well as the type of criteria .
19,823
def filter_options page_num = @options . delete ( :page ) per_page_num = @options . delete ( :per_page ) if ( page_num || per_page_num ) @options [ :limit ] = limits = ( per_page_num || 20 ) . to_i @options [ :skip ] = ( page_num || 1 ) . to_i * limits - limits end end
Filters the unused options out of the options + Hash + . Currently this takes into account the page and per_page options that would be passed in if using will_paginate .
19,824
def update_selector ( attributes , operator ) attributes . each { | key , value | @selector [ key ] = { operator => value } } ; self end
Update the selector setting the operator on the value for each key in the supplied attributes + Hash + .
19,825
def active_record? ( * args ) version , comparator = args . pop , ( args . pop || :== ) result = if version . nil? defined? ( :: ActiveRecord ) elsif defined? ( :: ActiveRecord ) ar_version = :: ActiveRecord :: VERSION :: STRING . to_f ar_version = ar_version . floor if version . is_a? ( Integer ) ar_version . send ( c...
Return a boolean indicating whether the version of ActiveRecord matches the constraints in the args .
19,826
def private_page ( id , options = { } ) response = get ( "/api/private_pages/#{id}" , options ) VulnDBHQ :: PrivatePage . from_response ( response ) end
Initializes a new Client object
19,827
def inherit ( app_env = self . app_env , actions = Dispatcher . new_registry , & block ) self . class . new ( app_env , actions , merged_chain_dsl ( & block ) ) end
Initialize a new instance
19,828
def register ( name , other = Chain :: EMPTY , exception_chain = Chain :: EMPTY , & block ) actions [ name ] = chain ( name , other , exception_chain , & block ) self end
Register a new chain under the given + name +
19,829
def create_message ( group_id , text , attachments = [ ] ) data = { :message => { :source_guid => SecureRandom . uuid , :text => text } } data [ :message ] [ :attachments ] = attachments if attachments . any? post ( "/groups/#{group_id}/messages" , data ) . message end
Create a message for a group
19,830
def messages ( group_id , options = { } , fetch_all = false ) if fetch_all get_all_messages ( group_id ) else get_messages ( group_id , options ) end end
List messages for a group
19,831
def install_symlink FileUtils . mkdir_p File . dirname ( destination_path ) FileUtils . symlink source_path , destination_path , force : true end
Recursively creates the necessary directories and make the symlink .
19,832
def core__get_partials_for_module ( module_name ) module_configs = core__get_module_configs ( module_name ) return [ ] unless module_configs module_partials = [ ] if module_configs [ :partials ] module_configs [ :partials ] . each do | key , value | module_partials . push ( core__generate_partial ( key , value , module...
This function return the list of partials for a specific module .
19,833
def core__generate_partial ( key , values , module_name ) partial = { } partial [ :key ] = key partial [ :path ] = values [ :path ] ? values [ :path ] : '' partial [ :position ] = values [ :position ] ? values [ :position ] : 999 partial end
This function create a correct partial object for the header .
19,834
def core__get_widgets_for_module module_name module_configs = core__get_module_configs ( module_name ) return [ ] unless module_configs module_widgets = [ ] if module_configs [ :widgets ] module_configs [ :widgets ] . each do | key , value | module_widgets . push ( core__generate_widget ( key , value , module_name ) ) ...
This function return the list of widgets for a specific module .
19,835
def core__generate_widget key , values , module_name widget = { } widget [ :key ] = key widget [ :icon ] = values [ :icon ] ? values [ :icon ] : 'check-circle' widget [ :path ] = values [ :path ] ? values [ :path ] : '' widget [ :position ] = values [ :position ] ? values [ :position ] : 999 widget [ :title ] = values ...
This function create a correct widget object for the header .
19,836
def core__get_menu_for_module module_name module_configs = core__get_module_configs ( module_name ) return [ ] unless module_configs module_menu = [ ] if module_configs [ :menu ] module_configs [ :menu ] . each do | key , value | module_menu . push ( core__generate_menu_item ( key , value , module_name ) ) end end retu...
This function returns the list of the items for the menu for a specific module .
19,837
def core__generate_menu_item key , values , module_name menu_item = { } menu_item [ :key ] = key menu_item [ :title ] = values [ :title ] ? core__get_menu_title_translation ( values [ :title ] , module_name ) : 'Undefined' menu_item [ :icon ] = values [ :icon ] ? values [ :icon ] : 'check-circle' menu_item [ :url ] = v...
This function create a correct menu item object for the menu .
19,838
def core__generate_menu_sub_item key , values , module_name menu_sub_item = { } menu_sub_item [ :key ] = key menu_sub_item [ :title ] = values [ :title ] ? core__get_menu_title_translation ( values [ :title ] , module_name ) : 'Undefined' menu_sub_item [ :url ] = values [ :url ] ? values [ :url ] : '' menu_sub_item [ :...
This function create a correct menu sub itam object for the menu .
19,839
def core__get_menu_title_translation title , module_name return title if ( ! title . start_with? ( 'translate' ) ) title_key = core__get_string_inside_strings ( title , '[' , ']' ) module_languages = core__get_module_languages ( module_name ) return title if ! module_languages || ! module_languages [ :menu ] || ! modul...
This function check the title name and if it need a translaction it return the value .
19,840
def core__get_assets_for_module module_name module_configs = core__get_module_configs ( module_name ) return [ ] unless module_configs module_assets = [ ] if module_configs [ :assets ] module_configs [ :assets ] . each do | key , value | module_assets . push ( value ) end end return module_assets end
This function return the lists of assets for a specific module .
19,841
def create_access_policy ( name : 'Policy' , duration_minutes : 300 , permission : 2 ) warn ( "DEPRECATION WARNING: Service#create_access_policy is deprecated. Use AzureMediaService::AccessPolicy.create() instead." ) post_body = { "Name" => name , "DurationInMinutes" => duration_minutes , "Permissions" => permission } ...
access policy create
19,842
def process_join ( data ) @state . update data [ 'state' ] if data . key? 'state' @timeline . update data [ 'timeline' ] if data . key? 'timeline' end
Initializes a new Room instance .
19,843
def process_leave ( data ) @state . update data [ 'state' ] if data . key? 'state' @timeline . update data [ 'timeline' ] if data . key? 'timeline' end
Process leave events for this room .
19,844
def process_invite_event ( event ) return unless event [ 'type' ] == 'm.room.member' return unless event [ 'content' ] [ 'membership' ] == 'invite' @users . process_invite self , event sender = @users [ event [ 'sender' ] ] invitee = @users [ event [ 'state_key' ] ] return if @state . member? invitee broadcast ( :invit...
Process an invite event for this room .
19,845
def get_value ( name , element = nil ) return name . call ( element ) if name . respond_to? :call name = name . to_s . dup element . placeholders . each { | k , v | name [ k ] &&= v } if element elements [ name ] . try ( :value ) || params [ name ] || name end
Gets element value by element s name . If name is lambda - returns lambda s result If name is present in the resolvers elements hash - returns element s value If name is present in the resolvers params hash - returns params value Otherwise returns the argument without changes
19,846
def resolve_dependency ( dependency ) dependency . each do | operator , arguments | operator = operator . to_sym case operator when :and , :or return resolve_multi_dependency ( operator , arguments ) when :not return ! resolve_dependency ( arguments ) end arguments = [ arguments ] unless arguments . is_a? ( Array ) val...
Gets dependency rules hash and returns true or false depending on the result of a recursive processing of the rules
19,847
def resolve_multi_dependency ( type , arguments ) if arguments . size == 0 fail HungryFormException , "No arguments for #{type.upcase} comparison: #{arguments}" end result = type == :and arguments . each do | argument | return ! result unless resolve_dependency ( argument ) end result end
Method resolves AND or OR conditions . Walks through the arguments and resolves their dependencies .
19,848
def append_ancestor_entry ( ancestors , ancestor , class_methods , instance_methods = nil ) if class_methods || instance_methods ancestor_entry = { } ancestor_entry [ :class ] = class_methods if class_methods ancestor_entry [ :instance ] = instance_methods if instance_methods ancestors << { ancestor => ancestor_entry }...
ancestor is included only when contributes some methods
19,849
def get_option_value_selected ( option_value ) if @args [ :multiple ] values = @args [ :value ] . is_a? ( Array ) ? @args [ :value ] : @args [ :value ] . split ( ',' ) return values . include? ( option_value ) ? "selected='selected'" : '' end @args [ :value ] == option_value ? "selected='selected'" : '' end
This function return a string used on the HTML option to set a an option value selected or not .
19,850
def load_by_name name path = self . locate_definition name raise TargetLoadError . new ( "Target definition file does not exist for #{name}" ) if path . nil? config = YAML :: load_file ( path ) raise TargetLoadError . new ( "Target definition file #{path} is not valid YAML" ) if config . nil? config = config . deep_sym...
load target with + name + .
19,851
def locate_file name Settings . instance . target_dir . each do | dir | Dir . chdir File . expand_path ( dir ) do return File . expand_path ( name ) if File . exists? name end end raise TargetLoadError . new ( "Couldn't find file #{name}" ) nil end
Locate a file with name in one of the target_dirs
19,852
def count_parameter_permutations @parameters . each_pair . map { | k , v | v } . reduce ( 1 ) { | n , arr | n * arr . size } end
return the total number of possible permutations of
19,853
def method_missing ( method , * args , & block ) const_methods = @constructor . class . instance_methods ( false ) if const_methods . include? method return @constructor . send ( method , * args , & block ) else super end end
pass calls to missing methods to the constructor iff the constructor s class directly defines that method
19,854
def respond_to? ( method , * args , & block ) const_methods = @constructor . class . instance_methods ( false ) if const_methods . include? method true else super end end
accurately report ability to respond to methods passed to constructor
19,855
def get_movie_info ( movie_id , action ) url = nil case action when "details" url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}.json?apikey=#{@api_key}" when "reviews" url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}/reviews.json?apikey=#{@api_key}" when "cast" url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}/cast.json?apikey=#{@api_k...
Get various bits of info for a given movie id .
19,856
def get_lists_action ( action ) url = nil case action when "new_releases" url = "#{LISTS_DETAIL_BASE_URL}/dvds/new_releases.json?apikey=#{@api_key}" when "opening" url = "#{LISTS_DETAIL_BASE_URL}/movies/opening.json?apikey=#{@api_key}" when "upcoming" url = "#{LISTS_DETAIL_BASE_URL}/movies/upcoming.json?apikey=#{@api_k...
Provides access to the various lists that Rotten Tomatoes provides .
19,857
def parse_movies_array ( hash ) moviesArray = Array . new hash [ "movies" ] . each do | movie | moviesArray . push ( Movie . new ( movie , self ) ) end return moviesArray end
Parse the movies out of a hash .
19,858
def parse_actors_array ( hash ) actorsArray = Array . new hash [ "cast" ] . each do | actor | actorsArray . push ( Actor . new ( actor ) ) end return actorsArray end
Parse the actors out of a movie hash .
19,859
def get ( url ) data = nil resp = HTTParty . get ( url ) if resp . code == 200 return resp . body end end
Get the response of a given URL .
19,860
def sync! events = @matrix . sync since : @since process_sync events rescue ApiError => err broadcast ( :sync_error , err ) end
Syncs against the server .
19,861
def process_sync ( events ) return unless events . is_a? Hash @since = events [ 'next_batch' ] broadcast ( :sync , events ) @rooms . process_events events [ 'rooms' ] if events . key? 'rooms' end
Process the sync result .
19,862
def get_signed_in_scope if signed_in? Devise . mappings . keys . each do | res | l = send "#{res.to_s}_signed_in?" if send "#{res.to_s}_signed_in?" return res . to_s end end end return 'user' end
returns the name in small case of the class of the currently signed in resource
19,863
def resource_in_navbar? ( resource ) return false unless resource return ( Auth . configuration . auth_resources [ resource . class . name ] [ :nav_bar ] && Auth . configuration . enable_sign_in_modals ) end
SHOULD THE RESOURCE SIGN IN OPTIONS BE SHOWN IN THE NAV BAR?
19,864
def << ( arg ) raise ExtraArgumentError . new ( @name ) unless more_args? if @arg_names . size > @args . size name = @arg_names [ @args . size ] if @max_arg_count == - 1 && @arg_names . size == @args . size + 1 @args [ name ] = [ arg ] else @args [ name ] = arg end elsif ! @arg_names . empty? && @max_arg_count == - 1 @...
Adds an argument to this parameter . Arguments can be accessed inside the application code using the args method .
19,865
def check_args raise MissingArgumentError . new ( @name ) unless args_full? unless @arg_values . empty? @args . each do | name , arg | if @arg_values . key? name arg = [ arg ] unless arg . is_a? Array arg . each do | a | unless a =~ @arg_values [ name ] raise UnexpectedArgumentError . new ( a ) end end end end end end
Checks the arguments for this parameter
19,866
def method_missing ( name , * args , & block ) if args . empty? && ! block_given? && @arg_names . include? ( name ) @args [ name ] else super end end
If a named argument with the specified method name exists a call to that method will return the value of the argument .
19,867
def fetch_scrollback ( last_event_id ) event_sent = false if last_event_id channels . each do | channel | channel . scrollback ( since : last_event_id ) . each do | event | event_sent = true queue . push ( event ) end end end queue . push ( Pubsubstub . heartbeat_event ) unless event_sent end
This method is not ideal as it doesn t guarantee order in case of multi - channel subscription
19,868
def contains? ( col , row = nil ) return contains_point? ( col ) if col . respond_to? :x col . between? ( left , left + width - 1 ) && row . between? ( top , top + height - 1 ) end
Create a new region with specified + pos + as top left corner and + size + as width and height . The stored positions are copies of the passed position and size to avoid aliasing .
19,869
def draw ( surface , z_order , colour ) surface . draw_rectangle ( position , size , z_order , colour ) end
Duplicate a Region must be done explicitly to avoid aliasing . Draw a rectangle on the specified + surface + at the specified + z_order + and with the specified + colour +
19,870
def contains_point? ( pt ) pt . x . between? ( left , left + width - 1 ) && pt . y . between? ( top , top + height - 1 ) end
Return whether the passed Point + pt + is contained within the current Region .
19,871
def select_algorithm return if algorithm max = Settings . instance . sweep_cutoff n = @target . count_parameter_permutations if n < max @algorithm = ParameterSweeper . new ( @target . parameters , @id ) else @algorithm = TabuSearch . new ( @target . parameters , @id ) end end
select the optimisation algorithm to use
19,872
def run start_time = Time . now in_progress = true @algorithm . setup @start @current_params = @start max_scores = @target . count_parameter_permutations while in_progress run_iteration best = @best @best = @algorithm . best ptext = @best [ :parameters ] . each_pair . map { | k , v | "#{k}:#{v}" } . join ( ", " ) if @b...
Runs the experiment until the completion criteria are met . On completion returns the best parameter set .
19,873
def create_tempdir token = loop do test_token = SecureRandom . hex break test_token unless File . exist? test_token end Dir . mkdir ( token ) @last_tempdir = token token end
create a guaranteed random temporary directory for storing outputs return the dirname
19,874
def set_id id @id = id if @id . nil? t = Time . now parts = %w[ y m d H M S Z ] . map { | p | t . strftime "%#{p}" } @id = "experiment_#{parts.join('_')}" end end
set experiment ID with either user provided value or date - time as fallback
19,875
def register ( key , proc = nil , & block ) Helper . register ( obj : self , key : key , proc : proc , block : block ) end
Registers a new callback in the registry . This will add a new method matching + key + to the registry that can be used both outside the registry and when registering other callbacks dependant of the current entry . Results from the callback will not be cached meaning that the callback may return a different object eve...
19,876
def register_singleton ( key , proc = nil , & block ) Helper . register_singleton ( obj : self , key : key , proc : proc , block : block ) end
Registers a new callback in the registry . This will add a new method matching + key + to the registry that can be used both outside the registry and when registering other callbacks dependant of the current entry . Results from the callnack will be cached meaning that the callback will return the same object every tim...
19,877
def generate ( name = default_fauxture_name , attributes = { } ) name , attributes = default_fauxture_name , name if name . is_a? Hash Sweatshop . create ( self , name , attributes ) end
Creates an instance from hash of attributes saves it and adds it to the record map . Attributes given as the second argument are merged into attributes from fixture .
19,878
def make ( name = default_fauxture_name , attributes = { } ) name , attributes = default_fauxture_name , name if name . is_a? Hash Sweatshop . make ( self , name , attributes ) end
Creates an instance from given hash of attributes and adds it to records map without saving .
19,879
def environment ( name = :production ) name = name . to_sym unless @environments [ name ] raise ( UnknownEnvironment , "unknown environment: #{name}" , caller ) end return @environments [ name ] end
Creates a new project using the given configuration file .
19,880
def load_configuration ( path ) config = YAML . load_file ( path ) unless config . kind_of? ( Hash ) raise ( InvalidConfig , "DeploYML file #{path.dump} does not contain a Hash" , caller ) end return config end
Loads configuration from a YAML file .
19,881
def load_environments! base_config = infer_configuration if File . file? ( @config_file ) base_config . merge! ( load_configuration ( @config_file ) ) end @environments = { } if File . directory? ( @environments_dir ) Dir . glob ( File . join ( @environments_dir , '*.yml' ) ) do | path | config = base_config . merge ( ...
Loads the project configuration .
19,882
def start config = { } begin config = YAML :: load_file ( CONFIG_FILE ) rescue Exception => e load 'lib/cogbot/setup.rb' config [ 'main' ] = Cogbot :: Setup . init end Daemons . daemonize ( :app_name => 'cogbot' , :dir_mode => :normal , :log_dir => LOG_DIR , :log_output => true , :dir => CONFIG_DIR ) plugins = [ ] conf...
manages the start cli command
19,883
def stop pid_file = File . join ( CONFIG_DIR , 'cogbot.pid' ) pid = File . read ( pid_file ) . to_i if File . exist? ( pid_file ) Process . kill ( 'TERM' , pid ) end
manages the stop cli command
19,884
def dependency_versions ( args = { } , & bl ) versions = { } args = { :recursive => true , :dev_deps => true , :versions => versions } . merge ( args ) deps . each do | dep | gem = Polisher :: Gem . retrieve ( dep . name ) versions . merge! ( gem . versions ( args , & bl ) ) end versions end
Return list of versions of dependencies of component .
19,885
def dependency_tree ( args = { } , & bl ) dependencies = { } args = { :recursive => true , :dev_deps => true , :matching => :latest , :dependencies => dependencies } . merge ( args ) process = [ ] deps . each do | dep | resolved = nil begin resolved = Polisher :: Gem . matching ( dep , args [ :matching ] ) rescue end y...
Return mapping of gems to dependency versions
19,886
def missing_dependencies missing = [ ] dependency_versions ( :recursive => false ) . each do | pkg , target_versions | found = false target_versions . each do | _target , versions | dependency = dependency_for ( pkg ) found = versions . any? { | version | dependency . match? ( pkg , version ) } end missing << pkg unles...
Return missing dependencies
19,887
def dependency_states states = { } deps . each do | dep | gem = Polisher :: Gem . new :name => dep . name states . merge! dep . name => gem . state ( :check => dep ) end states end
Return list of states which gem dependencies are in
19,888
def add ( message ) @services . each do | service | if service . can_send? ( message ) if @queued_messages [ service ] . nil? @queued_messages [ service ] = [ ] end @queued_messages [ service ] << message return true end end return false end
Adds a PushMessage to the queue
19,889
def flush failed_messages = [ ] new_token_messages = [ ] @queued_messages . each do | service , messages | service . init_push messages . each do | message | service . send ( message ) end ( failed , new_token ) = service . end_push failed_messages += failed new_token_messages += new_token end @queued_messages = { } re...
Flushes the queue by transmitting the enqueued messages using the registered services
19,890
def normalize_hash ( hash ) new_hash = { } hash . each do | key , value | new_hash [ key . to_sym ] = normalize ( value ) end return new_hash end
Converts all the keys of a Hash to Symbols .
19,891
def normalize ( value ) case value when Hash normalize_hash ( value ) when Array normalize_array ( value ) else value end end
Normalizes a value .
19,892
def parse_server ( server ) name = nil options = { } case server when Symbol , String name = server . to_sym when Hash unless server . has_key? ( :name ) raise ( MissingOption , "the 'server' option must contain a 'name' option for which server to use" , caller ) end if server . has_key? ( :name ) name = server [ :name...
Parses the value for the server setting .
19,893
def parse_address ( address ) case address when Hash Addressable :: URI . new ( address ) when String Addressable :: URI . parse ( address ) else raise ( InvalidConfig , "invalid address: #{address.inspect}" , caller ) end end
Parses an address .
19,894
def parse_dest ( dest ) case dest when Array dest . map { | address | parse_address ( address ) } else parse_address ( dest ) end end
Parses the value for the dest setting .
19,895
def parse_commands ( command ) case command when Array command . map { | line | line . to_s } when String command . enum_for ( :each_line ) . map { | line | line . chomp } else raise ( InvalidConfig , "commands must be an Array or a String" ) end end
Parses a command .
19,896
def reviews data = JSON . parse ( @badfruit . get_movie_info ( @id , "reviews" ) ) reviews = Array . new data [ "reviews" ] . each do | review | reviews . push ( Review . new ( review ) ) end return reviews end
Get all of the reivews for a movie .
19,897
def units @units ||= { } . tap do | u | UNIT_TYPES . each do | type | k = type . to_s . pluralize . to_sym u [ k ] = [ ] next unless manifest next if manifest [ k ] . nil? manifest [ k ] . each { | v | u [ k ] << create_unit ( type , attributes : v ) } end end end
Unit objects defined by the manifest and organized by type .
19,898
def install return false unless install? quiet : ! ( logger . level == Logger :: DEBUG ) UNIT_TYPES . each do | type | units [ type . to_s . pluralize . to_sym ] . each do | unit | return nil unless install_unit ( unit , type ) end end true end
Installs all units from the manifest .
19,899
def install? ( quiet : false ) result = true UNIT_TYPES . each do | type | units [ type . to_s . pluralize . to_sym ] . each do | unit | result = install_unit? ( unit , type , quiet ) ? result : false end end result end
Checks all units in the manifest for any detectable install issues .