idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
19,700
def create_class ( class_element ) begin tt_class = Tableau :: Class . new ( @day , @time ) data = class_element . xpath ( 'table/tr/td//text()' ) raise "Misformed cell for #{module_id}" if data . count < 4 rescue Exception => e p "EXCEPTION: #{e.message}" , "Data Parsed:" , data return nil end if @@WEEKS_REGEX . match...
Create a Class from the given data element
19,701
def create_class_weeks ( week_data ) week_span_regex = / \d \d / week_start_regex = / / week_end_regex = / / week_single_regex = / \d / class_weeks = Array . new week_data . scan ( @@WEEKS_REGEX ) . each do | weekspan | if weekspan =~ week_span_regex start = week_start_regex . match ( weekspan ) [ 0 ] . to_i finish = w...
Create the week range array for the given week string
19,702
def create_all_data ( pParser ) return nil unless pParser wrapper = self pParser . fileLanguage . each do | listOfFile | listOfFile . fileElements . each do | singleElement | @outputEngine . kuniri do wrapper . handle_element ( singleElement ) end currentFilePathAndName = singleElement . name write_file ( currentFilePa...
Go through all the data and generate the output
19,703
def markdown ( text ) erbified = ERB . new ( text . html_safe ) . result ( binding ) red = Redcarpet :: Markdown . new ( Redcarpet :: Render :: HTML , :autolink => true , :space_after_headers => true ) red . render ( erbified ) . html_safe end
methods from application_helper
19,704
def gen_views t = [ "*** generate ui ***" ] $afile = Array . new Jinda :: Module . all . each do | m | m . services . each do | s | dir = "app/views/#{s.module.code}" unless gen_view_file_exist? ( dir ) gen_view_mkdir ( dir , t ) end if s . code == 'link' f = "app/views/#{s.module.code}/index.haml" $afile << f unless g...
Jinda Rake Task
19,705
def decode_work_type ( obj ) if obj [ 'type' ] =~ WORK_TYPE_WITH_PREFIX_PATTERN return 'GenericWork' if Regexp . last_match ( 2 ) . nil? Regexp . last_match ( 2 ) else work_type = obj [ 'type' ] . downcase WORK_TYPES [ work_type ] end end
Given an object s type detrmine and return its af - model
19,706
def run_local ( argument = @argument , main_class = 'net.sf.sail.emf.launch.EMFLauncher2' ) if RUBY_PLATFORM =~ / / java . lang . Thread . currentThread . setContextClassLoader ( JRuby . runtime . jruby_class_loader ) require_resources configUrl = URL . new ( JavaIO :: File . new ( "dummy.txt" ) . toURL , argument ) un...
This will start the jnlp locally in Java without using Java Web Start
19,707
def render_image_iterm2 return nil unless valid? screen = ENV [ 'TERM' ] . start_with? 'screen' prefix = screen ? "\ePtmux;\e\e]" : "\e]" suffix = screen ? "\a\e\\" : "\a" png = qrcode . as_png ( size : 600 ) png_base64 = Base64 . encode64 ( png . to_s ) . chomp options = 'inline=1' "#{prefix}1337;File=#{options}:#{png...
Render the QR code as an inline image for iTerm2 . Returns a string .
19,708
def remove_class ( rem_class ) @modules . each do | m | if m . name == rem_class . name m . classes . delete ( rem_class ) break end end end
Removes a class from the timetable
19,709
def classes_for_day ( day ) classes = Tableau :: ClassArray . new @modules . each do | mod | cfd = mod . classes_for_day ( day ) cfd . each { | cl | classes << cl } if cfd end classes . count > 0 ? classes : nil end
Returns an array of the given day s classes
19,710
def class_for_time ( day , time ) cfd = self . classes_for_day ( day ) cfd . each { | c | return c if c . time == time } nil end
Returns the class at the given day & time
19,711
def earliest_class earliest_classes = Tableau :: ClassArray . new @modules . each { | m | earliest_classes << m . earliest_class } earliest = earliest_classes . first earliest_classes . each { | c | earliest = c if c . time < earliest . time } earliest end
Returns the earliest class on the timetable
19,712
def conflicts conflicts = Tableau :: ClassArray . new ( 0 .. 4 ) . each do | day | days_classes = self . classes_for_day ( day ) next if ! days_classes || days_classes . count == 0 last = days_classes . count - 1 for i in 0 .. last i_c = days_classes [ i ] time_range = i_c . time .. ( i_c . time + 3600 * i_c . duration...
Returns an array of time conflicts found in the timetable
19,713
def render_hash ( hsh ) str = "" indiff_hsh = hsh . with_indifferent_access indiff_hsh . keys . sort . each do | key | str << "#{key}: " value = indiff_hsh [ key ] PP :: pp ( value , str ) end str end
renders hashes with keys in alpha - sorted order
19,714
def html ( string ) ptr = Libcgraph . agstrdup_html ( graph . ptr , string ) string = ptr . read_string Libcgraph . agstrfree graph . ptr , ptr string end
Creates an HTML label
19,715
def edge ( name , tail , head , attrs = { } ) component Edge , [ name , tail , head ] , attrs end
Creates a new edge
19,716
def sub_graph ( name , attrs = { } ) graph = component SubGraph , [ name ] , attrs yield graph if block_given? graph end
Creates a new sub - graph
19,717
def save ( filename , format = 'png' , layout = 'dot' ) Libgvc . gvLayout ( @@gvc , ptr , layout . to_s ) Libgvc . gvRenderFilename ( @@gvc , ptr , format . to_s , filename ) ; Libgvc . gvFreeLayout ( @@gvc , ptr ) nil end
Renders the graph to an images and saves the result to a file
19,718
def render ( format = 'png' , layout = 'dot' ) Libgvc . gvLayout ( @@gvc , ptr , layout . to_s ) data_ptr = FFI :: MemoryPointer . new ( :pointer , 1 ) len_ptr = FFI :: MemoryPointer . new ( :int , 1 ) Libgvc . gvRenderData ( @@gvc , ptr , format . to_s , data_ptr , len_ptr ) len = len_ptr . read_uint data_ptr = data_p...
Renders the graph to an image and returns the result as a string
19,719
def setup_variable_behaviour expression = MODULEBASE + type_of_language + VARIABLECLASS + type_of_language begin clazz = Object . const_get ( expression ) @variableBehaviour = clazz . new ( who_am_i ) rescue NameError Util :: LoggerKuniri . error ( 'Class name error' ) end end
Setup basic configurations for make attribute work correctly . It is mandatory to call it with the correct parameters in the child class .
19,720
def analyse_source ( pPath ) @name = File . basename ( pPath , ".*" ) @path = File . dirname ( pPath ) analyse_first_step ( pPath ) analyse_second_step end
Analyse source code .
19,721
def start_parser if ( @filesPath . empty? ) raise Error :: ConfigurationFileError , "Source path not have #{@language} files." end @filesPath . each do | file | language = @factory . get_language ( @language ) fileElement = Languages :: FileElementData . new ( file ) source = File . open ( file , 'rb' ) language . anal...
Start parse in the project .
19,722
def callback ( callback_type ) callback_class = "#{callback_type.camelize}Callback" callback_file = "callback/#{callback_type}_callback" begin instantiate_callback callback_file , callback_class , callback_type rescue LoadError => error if @@allowed_payneteasy_callback_types . include? callback_type instantiate_callbac...
Get callback processor by callback type
19,723
def instantiate_callback ( callback_file , callback_class , callback_type ) require callback_file PaynetEasy :: PaynetEasyApi :: Callback . const_get ( callback_class ) . new ( callback_type ) end
Load callback class file and return new callback object
19,724
def equal_children? ( other ) self . class . children . all? { | child | send ( child ) == other . send ( child ) } end
Compares this node with another node returns true if the nodes are equal . Returns true if all children of the current object and the other object are equal .
19,725
def equal_leafs? ( other ) self . class . leafs . all? { | leaf | send ( leaf ) == other . send ( leaf ) } end
Returns true if all leaf values of the current object and the other object are equal .
19,726
def benchmark ( times = 1 , & block ) elapsed = ( 1 .. times ) . collect do GC . start :: Benchmark . realtime ( & block ) * times end Result . new ( elapsed ) end
Run a given block and calculate the average execution time . The block will be executed 1 times by default .
19,727
def format ( options ) options . map do | key , value | [ { format : :f , size : :s , length : :hls_time , } [ key ] || key , value ] . map ( & :to_s ) . join ( '=' ) end end
Formats keys to melt arguments
19,728
def melt_args ( options ) [ options [ :infile ] , "-consumer avformat:#{outfile}" , ] . concat ( pipe ( options , %i[ symbolize_keys add_defaults select transform table format ] ) ) end
Constructs melt arguments from options hash
19,729
def render! cmd = melt melt_args ( options . merge ( outfile : outfile ) ) . join ( ' ' ) puts "Run: #{cmd}" puts run ( cmd ) do | _stdin , _stdout , stderr | stderr . each ( "\r" ) do | line | STDOUT . write "\r#{line}" end end end
Renders the project
19,730
def select ( options ) options = options . clone options . delete ( :real_time ) unless options . delete ( :enable_real_time ) options . select do | key , value | ! value . nil? && %i[ format hls_list_size real_time length preset size start_number vcodec ] . include? ( key ) end end
Selects certain options
19,731
def table ( options ) lpadding = options . keys . max_by ( & :length ) . length + 2 rpadding = options . values . max_by { | v | v . to_s . length } . to_s . length puts 'PROPERTY' . ljust ( lpadding ) + 'VALUE' puts '=' * ( lpadding + rpadding ) options . keys . sort . each do | key | puts key . to_s . ljust ( lpaddin...
Prints a table and passes through the options hash
19,732
def transform ( options ) options . map do | key , value | [ key , ( { real_time : -> ( x ) { "-#{x}" } , } [ key ] || proc { | x | x } ) . call ( value ) ] end . to_h end
Transforms certain options values
19,733
def items @items = [ ] @data . each do | object_data | if object_data [ "type" ] @items << "Skydrive::#{object_data["type"].capitalize}" . constantize . new ( client , object_data ) elsif object_data [ "id" ] . match / \. / @items << Skydrive :: Comment . new ( client , object_data ) end end @items end
Array of items in the collection
19,734
def read_attribute ( field , context ) if field . multivalued? arr = json_attributes [ field . name ] unless arr arr = EmbeddedDocumentArray . new ( field . type , context ) json_attributes [ field . name ] = arr end return arr else val = json_attributes [ field . name ] if val . nil? and ! field . default . nil? val =...
Read a field . The field param must be a FieldDefinition and the context should be the record which is being read from .
19,735
def write_attribute ( field , val , context ) if field . multivalued? val = val . values if val . is_a? ( Hash ) json_attributes [ field . name ] = EmbeddedDocumentArray . new ( field . type , context , val ) else old_value = read_attribute ( field , context ) converted_value = field . convert ( val ) converted_value ....
Write a field . The field param must be a FieldDefinition and the context should be the record which is being read from .
19,736
def method_missing ( method_name , * args , & block ) mapped_key = key_map [ method_name . to_sym ] if attributes . has_key? ( mapped_key ) attributes [ mapped_key ] else super end end
Look for one of the mapped keys and return the value or throw method missing error .
19,737
def add_global_variable ( * pVariable ) pVariable . flatten . each do | element | next unless element . is_a? ( Languages :: VariableGlobalData ) @global_variables . push ( element ) end end
Add global variable inside file .
19,738
def permitted? ( model_name , requested_flags = 0 ) return false if self . kind != Kind :: ROLE return true if admin? p = self . model_permissions . find_by_model ( model_name ) if requested_flags == 0 p else p && p . permitted? ( requested_flags ) end end
return true if the role has enough permission on the controller .
19,739
def auth url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/auth" payload = { app : { name : @client . app_info [ :name ] , version : @client . app_info [ :version ] , vendor : @client . app_info [ :vendor ] , id : @client . app_info [ :id ] } , permissions : @client . app_info [ :permissions ] } uri = URI ( ur...
Any application that wants to access API endpoints that require authorised access must receive an authorisation token from SAFE Launcher .
19,740
def is_token_valid url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/auth" uri = URI ( url ) http = Net :: HTTP . new ( uri . host , uri . port ) req = Net :: HTTP :: Get . new ( uri . path , { 'Authorization' => "Bearer #{@client.key_helper.get_token()}" } ) res = http . request ( req ) res . code == "200" en...
Check whether the authorisation token obtained from SAFE Launcher is still valid .
19,741
def revoke_token url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/auth" uri = URI ( url ) http = Net :: HTTP . new ( uri . host , uri . port ) req = Net :: HTTP :: Delete . new ( uri . path , { 'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}" } ) res = http . request ( req ) res . code == "...
Revoke the authorisation token obtained from SAFE Launcher .
19,742
def create_directory ( dir_path , options = { } ) options [ :root_path ] = 'app' if ! options . has_key? ( :root_path ) options [ :is_private ] = true if ! options . has_key? ( :is_private ) url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/directory/#{options[:root_path]}/#{SafeNet.escape(dir_path)}" payl...
Create a public or private directory either in the application s root directory or in SAFE Drive . Only authorised requests can create a directory .
19,743
def get_directory ( dir_path , options = { } ) options [ :root_path ] = 'app' if ! options . has_key? ( :root_path ) url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/directory/#{options[:root_path]}/#{SafeNet.escape(dir_path)}" uri = URI ( url ) http = Net :: HTTP . new ( uri . host , uri . port ) req = N...
Fetch a directory . Only authorised requests can invoke this API .
19,744
def create_file ( file_path , contents , options = { } ) options [ :root_path ] = 'app' if ! options . has_key? ( :root_path ) contents ||= "" url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/file/#{options[:root_path]}/#{SafeNet.escape(file_path)}" uri = URI ( url ) http = Net :: HTTP . new ( uri . host ...
Create a file . Only authorised requests can invoke the API .
19,745
def get_file_meta ( file_path , options = { } ) options [ :root_path ] = 'app' if ! options . has_key? ( :root_path ) url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/file/#{options[:root_path]}/#{SafeNet.escape(file_path)}" uri = URI ( url ) http = Net :: HTTP . new ( uri . host , uri . port ) headers = ...
Fetch the metadata of a file . Only authorised requests can invoke the API .
19,746
def get_file ( file_path , options = { } ) options [ :offset ] = 0 if ! options . has_key? ( :offset ) options [ :root_path ] = 'app' if ! options . has_key? ( :root_path ) url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/file/#{options[:root_path]}/#{SafeNet.escape(file_path)}?" query = [ ] query << "off...
Read a file . The file can be streamed in chunks and also fetched as partial content based on the range header specified in the request . Only authorised requests can invoke the API .
19,747
def move_file ( src_root_path , src_path , dst_root_path , dst_path , action = 'move' ) url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/movefile" payload = { } payload [ "srcRootPath" ] = src_root_path payload [ "srcPath" ] = src_path payload [ "destRootPath" ] = dst_root_path payload [ "destPath" ] = ds...
Move or copy a file
19,748
def delete_file ( file_path , options = { } ) options [ :root_path ] = 'app' if ! options . has_key? ( :root_path ) url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/nfs/file/#{options[:root_path]}/#{SafeNet.escape(file_path)}" uri = URI ( url ) http = Net :: HTTP . new ( uri . host , uri . port ) req = Net ::...
Delete a file . Only authorised requests can invoke the API .
19,749
def register_service ( long_name , service_name , service_home_dir_path , options = { } ) url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/dns" payload = { longName : long_name , serviceName : service_name , rootPath : 'app' , serviceHomeDirPath : service_home_dir_path , } payload [ "metadata" ] = options [ :...
Register a long name and a service . Only authorised requests can invoke the API .
19,750
def set ( name , contents = '' , type = 500 ) sd = @client . sd . update ( name , contents ) if sd . is_a? ( Hash ) && ( sd [ "errorCode" ] == - 22 ) sd = @client . sd . create ( name , contents ) end sd end
create or update
19,751
def to_file ( file = suggested_filename ) execute do | contents | if file . is_a? ( String ) FileUtils . mv contents , file else file . write contents . read file . rewind end end file end
Save the PDF to the file
19,752
def execute latex = compile_latex Dir . mktmpdir do | dir | @pass_count = 0 @log = '' success = false while log_suggests_rerunning? && @pass_count < 5 @pass_count += 1 success = execute_xelatex ( latex , dir ) end pdf_file = Pathname . new ( dir ) . join ( "output.pdf" ) if success && pdf_file . exist? yield pdf_file e...
Compile the Latex template into a PDF file
19,753
def compile_latex begin context = @context . new ( @partials_path || @view . dirname , @data ) content = ErbLatex :: File . evaluate ( @view , context . getBinding ) if layout ErbLatex :: File . evaluate ( layout_file , context . getBinding { content } ) else content end rescue LocalJumpError => e raise LatexError . ne...
Runs the ERB pre - process on the latex file
19,754
def execute_xelatex ( latex , dir ) success = false @log = '' if @packages_path ENV [ 'TEXINPUTS' ] = "#{@packages_path}:" end Open3 . popen2e ( ErbLatex . config . xelatex_path , "--no-shell-escape" , "-shell-restricted" , "-jobname=output" , "-output-directory=#{dir}" , ) do | stdin , output , wait_thr | stdin . writ...
Execute xelatex on the file .
19,755
def to_sql ( options = { } ) sql = "UPDATE #{table.to_sql(options)} SET " sql << updates . map { | u | u . to_sql ( options ) } . join ( ', ' ) sql << " WHERE " << where . to_sql ( options ) if self . where sql end
Generates the SQL UPDATE query .
19,756
def attributes ( @original_attributes || { } ) . merge ( @attributes ) . keys . inject ( { } ) do | hash , key | hash [ key ] = read_attribute ( key ) hash end end
Returns a hash of attributes .
19,757
def modify_attribute ( action , key , * values ) key = Ldaptic . encode ( key ) values . flatten! . map! { | v | Ldaptic . encode ( v ) } @original_attributes [ key ] ||= [ ] virgin = @original_attributes [ key ] . dup original = Ldaptic :: AttributeSet . new ( self , key , @original_attributes [ key ] ) original . __s...
Note the values are not typecast and thus must be strings .
19,758
def method_missing ( method , * args , & block ) attribute = Ldaptic . encode ( method ) if attribute [ - 1 ] == ?= attribute . chop! if may_must ( attribute ) return write_attribute ( attribute , * args , & block ) end elsif attribute [ - 1 ] == ?? attribute . chop! if may_must ( attribute ) if args . empty? return ! ...
Delegates to + read_attribute + or + write_attribute + . Pops an element out of its set if the attribute is marked SINGLE - VALUE .
19,759
def reload new = search ( :scope => :base , :limit => true ) @original_attributes = new . instance_variable_get ( :@original_attributes ) @attributes = new . instance_variable_get ( :@attributes ) @dn = Ldaptic :: DN ( new . dn , self ) @children = { } self end
Refetches the attributes from the server .
19,760
def sort_classes ( timetable , classes ) classes . each do | c | if ! ( cmodule = timetable . module_for_code ( c . code ) ) cmodule = Tableau :: Module . new ( c . code ) timetable . push_module ( cmodule ) end cmodule . add_class ( c ) end end
Sort all the parsed classes into modules
19,761
def fetch ( options = { } ) params = { :USERNAME => @username , :PASSWORD => @password , :VNDNUMBER => @vadnumber } params [ :TYPEOFREPORT ] = options [ :type_of_report ] || REPORT_TYPE_SALES params [ :DATETYPE ] = options [ :date_type ] || DATE_TYPE_DAILY params [ :REPORTTYPE ] = options [ :report_type ] || REPORT_SUM...
Create new instance of Fetcher
19,762
def partial ( template , data = { } ) context = self . class . new ( @directory , data ) ErbLatex :: File . evaluate ( Pathname . new ( template ) , context . getBinding , @directory ) end
create new Context
19,763
def add_attribute ( pAttribute ) pAttribute . each do | attributeElement | next unless attributeElement . is_a? ( Languages :: AttributeData ) @attributes . push ( attributeElement ) end end
Add attribute to class data notice the possibility of call this method more than one time .
19,764
def bundles_set ( bundle_or_name , tags = [ ] ) params = prepare_bundles_set_params ( bundle_or_name , tags ) response = request ( API_PATH_BUNDLES_SET , params ) parse_and_eval_execution_response ( response . body ) end
Assignes a set of tags to a single bundle wipes away previous settings for bundle .
19,765
def tags_rename ( from_name_or_tag , to_name_or_tag ) params = prepare_tags_rename_params ( from_name_or_tag , to_name_or_tag ) response = request ( API_PATH_TAGS_RENAME , params ) parse_and_eval_execution_response ( response . body ) end
Renames an existing tag with a new tag name .
19,766
def posts_recent ( options = { } ) params = prepare_posts_params ( options . clone , [ :count , :tag ] ) response = request ( API_PATH_POSTS_RECENT , params ) parse_post_collection ( response . body ) end
Returns a list of the most recent posts filtered by argument .
19,767
def posts_all ( options = { } ) params = prepare_posts_params ( options . clone , [ :tag ] ) response = request ( API_PATH_POSTS_ALL , params ) parse_post_collection ( response . body ) end
Returns a list of all posts filtered by argument .
19,768
def posts_dates ( options = { } ) params = prepare_posts_params ( options . clone , [ :tag ] ) response = request ( API_PATH_POSTS_DATES , params ) parse_posts_dates_response ( response . body ) end
Returns a list of dates with the number of posts at each date .
19,769
def posts_delete ( url ) params = prepare_posts_params ( { :url => url } , [ :url ] ) response = request ( API_PATH_POSTS_DELETE , params ) parse_and_eval_execution_response ( response . body ) end
Deletes the post matching given + url + from del . icio . us . + url + can be either an URI instance or a string representation of a valid URL .
19,770
def init_http_client ( options ) http = Net :: HTTP . new ( @base_uri . host , 443 ) http . use_ssl = true if @base_uri . scheme == "https" http . verify_mode = OpenSSL :: SSL :: VERIFY_NONE self . http_client = http end
Initializes the HTTP client . It automatically enable + use_ssl + flag according to +
19,771
def http_build_query ( params = { } ) params . collect do | k , v | "#{URI.encode(k.to_s)}=#{URI.encode(v.to_s)}" unless v . nil? end . compact . join ( '&' ) end
Composes an HTTP query string from an hash of + options + . The result is URI encoded .
19,772
def request ( path , params = { } ) raise Error , 'Invalid HTTP Client' unless http_client wait_before_new_request uri = @base_uri . merge ( path ) uri . query = http_build_query ( params ) unless params . empty? begin @last_request = Time . now @last_request_uri = uri response = make_request ( uri ) rescue => e raise ...
Sends an HTTP GET request to + path + and appends given + params + .
19,773
def make_request ( uri ) http_client . start do | http | req = Net :: HTTP :: Get . new ( uri . request_uri , @headers ) req . basic_auth ( @username , @password ) http . request ( req ) end end
Makes the real HTTP request to given + uri + and returns the + response + . This method exists basically to simplify unit testing with mocha .
19,774
def parse_update_response ( body ) dom = parse_and_validate_response ( body , :root_name => 'update' ) dom . root . if_attribute_value ( :time ) { | v | Time . parse ( v ) } end
Parses the response of an Update request and returns the update Timestamp .
19,775
def prepare_tags_rename_params ( from_name_or_tag , to_name_or_tag ) from , to = [ from_name_or_tag , to_name_or_tag ] . collect do | v | prepare_param_tag ( v ) end { :old => from , :new => to } end
Prepares the params for a tags_rename call and returns a Hash with the params ready for the HTTP request .
19,776
def prepare_param_post ( post_or_values , & block ) post = case post_or_values when WWW :: Delicious :: Post post_or_values when Hash Post . new ( post_or_values ) else raise ArgumentError , 'Expected `args` to be `WWW::Delicious::Post` or `Hash`' end yield ( post ) if block_given? raise ArgumentError , 'Both `url` and...
Prepares the + post + param for an API request .
19,777
def prepare_param_bundle ( name_or_bundle , tags = [ ] , & block ) bundle = case name_or_bundle when WWW :: Delicious :: Bundle name_or_bundle else Bundle . new ( :name => name_or_bundle , :tags => tags ) end yield ( bundle ) if block_given? bundle end
Prepares the + bundle + param for an API request .
19,778
def prepare_param_tag ( name_or_tag , & block ) tag = case name_or_tag when WWW :: Delicious :: Tag name_or_tag else Tag . new ( :name => name_or_tag . to_s ) end yield ( tag ) if block_given? raise "Invalid `tag` value supplied" unless tag . api_valid? tag end
Prepares the + tag + param for an API request .
19,779
def compare_params ( params , valid_params ) raise ArgumentError , "Expected `params` to be a kind of `Hash`" unless params . kind_of? ( Hash ) raise ArgumentError , "Expected `valid_params` to be a kind of `Array`" unless valid_params . kind_of? ( Array ) difference = params . keys - valid_params raise Error , "Invali...
Checks whether user given + params + are valid against a defined collection of + valid_params + .
19,780
def deals ( query = { } ) division = query . delete ( :division ) query . merge! :client_id => @api_key path = division ? "/#{division}" : "" path += "/deals.json" self . class . get ( path , :query => query ) . deals end
Returns a list of deals .
19,781
def []= ( * args ) raise ArgumentError => 'wrong number of arguments' unless args . size > 1 unless args [ - 1 ] . is_a? ( Sycl :: Hash ) || args [ - 1 ] . is_a? ( Sycl :: Array ) args [ - 1 ] = Sycl :: from_object ( args [ - 1 ] ) end super end
Make sure that if we write to this array we promote any inputs to their Sycl equivalents . This lets dot notation styled YAML and other Sycl goodies continue .
19,782
def []= ( k , v ) unless v . is_a? ( Sycl :: Hash ) || v . is_a? ( Sycl :: Array ) v = Sycl :: from_object ( v ) end super end
Make sure that if we write to this hash we promote any inputs to their Sycl equivalents . This lets dot notation styled YAML and other Sycl goodies continue .
19,783
def first_day_of ( klass_name ) klass = klass_name . to_s . constantize klass . order ( "created_at ASC" ) . first . try ( :created_at ) || Time . now end
returns the earliest created_at of a given class returns Time . now if none is available
19,784
def read_file_or_stdin ( filename = nil ) filename . nil? ? ! STDIN . tty? && STDIN . read : File . read ( filename ) end
Reads a file or from STDIN if piped
19,785
def run ( * args , & block ) return Open3 . popen3 ( * args , & block ) if block_given? Open3 . popen3 ( * args ) end
Delegates to Open3
19,786
def symbolize_keys ( hash ) hash . each_with_object ( { } ) { | ( k , v ) , memo | memo [ k . to_sym ] = v } end
Symbolizes a hash s keys
19,787
def tcfg_get ( key ) t_tcfg = tcfg unless t_tcfg . key? key raise NoSuchConfigurationKeyError , "No configuration defined for '#{key}'" end t_tcfg [ key ] end
return a single piece of configuration by key
19,788
def get_language ( pType ) pType . downcase! return Languages :: RubySyntax . new if pType == 'ruby' raise Error :: LanguageError end
Handling the class creation .
19,789
def concat ( objects ) objects = objects . collect do | obj | obj = @klass . new ( obj ) if obj . is_a? ( Hash ) raise ArgumentError . new ( "#{obj.inspect} is not a #{@klass}" ) unless obj . is_a? ( @klass ) obj . parent = @parent obj end super ( objects ) end
Concatenate an array of objects to the array . The objects must either be an EmbeddedDocument of the correct class or a Hash .
19,790
def build ( obj ) obj = @klass . new ( obj ) if obj . is_a? ( Hash ) raise ArgumentError . new ( "#{obj.inspect} is not a #{@klass}" ) unless obj . is_a? ( @klass ) obj . parent = @parent self << obj obj end
Similar add an EmbeddedDocument to the array and return the object . If the object passed in is a Hash it will be used to make a new EmbeddedDocument .
19,791
def put url , body = nil , options = { } response = filtered_response ( self . class . put ( url , { :body => body , :query => options , headers : { 'content-type' => '' } } ) ) end
Do a put request
19,792
def filtered_response response raise Skydrive :: Error . new ( { "code" => "no_response_received" , "message" => "Request didn't make through or response not received" } ) unless response if response . success? filtered_response = response . parsed_response if response . response . code =~ / / raise Skydrive :: Error ....
Filter the response after checking for any errors
19,793
def get_output ( pType ) pType . downcase! return XMLOutputFormat . new if pType == 'xml' raise Error :: ParserError if pType == 'yml' end
Handling the output tyoe .
19,794
def method_missing ( name , * args , & block ) if writable_master . respond_to? ( name ) Client . send ( :send_to_master , name ) send ( name , * args , & block ) else super end end
Send everything else to master .
19,795
def process_callback ( payment_transaction , callback_response ) begin validate_callback payment_transaction , callback_response rescue Exception => error payment_transaction . add_error error payment_transaction . status = PaymentTransaction :: STATUS_ERROR raise error end update_payment_transaction payment_transactio...
Process API gateway Response and update Payment transaction
19,796
def validate_signature ( payment_transaction , callback_response ) expected_control_code = Digest :: SHA1 . hexdigest ( callback_response . status + callback_response . payment_paynet_id . to_s + callback_response . payment_client_id . to_s + payment_transaction . query_config . signing_key ) if expected_control_code !...
Validate callback response control code
19,797
def update_payment_transaction ( payment_transaction , callback_response ) payment_transaction . status = callback_response . status payment_transaction . payment . paynet_id = callback_response . payment_paynet_id if callback_response . error? || callback_response . declined? payment_transaction . add_error callback_r...
Updates Payment transaction by Callback data
19,798
def report_errors begin yield true rescue Exception => error say 'massimo had a problem' , :red indent do say error . message , :magenta say error . backtrace . first , :magenta end growl "#{error.message}\n#{error.backtrace.first}" , 'massimo problem' false end end
Run the given block and cleanly report any errors
19,799
def method_missing ( method , * args ) method = method . to_s method_class = method_as_class ( method ) options = args . last . is_a? ( Hash ) ? args . pop : { } FreshdeskAPI :: Collection . new ( self , method_class , options ) end
Handles resources such as tickets .