idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
21,600
def colorize_null ( params = { } , & block ) component [ :null_colorizer ] = ( params [ :using ] or block ) component [ :null_colorizer ] ||= proc do | value | params [ :with ] end end
Defines a colorizer to null values .
21,601
def format ( indexes , params = { } , & block ) [ * indexes ] . each do | index | index = parse_index ( index ) if index component [ :formatters ] [ index ] = ( params [ :using ] or block ) component [ :formatters ] [ index ] ||= proc do | ctx | params [ :with ] % ctx . value end else format_null params , & block end e...
Sets a component to format a column .
21,602
def format_null ( params = { } , & block ) component [ :null_formatter ] = ( params [ :using ] or block ) component [ :null_formatter ] ||= proc do | value | params [ :with ] % value end end
Defines a formatter to null values .
21,603
def to_s header_output = build_header_output data_output = build_data_output string = '' string << Yummi . colorize ( @title , @style [ :title ] ) << $/ if @title string << Yummi . colorize ( @description , @style [ :description ] ) << $/ if @description table_data = header_output + data_output if @layout == :vertical ...
Return a colorized and formatted table .
21,604
def width string = to_s max_width = 0 string . each_line do | line | max_width = [ max_width , line . uncolored . chomp . size ] . max end max_width end
Calculates the table width using the rendered lines
21,605
def content ( data ) string = '' data . each_index do | i | row = data [ i ] row . each_index do | j | column = row [ j ] column ||= { :value => nil , :color => nil } width = max_width data , j alignment = ( @align [ j ] or @default_align ) value = Aligner . align alignment , column [ :value ] . to_s , width value = Yu...
Gets the content string for the given color map and content
21,606
def build_header_output output = [ ] @header . each do | line | _data = [ ] line . each do | h | _data << { :value => h , :color => @style [ :header ] } end output << _data end output end
Builds the header output for this table .
21,607
def build_row_contexts rows = @data . size row_contexts = [ :default ] * rows offset = 0 @contexts . each do | ctx | if ctx == :default break end size = ctx [ :rows ] row_contexts [ offset ... ( size + offset ) ] = [ ctx [ :id ] ] * size offset += size end @contexts . reverse_each do | ctx | if ctx == :default break en...
maps the context for each row
21,608
def build_data_output output = [ ] row_contexts = build_row_contexts @data . each_index do | row_index | @current_context = row_contexts [ row_index ] row = row_to_array ( @data [ row_index ] , row_index ) _row_data = [ ] row . each_index do | col_index | next if not @header . empty? and @header [ 0 ] . size < col_inde...
Builds the data output for this table .
21,609
def raise type = nil , message = nil , & block failure = Tokyo . __send__ ( @assert ? :assert_raised_as_expected : :refute_raised_as_expected , @object , type , message , block ) Tokyo . fail ( failure , caller [ 0 ] ) if failure end
ensure the given block raises as expected
21,610
def throw expected_symbol = nil , & block failure = Tokyo . __send__ ( @assert ? :assert_thrown_as_expected : :refute_thrown_as_expected , @object , expected_symbol ? expected_symbol . to_sym : nil , block ) Tokyo . fail ( failure , caller [ 0 ] ) if failure end
ensure given block thrown as expected
21,611
def eval_attrs result = { } @attrs . each_pair do | k , v | result [ k . to_sym ] = instance_eval ( k . to_s ) end result end
Copy attributes with eval
21,612
def oauth_access_token_from_header auth_header = request . env [ 'HTTP_AUTHORIZATION' ] || '' match = auth_header . match ( / \s / ) return match [ 1 ] if match . present? false end
grabs access_token from header if one is present
21,613
def call ( a , b = nil , c = nil ) if block self . send method , * [ a , b , c ] . compact + args , & block else self . send method , * [ a , b , c ] . compact + args end end
order of params to be called can differ so naming is ambiguous
21,614
def load ( typecode ) offset = 0 typecode . typecodes . collect do | t | value = GCCValue . new @function , "*(#{GCCType.new( t ).identifier} *)( #{self} + #{offset} )" offset += t . storage_size value end end
Add code to read all components of a typed value from memory
21,615
def save ( value ) offset = 0 value . class . typecodes . zip ( value . values ) . each do | t , v | @function << "#{@function.indent}*(#{GCCType.new( t ).identifier} *)( #{self} + #{offset} ) = #{v};\n" offset += t . storage_size end end
Add code to write all components of a typed value to memory
21,616
def conditional ( a , b ) if a . is_a? ( Proc ) and b . is_a? ( Proc ) conditional a . call , b . call else GCCValue . new @function , "( #{self} ) ? ( #{a} ) : ( #{b} )" end end
Create code for conditional selection of value
21,617
def if_else ( action1 , action2 ) @function << "#{@function.indent}if ( #{self} ) {\n" @function . indent_offset + 1 action1 . call @function . indent_offset - 1 @function << "#{@function.indent}} else {\n" @function . indent_offset + 1 action2 . call @function . indent_offset - 1 @function << "#{@function.indent}};\n"...
Generate code for conditional statement
21,618
def ** ( other ) if GCCValue . generic? other GCCValue . new @function , "pow( #{self}, #{other} )" else x , y = other . coerce self x ** y end end
Generate code for computing exponentiation
21,619
def conditional_with_rgb ( a , b ) if a . is_a? ( RGB ) or b . is_a? ( RGB ) Hornetseye :: RGB conditional ( a . r , b . r ) , conditional ( a . g , b . g ) , conditional ( a . b , b . b ) else conditional_without_rgb a , b end end
Create code for conditional selection of RGB value
21,620
def conditional_with_complex ( a , b ) if a . is_a? ( InternalComplex ) or b . is_a? ( InternalComplex ) InternalComplex . new conditional ( a . real , b . real ) , conditional ( a . imag , b . imag ) else conditional_without_complex a , b end end
Create code for conditional selection of complex value
21,621
def build_env ( client , req ) rack_env = DefaultRackEnv . dup req . fill_rack_env ( rack_env ) rack_env [ "SERVER_PORT" ] ||= @port . to_s if ( rack_env [ "rack.input" ] . respond_to? :set_encoding ) rack_env [ "rack.input" ] . set_encoding "ASCII-8BIT" end rack_env [ "REMOTE_PORT" ] , rack_env [ "REMOTE_ADDR" ] = Soc...
Builds an env object from the information provided . Derived handlers can override this to provide additional information .
21,622
def chunked_read ( io , timeout ) begin loop do list = IO . select ( [ io ] , [ ] , [ ] , @read_timeout ) if ( list . nil? || list . empty? ) return end data = io . recv ( 4096 ) if ( data == "" ) return end yield data end ensure io . close if ( ! io . closed? ) end end
Reads from a connection yielding chunks of data as it goes until the connection closes . Once the connection closes it returns .
21,623
def process_client ( app ) loop do client = nil begin make_interruptable do client = @listener . synchronize do begin @listener && @listener . accept ( ) rescue => e return end end if ( ! client ) return end end req = Http :: Parser . new ( ) buf = "" chunked_read ( client , @timeout ) do | data | begin buf << data req...
Accepts a connection from a client and handles requests on it until the connection closes .
21,624
def run ( app ) synchronize do @interruptable = [ ] int_orig = trap "INT" do stop ( ) end term_orig = trap "TERM" do stop ( ) end begin @listener = create_listener ( @options ) @interruptable . extend Mutex_m if ( @max_clients > 1 ) @master = Thread . current @workers = ( 0 ... @max_clients ) . collect do Thread . new ...
Runs the application through the configured handler . Can only be run once at a time . If you try to run it more than once the second run will block until the first finishes .
21,625
def to_s @to_s ||= begin wks = @weeks . map { | w | w . map { | d | if d . nil? ' ' elsif d . day < 10 " #{d.day}" else "#{d.day}" end } . join ( ' ' ) } . join ( "\n" ) "Su Mo Tu We Th Fr Sa\n#{wks}\n" end end
Initializes an instance from a year and a month . Raises an error if the month is not in the allowed range i . e . it must be between 1 and 12 inclusive .
21,626
def Create ( * args ) api_objects = args response = execute_request 'Create' do | xml | xml . CreateRequest do xml . Options api_objects . each do | api_object | xml . Objects "xsi:type" => api_object . type_name do api_object . render! ( xml ) end end end end CreateResponse . new ( response ) end
Constructs a client .
21,627
def Retrieve ( object_type_name , filter , * properties ) object_type_name = object_type_name . type_name if object_type_name . respond_to? ( :type_name ) response = execute_request 'Retrieve' do | xml | xml . RetrieveRequestMsg do xml . RetrieveRequest do xml . Options xml . ObjectType object_type_name properties . ea...
Invokes the Retrieve method .
21,628
def Update ( * args ) api_objects = args response = execute_request 'Update' do | xml | xml . UpdateRequest do xml . Options api_objects . each do | api_object | xml . Objects "xsi:type" => api_object . type_name do api_object . render! ( xml ) end end end end UpdateResponse . new ( response ) end
Invokes the Update method .
21,629
def Delete ( * args ) api_objects = args response = execute_request 'Delete' do | xml | xml . DeleteRequest do xml . Options api_objects . each do | api_object | xml . Objects "xsi:type" => api_object . type_name do api_object . render! ( xml ) end end end end DeleteResponse . new ( response ) end
Invokes the Delete method .
21,630
def Perform ( action , * args ) definitions = args response = execute_request 'Perform' do | xml | xml . PerformRequestMsg do xml . Action action xml . Definitions do definitions . each do | definition | xml . Definition "xsi:type" => definition . type_name do definition . render! ( xml ) end end end xml . Options end ...
Invokes the Perform method .
21,631
def initialize_client! self . client = :: Savon . client ( :endpoint => config [ :endpoint ] , :namespace => config [ :namespace ] , :open_timeout => config [ :open_timeout ] , :read_timeout => config [ :read_timeout ] , :raise_errors => false , :logger => config [ :logger ] , :log => config [ :logger ] && config [ :lo...
Constructs and saves the savon client using provided config .
21,632
def execute_request ( method ) begin response = client . call ( method ) do | locals | xml = Builder :: XmlMarkup . new xml . instruct! ( :xml , :encoding => 'UTF-8' ) result = begin xml . s :Envelope , "xmlns" => config [ :namespace ] , "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" , "xmlns:xsi" => "http://www.w3....
Builds the SOAP request for the given method delegating body rendering to the provided block .
21,633
def dump_value ( value ) case value when Array value . map { | v | dump_value v } when String replace_interpolations value end end
Prepare value for translation .
21,634
def parse_value ( untranslated , each_translated ) case untranslated when Array untranslated . map { | from | parse_value ( from , each_translated ) } when String restore_interpolations untranslated , each_translated . next else untranslated end end
Parse translated value from the each_translated enumerator
21,635
def object_exists? ( object_name ) safe_name = "'#{object_name.gsub('\'','\'\'')}'" klass = self . class . name sql = if klass == 'ActiveRecord::ConnectionAdapters::SQLServerAdapter' "SELECT COUNT(*) AS \"one\" FROM \"sysobjects\" WHERE \"name\"=#{safe_name}" elsif klass == 'ActiveRecord::ConnectionAdapters::SQLite3Ada...
Searches the database to determine if an object with the specified name exists .
21,636
def exec_sp ( stmt ) klass = self . class . name if klass == 'ActiveRecord::ConnectionAdapters::SQLServerAdapter' rex = / \s \[ \] \s /i match = rex . match ( stmt ) if match exec_query ( "DECLARE @RET INTEGER; EXECUTE @RET=[#{match['PROC']}]#{match['ARGS']}; SELECT @RET AS [RET]" ) . first [ 'RET' ] else execute stmt ...
Executes a stored procedure .
21,637
def current_controller? ( * args ) args . any? { | v | v . to_s . downcase == controller . controller_name } end
Check if a particular controller is the current one
21,638
def yo ( username , options = { } ) options . merge! ( username : username . upcase ) response = connection_wrapper { @faraday . post '/yo/' , token_hash . merge ( options ) } response . success? end
Yo to specific user
21,639
def connection_wrapper ( & block ) begin response = block . call raise ClientError . new ( response . body [ 'error' ] ) if response . body . has_key? ( 'error' ) rescue Faraday :: ParsingError => e raise ClientError . new ( e . message ) rescue Faraday :: ClientError => e raise ConnectionError . new ( e . message ) en...
Connect with error handling
21,640
def published_inputs inputs . select { | i | i . published? } . sort_by { | i | i . published_at } end
Return all the published inputs in order of publication .
21,641
def after_transaction ( opts = { } , & block ) default_options = { only : nil , if_no_transaction : :run } opts = default_options . merge ( opts ) normalized = opts . dup opts . each { | k , v | normalized [ k . to_s ] = v } opts = normalized if ActiveRecord :: Base . connection . open_transactions > 0 callbacks = Acti...
Allows to execute any block of code after transaction completes . If no transaction is actually open the code runs immediately .
21,642
def register ( origin , target , & block ) raise ( ArgumentError , 'block is required' ) unless block_given? @mutex . synchronize do @coercions [ origin ] [ target ] = Coercion . new ( origin , target , & block ) end end
Registers a coercion with the Garcon library .
21,643
def write_to_s3 status_path = "#{@s3_path}/status.json" s3 . put_object ( @bucket , status_path , "#{to_json}\n" ) unless @status_url expire_date = Time . now + ( 3600 * 24 ) @status_url = s3 . get_object_http_url ( @bucket , status_path , expire_date ) s3 . put_object ( @bucket , status_path , "#{to_json}\n" ) end end
Writes this job s JSON representation to S3
21,644
def perform_backup begin prepare_backup update_status "Backing up #{rds_id} from account #{account_name}" create_disconnected_rds download_data_from_tmp_rds delete_disconnected_rds upload_output_to_s3 update_status "Backup of #{rds_id} complete" send_mail rescue Exception => e update_status "ERROR: #{e.message.split("\...
Top - level long - running method for performing the backup .
21,645
def create_disconnected_rds ( new_rds_name = nil ) @new_rds_id = new_rds_name if new_rds_name prepare_backup unless @original_server snapshot_original_rds create_tmp_rds_from_snapshot configure_tmp_rds wait_for_new_security_group wait_for_new_parameter_group destroy_snapshot end
Step 1 of the overall process - create a disconnected copy of the RDS
21,646
def prepare_backup unless @original_server = RDSBackup . get_rds ( rds_id ) names = RDSBackup . rds_accounts . map { | name , account | name } raise "Unable to find RDS #{rds_id} in accounts #{names.join ", "}" end @account_name = @original_server . tracker_account [ :name ] @rds = :: Fog :: AWS :: RDS . new ( RDSBacku...
Queries RDS for any pre - existing entities associated with this job . Also waits for the original RDS to become ready .
21,647
def snapshot_original_rds unless @new_instance || @snapshot update_status "Waiting for RDS instance #{@original_server.id}" @original_server . wait_for { ready? } update_status "Creating snapshot #{@snapshot_id} from RDS #{rds_id}" @snapshot = @rds . snapshots . create ( id : @snapshot_id , instance_id : rds_id ) end e...
Snapshots the original RDS
21,648
def create_tmp_rds_from_snapshot unless @new_instance update_status "Waiting for snapshot #{@snapshot_id}" @snapshot . wait_for { ready? } update_status "Booting new RDS #{@new_rds_id} from snapshot #{@snapshot.id}" @rds . restore_db_instance_from_db_snapshot ( @snapshot . id , @new_rds_id , 'DBInstanceClass' => @origi...
Creates a new RDS from the snapshot
21,649
def configure_tmp_rds update_status "Waiting for instance #{@new_instance.id}..." @new_instance . wait_for { ready? } update_status "Modifying RDS attributes for new RDS #{@new_instance.id}" @rds . modify_db_instance ( @new_instance . id , true , { 'DBParameterGroupName' => @original_server . db_parameter_groups . firs...
Updates the Master Password and applies the configured RDS Security Group
21,650
def wait_for_new_security_group old_group_name = @config [ 'rds_security_group' ] update_status "Applying security group #{old_group_name}" + " to #{@new_instance.id}" @new_instance . wait_for { new_group = ( db_security_groups . select do | group | group [ 'DBSecurityGroupName' ] == old_group_name end ) . first ( new_...
Wait for the new RDS Security Group to become active
21,651
def wait_for_new_parameter_group old_name = @original_server . db_parameter_groups . first [ 'DBParameterGroupName' ] update_status "Applying parameter group #{old_name} to #{@new_instance.id}" job = self @new_instance . wait_for { new_group = ( db_parameter_groups . select do | group | group [ 'DBParameterGroupName' ]...
Wait for the new RDS Parameter Group to become in - sync
21,652
def update_status ( message , new_status = nil ) @log = @options [ :logger ] || RDSBackup . default_logger ( STDOUT ) @message = message @status = new_status if new_status @status == 200 ? ( @log . info message ) : ( @log . error message ) write_to_s3 end
Writes a new status message to the log and writes the job info to S3
21,653
def send_mail return unless @options [ :email ] @log . info "Emailing #{@options[:email]}..." begin RDSBackup :: Email . new ( self ) . send! @log . info "Email sent to #{@options[:email]} for job #{backup_id}" rescue Exception => e @log . warn "Error sending email: #{e.message.split("\n").first}" end end
Sends a status email
21,654
def perform_search ( type , query ) Chef :: Search :: Query . new . search ( type , query ) . first . map ( & :name ) end
Perform a search and return the names of the nodes that match the search .
21,655
def keys @hash . deep . each_with_object ( [ ] ) do | ( key_path , value ) , result | result << key_path . to_key_path unless value . is_a? ( Hash ) end end
Return all maximal key paths in a tree
21,656
def invoke ( command , params = { } ) command_string = compile_command ( command , params ) output_command ( command_string ) execute ( command_string , params ) end
prepares the commands to correctly reference the application and path
21,657
def output_command ( command_string ) $stdout . puts $stdout . puts StringMasker . new ( command_string , :username => username , :password => password ) . to_s end
print the command on the screen
21,658
def execute ( command , params = { } ) unless params [ :dry_run ] if params [ :return ] System . execute ( command , :return => true ) else $stdout . puts System . execute ( command ) end end end
execute the command or not and return the results or not
21,659
def doc @document = Nokogiri :: HTML ( @body ) rescue Exception => e puts e . inspect puts e . backtrace end
Return the Nokogiri html document
21,660
def links @links = doc . css ( 'a' ) . map { | link | link [ 'href' ] . to_s } . uniq . delete_if { | href | href . empty? } . map { | url | absolutify ( url . strip ) } end
Return the entire links found in the page ; exclude empty links
21,661
def images @images = doc . css ( 'img' ) . map { | img | img [ 'src' ] . to_s } . uniq . delete_if { | src | src . empty? } . map { | url | absolutify ( url . strip ) } end
Return all images found in the page
21,662
def text temp_doc = doc temp_doc . css ( 'script, noscript, style, link' ) . each { | node | node . remove } @text = temp_doc . css ( 'body' ) . text . split ( "\n" ) . collect { | line | line . strip } . join ( "\n" ) end
Return plain text of the page without html tags
21,663
def set_channels! ( message ) channel_type = message . channel_type channels = @app_channels . select { | channel | channel [ "channel_type" ] . eql? ( channel_type ) } case message . channel_type when "twitter" channels = channels . select { | channel | channel [ "accounts" ] . select { | item | item [ "name" ] . eql?...
Sets the message channel_name attribute . The result is a list of application channels that should be advised about the inbound message
21,664
def process_message ( message ) logger . info ( "Calling event #{message.message_type} in the channel #{message.channel_type}" ) @listener_channels [ message . channel_type . to_sym ] . message ( message . message_type . to_sym , message ) end
Executes the blocks that are associated to that channel and event type
21,665
def add_check ( data , type , keywords , options = { } ) t = type . to_sym fail Exceptions :: UnknownCheckType , "Unknown check type \":#{t}\" given. Did you register it in advance?" unless comparators . key? ( t ) opts = { exceptions : [ ] , tag : '' } . merge options sample = Sample . new ( data , keywords , opts [ :...
Add a check to test against
21,666
def result if @cache [ :checks ] . new_objects? @cache [ :checks ] . stored_objects . each do | c | @result = Result . new ( c . sample ) unless c . success? end end @result end
The result of all checks defined
21,667
def migrate ( row , migrated ) super if spouse then spouse . household = migrated . detect { | m | Household === m } end end
Augments the migration by setting the spouse household .
21,668
def add! ( timings ) timings . descriptions . each { | d | add_cpu_time ( d , timings . cpu_time ( d ) ) add_wall_time ( d , timings . wall_time ( d ) ) } end
Add another timings object to this one
21,669
def total_energy etot = self . geometry_steps . collect { | gs | gs . total_energy } . compact . last if etot . nil? Float :: NAN else etot end end
Returns the best available value of the total energy
21,670
def method_added ( method_name ) return if hooks . include? ( method_name ) || hooked_methods . include? ( method_name ) add_hooks_to ( method_name ) end
this method is invoked whenever a new instance method is added to a class
21,671
def hash_of ( * keys ) keys . each . with_object ( { } ) { | k , h | h [ k ] = send ( k ) } end
A convenience method for making a hash with the given methods on self as the keys and return for the given methods as the values
21,672
def set_mark ( key , value , dup = true ) self . each { | elm | elm . set_mark ( key , ( dup and not ( Symbol === value ) ) ? value . dup : value ) } end
Fired to each element of the group . Values are duplicated by default . Put dup to false to avoid this behavior .
21,673
def rebuild_index ( options = { } , finder_options = { } ) logger . info "=== Rebuilding index for: #{self.index_type}" unless options [ :silent ] if options [ :drop ] logger . info "Dropping index for: #{self.index_type}" unless options [ :silent ] index_adapter . drop_index ( self ) end finder_options [ :batch_size ]...
Dispatches a command to the current adapter to rebuild the index .
21,674
def index ( * params , & block ) index_field = IndexField . new ( params , block ) add_index_field ( index_field ) define_finder index_field [ :finder_name ] end
Macro for defining a class attribute as an indexed field .
21,675
def application return @app if @app @stack . use Rack :: HtmlValidator if self . options [ :validate ] @stack . run Rack :: HtmlMockup . new ( self . project ) @app = @stack end
Build the final application that get s run by the Rack Handler
21,676
def define_event ( name , args = { } ) args = { :create_method => true } . merge ( args ) name = name . to_sym if args [ :create_method ] define_method name do return event ( name ) end end @unobservable_instance_events ||= Set . new if @unobservable_instance_events . include? name return false else @unobservable_insta...
Returns true if the instance event is defined . Returns false otherwise .
21,677
def attr_event ( * names ) args = ( names [ - 1 ] . is_a? Hash ) ? names . pop : { } names . each { | n | define_event ( n , args ) } return nil end
This helper method is similar to attr_reader and attr_accessor . It allows for instance events to be declared inside the body of the class .
21,678
def singleton_events ( all = true ) if all contributors = self . singleton_class . included_modules contributors -= self . class . included_modules contributors . push self . singleton_class Unobservable . collect_instance_events_defined_by ( contributors ) else Unobservable . collect_instance_events_defined_by ( [ sel...
Obtains the list of events that are unique to this object . If all = true then this list will also include events that were defined within a module that the object extended .
21,679
def event ( name ) @unobservable_events_map ||= { } e = @unobservable_events_map [ name ] if not e if self . events . include? name e = Event . new @unobservable_events_map [ name ] = e else raise NameError , "Undefined event: #{name}" end end return e end
Returns the Event that has the specified name . A NameError will be raised if the object does not define any event that has the given name .
21,680
def register ( * args , & block ) h = Unobservable . handler_for ( * args , & block ) @handlers << h return h end
Registers the given event handler so that it will be invoked when the event is raised .
21,681
def unregister ( * args , & block ) h = Unobservable . handler_for ( * args , & block ) index = @handlers . index ( h ) if index @handlers . slice! ( index ) return h else return nil end end
Removes a single instance of the specified event handler from the list of event handlers . Therefore if you ve registered the same event handler 3 times then you will need to unregister it 3 times as well .
21,682
def is_month_archive? segments = params [ :slug ] . split ( '/' ) ( get_type_by_url == 'AR' && ! segments [ 2 ] . blank? && segments [ 3 ] . blank? ) ? true : false end
returns a boolean as to whether the current view is a month archive
21,683
def is_year_archive? segments = params [ :slug ] . split ( '/' ) ( get_type_by_url == 'AR' && ! segments [ 1 ] . blank? && segments [ 2 ] . blank? && segments [ 3 ] . blank? ) ? true : false end
returns a boolean as to whether the current view is a year archive
21,684
def is_homepage? return false if ( ! defined? ( @content . length ) . blank? || @content . blank? ) @content . id == Setting . get ( 'home_page' ) . to_i ? true : false end
returns a boolean as to whether the current view is the homepage
21,685
def obtain_comments_form if Setting . get ( 'article_comments' ) == 'Y' type = Setting . get ( 'article_comment_type' ) @new_comment = Comment . new if File . exists? ( "#{Rails.root}/app/views/themes/#{current_theme}/comments_form." + get_theme_ext ) render ( :template => "themes/#{current_theme}/comments_form." + get...
returns the comment form that is created in the theme folder .
21,686
def obtain_term_type return nil if params [ :slug ] . blank? segments = params [ :slug ] . split ( '/' ) if ! segments [ 1 ] . blank? term = TermAnatomy . where ( :taxonomy => segments [ 1 ] ) . last term . taxonomy if ! term . blank? else nil end end
return what type of taxonomy it is either - category or tag
21,687
def mimetype ( path ) extension = File . basename ( path ) . split ( '.' ) [ - 1 ] Rack :: Mime . mime_type ( ".#{extension}" ) end
Get the mime type from a file name
21,688
def process document return unless document . valid emitter . log ( document . url . canonical_url . colorize ( :green ) ) document . emitter = emitter enqueue ( document . links ) document . write! processed_urls << document . url . canonical_url end
Process a document fetching its content and enqueueing it for sub processing
21,689
def enqueue links links . each_with_index do | document , index | next unless can_be_enqueued? ( document ) emitter . log ( "> Enqueueing: #{document.url.canonical_url}" ) unprocessed_documents << document unprocessed_urls << document . url . canonical_url end end
Enqueue new documents for each link found in the current document
21,690
def can_be_enqueued? ( document ) archivable? ( document ) && valid_domains . include? ( document . url . host ) && ! processed_urls . include? ( document . url . canonical_url ) && ! unprocessed_urls . include? ( document . url . canonical_url ) end
Determine if a document can be enqueued
21,691
def archivable? ( document ) archivable_document = document . url . valid has_been_marked_as_invalid = self . invalid_urls . include? ( document . url . raw_url ) if ! archivable_document && ! has_been_marked_as_invalid emitter . warning ( "> Invalid URL: #{document.url.raw_url}" ) invalid_urls << document . url . raw_...
Determine if a document is actually the type of document that can be archived
21,692
def done ( delay = nil ) super ( delay ) do yield if block_given? EM . next_tick do run_em_hooks :amqp_after if AMQP . conn and not AMQP . closing AMQP . stop_connection do AMQP . cleanup_state finish_em_loop end else AMQP . cleanup_state finish_em_loop end end end end
Breaks the event loop and finishes the spec . It yields to any given block first then stops AMQP EM event loop and cleans up AMQP state .
21,693
def primary_source return :ldap if using_ldap? && ! using_db? return :db if using_db? && ! using_ldap? source = @options [ :primary_source ] source = source . to_sym if source . is_a? ( String ) return source if [ :ldap , :db ] . include? ( source ) return :ldap if using_ldap? :db end
Gets the first authentication source for this user manager .
21,694
def authenticate ( email , password , client_ip ) return nil unless email && BarkestCore :: EmailTester . valid_email? ( email , false ) email = email . downcase sources . each do | source | if source == :ldap entry = @ldap . search ( filter : "(&(objectClass=user)(mail=#{email}))" ) if entry && entry . count == 1 user...
Attempts to authenticate the user and returns the model on success .
21,695
def ldap_system_admin_groups @ldap_system_admin_groups ||= begin val = @options [ :ldap_system_admin_groups ] val . blank? ? [ ] : val . strip . gsub ( ',' , ';' ) . split ( ';' ) . map { | v | v . strip . upcase } end end
Gets the list of ldap groups that map to system administrators .
21,696
def call ( parcel ) response_kind , response_message , response_headers = interactor . call parcel if response_kind kind_part , version_part = response_kind . split '#' , 2 response_kind = kind_part if version_part if version_part response_headers ||= { } response_headers [ :version ] = version_part end end return parc...
Rack - like call to run the Interactor s use - case .
21,697
def me data = get ( "/me" ) . body Resources :: Me . new ( { client : self } . merge ( data ) ) end
Get information about the authenticated user
21,698
def regexp ( * args ) options = args . pop if args . last . is_a? ( Hash ) options ||= { } symbols = args digits = symbols . delete ( :digits ) grouped_digits = symbols . delete ( :grouped_digits ) symbols = symbols . map { | s | s . is_a? ( Symbol ) ? send ( s ) : s } if grouped_digits symbols += [ group_separator , i...
Generate a regular expression to match any of the passed symbols .
21,699
def expand_url ( input , url = nil ) url ||= root url = if input . start_with? ( "http" , url ) input else File . join ( url , input ) end smart_slash ( url ) end
Prepends input with a url fragment