idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
11,100
def pad ( fill_value = - 1 , data = @raw . clone ) data = _pad data , 0 , fill_value , 0 _pad data , - 1 , fill_value , 6 end
Pad the dataset to full week increments
11,101
def page_title ( separator = Renalware . config . page_title_spearator ) [ content_for ( :page_title ) , Renalware . config . site_name ] . compact . join ( separator ) end
For use in layouts
11,102
def make_image ( opts = { } ) opts = { :volume => '/' , :size => 6000 , :destination => '/mnt/bundle' , :exclude => nil } . merge ( opts ) image_file = File . join ( opts [ :destination ] , opts [ :prefix ] ) cmds = [ "mkdir -p #{opts[:destination]}" ] cmds << "dd if=/dev/zero of=#{image_file} bs=1M count=#{opts[:size]...
create an image file and copy this instance to the image file .
11,103
def teardown triggers . each do | trigger | trigger . teardown end if autoscaling_groups . select { | n | n . name == name } . empty? puts "Cloud #{cloud.name} autoscaling group does not exist" else self . minimum_instances = 0 self . maximum_instances = 0 @new_launch_configuration_name = old_launch_configuration_name ...
First change the min_count to
11,104
def map_levels return [ ] unless defined? ( :: Logger :: Severity ) @@map_levels ||= :: Logger :: Severity . constants . each_with_object ( [ ] ) do | constant , levels | levels [ :: Logger :: Severity . const_get ( constant ) ] = level_by_index_or_error ( constant ) end end
Mapping of Rails and Ruby Logger levels to Sapience levels
11,105
def broadcasting_to_configured_subscribers subscribers = Array ( Renalware . config . broadcast_subscription_map [ self . class . name ] ) subscribers . each do | subscriber | subscriber = Subscriber . new ( subscriber ) unless subscriber . respond_to? ( :klass ) subscribe ( subscriber . instance , async : subscriber ....
Subscribes any listeners configured in Renalware . config . broadcast_subscription_map to the current instance .
11,106
def recipe ( recipe_name , hsh = { } ) _recipes << recipe_name unless _recipes . include? ( recipe_name ) head = { } tail = head recipe_name . split ( "::" ) . each do | key | unless key == "default" n = { } tail [ key ] = n tail = n end end tail . replace hsh override_attributes . merge! ( head ) unless hsh . empty? e...
Adds a chef recipe to the cloud
11,107
def measure ( level , message , params = { } , & block ) index = Sapience . config . level_to_index ( level ) if level_index <= index measure_internal ( level , index , message , params , & block ) else yield params if block end end
Dynamically supply the log level with every measurement call
11,108
def available_pd_treatments_for ( regime ) scope = "renalware.pd.treatments" key = regime . capd? ? "capd" : "apd" I18n . t ( key , scope : scope ) end
The list of treatment options stored in I18n
11,109
def log ( log , message = nil , progname = nil , & block ) return add ( log , message , progname , & block ) unless log . is_a? ( Sapience :: Log ) if @@appender_thread @@appender_thread << lambda do Sapience . appenders . each do | appender | next unless appender . valid? begin appender . log ( log ) rescue StandardEr...
Returns a Logger instance
11,110
def with_payload ( payload ) current_payload = self . payload Thread . current [ :sapience_payload ] = current_payload ? current_payload . merge ( payload ) : payload yield ensure Thread . current [ :sapience_payload ] = current_payload end
Thread specific context information to be logged with every log entry
11,111
def include_message? ( log ) return true if @filter . nil? if @filter . is_a? ( Regexp ) ! ( @filter =~ log . name ) . nil? elsif @filter . is_a? ( Proc ) @filter . call ( log ) == true end end
Whether to log the supplied message based on the current filter if any
11,112
def extract_backtrace stack = caller while ( first = stack . first ) && first . include? ( SELF_PATTERN ) stack . shift end stack end
Extract the callers backtrace leaving out Sapience
11,113
def dereference_descriptor ( resource , base_path : nil , reference_fields : nil ) options = { base_path : base_path , reference_fields : reference_fields , } case resource when Hash resource . inject ( { } ) do | new_resource , ( key , val ) | if reference_fields . nil? || reference_fields . include? ( key ) new_resou...
Dereference a resource that can be a URL or path to a JSON file or a hash Returns a Hash with all values that are URLs or paths dereferenced
11,114
def describe_instances ( id = nil ) begin @describe_instances = ec2 . describe_instances . reservationSet . item . map do | r | r . instancesSet . item . map do | i | inst_options = i . merge ( r . merge ( :cloud => cloud ) ) . merge ( cloud . cloud_provider . dsl_options ) Ec2Instance . new ( inst_options ) end end . ...
Describe instances Describe the instances that are available on this cloud
11,115
def aws_options ( opts = { } ) uri = URI . parse ( ec2_url ) { :access_key_id => access_key , :secret_access_key => secret_access_key , :use_ssl => ( uri . scheme == 'https' ) , :path => uri . path , :host => uri . host , :port => uri . port } . merge ( opts ) end
prepare options for AWS gem
11,116
def ec2 @ec2 ||= begin AWS :: EC2 :: Base . new ( aws_options ) rescue AWS :: ArgumentError => e puts "Error contacting AWS: #{e}" raise e rescue Exception => e puts "Generic error #{e.class}: #{e}" end end
Proxy to the raw Grempe amazon - aws
11,117
def credential_file ( file = nil ) unless file . nil? dsl_options [ :credential_file ] = file dsl_options . merge! ( Ec2 . load_keys_from_credential_file ( file ) ) else fetch ( :credential_file ) end end
Read credentials from credential_file if one exists
11,118
def generic_set ( key , value , tree = data ) modify ( key , value , tree ) || uncomment ( key , value , tree ) || add_new ( key , value , tree ) end
powerfull method that sets any value in config . It try to be smart to at first modify existing value then replace commented out code and if even that doesn t work then append it at the end
11,119
def story updates = changes return unless tell_story? ( updates ) [ preface , ( updates unless destroy? ) ] . compact . join ( "\n" ) end
Single version historical analysis
11,120
def report_error return if yield error = aug . error if aug . error [ :code ] . nonzero? raise "Augeas error #{error[:message]}. Details: #{error[:details]}." end msg = aug . get ( "/augeas/text/store/error/message" ) location = aug . get ( "/augeas/text/store/error/lens" ) raise "Augeas serializing error: #{msg} at #{...
Calls block and if it failed raise exception with details from augeas why it failed
11,121
def change_log text = changes . map { | k , v | digest ( k , v ) } . compact . join ( "\n" ) text = text . gsub ( ' id:' , ':' ) if PaperTrailScrapbook . config . drop_id_suffix text end
Attribute change analysis
11,122
def method_missing ( name , * args ) value = @values [ name ] if value . nil? && ! @values . has_key? ( name ) address = "<#{self.class.name}:0x00#{(self.object_id << 1).to_s(16)}>" raise NoMethodError . new ( "undefined method `#{name}' for ##{address}" ) end value end
Fetch a configuration value . The name must be a lowercase version of an uppercase name defined in the environment . A NoMethodError is raised if no value matching the specified name is available .
11,123
def required_string ( name ) required_custom ( name ) do | env | if value = env [ name . to_s . upcase ] { name => value } else raise ConfigError . new ( "A value must be provided for #{name.to_s.upcase}" ) end end end
Define a required string config var .
11,124
def required_int ( name ) required_custom ( name ) do | env | if value = env [ name . to_s . upcase ] { name => parse_int ( name , value ) } else raise ConfigError . new ( "A value must be provided for #{name.to_s.upcase}" ) end end end
Define a required integer config var .
11,125
def required_bool ( name ) required_custom ( name ) do | env | if value = env [ name . to_s . upcase ] { name => parse_bool ( name , value ) } else raise ConfigError . new ( "A value must be provided for #{name.to_s.upcase}" ) end end end
Define a required boolean config var .
11,126
def optional_string ( name , default ) optional_custom ( name ) do | env | if value = env [ name . to_s . upcase ] { name => value } else { name => default } end end end
Define a required string config var with a default value .
11,127
def optional_int ( name , default ) optional_custom ( name ) do | env | if value = env [ name . to_s . upcase ] { name => parse_int ( name , value ) } else { name => default } end end end
Define a required integer config var with a default value .
11,128
def optional_bool ( name , default ) optional_custom ( name ) do | env | if value = env [ name . to_s . upcase ] { name => parse_bool ( name , value ) } else { name => default } end end end
Define a required boolean config var with a default value .
11,129
def parse_bool ( name , value ) if [ '1' , 'true' , 'enabled' ] . include? ( value . downcase ) true elsif [ '0' , 'false' ] . include? ( value . downcase ) false else raise ArgumentError . new ( "#{value} is not a valid boolean for #{name.to_s.upcase}" ) end end
Convert a string to boolean . An ArgumentError is raised if the string is not a valid boolean .
11,130
def define_config ( name , & blk ) if @definitions . has_key? ( name ) raise ConfigError . new ( "#{name.to_s.upcase} is already registered" ) end @definitions [ name ] = Proc . new do | env | value = yield env if value . kind_of? ( Hash ) value else { name => value } end end end
Define a handler for a configuration value .
11,131
def analyze @changes = sort_changes ( @changes ) @changes = @changes . map { | file_path , times_changed | { :file_path => file_path , :times_changed => times_changed } } calculate_revision_changes @method_changes = sort_changes ( @method_changes ) @method_changes = @method_changes . map { | method , times_changed | { ...
Analyze the source control data filter sort and find more information on the edited files
11,132
def to_h hash = { :churn => { :changes => @changes } } hash [ :churn ] [ :class_churn ] = @class_changes hash [ :churn ] [ :method_churn ] = @method_changes first_revision = @revisions . first first_revision_changes = @revision_changes [ first_revision ] if first_revision_changes changes = first_revision_changes hash [...
collect all the data into a single hash data structure .
11,133
def get_status ( filters : [ ] ) connect do | cid | filters = PBS :: Torque :: Attrl . from_list filters batch_status = Torque . pbs_statserver cid , filters , nil batch_status . to_h . tap { Torque . pbs_statfree batch_status } end end
Get a hash with status info for this batch server
11,134
def get_queues ( id : '' , filters : [ ] ) connect do | cid | filters = PBS :: Torque :: Attrl . from_list ( filters ) batch_status = Torque . pbs_statque cid , id . to_s , filters , nil batch_status . to_h . tap { Torque . pbs_statfree batch_status } end end
Get a list of hashes of the queues on the batch server
11,135
def get_nodes ( id : '' , filters : [ ] ) connect do | cid | filters = PBS :: Torque :: Attrl . from_list ( filters ) batch_status = Torque . pbs_statnode cid , id . to_s , filters , nil batch_status . to_h . tap { Torque . pbs_statfree batch_status } end end
Get a list of hashes of the nodes on the batch server
11,136
def select_jobs ( attribs : [ ] ) connect do | cid | attribs = PBS :: Torque :: Attropl . from_list ( attribs . map ( & :to_h ) ) batch_status = Torque . pbs_selstat cid , attribs , nil batch_status . to_h . tap { Torque . pbs_statfree batch_status } end end
Get a list of hashes of the selected jobs on the batch server
11,137
def get_jobs ( id : '' , filters : [ ] ) connect do | cid | filters = PBS :: Torque :: Attrl . from_list ( filters ) batch_status = Torque . pbs_statjob cid , id . to_s , filters , nil batch_status . to_h . tap { Torque . pbs_statfree batch_status } end end
Get a list of hashes of the jobs on the batch server
11,138
def submit_script ( script , queue : nil , headers : { } , resources : { } , envvars : { } , qsub : true ) send ( qsub ? :qsub_submit : :pbs_submit , script . to_s , queue . to_s , headers , resources , envvars ) end
Submit a script to the batch server
11,139
def submit_string ( string , ** kwargs ) Tempfile . open ( 'qsub.' ) do | f | f . write string . to_s f . close submit_script ( f . path , ** kwargs ) end end
Submit a script expanded into a string to the batch server
11,140
def submit ( content , args : [ ] , env : { } , chdir : nil ) call ( :qsub , * args , env : env , stdin : content , chdir : chdir ) . strip end
Submit a script expanded as a string to the batch server
11,141
def pbs_submit ( script , queue , headers , resources , envvars ) attribs = [ ] headers . each do | name , value | attribs << { name : name , value : value } end resources . each do | rsc , value | attribs << { name : :Resource_List , resource : rsc , value : value } end unless envvars . empty? attribs << { name : :Var...
Submit a script using Torque library
11,142
def qsub_arg ( key , value ) case key when :Execution_Time [ '-a' , value . to_s ] when :Checkpoint [ '-c' , value . to_s ] when :Error_Path [ '-e' , value . to_s ] when :fault_tolerant [ '-f' ] when :Hold_Types [ '-h' ] when :Join_Path [ '-j' , value . to_s ] when :Keep_Files [ '-k' , value . to_s ] when :Mail_Points ...
Mapping of Torque attribute to qsub arguments
11,143
def call ( cmd , * args , env : { } , stdin : "" , chdir : nil ) cmd = bin . join ( cmd . to_s ) . to_s args = args . map ( & :to_s ) env = env . to_h . each_with_object ( { } ) { | ( k , v ) , h | h [ k . to_s ] = v . to_s } . merge ( { "PBS_DEFAULT" => host , "LD_LIBRARY_PATH" => %{#{lib}:#{ENV["LD_LIBRARY_PATH"]}} }...
Call a forked PBS command for a given host
11,144
def fetch ( included_filename ) if source = @cache [ included_filename ] return source end if @m . locked? && @owns_lock == Thread . current @cache [ included_filename ] = yield else ret = nil @cache [ included_filename ] = @m . synchronize do begin @owns_lock = Thread . current ret = yield ensure @owns_lock = nil end ...
fetch can be called recursively in the yield ed block so must make sure not to try to lock the Mutex if it s already locked by the current thread as this would result in an error .
11,145
def compile ( root_node ) root_node . extend CompilerAccessible root_node . current_compiler = self root_node . accept ( NodesVisitor . new ) root_node . compiled_output end
compiles nodes into output code
11,146
def parse_exception ( e ) msg = e . to_s json = msg . to_s . sub ( / / , '' ) . split ( "\n" ) . map ( & :chomp ) json . map { | str | JSON . parse ( str ) } rescue JSON :: ParserError raise e end
Parses the exception JSON message .
11,147
def parse_streams ( e_ary ) e_ary . map { | x | x . is_a? ( Hash ) && x [ 'stream' ] } . compact . join end
Gets all the console output from the stream logs .
11,148
def source return @source unless @source . nil? @source = %i( string template id path ) . find { | from | @options . key? ( from ) } end
Gets the source to generate the image from .
11,149
def image ( img = nil ) return @image if img . nil? ImageGC . instance . add ( img . id ) if @options [ :rm ] @image = img end
Sets or gets the Docker image .
11,150
def rspec_options config = :: RSpec . configuration { } . tap do | opts | opts [ :path ] = config . dockerfile_path if config . dockerfile_path? opts [ :rm ] = config . rm_build if config . rm_build? opts [ :log_level ] = config . log_level if config . log_level? end end
Gets the default options configured using RSpec . configuration .
11,151
def default_options { path : ENV [ 'DOCKERFILE_PATH' ] || '.' , rm : ci? && ! travis_ci? , log_level : ci? ? :ci : :silent } . merge ( rspec_options ) end
Gets the default configuration options after merging them with RSpec configuration options .
11,152
def parse_options ( opts ) opts_hs_ary = opts . map { | x | x . is_a? ( Hash ) ? x : { path : x } } opts_hs_ary . reduce ( default_options ) { | a , e | a . merge ( e ) } end
Parses the configuration options passed to the constructor .
11,153
def build_from_string ( string , dir = '.' ) dir = @options [ :string_build_path ] if @options [ :string_build_path ] Dir . mktmpdir do | tmpdir | FileUtils . cp_r ( "#{dir}/." , tmpdir ) dockerfile = File . join ( tmpdir , 'Dockerfile' ) File . open ( dockerfile , 'w' ) { | f | f . write ( string ) } build_from_dir ( ...
Builds the image from a string . Generates the Docker tag if required .
11,154
def build_from_dir ( dir ) image ( :: Docker :: Image . build_from_dir ( dir , & build_block ) ) add_repository_tag rescue :: Docker :: Error :: DockerError => e DockerExceptionParser . new ( e ) end
Builds the image from a directory with a Dockerfile .
11,155
def build_from_path ( path ) if ! File . directory? ( path ) && File . basename ( path ) == 'Dockerfile' path = File . dirname ( path ) end File . directory? ( path ) ? build_from_dir ( path ) : build_from_file ( path ) end
Builds the image from a directory or a file .
11,156
def build_from_template ( file ) context = @options [ :context ] || { } template = IO . read ( file ) eruby = Erubis :: Eruby . new ( template ) string = eruby . evaluate ( context ) build_from_string ( string , File . dirname ( file ) ) end
Builds the image from a template .
11,157
def build_from_id ( id ) @image = :: Docker :: Image . get ( id ) add_repository_tag rescue :: Docker :: Error :: NotFoundError @image = :: Docker :: Image . create ( 'fromImage' => id ) add_repository_tag rescue :: Docker :: Error :: DockerError => e DockerExceptionParser . new ( e ) end
Gets the image from a Image ID .
11,158
def add_repository_tag return unless @options . key? ( :tag ) repo , repo_tag = @options [ :tag ] . split ( ':' , 2 ) @image . tag ( repo : repo , tag : repo_tag , force : true ) end
Adds a repository name and a tag to the Docker image .
11,159
def in_config_zone time , config : nil if time . respond_to? :in_time_zone time . in_time_zone ( config [ :time_zone ] ) elsif time . is_a? Date config [ :time_zone ] . local ( time . year , time . month , time . day ) else raise TypeError . new ( "Can't convert #{time.class} to a Time" ) end end
fix for ActiveRecord < 4 doesn t implement in_time_zone for Date
11,160
def is_active? ( page_name , product_types = nil ) controller . controller_name . include? ( page_name ) || controller . action_name . include? ( page_name ) || ( @product != nil && product_types != nil && product_types . split ( ',' ) . include? ( @product . product_type ) && ! @product . name . include? ( 'Historian'...
active state nav
11,161
def admirers ( options = { } ) options = options . merge ( :access_token => token , :access_secret => secret ) if ( token && secret ) favorite_listings = FavoriteListing . find_all_listings_favored_by ( id , options ) user_ids = favorite_listings . map { | f | f . user_id } . uniq ( user_ids . size > 0 ) ? Array ( Etsy...
Return a list of users who have favorited this listing
11,162
def listings ( state = nil , options = { } ) state = state ? { :state => state } : { } Listing . find_all_by_shop_id ( id , state . merge ( options ) . merge ( oauth ) ) end
The collection of listings associated with this shop
11,163
def addresses options = ( token && secret ) ? { :access_token => token , :access_secret => secret } : { } @addresses ||= Address . find ( username , options ) end
The addresses associated with this user .
11,164
def profile unless @profile if associated_profile @profile = Profile . new ( associated_profile ) else options = { :fields => 'user_id' , :includes => 'Profile' } options = options . merge ( :access_token => token , :access_secret => secret ) if ( token && secret ) tmp = User . find ( username , options ) @profile = Pr...
The profile associated with this user .
11,165
def result if success? results = to_hash [ 'results' ] || [ ] count == 1 ? results . first : results else Etsy . silent_errors ? [ ] : validate! end end
Results of the API request
11,166
def client if @client return @client else @client = Net :: HTTP . new ( @host , Etsy . protocol == "http" ? 80 : 443 ) @client . use_ssl = true if Etsy . protocol == "https" return @client end end
Create a new client that will connect to the specified host
11,167
def add_multipart_data ( req , params ) crlf = "\r\n" boundary = Time . now . to_i . to_s ( 16 ) req [ "Content-Type" ] = "multipart/form-data; boundary=#{boundary}" body = "" params . each do | key , value | esc_key = CGI . escape ( key . to_s ) body << "--#{boundary}#{crlf}" if value . respond_to? ( :read ) body << "...
Encodes the request as multipart
11,168
def fix_headers! ( env ) env . keys . select { | k | k =~ / / } . each do | k | env [ k . gsub ( "HTTP_" , "" ) ] = env [ k ] env . delete ( k ) end env end
rack converts X_FOO to HTTP_X_FOO so strip HTTP_
11,169
def resolve command_string if detected_command = @commands . detect { | cmd | cmd . matches? command_string } detected_command elsif parent_context parent_context . resolve ( command_string ) else raise "Command #{command_string} could not be resolved from the current context." end end
Look in current context and recursively through any available parent contexts to find definition of command . An Exception is raised if no implementation of command is found .
11,170
def decode ( node , cache = RollingCache . new , as_map_key = false ) case node when String if cache . has_key? ( node ) cache . read ( node ) else parsed = if ! node . start_with? ( ESC ) node elsif node . start_with? ( TAG ) Tag . new ( node [ 2 .. - 1 ] ) elsif handler = @handlers [ node [ 1 ] ] handler . from_rep (...
Decodes a transit value to a corresponding object
11,171
def parent_models models . group_by ( & :table_name ) . each_value . map do | models | models . min_by { | model | models . include? ( model . superclass ) ? 1 : 0 } end end
Return list of not inherited models
11,172
def run ( command , expected_exit_status = 0 , timeout = nil , options = { } , env = { } ) sigchld_r , sigchld_w = IO . pipe prev_sigchld_handler = install_sigchld_handler ( sigchld_w ) start = Time . now . to_i child_pid , stdin , stdout , stderr = POSIX :: Spawn . popen4 ( env , command , options ) stdin . close io_m...
Runs the supplied command in a subshell .
11,173
def create_doc ( text , type = nil ) @documents . include? ( type ) ? doc_of_type ( text , type ) : unknown_type ( text ) end
create_doc creates a document of the specified format from the given string .
11,174
def doc_of_type ( text , type ) raise "No Atom document of type: #{type}" unless @documents . include? ( type . to_s ) GoogleApps :: Atom . send ( type , text ) end
doc_of_type takes a document type and a string and returns a document of that type in the current format .
11,175
def export_status ( username , id ) response = make_request ( :get , URI ( export + "/#{username}" + build_id ( id ) ) . to_s , headers : { 'content-type' => 'application/atom+xml' } ) create_doc ( response . body , :export_status ) end
export_status checks the status of a mailbox export request . It takes the username and the request_id as arguments
11,176
def fetch_export ( username , req_id , filename ) export_status_doc = export_status ( username , req_id ) if export_ready? ( export_status_doc ) download_export ( export_status_doc , filename ) . each_with_index { | url , index | url . gsub! ( / / , "#{filename}#{index}" ) } else nil end end
fetch_export downloads the mailbox export from Google . It takes a username request id and a filename as arguments . If the export consists of more than one file the file name will have numbers appended to indicate the piece of the export .
11,177
def download ( url , filename ) File . open ( filename , "w" ) do | file | file . puts ( make_request ( :get , url , headers : { 'content-type' => 'application/atom+xml' } ) . body ) end end
download makes a get request of the provided url and writes the body to the provided filename .
11,178
def get_groups ( options = { } ) limit = options [ :limit ] || 1000000 response = make_request ( :get , group + "#{options[:extra]}" + "?startGroup=#{options[:start]}" , headers : { 'content-type' => 'application/atom+xml' } ) pages = fetch_pages ( response , limit , :feed ) return_all ( pages ) end
get_groups retrieves all the groups from the domain
11,179
def get_next_page ( next_page_url , type ) response = make_request ( :get , next_page_url , headers : { 'content-type' => 'application/atom+xml' } ) GoogleApps :: Atom . feed ( response . body ) end
get_next_page retrieves the next page in the response .
11,180
def fetch_pages ( response , limit , type ) pages = [ GoogleApps :: Atom . feed ( response . body ) ] while ( pages . last . next_page ) and ( pages . count * PAGE_SIZE [ :user ] < limit ) pages << get_next_page ( pages . last . next_page , type ) end pages end
fetch_feed retrieves the remaining pages in the request . It takes a page and a limit as arguments .
11,181
def argument_name_without_leading_underscore name = if argument_name_string [ FIRST_CHARACTER ] == UNDERSCORE argument_name_string . reverse . chop . reverse else argument_name_string end name . to_sym end
Leading underscores are used to indicate a parameter isn t used
11,182
def copy_files files_to_copy . each do | origin , destination | template ( origin , destination , force : true ) end end
Copy template files
11,183
def modify_files gemspec_file = "#{@base_path}/conduit-#{@dasherized_name}.gemspec" str = " # Dependencies\n" " #\n" " spec.add_dependency \"conduit\", \"~> 1.0.6\"\n" " # xml parser\n" " spec.add_dependency \"nokogiri\"\n\n" " # Development Dependencies\n" " #\n" " # to compare xml files in tests\n" " spec.ad...
Adds missing lines to the files
11,184
def update_by_person ( email , params , person_repo : Person . new ) person = person_repo . find_exactly_by_email ( email ) deal = get_by_person_id ( person [ :id ] , person_repo : person_repo ) . first update ( deal [ :id ] , params ) end
Finds a person by their email then finds the first deal related to that person and updates it with the params provided
11,185
def clone_subtree start_node new_tree = self . class . new list = [ start_node ] + start_node . descendents list . each do | x | new_tree . add_node ( x ) end each_edge do | node1 , node2 , edge | if new_tree . include? ( node1 ) and new_tree . include? ( node2 ) new_tree . add_edge ( node1 , node2 , edge ) end end new...
Create a deep clone of the tree
11,186
def clone_tree_without_branch node new_tree = self . class . new original = [ root ] + root . descendents skip = [ node ] + node . descendents nodes . each do | x | if not skip . include? ( x ) new_tree . add_node ( x ) else end end each_edge do | node1 , node2 , edge | if new_tree . include? ( node1 ) and new_tree . i...
Clone a tree without the branch starting at node
11,187
def + ( other ) config = clone specs = other . spec . to_h specs . each { | key , val | config [ key ] = val } methods = other . spec . singleton_methods methods . map! { | name | name . to_s . tr ( '=' , '' ) . to_sym } methods . uniq! methods -= specs . keys methods . each do | name | config . spec . define_singleton...
It s important to define all block specs we need to lazy load
11,188
def parse_body ( body ) body . reduce ( { } ) do | result , ( field , value ) | value = Config . field_value_id ( resource . singular , field , value ) field = Config . field_id ( resource . singular , field ) result . tap { | result | result [ field ] = value } end end
Replaces custom fields with their Pipedrive ID if the ID is defined in the configuration
11,189
def process File . write ( CONFIG_FILE , prepare_default_content . join ( "\n" ) ) unless File . exist? ( CONFIG_FILE ) system ( 'vi ' + CONFIG_FILE ) end
write config file
11,190
def perform ( checks , check_data = { } ) response = @connection . get do | request | request . path = @config [ :api_endpoint ] request . body = build_request_xml ( checks , check_data ) . to_s end @config [ :raw ] ? response : response . body rescue Faraday :: Error :: ClientError => e if e . response . nil? raise AP...
Perform a credit check
11,191
def build_request_xml ( checks , check_data = { } ) builder = Nokogiri :: XML :: Builder . new do | xml | xml . callvalidate do authentication ( xml ) xml . sessions do xml . session ( "RID" => Time . now . to_f ) do xml . data do personal_data ( xml , check_data [ :personal_data ] ) card_data ( xml , check_data [ :car...
Compile the complete XML request to send to Callcredit
11,192
def required_checks ( xml , checks ) required_checks = [ * checks ] . map { | c | Util . underscore ( c ) . to_sym } xml . ChecksRequired do Constants :: CHECKS . each do | check | included = required_checks . include? ( Util . underscore ( check ) . to_sym ) xml . send ( check , included ? "yes" : "no" ) end end end
Checks to be performed
11,193
def stop_if_signal_caught Thread . new do loop do sleep 1 if @shutdown logger . info "Recevied SIG#{@shutdown}, shutting down consumers" @consumer_instances . each { | instance | instance . shutdown } @client . channel . work_pool . shutdown @shutdown = nil end end end end
Checks for presence of
11,194
def subscribe_to_queue ( consumer_class ) queue = channel . queue ( consumer_class . queue_name , durable : true , arguments : { 'x-ha-policy' => 'all' } ) queue . subscribe ( manual_ack : true ) do | delivery_info , properties , message | process_message ( consumer_class , delivery_info , properties , message ) end lo...
Declare a queue and subscribe to it
11,195
def process_message ( consumer_class , delivery_info , properties , message ) message = JSON . parse ( message , symbolize_names : true ) message_id = message . fetch ( :message_id ) produced_at = message . fetch ( :produced_at ) payload = message . fetch ( :payload ) logger . info "Processing message #{message_id} via...
Handle receipt of a subscribed message
11,196
def set_process_name ( status = 'idle' , message_id = nil ) formatted_status = String ( status ) . split ( '::' ) . last ident = [ formatted_status , message_id ] . compact . join ( '#' ) $PROGRAM_NAME = "#{process_name}[#{ident}]" end
Update the name of this process as viewed in ps or top
11,197
def publish ( queue_name , payload , options = { } ) message_id = options . fetch ( :message_id ) { SecureRandom . hex ( 6 ) } produced_at = options . fetch ( :produced_at ) { Time . now . utc . iso8601 } message = { message_id : message_id , produced_at : produced_at , payload : payload } message = JSON . generate ( m...
Serializes the given message and publishes it to the default RabbitMQ exchange
11,198
def close if Native . inotify_rm_watch ( @notifier . fd , @id ) == 0 @notifier . watchers . delete ( @id ) return end raise SystemCallError . new ( "Failed to stop watching #{path.inspect}" , FFI . errno ) end
Disables this Watcher so that it doesn t fire any more events .
11,199
def absolute_name return watcher . path if name . empty? return File . join ( watcher . path , name ) end
The absolute path of the file that the event occurred on .