idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
9,700 | def calculate_sort_name_and_direction ( user_params = { } ) default_column , default_direction = ( configuration [ :default_sort_order ] || "updated_at:desc" ) . split ( ":" ) sort_name , direction = user_params [ 'order' ] . to_s . split ( ":" ) unless sort_name . present? && configuration [ :sort_orders ] [ sort_name... | Clean and validate a sort order and direction from user params . |
9,701 | def call if requested_command && commands . has_key? ( requested_command ) self . command_method = commands [ requested_command ] . method ( :call ) end command_method . call ( _args . drop ( 1 ) ) self end | Creates a new instance of the Cli to respond to user input . |
9,702 | def properties = value value . each do | k , v | self . add_property k . to_s , v end end | assign hash to properties |
9,703 | def selectors = value value . each do | k , v | self . add_selector k . to_s , v end end | assign hash to selectors |
9,704 | def handle_class_module ( class_mod , class_name , options = { } ) progress ( class_mod [ 0 , 1 ] ) parent = options [ :parent ] parent_name = @known_classes [ parent ] || parent if @@module_name enclosure = @top_level . find_module_named ( @@module_name ) else enclosure = @top_level end if class_mod == "class" cm = en... | handle class or module |
9,705 | def recognize ( max_samples = 2048 , & b ) unless ALGORITHMS . include? ( algorithm ) raise NotImplementedError , "Unknown speech recognition algorithm: #{algorithm}" end start unless recognizing? FFI :: MemoryPointer . new ( :int16 , max_samples ) do | buffer | loop do send ( "recognize_#{algorithm}" , max_samples , b... | Recognize speech and yield hypotheses in infinite loop |
9,706 | def recognize_continuous ( max_samples , buffer ) process_audio ( buffer , max_samples ) . tap do if hypothesis = decoder . hypothesis decoder . end_utterance yield hypothesis decoder . start_utterance end end end | Yields as soon as any hypothesis is available |
9,707 | def decode ( audio_path_or_file , max_samples = 2048 ) case audio_path_or_file when String File . open ( audio_path_or_file , 'rb' ) { | f | decode_raw ( f , max_samples ) } else decode_raw ( audio_path_or_file , max_samples ) end end | Decode a raw audio stream as a single utterance opening a file if path given |
9,708 | def decode_raw ( audio_file , max_samples = 2048 ) start_utterance FFI :: MemoryPointer . new ( :int16 , max_samples ) do | buffer | while data = audio_file . read ( max_samples * 2 ) buffer . write_string ( data ) process_raw ( buffer , data . length / 2 ) end end end_utterance end | Decode a raw audio stream as a single utterance . |
9,709 | def process_raw ( buffer , size , no_search = false , full_utt = false ) api_call :ps_process_raw , ps_decoder , buffer , size , no_search ? 1 : 0 , full_utt ? 1 : 0 end | Decode raw audio data . |
9,710 | def log_prob_to_linear ( log_prob ) logmath = ps_api . ps_get_logmath ( ps_decoder ) ps_api . logmath_exp ( logmath , log_prob ) end | Convert logarithmic probability to linear floating point |
9,711 | def read_audio ( buffer , max_samples = 2048 ) samples = ps_api . ad_read ( @ps_audio_device , buffer , max_samples ) samples if samples >= 0 end | Read next block of audio samples while recording ; read upto max samples into buf . |
9,712 | def read_audio ( buffer , max_samples = 2048 ) if file . nil? raise "Can't read audio: use AudioFile#start_recording to open the file first" end if data = file . read ( max_samples * 2 ) buffer . write_string ( data ) data . length / 2 end end | Read next block of audio samples from file ; up to max samples into buffer . |
9,713 | def on_threadpool? tp = nil @mutex . synchronize do return false unless @threadpool tp = @threadpool . dup end tp . respond_to? ( :include? ) and tp . include? ( Thread . current ) end | returns true if the current thread is one of the threadpool threads |
9,714 | def process ( event , watch_type = nil ) @zk . raw_event_handler ( event ) logger . debug { "EventHandler#process dispatching event for #{watch_type.inspect}: #{event.inspect}" } event . zk = @zk cb_keys = if event . node_event? [ event . path , ALL_NODE_EVENTS_KEY ] elsif event . session_event? [ state_key ( event . s... | called from the Client registered callback when an event fires |
9,715 | def restricting_new_watches_for? ( watch_type , path ) synchronize do if set = @outstanding_watches [ watch_type ] return set . include? ( path ) end end false end | returns true if there s a pending watch of type for path |
9,716 | def delete_message ( message_title ) full_path = "#{full_queue_path}/#{message_title}" locker = @zk . locker ( "#{full_queue_path}/#{message_title}" ) if locker . lock! begin @zk . delete ( full_path ) return true ensure locker . unlock! end else return false end end | you barely ever need to actually use this method but lets you remove a message from the queue by specifying its title |
9,717 | def destroy! unsubscribe children = @zk . children ( full_queue_path ) locks = [ ] children . each do | path | lock = @zk . locker ( "#{full_queue_path}/#{path}" ) lock . lock! locks << lock end children . each do | path | begin @zk . delete ( "#{full_queue_path}/#{path}" ) rescue ZK :: Exceptions :: NoNode end end beg... | highly destructive method! WARNING! Will delete the queue and all messages in it |
9,718 | def shutdown ( timeout = 5 ) @mutex . lock begin return true if @state == :shutdown @state = :shutdown @cond . broadcast ensure @mutex . unlock rescue nil end return true unless @thread unless @thread . join ( timeout ) == @thread logger . error { "#{self.class} timed out waiting for dispatch thread, callback: #{callba... | how long to wait on thread shutdown before we return |
9,719 | def wait_until_blocked ( timeout = nil ) @mutex . synchronize do return true unless @blocked == NOT_YET start = Time . now time_to_stop = timeout ? ( start + timeout ) : nil logger . debug { "#{__method__} @blocked: #{@blocked.inspect} about to wait" } @cond . wait ( timeout ) if ( time_to_stop and ( Time . now > time_... | this is for testing allows us to wait until this object has gone into blocking state . |
9,720 | def wait_for_result ( timeout ) time_to_stop = timeout ? ( Time . now + timeout ) : nil until @result if timeout now = Time . now if @result return elsif ( now >= time_to_stop ) @result = TIMED_OUT return end @cond . wait ( time_to_stop . to_f - now . to_f ) else @cond . wait_until { @result } end end end | this method must be synchronized on |
9,721 | def watch_appropriate_nodes remaining_paths . last ( threshold + 1 ) . reverse_each do | path | next if watched_paths . include? path watched_paths << path finish_node ( path ) unless zk . exists? ( path , :watch => true ) end end | ensures that threshold + 1 nodes are being watched |
9,722 | def require_service_provider_library ( service , provider ) require "fog/#{provider}/#{service}" rescue LoadError Fog :: Logger . deprecation ( "Unable to require fog/#{provider}/#{service}" ) Fog :: Logger . deprecation ( format ( E_SERVICE_PROVIDER_PATH , service : service , provider : provider ) ) require "fog/#{ser... | This method should be removed once all providers are extracted . Bundler will correctly require all dependencies automatically and thus fog - core wont need to know any specifics providers . Each provider will have to load its dependencies . |
9,723 | def apply ( config ) config . debug = debug? config . fde = fde? if config . fde? config . homedir = homedir if homedir config . logfile = logfile if logfile config . login = login if login config . token = token if token config . pretend = pretend? config . profile = profile? config . future_parser = future_parser? co... | Create a new instance optionally providing CLI args to parse immediately . Apply these flags to config . Returns config . |
9,724 | def construct_hash vars = instance_variables . reject { | x | [ :@client , :@original ] . include? x } Hash [ vars . map { | key | [ key . to_s [ 1 .. key . length ] , instance_variable_get ( key ) ] } ] end | Construct hash from mutated parameters |
9,725 | def create_subscription ( opts ) resp = raw_post make_subscription_url ( opts . merge ( { :use_subscription_id => true } ) ) , EMPTY_BODY , make_headers ( opts ) [ resp . status , extract_response_body ( resp ) ] end | Creates a notification subscription |
9,726 | def remove_subscription ( opts ) resp = raw_delete make_subscription_url ( opts . merge ( { :use_subscription_id => true } ) ) , make_headers ( opts ) [ resp . status , extract_response_body ( resp ) ] end | Removes a notification subscription |
9,727 | def validate_subscription_type ( subscription_type ) unless subscription_type && SUBSCRIBABLE_TYPES . include? ( subscription_type ) raise Fitgem :: InvalidArgumentError , "Invalid subscription type (valid values are #{SUBSCRIBABLE_TYPES.join(', ')})" end true end | Ensures that the type supplied is valid |
9,728 | def make_subscription_url ( opts ) validate_subscription_type opts [ :type ] path = if opts [ :type ] == :all "" else "/" + opts [ :type ] . to_s end url = "/user/#{@user_id}#{path}/apiSubscriptions" if opts [ :use_subscription_id ] unless opts [ :subscription_id ] raise Fitgem :: InvalidArgumentError , "Must include o... | Create the subscription management API url |
9,729 | def log_weight ( weight , date , opts = { } ) opts [ :time ] = format_time ( opts [ :time ] ) if opts [ :time ] post ( "/user/#{@user_id}/body/log/weight.json" , opts . merge ( :weight => weight , :date => format_date ( date ) ) ) end | Log weight to fitbit for the current user |
9,730 | def log_body_fat ( fatPercentage , date , opts = { } ) opts [ :fat ] = fatPercentage opts [ :date ] = format_date ( date ) opts [ :time ] = format_time ( opts [ :time ] ) if opts [ :time ] post ( "/user/#{@user_id}/body/fat.json" , opts ) end | Log body fat percentage |
9,731 | def create_or_update_body_weight_goal ( startDate , startWeight , goalWeight ) opts = { startDate : format_date ( startDate ) , startWeight : startWeight , weight : goalWeight } post ( "/user/#{@user_id}/body/log/weight/goal.json" , opts ) end | Create or update a user s weight goal |
9,732 | def determine_body_uri ( base_uri , opts = { } ) if opts [ :date ] date = format_date opts [ :date ] "#{base_uri}/date/#{date}.json" elsif opts [ :base_date ] && ( opts [ :period ] || opts [ :end_date ] ) date_range = construct_date_range_fragment opts "#{base_uri}/#{date_range}.json" else raise Fitgem :: InvalidArgume... | Determine the URI for the body_weight or body_fat method |
9,733 | def create_or_update_weekly_goal ( opts ) unless opts [ :type ] && [ :steps , :distance , :floors ] . include? ( opts [ :type ] ) raise InvalidArgumentError , 'Must specify type in order to create or update a weekly goal. One of (:steps, :distance, or :floors) is required.' end unless opts [ :value ] raise InvalidArgum... | Create or update a user s weekly goal |
9,734 | def update_alarm ( alarm_id , device_id , opts ) opts [ :time ] = format_time opts [ :time ] , include_timezone : true post ( "/user/#{@user_id}/devices/tracker/#{device_id}/alarms/#{alarm_id}.json" , opts ) end | Update an existing alarm |
9,735 | def format_time ( time , opts = { } ) format = opts [ :include_timezone ] ? "%H:%M%:z" : "%H:%M" if time . is_a? String case time when 'now' return DateTime . now . strftime format else unless time =~ / \d \: \d / raise Fitgem :: InvalidTimeArgument , "Invalid time (#{time}), must be in HH:mm format" end timezone = Dat... | Format any of a variety of time - related types into the formatted string required when using the fitbit API . |
9,736 | def label_for_measurement ( measurement_type , respect_user_unit_preferences = true ) unless [ :duration , :distance , :elevation , :height , :weight , :measurements , :liquids , :blood_glucose ] . include? ( measurement_type ) raise InvalidMeasurementType , "Supplied measurement_type parameter must be one of [:duratio... | Fetch the correct label for the desired measurement unit . |
9,737 | def table_name_to_namespaced_model ( table_name ) model = to_class ( table_name . singularize . camelcase ) return model if model != nil underscore_position = table_name . index ( '_' ) while underscore_position != nil namespaced_table_name = table_name . dup namespaced_table_name [ underscore_position ] = '/' model = ... | Tries to find the model class corresponding to specified table name . Takes into account that the model can be defined in a namespace . Searches only up to one level deep - won t find models nested in two or more modules . |
9,738 | def to_class ( name ) begin constant = name . constantize rescue NameError return nil rescue LoadError => e $stderr . puts "failed to load '#{name}', ignoring (#{e.class}: #{e.message})" return nil end return constant . is_a? ( Class ) ? constant : nil end | Checks if there is a class of specified name and if so returns the class object . Otherwise returns nil . |
9,739 | def display_messages [ :errors , :warnings ] . each do | type | send ( type ) . each do | msg | output . puts ( msg . to_s ) end end end | Displays all warnings and errors . |
9,740 | def generate_rules ( grammar ) rules = [ ] action_index = 0 rule_indices = grammar . rule_indices term_indices = grammar . terminal_indices grammar . rules . each_with_index do | rule , rule_index | rule . branches . each do | branch | row = [ TYPES [ :action ] , action_index ] action_index += 1 branch . steps . revers... | Builds the rules table of the parser . Each row is built in reverse order . |
9,741 | def warn_for_unused_rules ( compiled_grammar ) compiled_grammar . rules . each_with_index do | rule , index | next if index == 0 || rule . references > 0 compiled_grammar . add_warning ( "Unused rule #{rule.name.inspect}" , rule . source_line ) end end | Adds warnings for any unused rules . The first defined rule is skipped since it s the root rule . |
9,742 | def warn_for_unused_terminals ( compiled_grammar ) compiled_grammar . terminals . each do | terminal | next if terminal . references > 0 compiled_grammar . add_warning ( "Unused terminal #{terminal.name.inspect}" , terminal . source_line ) end end | Adds warnings for any unused terminals . |
9,743 | def on_grammar ( node , compiled_grammar ) node . children . each do | child | if child . type == :rule on_rule_prototype ( child , compiled_grammar ) end end node . children . each do | child | process ( child , compiled_grammar ) end end | Processes the root node of a grammar . |
9,744 | def on_name ( node , compiled_grammar ) if compiled_grammar . name compiled_grammar . add_warning ( "Overwriting existing parser name #{compiled_grammar.name.inspect}" , node . source_line ) end parts = node . children . map { | child | process ( child , compiled_grammar ) } compiled_grammar . name = parts . join ( '::... | Sets the name of the parser . |
9,745 | def on_terminals ( node , compiled_grammar ) node . children . each do | child | name = process ( child , compiled_grammar ) if compiled_grammar . has_terminal? ( name ) compiled_grammar . add_error ( "The terminal #{name.inspect} has already been defined" , child . source_line ) else compiled_grammar . add_terminal ( ... | Processes the assignment of terminals . |
9,746 | def on_rule ( node , compiled_grammar ) name = process ( node . children [ 0 ] , compiled_grammar ) if compiled_grammar . has_terminal? ( name ) compiled_grammar . add_error ( "the rule name #{name.inspect} is already used as a terminal name" , node . source_line ) end if compiled_grammar . has_rule_with_branches? ( na... | Processes the assignment of a rule . |
9,747 | def on_rule_prototype ( node , compiled_grammar ) name = process ( node . children [ 0 ] , compiled_grammar ) return if compiled_grammar . has_rule? ( name ) rule = Rule . new ( name , node . source_line ) compiled_grammar . add_rule ( rule ) end | Creates a basic prototype for a rule . |
9,748 | def on_branch ( node , compiled_grammar ) steps = process ( node . children [ 0 ] , compiled_grammar ) if node . children [ 1 ] code = process ( node . children [ 1 ] , compiled_grammar ) else code = nil end return Branch . new ( steps , node . source_line , code ) end | Processes a single rule branch . |
9,749 | def sys_up_time varbind = @varbind_list [ 0 ] if varbind && ( varbind . name == SYS_UP_TIME_OID ) return varbind . value else raise InvalidTrapVarbind , "Expected sysUpTime.0, found " + varbind . to_s end end | Returns the value of the mandatory sysUpTime varbind for this trap . |
9,750 | def trap_oid varbind = @varbind_list [ 1 ] if varbind && ( varbind . name == SNMP_TRAP_OID_OID ) return varbind . value else raise InvalidTrapVarbind , "Expected snmpTrapOID.0, found " + varbind . to_s end end | Returns the value of the mandatory snmpTrapOID varbind for this trap . |
9,751 | def subtree_of? ( parent_tree ) parent_tree = make_object_id ( parent_tree ) if parent_tree . length > self . length false else parent_tree . each_index do | i | return false if parent_tree [ i ] != self [ i ] end true end end | Returns true if this ObjectId is a subtree of the provided parent tree ObjectId . For example 1 . 3 . 6 . 1 . 5 is a subtree of 1 . 3 . 6 . 1 . |
9,752 | def index ( parent_tree ) parent_tree = make_object_id ( parent_tree ) if not subtree_of? ( parent_tree ) raise ArgumentError , "#{self.to_s} not a subtree of #{parent_tree.to_s}" elsif self . length == parent_tree . length raise ArgumentError , "OIDs are the same" else ObjectId . new ( self [ parent_tree . length .. -... | Returns an index based on the difference between this ObjectId and the provided parent ObjectId . |
9,753 | def varbind_list ( object_list , option = :KeepValue ) raise ArgumentError , "A list of ObjectId or VarBind objects is NilClass" if object_list . nil? vb_list = VarBindList . new if object_list . respond_to? :to_str vb_list << oid ( object_list ) . to_varbind elsif object_list . respond_to? :to_varbind vb_list << apply... | Returns a VarBindList for the provided list of objects . If a string is provided it is interpretted as a symbolic OID . |
9,754 | def name ( oid ) current_oid = ObjectId . new ( oid ) index = [ ] while current_oid . size > 1 name = @by_oid [ current_oid . to_s ] if name return index . empty? ? name : "#{name}.#{index.join('.')}" end index . unshift current_oid . slice! ( - 1 ) end ObjectId . new ( oid ) . to_s end | Returns the symbolic name of the given OID . |
9,755 | def get_next ( object_list ) varbind_list = @mib . varbind_list ( object_list , :NullValue ) request = GetNextRequest . new ( @@request_id . next , varbind_list ) try_request ( request ) end | Sends a get - next request for the supplied list of ObjectId or VarBind objects . |
9,756 | def get_bulk ( non_repeaters , max_repetitions , object_list ) varbind_list = @mib . varbind_list ( object_list , :NullValue ) request = GetBulkRequest . new ( @@request_id . next , varbind_list , non_repeaters , max_repetitions ) try_request ( request ) end | Sends a get - bulk request . The non_repeaters parameter specifies the number of objects in the object_list to be retrieved once . The remaining objects in the list will be retrieved up to the number of times specified by max_repetitions . |
9,757 | def set ( object_list ) varbind_list = @mib . varbind_list ( object_list , :KeepValue ) request = SetRequest . new ( @@request_id . next , varbind_list ) try_request ( request , @write_community ) end | Sends a set request using the supplied list of VarBind objects . |
9,758 | def trap_v1 ( enterprise , agent_addr , generic_trap , specific_trap , timestamp , object_list = [ ] ) vb_list = @mib . varbind_list ( object_list , :KeepValue ) ent_oid = @mib . oid ( enterprise ) agent_ip = IpAddress . new ( agent_addr ) specific_int = Integer ( specific_trap ) ticks = TimeTicks . new ( timestamp ) t... | Sends an SNMPv1 style trap . |
9,759 | def trap_v2 ( sys_up_time , trap_oid , object_list = [ ] ) vb_list = create_trap_vb_list ( sys_up_time , trap_oid , object_list ) trap = SNMPv2_Trap . new ( @@request_id . next , vb_list ) send_request ( trap , @community , @host , @trap_port ) end | Sends an SNMPv2c style trap . |
9,760 | def inform ( sys_up_time , trap_oid , object_list = [ ] ) vb_list = create_trap_vb_list ( sys_up_time , trap_oid , object_list ) request = InformRequest . new ( @@request_id . next , vb_list ) try_request ( request , @community , @host , @trap_port ) end | Sends an inform request using the supplied varbind list . |
9,761 | def create_trap_vb_list ( sys_up_time , trap_oid , object_list ) vb_args = @mib . varbind_list ( object_list , :KeepValue ) uptime_vb = VarBind . new ( SNMP :: SYS_UP_TIME_OID , TimeTicks . new ( sys_up_time . to_int ) ) trap_vb = VarBind . new ( SNMP :: SNMP_TRAP_OID_OID , @mib . oid ( trap_oid ) ) VarBindList . new (... | Helper method for building VarBindList for trap and inform requests . |
9,762 | def walk ( object_list , index_column = 0 ) raise ArgumentError , "expected a block to be given" unless block_given? vb_list = @mib . varbind_list ( object_list , :NullValue ) raise ArgumentError , "index_column is past end of varbind list" if index_column >= vb_list . length is_single_vb = object_list . respond_to? ( ... | Walks a list of ObjectId or VarBind objects using get_next until the response to the first OID in the list reaches the end of its MIB subtree . |
9,763 | def validate_row ( vb_list , start_list , index_column ) start_vb = start_list [ index_column ] index_vb = vb_list [ index_column ] row_index = index_vb . name . index ( start_vb . name ) vb_list . each_index do | i | if i != index_column expected_oid = start_list [ i ] . name + row_index if vb_list [ i ] . name != exp... | Helper method for walk . Checks all of the VarBinds in vb_list to make sure that the row indices match . If the row index does not match the index column then that varbind is replaced with a varbind with a value of NoSuchInstance . |
9,764 | def get_response ( request ) begin data = @transport . recv ( @max_bytes ) message = Message . decode ( data , @mib ) response = message . pdu end until request . request_id == response . request_id response end | Wait until response arrives . Ignore responses with mismatched IDs ; these responses are typically from previous requests that timed out or almost timed out . |
9,765 | def is_defined? ( top_mod , sub_mod = nil ) return_value = Object . const_defined? top_mod unless ! return_value || sub_mod . nil? return_value = Object . const_get ( top_mod ) . const_defined? sub_mod end return_value end | Only here to be stubbed for testing . Gross . |
9,766 | def build! ( options ) options . each { | key , value | options [ key ] = false if options [ key ] == "false" } @id = options [ "id" ] @owner = options [ "owner" ] @status = options [ "status" ] @error = options [ "error" ] @name = options [ "name" ] @browser = options [ "browser" ] @browser_version = options [ "browse... | Sets all internal variables from a hash |
9,767 | def generate start_time = Time . now . to_f env . each_logical_path do | logical_path | if File . basename ( logical_path ) [ / \. / , 0 ] == 'index' logical_path . sub! ( / \/ \. / , '.' ) end next unless compile_path? ( logical_path ) if digest_path = @digests [ logical_path ] abs_digest_path = "#{@target}/#{digest_p... | Generate non - digest assets by making a copy of the digest asset with digests stripped from js and css . The new files are also gzipped . Other assets are copied verbatim . |
9,768 | def init_with ( environment , coder , asset_options = { } ) asset_options [ :bundle ] = false super ( environment , coder ) @source = coder [ 'source' ] @dependency_digest = coder [ 'dependency_digest' ] @required_assets = coder [ 'required_paths' ] . map { | p | p = expand_root_path ( p ) unless environment . paths . ... | Initialize asset from serialized hash |
9,769 | def encode_with ( coder ) super coder [ 'source' ] = source coder [ 'dependency_digest' ] = dependency_digest coder [ 'required_paths' ] = required_assets . map { | a | relativize_root_path ( a . pathname ) . to_s } coder [ 'dependency_paths' ] = dependency_paths . map { | d | { 'path' => relativize_root_path ( d . pat... | Serialize custom attributes . |
9,770 | def extract_config options @username = options [ :username ] @access_key = options [ :access_key ] @cli_options = options [ :connect_options ] @sc4_executable = options [ :sauce_connect_4_executable ] @skip_connection_test = options [ :skip_connection_test ] @quiet = options [ :quiet ] @timeout = options . fetch ( :tim... | extract options from the options hash with highest priority over Sauce . config but fall back on Sauce . config otherwise |
9,771 | def generated? wme return true if generated_wmes . any? { | w | w == wme } return children . any? { | t | t . generated? wme } end | for neg feedback loop protection |
9,772 | def website_url ( resource = '' , params = { } ) api_url = ENV [ 'ZENATON_API_URL' ] || ZENATON_API_URL url = "#{api_url}/#{resource}" if params . is_a? ( Hash ) params [ API_TOKEN ] = @api_token append_params_to_url ( url , params ) else add_app_env ( "#{url}?#{API_TOKEN}=#{@api_token}&" , params ) end end | Gets the url for zenaton api |
9,773 | def start_task ( task ) max_processing_time = if task . respond_to? ( :max_processing_time ) task . max_processing_time end @http . post ( worker_url ( 'tasks' ) , ATTR_PROG => PROG , ATTR_NAME => class_name ( task ) , ATTR_DATA => @serializer . encode ( @properties . from ( task ) ) , ATTR_MAX_PROCESSING_TIME => max_p... | Start a single task |
9,774 | def start_workflow ( flow ) @http . post ( instance_worker_url , ATTR_PROG => PROG , ATTR_CANONICAL => canonical_name ( flow ) , ATTR_NAME => class_name ( flow ) , ATTR_DATA => @serializer . encode ( @properties . from ( flow ) ) , ATTR_ID => parse_custom_id_from ( flow ) ) end | Start the specified workflow |
9,775 | def find_workflow ( workflow_name , custom_id ) params = { ATTR_ID => custom_id , ATTR_NAME => workflow_name } params [ ATTR_PROG ] = PROG data = @http . get ( instance_website_url ( params ) ) [ 'data' ] data && @properties . object_from ( data [ 'name' ] , @serializer . decode ( data [ 'properties' ] ) ) rescue Zenat... | Finds a workflow |
9,776 | def send_event ( workflow_name , custom_id , event ) body = { ATTR_PROG => PROG , ATTR_NAME => workflow_name , ATTR_ID => custom_id , EVENT_NAME => event . class . name , EVENT_INPUT => @serializer . encode ( @properties . from ( event ) ) } @http . post ( send_event_url , body ) end | Sends an event to a workflow |
9,777 | def dispatch ( jobs ) jobs . map ( & method ( :check_argument ) ) jobs . map ( & method ( :local_dispatch ) ) if process_locally? ( jobs ) @processor &. process ( jobs , false ) unless jobs . length . zero? nil end | Executes jobs asynchronously |
9,778 | def method_missing ( name , * args ) if known_action? ( name ) execute_request ( ACTIONS [ name ] , args . first ) elsif known_resource? ( name ) build_path ( name , args . first ) elsif known_exception? ( name ) build_path ( EXCEPTIONS [ name ] [ :path ] , nil ) execute_request ( EXCEPTIONS [ name ] [ :action ] , args... | Uh oh! This will allow the class including this module to build a path by chaining calls to resources terminated with a method linked to an action that will execute the api call . |
9,779 | def respond_to_missing? ( name , include_private = false ) known_action? ( name ) || known_resource? ( name ) || known_exception? ( name ) || super end | We d better not lie when asked . |
9,780 | def fetch Net :: HTTP . start ( uri . host , uri . port , use_ssl : true ) do | https | req = Net :: HTTP . const_get ( action ) . new ( uri ) set_body ( req ) set_format_header ( req ) wrap_response ( https . request ( req ) ) end end | Prepares a fancy request object and ensures the inputs make as much sense as possible . It s still totally possible to just provide a path that doesn t match a real url though . |
9,781 | def day_link ( text , date , day_action ) link_to ( text , params . merge ( :action => day_action , :year => date . year , :month => date . month , :day => date . day ) , :class => 'ec-day-link' ) end | override this in your own helper for greater control |
9,782 | def cal_row_heights ( options ) num_cal_rows = options [ :event_strips ] . first . size / 7 min_height = ( options [ :height ] - options [ :day_names_height ] ) / num_cal_rows row_heights = [ ] num_event_rows = 0 1 . upto ( options [ :event_strips ] . first . size + 1 ) do | index | num_events = 0 options [ :event_stri... | calculate the height of each row by default it will be the height option minus the day names height divided by the total number of calendar rows this gets tricky however if there are too many event rows to fit into the row s height then we need to add additional height |
9,783 | def event_strips_for_month ( shown_date , first_day_of_week = 0 , find_options = { } ) if first_day_of_week . is_a? ( Hash ) find_options . merge! ( first_day_of_week ) first_day_of_week = 0 end strip_start , strip_end = get_start_and_end_dates ( shown_date , first_day_of_week ) events = events_for_date_range ( strip_s... | For the given month find the start and end dates Find all the events within this range and create event strips for them |
9,784 | def get_start_and_end_dates ( shown_date , first_day_of_week = 0 ) start_of_month = Date . civil ( shown_date . year , shown_date . month , 1 ) strip_start = beginning_of_week ( start_of_month , first_day_of_week ) if start_of_month . next_month == beginning_of_week ( start_of_month . next_month , first_day_of_week ) s... | Expand start and end dates to show the previous month and next month s days that overlap with the shown months display |
9,785 | def events_for_date_range ( start_d , end_d , find_options = { } ) self . scoped ( find_options ) . find ( :all , :conditions => [ "(? <= #{self.quoted_table_name}.#{self.end_at_field}) AND (#{self.quoted_table_name}.#{self.start_at_field}< ?)" , start_d . to_time . utc , end_d . to_time . utc ] , :order => "#{self.quo... | Get the events overlapping the given start and end dates |
9,786 | def create_event_strips ( strip_start , strip_end , events ) event_strips = [ [ nil ] * ( strip_end - strip_start + 1 ) ] events . each do | event | cur_date = event . start_at . to_date end_date = event . end_at . to_date cur_date , end_date = event . clip_range ( strip_start , strip_end ) start_range = ( cur_date - s... | Create the various strips that show events . |
9,787 | def clip_range ( start_d , end_d ) start_at_d = start_at . to_date end_at_d = end_at . to_date if ( start_at_d < start_d and end_at_d >= start_d ) clipped_start = start_d else clipped_start = start_at_d end if ( end_at_d > end_d ) clipped_end = end_d else clipped_end = end_at_d end [ clipped_start , clipped_end ] end | start_d - start of the month or start of the week end_d - end of the month or end of the week |
9,788 | def view ( spec ) results = CouchPotato :: View :: ViewQuery . new ( couchrest_database , spec . design_document , { spec . view_name => { :map => spec . map_function , :reduce => spec . reduce_function } } , ( { spec . list_name => spec . list_function } unless spec . list_name . nil? ) , spec . lib , spec . language ... | executes a view and return the results . you pass in a view spec which is usually a result of a SomePersistentClass . some_view call . |
9,789 | def load ( options = { } , & block ) options . each do | k , v | self . send ( "#{k}=" , v ) end self . routes = block end | Instantiates a new object . Should never be called directly . Sets the urls to be indexed . |
9,790 | def resources ( type , options = { } ) path ( type ) unless options [ :skip_index ] link_params = options . reject { | k , v | k == :objects } get_objects = lambda { options [ :objects ] ? options [ :objects ] . call : type . to_s . classify . constantize } get_objects . call . find_each ( :batch_size => Sitemap . conf... | Adds the associated object types . |
9,791 | def render ( object = "fragment" ) xml = Builder :: XmlMarkup . new ( :indent => 2 ) file = File . read ( File . expand_path ( "../../views/#{object}.xml.builder" , __FILE__ ) ) instance_eval file end | Parses the loaded data and returns the xml entries . |
9,792 | def process_fragment! file = Tempfile . new ( "sitemap.xml" ) file . write ( render ) file . close self . fragments << file end | Creates a temporary file from the existing entries . |
9,793 | def file_url ( path = "sitemap.xml" ) if context file_path = File . join ( "/" , context , path ) else file_path = File . join ( "/" , path ) end URI :: HTTP . build ( :host => host , :path => file_path ) . to_s end | URL to the sitemap file . |
9,794 | def build ( steps ) raise ArgumentError , "Must provide scenario steps" unless steps steps . each_with_index do | step , index | begin instruction , args = step . split ' ' , 2 args = split_quoted_string args if args && ! args . empty? self . __send__ instruction , * args else self . __send__ instruction end rescue => ... | Build the scenario steps provided |
9,795 | def register ( user , password = nil , opts = { } ) send_opts = opts . dup send_opts [ :retrans ] ||= DEFAULT_RETRANS user , domain = parse_user user if password send register_message ( domain , user ) , send_opts recv opts . merge ( response : 401 , auth : true , optional : false ) send register_auth ( domain , user ,... | Send a REGISTER message with the specified credentials |
9,796 | def receive_invite ( opts = { } ) recv ( opts . merge ( request : 'INVITE' , rrs : true ) ) do | recv | action = doc . create_element ( 'action' ) do | action | action << doc . create_element ( 'ereg' ) do | ereg | ereg [ 'regexp' ] = '<sip:(.*)>.*;tag=([^;]*)' ereg [ 'search_in' ] = 'hdr' ereg [ 'header' ] = 'From:' e... | Expect to receive a SIP INVITE |
9,797 | def receive_answer ( opts = { } ) options = { rrs : true , rtd : true } receive_200 ( options . merge ( opts ) ) do | recv | recv << doc . create_element ( 'action' ) do | action | action << doc . create_element ( 'ereg' ) do | ereg | ereg [ 'regexp' ] = '<sip:(.*)>.*;tag=([^;]*)' ereg [ 'search_in' ] = 'hdr' ereg [ 'h... | Sets an expectation for a SIP 200 message from the remote party as well as storing the record set and the response time duration |
9,798 | def wait_for_answer ( opts = { } ) receive_trying opts receive_ringing opts receive_progress opts receive_answer opts ack_answer opts end | Convenience method to wait for an answer from the called party |
9,799 | def receive_message ( regexp = nil ) recv = Nokogiri :: XML :: Node . new 'recv' , doc recv [ 'request' ] = 'MESSAGE' scenario_node << recv if regexp action = Nokogiri :: XML :: Node . new 'action' , doc ereg = Nokogiri :: XML :: Node . new 'ereg' , doc ereg [ 'regexp' ] = regexp ereg [ 'search_in' ] = 'body' ereg [ 'c... | Expect to receive a MESSAGE message |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.