idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
18,100
def split_paths ( paths ) new_paths = { } paths . each do | p | if p . split ( '/' ) . length > 1 new_paths [ p . split ( '/' ) . last . to_s ] = p else new_paths [ 'home' ] = '/' end end new_paths end
Accounting for space - separated command line arrays
18,101
def wraith_setup ( value , name = 'phantomjs' ) if @settings . key? ( :urls ) value [ 'domains' ] = @settings [ :urls ] else value [ 'domains' ] = { } value [ 'domains' ] [ 'main' ] = domain end value [ 'screen_widths' ] ||= [ 1280 , 1024 , 767 ] value [ 'fuzz' ] ||= '20%' value [ 'threshold' ] ||= 0 value [ 'paths' ] ...
Wraith is a complicated gem with significant configuration
18,102
def config_exists ( file , root ) present_location = File . join ( root , file ) File . exist? ( present_location ) ? present_location : false end
See if a config file exists
18,103
def jshint_ignore ( settings_data_key ) return unless settings_data_key . is_a? ( Hash ) && settings_data_key . key? ( 'jshintignore' ) jshintignore_file = [ ] settings_data_key [ 'jshintignore' ] . each { | i | jshintignore_file << "#{i}\n" } @settings [ :jshintignore ] = temp_it ( 'jshintignore.json' , jshintignore_f...
Save jshintignore if available
18,104
def format_prefix values = CEF :: PREFIX_ATTRIBUTES . keys . map { | k | self . send ( k ) } escaped = values . map do | value | escape_prefix_value ( value ) end escaped . join ( '|' ) end
returns a pipe - delimeted list of prefix attributes
18,105
def format_extension extensions = CEF :: EXTENSION_ATTRIBUTES . keys . map do | meth | value = self . send ( meth ) next if value . nil? shortname = CEF :: EXTENSION_ATTRIBUTES [ meth ] [ shortname , escape_extension_value ( value ) ] . join ( "=" ) end times = CEF :: TIME_ATTRIBUTES . keys . map do | meth | value = se...
returns a space - delimeted list of attribute = value pairs for all optionals
18,106
def validate_params if params [ :encrypted_password ] . nil? or params [ :shared_user_ids ] . nil? or params [ :board ] . nil? render json : { } , status : 422 return end result = has_board_access ( params [ :board ] [ :id ] ) if result [ :status ] != :ok render json : { } , status : result [ :status ] return else if !...
Validates the contents of params against the database records .
18,107
def create user = User . new ( user_params ) if user . save UserMailer . confirm_account ( user ) . deliver_now render json : user , status : :created else render json : user . errors , status : 422 end end
Creates a new user
18,108
def confirm token = params [ :token ] . to_s user = User . find_by ( confirmation_token : token ) if user . present? && user . confirmation_token_valid? if user . mark_as_confirmed! render json : { status : 'Account confirmed successfully.' } else render json : user . errors , status : 422 end else render json : [ 'Inv...
confirm user account
18,109
def search user = User . where ( "email = ? AND id != ?" , params [ :email ] , @user . id ) . first if user render json : user else render json : { } , status : :not_found end end
Returns the user with matching email
18,110
def commit_export ( commit_sha = head_sha ) commit_sha = commit_sha . to_s ce_commit = @g . gcommit ( commit_sha ) if first_commit == commit_sha ce_diff = diff_initial ( first_commit ) else last_commit = @g . gcommit ( previous_commit ( commit_sha ) ) ce_diff = diff ( last_commit , ce_commit ) end { commit_sha : commit...
Set up instance variables
18,111
def compare ( sha1 = master_commit_sha , sha2 = head_sha ) diff_return = { } sha1 = define_psuedo_commit if @settings [ :commit ] git_spread = commit_range ( sha1 , sha2 ) . reverse git_spread . each do | git_sha | files = @psuedo_commit ? working_copy_files : files_by_sha ( git_sha ) diff_return [ git_sha ] = match_as...
Compare two commits and get line number ranges of changed patches
18,112
def lints_and_stats ( lint_by_path = false , git_shas = compare , nuclear = false ) return false if git_shas . blank? base_branch = branch git_ouput = { } git_shas . each do | sha , exts | create_branch ( sha ) unless @psuedo_commit sha = sha . to_s puts sha . color ( :blue ) exts . each do | ext , files | lint_opts = ...
Run appropriate lint for every sha in commit history . For each sha a new branch is created then deleted
18,113
def associations { css : [ 'css' ] , scss : [ 'scss' , 'sass' ] , js : [ 'js' ] , ruby : [ 'rb' , 'Gemfile' , 'lock' , 'yml' , 'Rakefile' , 'ru' , 'rdoc' , 'rake' , 'Capfile' , 'jbuilder' ] , rails : [ 'slim' , 'haml' , 'jbuilder' , 'erb' ] , images : [ 'png' , 'jpg' , 'jpeg' , 'gif' ] , static : [ 'pdf' , 'txt' , 'doc...
Define associations to linters based on file extension
18,114
def diff ( old_commit , new_commit ) stats = @g . diff ( old_commit , new_commit ) . stats lines = lines_added ( new_commit . sha ) return if ! lines . is_a? ( Hash ) || stats . blank? lines . each do | filename , filelines | stats [ :files ] [ filename ] [ :lines_added ] = filelines if stats [ :files ] . key? ( filena...
Get general stats of commit on HEAD versus last commit on master branch
18,115
def diff_initial ( commit_sha ) data = commit_information ( commit_sha ) value = { total : { insertions : 0 , deletions : 0 , lines : 0 , files : data . length } , files : { } } data . each do | d | item = d . split ( "\t" ) insertions = item [ 0 ] . to_i value [ :total ] [ :insertions ] += insertions value [ :total ] ...
Get diff stats on just the initial commit Ruby - git doesn t support this well
18,116
def match_associations ( commit_sha , files ) new_lines = lines_added ( commit_sha ) files = files . split ( "\n" ) . group_by { | f | f . split ( '.' ) . pop } associations . each do | ext , related | files [ ext ] ||= [ ] related . each do | child | next if files [ child ] . blank? files [ child ] . each do | c | fil...
Associate files by extension and match their changes
18,117
def lints_and_stats_nuclear ( lint_opts ) { lints : { scsslint : Maximus :: Scsslint . new ( lint_opts ) . result , jshint : Maximus :: Jshint . new ( lint_opts ) . result , rubocop : Maximus :: Rubocop . new ( lint_opts ) . result , railsbp : Maximus :: Railsbp . new ( lint_opts ) . result , brakeman : Maximus :: Brak...
All data retrieved from reports
18,118
def lints_and_stats_switch ( ext , lint_opts ) result = { lints : { } , statistics : { } } lints = result [ :lints ] statistics = result [ :statistics ] case ext when :scss lints [ :scsslint ] = Maximus :: Scsslint . new ( lint_opts ) . result statistics [ :stylestat ] = Maximus :: Stylestats . new ( { config : @config...
Specific data retrieved by file extension
18,119
def destroy_branch ( base_branch , sha ) if base_branch == "maximus_#{sha}" @g . branch ( 'master' ) . checkout else @g . branch ( base_branch ) . checkout end @g . branch ( "maximus_#{sha}" ) . delete end
Destroy created branch
18,120
def lint_file_paths ( files , ext ) file_list = files . map { | f | f [ :filename ] } . compact ext == :ruby ? file_list . join ( ' ' ) : file_list . join ( ',' ) end
Get list of file paths
18,121
def join ( * names ) joined_path = if root? then '' else self . to_s end names . each do | name | name = name . to_s joined_path << @separator unless name . start_with? ( @separator ) joined_path << name unless name == @separator end return self . class . new ( joined_path , @separator ) end
Joins directory names together with the path but does not resolve the resulting path .
18,122
def validate_claims ( options = { } ) validate_exp ( options [ :max_clock_skew ] ) unless options [ :ignore_exp ] validate_nbf ( options [ :max_clock_skew ] ) unless options [ :ignore_nbf ] validate_iss ( options [ :valid_iss ] ) validate_aud ( options [ :valid_aud ] ) self end
Validates the set of claims .
18,123
def validate_exp ( max_clock_skew = 0 ) max_clock_skew ||= 0 exp = time_claim ( "exp" ) if exp && exp <= ( Time . now - max_clock_skew ) raise Sandal :: ExpiredTokenError , "The token has expired." end end
Validates the expires claim .
18,124
def validate_nbf ( max_clock_skew = 0 ) max_clock_skew ||= 0 nbf = time_claim ( "nbf" ) if nbf && nbf > ( Time . now + max_clock_skew ) raise Sandal :: ClaimError , "The token is not valid yet." end end
Validates the not - before claim .
18,125
def validate_iss ( valid_iss ) return unless valid_iss && valid_iss . length > 0 unless valid_iss . include? ( self [ "iss" ] ) raise Sandal :: ClaimError , "The issuer is invalid." end end
Validates the issuer claim .
18,126
def validate_aud ( valid_aud ) return unless valid_aud && valid_aud . length > 0 aud = self [ "aud" ] aud = [ aud ] unless aud . is_a? ( Array ) unless ( aud & valid_aud ) . length > 0 raise Sandal :: ClaimError , "The audence is invalid." end end
Validates the audience claim .
18,127
def time_claim ( name ) claim = self [ name ] if claim begin Time . at ( claim ) rescue raise Sandal :: ClaimError , "The \"#{name}\" claim is invalid." end end end
Gets the value of a claim as a Time .
18,128
def sort objects . values . each do | object | SORTABLE_ITEMS . select { | key | object . has_key? ( key ) } . each do | key | object [ key ] . sort_by! ( & method ( :comparator ) ) end end project end
Returns a new instance of Sorter
18,129
def comparator uuid prefix = objects [ uuid ] [ Keys :: ISA ] == Keys :: PBXGroup ? ' ' : '' prefix + Helpers . resolve_attributes ( uuid , objects ) end
The comparator used during the sort
18,130
def check ( filename , content ) node = parse ( filename , content ) node . file = filename check_node ( node ) end
check the ruby sexp nodes for the ruby file .
18,131
def after_check @checkers . each do | checker | after_check_callbacks = checker . class . get_callbacks ( :after_check ) after_check_callbacks . each do | block | checker . instance_exec & block end end end
trigger all after_check callbacks defined in all checkers .
18,132
def parse ( filename , content ) Sexp . from_array ( Ripper :: SexpBuilder . new ( content ) . parse ) rescue Exception raise AnalyzerException . new ( "#{filename} looks like it's not a valid Ruby file. Skipping..." ) end
parse ruby code .
18,133
def check_node ( node ) checkers = @checks [ node . sexp_type ] if checkers checkers . each { | checker | checker . node_start ( node ) if checker . parse_file? ( node . file ) } end node . children . each { | child_node | child_node . file = node . file check_node ( child_node ) } if checkers checkers . each { | check...
recursively check ruby sexp node .
18,134
def emit ( event ) self . socksetup if self . sock . nil? unless self . eventDefaults . nil? self . eventDefaults . each do | k , v | event . send ( "%s=" % k , v ) end end self . sock . send event . to_s , 0 end
fire the message off
18,135
def bind_meta_app args = { } , & block arg_string = args . values_at ( :key , :listen_to , :respond_on , :application ) . join ( " " ) arg_string += "::#{args[:parameters]}" if args [ :parameters ] application "bind_meta_app" , arg_string , & block end
Binds an application to the specified call legs .
18,136
def bridge * args , & block variables = if args . last . is_a? Hash key_value_pairs = args . pop . sort { | x , y | x . to_s <=> y . to_s } key_value_pairs . map! { | k , v | "#{k}=#{v}" } "{#{key_value_pairs.join(",")}}" else "" end endpoints = if args . first . is_a? Array args . map { | e | e . join ( "," ) } . join...
Bridges an incoming call to an endpoint optionally taking an array of channel variables to set . If given an array of arrays each contained array of endpoints will be called simultaneously with the next array of endpoints as failover . See the examples below for different constructs and the callstring it sends to FreeS...
18,137
def play_and_get_digits file , invalid_file , args = { } , & block min = args [ :min ] || 1 max = args [ :max ] || 2 tries = args [ :tries ] || 3 terminators = args [ :terminators ] || "#" timeout = args [ :timeout ] || 5000 variable = args [ :variable ] || "read_digits_var" regexp = args [ :regexp ] || "\\d+" args = [...
Plays a sound file and reads DTMF presses .
18,138
def record path , params = { } , & block args = [ path , params [ :limit ] ] . compact . join ( " " ) application "record" , args , & block end
Records a message with an optional limit on the maximum duration of the recording .
18,139
def query ( rank ) flush current = @head return unless current mid_rank = ( rank * @observations ) . floor max_rank = mid_rank + ( invariant ( mid_rank , @observations ) / 2 ) . floor rank = 0.0 while current . successor rank += current . rank if rank + current . successor . rank + current . successor . delta > max_ran...
Get a quantile value for a given rank .
18,140
def file_list ( path , ext = 'scss' , remover = '' ) collect_path = path . include? ( "*" ) ? path : "#{path}/**/*.#{ext}" Dir [ collect_path ] . collect { | file | file . gsub ( remover , '' ) . gsub ( / \/ \/ / , 'app/' ) if File . file? ( file ) } end
Find all files that were linted by extension
18,141
def truthy? ( str ) return true if str == true || str =~ ( / /i ) return false if str == false || str . blank? || str =~ ( / /i ) end
Convert string to boolean
18,142
def edit_yaml ( yaml_location , & block ) d = YAML . load_file ( yaml_location ) block . call ( d ) File . open ( yaml_location , 'w' ) { | f | f . write d . to_yaml } end
Edit and save a YAML file
18,143
def path_exists? ( path = @path ) path = path . split ( ' ' ) if path . is_a? ( String ) && path . include? ( ' ' ) if path . is_a? ( Array ) path . each do | p | unless File . exist? ( p ) puts "#{p} does not exist" return false end end else path = path . gsub ( '/**' , '' ) . gsub ( '/*' , '' ) . gsub ( / \/ \. / , '...
Ensure path exists
18,144
def discover_path ( root = @config . working_dir , folder = '' , extension = '' ) return @path unless @path . blank? if is_middleman? File . join ( root , 'source' , folder ) elsif is_rails? File . join ( root , 'app' , 'assets' , folder ) else extension . blank? ? File . join ( root ) : File . join ( root , '/**' , "/...
Default paths to check for lints and some stats
18,145
def ensure_comment post_id = params [ :post_id ] comment_id = params [ :comment_id ] || params [ :id ] result = has_comment_access post_id , comment_id @comment = result [ :comment ] status = result [ :status ] head status if status != :ok end
Ensures user is owner of the comment and sets the
18,146
def has_comment_access ( post_id , comment_id ) comment = Unsakini :: Comment . where ( id : comment_id , post_id : post_id , user_id : @user . id ) . first if comment . nil? return { status : :forbidden , comment : comment } else return { status : :ok , comment : comment } end end
Validate if user has access to comment in the post
18,147
def with_closed_scope ( is_method = false ) old_in_method = @in_method @in_method ||= is_method @stack . push ( SCOPE_BLOCKER_9000 ) @stack . push ( Set . new ) yield ensure @stack . pop @stack . pop @in_method = old_in_method end
An open scope denies reference to local variables in enclosing scopes .
18,148
def has_variable? ( var ) @stack . reverse_each do | scope | if SCOPE_BLOCKER_9000 == scope return false elsif scope . include? ( var ) return true end end end
Checks if the given variable is in scope .
18,149
def create @comment = Comment . new ( params . permit ( :content ) ) @comment . user = @user @comment . post = @post if @comment . save render json : @comment else render json : @comment . errors , status : 422 end end
Creates new comment belonging to the post
18,150
def update if @comment . update ( params . permit ( :content ) ) render json : @comment else render json : @comment . errors , status : 422 end end
Updates a comment
18,151
def ensure_board board_id = params [ :board_id ] || params [ :id ] result = has_board_access ( board_id ) @board = result [ :board ] @user_board = result [ :user_board ] head result [ :status ] if result [ :status ] != :ok end
Ensure user has access to the board and sets the
18,152
def has_board_access ( board_id ) board = nil if ! board_id . nil? board = Unsakini :: Board . find_by_id ( board_id ) else return { status : :bad_request } end if ( board ) user_board = Unsakini :: UserBoard . where ( user_id : @user . id , board_id : board_id ) . first return { status : :forbidden } if user_board . n...
Validate if user has access to board
18,153
def send value LOCK . synchronize do unify @end . head , value unify @end . tail , Stream . new @end = @end . tail end end
Create a stream object bind it to the input variable Instance variables are necessary because
18,154
def make_mash_with_consistent_hash ( obj ) m = Hashie :: Mash . new ( obj ) def m . hash inspect . hash end return m end
Lame workaround for the fact that mash doesn t hash correctly
18,155
def each_word ( & block ) return enum_for ( __method__ ) unless block if @path File . open ( @path ) do | file | file . each_line do | line | yield line . chomp end end elsif @words @words . each ( & block ) end end
Iterates over each word in the list .
18,156
def each ( & block ) return enum_for ( __method__ ) unless block mutator = unless @mutations . empty? Fuzzing :: Mutator . new ( @mutations ) end each_word do | word | yield word if mutator mutator . each ( word , & block ) end end end
Iterates over each word and each mutation from the list .
18,157
def save ( path ) File . open ( path , 'w' ) do | file | each { | word | file . puts word } end return self end
Saves the words to a new file .
18,158
def load_owner unless params [ :owner_id ] . nil? if current_owner . present? searched_owner = current_owner . class . find ( params [ :owner_id ] ) rescue nil if searched_owner . nil? && current_owner . class . respond_to? ( :friendly ) searched_owner = current_owner . class . friendly . find ( params [ :owner_id ] ) ...
subscription . subscription_owner
18,159
def originate url , args = { } , & block extension = args . delete ( :extension ) dialplan = args . delete ( :dialplan ) context = args . delete ( :context ) vars = args . map { | k , v | "#{k}=#{v}" } . join ( "," ) arg_string = "{#{vars}}" + [ url , extension , dialplan , context ] . compact . join ( " " ) command "o...
Access the hash table that comes with FreeSWITCH .
18,160
def add_warning ( message , filename = @node . file , line_number = @node . line_number ) warnings << Warning . new ( filename : filename , line_number : line_number , message : message ) end
add an warning .
18,161
def call ( object ) current = target = object . class while current != Object if registry . key? ( current ) return registry . fetch ( current ) end current = current . superclass end fail TypeNotFoundError , target end
TypeNotFoundError Perform type lookup
18,162
def rubyify_keys! keys . each { | k | v = delete ( k ) new_key = k . to_s . underscore self [ new_key ] = v v . rubyify_keys! if v . is_a? ( Hash ) v . each { | p | p . rubyify_keys! if p . is_a? ( Hash ) } if v . is_a? ( Array ) } self end
Converts all of the keys to strings optionally formatting key name
18,163
def get_annotation_value annotationStmt raise "annotation should have one argument" unless annotationStmt . arguments . length == 1 return annotationStmt . arguments . first . to_s end
the annotation should have one argument and we just want whatever it is
18,164
def cost_of block assumes = block . select { | s | s . is_a? ( AssumeStatement ) } cost = assumes . inject ( 0 ) do | acc , stmt | if values = stmt . get_attribute ( :' ' ) acc += values . first . show . to_i end acc end return cost end
Iterates over timing annotations of a block and sums them up .
18,165
def extract_branches blocks branches = [ ] blocks . each do | block | block . each do | stmt | case stmt when GotoStatement next if stmt . identifiers . length < 2 unless stmt . identifiers . length == 2 fail "Unexpected goto statement: #{stmt}" end if annotation = stmt . previous_sibling fail "Expected :branchcond ann...
Given a set of blocks returns GotoStatement s of branches
18,166
def wordforms ( word , limit = 10 ) check_params ( word , limit ) arg1 = [ 'Word' , word ] arg2 = [ 'Limit' , limit ] answer = query ( @cl_Wordforms , arg1 , arg2 ) get_answer ( answer ) end
Two parameter methods .
18,167
def right_collocation_finder ( word , pos , limit = 10 ) check_params ( word , pos , limit ) arg1 = [ 'Wort' , word ] arg2 = [ 'Wortart' , pos ] arg3 = [ 'Limit' , limit ] answer = query ( @cl_RightCollocationFinder , arg1 , arg2 , arg3 ) get_answer ( answer ) end
Three parameter methods .
18,168
def cooccurrences ( word , sign , limit = 10 ) check_params ( word , sign , limit ) arg1 = [ 'Wort' , word ] arg2 = [ 'Mindestsignifikanz' , sign ] arg3 = [ 'Limit' , limit ] answer = query ( @cl_Cooccurrences , arg1 , arg2 , arg3 ) get_answer ( answer ) end
Returns statistically significant co - occurrences of the input word .
18,169
def get_answer ( doc , mod = '' ) result = [ ] XPath . each ( doc , "//result/*/*#{mod}" ) do | el | warn ( el . text ) if $DEBUG result << el . text end result . any? ? result : nil end
This method extracts valuable data from the XML structure of the soap response . It returns an array with extracted xml text nodes or nil if the service provided no answer .
18,170
def send_message ( topic , tag , body , key = '' ) @producer . send_message ( topic , tag , body , key ) end
Create a new aliyun ONS Producer instance .
18,171
def send_timer_message ( topic , tag , body , timer , key = '' ) @producer . send_timer_message ( topic , tag , body , timer . to_i * 1000 , key ) end
Send a timer message .
18,172
def distribute_results! response = JSON . parse ( @socket . readline ) if response [ "event" ] @event_queue << response else @result_queue << response end rescue StandardError @alive = false Thread . exit end
Distributes results to the event and result queues .
18,173
def dispatch_events! loop do event = @event_queue . pop callbacks . each do | callback | Thread . new do callback . call event end end end end
Takes events from the event queue and dispatches them to callbacks .
18,174
def find_google_ssh_public_key keyfile = ENV . fetch ( 'BEAKER_gce_ssh_public_key' , File . join ( ENV [ 'HOME' ] , '.ssh' , 'google_compute_engine.pub' ) ) if @options [ :gce_ssh_public_key ] && ! File . exist? ( keyfile ) keyfile = @options [ :gce_ssh_public_key ] end raise ( "Could not find GCE Public SSH Key at '#{...
Do some reasonable sleuthing on the SSH public key for GCE
18,175
def provision attempts = @options [ :timeout ] . to_i / SLEEPWAIT start = Time . now test_group_identifier = "beaker-#{start.to_i}-" machineType = @gce_helper . get_machineType ( start , attempts ) network = @gce_helper . get_network ( start , attempts ) @firewall = test_group_identifier + generate_host_name @gce_helpe...
Create a new instance of the Google Compute Engine hypervisor object
18,176
def cleanup ( ) attempts = @options [ :timeout ] . to_i / SLEEPWAIT start = Time . now @gce_helper . delete_firewall ( @firewall , start , attempts ) @hosts . each do | host | @gce_helper . delete_instance ( host [ 'vmhostname' ] , start , attempts ) @logger . debug ( "Deleted Google Compute instance #{host['vmhostname...
Shutdown and destroy virtual machines in the Google Compute Engine including their associated disks and firewall rules
18,177
def country_code_select ( priority_countries , options ) selected = object . send ( @method_name ) countries = "" if priority_countries countries += options_for_select ( priority_countries , selected ) countries += "<option value=\"\" disabled=\"disabled\">-------------</option>\n" elsif options [ :include_blank ] coun...
Adapted from Rails country_select . Just uses country codes instead of full names .
18,178
def index admin = true shared = false admin = params [ :is_admin ] == 'true' if params [ :admin ] shared = params [ :shared ] == 'true' if params [ :shared ] result = @user . user_boards . shared ( shared ) result = result . admin if admin paginate json : result , per_page : 10 end
Returns boards belonging to current user
18,179
def create @user_board = UserBoard . new ( name : params [ :board ] [ :name ] , user_id : @user . id , encrypted_password : params [ :encrypted_password ] , is_admin : true ) if @user_board . save render json : @user_board , status : :created else render json : @user_board . errors . full_messages , status : 422 end en...
Creates board belonging to current user .
18,180
def update if @user_board . update ( name : params [ :board ] [ :name ] , encrypted_password : params [ :encrypted_password ] ) render json : @user_board else errors = @board . errors . full_messages . concat @user_board . errors . full_messages render json : errors , status : 422 end end
Updates a single board .
18,181
def generate_url url , token , type , version case type when 'analyze' url = "http://api.diffbot.com/v3/#{type}?token=#{token}&url=#{url}" when 'custom' url = "http://api.diffbot.com/v3/#{options[:api_name]}?token=#{token}&url=#{url}" when 'article' , 'image' , 'product' url = "http://api.diffbot.com/v2/#{type}?token=#...
generate an url consisting of your api key and the endpoint you d like to use
18,182
def parse_options options = { } , request = '' options . each do | opt , value | case opt when :timeout , :paging , :mode request += "&#{opt}=#{value}" when :callback , :stats request += "&#{opt}" when :fields request += "&#{opt}=" + value . join ( ',' ) if value . is_a? ( Array ) end end request end
add the options hash to your input url
18,183
def info { name : name , rgb : rgb , hsb : hsb , hex : hex , mode : mode , dark : dark? } end
Returns information of the color object
18,184
def next ( n = 1 ) @@colorset [ mode ] ||= Colorable :: Colorset . new ( order : mode ) idx = @@colorset [ mode ] . find_index ( self ) @@colorset [ mode ] . at ( idx + n ) . tap { | c | c . mode = mode } if idx end
Returns a next color object in X11 colors . The color sequence is determined by its color mode .
18,185
def check ( filename , content ) @checkers . each do | checker | checker . check ( filename , content ) if checker . parse_file? ( filename ) end end
check the ruby plain code .
18,186
def ensure_post post_id = params [ :post_id ] || params [ :id ] board_id = params [ :board_id ] result = has_post_access ( board_id , post_id ) status = result [ :status ] @post = result [ :post ] head status if status != :ok end
Ensures user is owner of the post and sets the
18,187
def has_post_access ( board_id , post_id ) post = Unsakini :: Post . where ( id : post_id , board_id : board_id ) . joins ( "LEFT JOIN #{UserBoard.table_name} ON #{UserBoard.table_name}.board_id = #{Post.table_name}.board_id" ) . where ( "#{UserBoard.table_name}.user_id = ?" , @user . id ) . first if post . nil? return...
Validate if user has access to the post in the board
18,188
def compile_scss puts "\nCompiling assets for stylestats..." . color ( :blue ) if is_rails? Rails . application . load_tasks unless @config . is_dev? compile_scss_rails else load_compass compile_scss end end
Find all CSS files or compile .
18,189
def load_compass if Gem :: Specification :: find_all_by_name ( 'compass' ) . any? require 'compass' Compass . sass_engine_options [ :load_paths ] . each do | path | Sass . load_paths << path end end end
Load Compass paths if the gem exists
18,190
def load_scss_load_paths Dir . glob ( @path ) . select { | d | File . directory? d } . each do | directory | Sass . load_paths << directory end end
Add directories to load paths
18,191
def compile_scss_normal Dir [ "#{@path}.scss" ] . select { | f | File . file? f } . each do | file | next if File . basename ( file ) . chr == '_' scss_file = File . open ( file , 'rb' ) { | f | f . read } output_file = File . open ( file . split ( '.' ) . reverse . drop ( 1 ) . reverse . join ( '.' ) , "w" ) output_fi...
Turn scss files into css files Skips if the file starts with an underscore
18,192
def find_css ( path = @path ) Dir . glob ( path ) . select { | f | File . file? f } . map { | file | file } end
Find all css files
18,193
def create @post = Post . new ( params . permit ( :title , :content , :board_id ) ) @post . user = @user if ( @post . save ) render json : @post , status : :created else render json : @post . errors , status : 422 end end
Creates a single post belonging to the board
18,194
def encrypt ( value ) return value if is_empty_val ( value ) c = cipher . encrypt c . key = Digest :: SHA256 . digest ( cipher_key ) c . iv = iv = c . random_iv Base64 . encode64 ( iv ) + Base64 . encode64 ( c . update ( value . to_s ) + c . final ) end
Encrypts model attribute value
18,195
def decrypt ( value ) return value if is_empty_val ( value ) c = cipher . decrypt c . key = Digest :: SHA256 . digest ( cipher_key ) c . iv = Base64 . decode64 value . slice! ( 0 , 25 ) c . update ( Base64 . decode64 ( value . to_s ) ) + c . final end
Decrypts model attribute value
18,196
def transform ( root , opts = { } ) new_copy = opts [ :in_place ] ? root : clone_sexp ( root ) scope_stack = ScopeStack . new transform_tree ( new_copy , scope_stack ) new_copy end
Transforms the given AST into a RipperPlus AST .
18,197
def add_variables_from_node ( lhs , scope_stack , allow_duplicates = true ) case lhs [ 0 ] when :@ident scope_stack . add_variable ( lhs [ 1 ] , allow_duplicates ) when :const_path_field , :@const , :top_const_field if scope_stack . in_method? raise DynamicConstantError . new end when Array add_variable_list ( lhs , sc...
Adds variables to the given scope stack from the given node . Allows nodes from parameter lists left - hand - sides block argument lists and so on .
18,198
def transform_in_order ( tree , scope_stack ) range = Symbol === tree [ 0 ] ? 1 .. - 1 : 0 .. - 1 tree [ range ] . each do | subtree | if Array === subtree && ! ( Fixnum === subtree [ 0 ] ) transform_tree ( subtree , scope_stack ) end end end
If this node s subtrees are ordered as they are lexically as most are transform each subtree in order .
18,199
def transform_params ( param_node , scope_stack ) param_node = param_node [ 1 ] if param_node [ 0 ] == :paren if param_node positional_1 , optional , rest , positional_2 , block = param_node [ 1 .. 5 ] add_variable_list ( positional_1 , scope_stack , false ) if positional_1 if optional optional . each do | var , value ...
Transforms a parameter list and adds the new variables to current scope . Used by both block args and method args .