idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
23,600
def new_value ( * args , & block ) value = value_from_args ( args , & block ) value = if incremental incremental_value ( value ) else filter_value ( transformed_value ( value ) ) end if value_valid? ( value ) self . custom_value = value elsif invalid . to_s == 'default' && ! incremental default_value else fail Argument...
Extracts options and sets all the parameters .
23,601
def to_h PARAMETERS . each_with_object ( { } ) do | param , hash | next if send ( param ) . nil? hash [ param ] = send ( param ) end end
Looks through the parameters and returns the non - nil values as a hash
23,602
def value_from_args ( args , & block ) return block if ChainOptions :: Util . blank? ( args ) && block && allow_block flat_value ( args ) end
Returns the block if nothing else if given and blocks are allowed to be values .
23,603
def flat_value ( args ) return args . first if args . is_a? ( Enumerable ) && args . count == 1 args end
Reverses the auto - cast to Array that is applied at new_value .
23,604
def transformed_value ( value ) return value unless transform transformed = Array ( value ) . map ( & transform ) value . is_a? ( Enumerable ) ? transformed : transformed . first end
Applies a transformation to the given value .
23,605
def get_entry_for ( entry , language ) if entry . length > 1 entry_string = get_entry_for_rec ( entry [ 1 .. - 1 ] , language , hashes [ language ] [ entry [ 0 ] ] ) else entry_string = hashes [ language ] [ entry [ 0 ] ] end if entry_string . kind_of? ( Array ) entry_string = entry_string . map ( & :inspect ) . join (...
Takes in a locale code and returns the string for that language
23,606
def from ( content , options = { } ) format = options [ :format ] . to_s mime_type = options [ :mime_type ] && options [ :mime_type ] . to_s type_uri = options [ :type_uri ] && options [ :type_uri ] . to_s base_uri = options [ :base_uri ] && options [ :base_uri ] . to_s content = Uri . new ( content ) if content . is_a...
Core parsing method for non - streams
23,607
def model if @resource_tree . size > 1 parent_model_id = params [ "#{@resource_tree.first.name.to_s.singularize}_id" ] model = @resource_tree . first . model . find ( parent_model_id ) @resource_tree . drop ( 1 ) . each do | resource | model = model . send resource . name end model else super . all end end
Determine the model to use depending on the request . If a sub - resource was requested use the parent model to get the association . Otherwise use all the resource s model s records .
23,608
def default_action_block proc do all_records = model if allowed? ( :paging ) && params [ :page ] page = params [ :page ] per_page = params [ :per_page ] || 10 lower_bound = ( per_page - 1 ) * page upper_bound = lower_bound + per_page - 1 body all_records [ lower_bound .. upper_bound ] else body all_records end end end
Determine the default action to use depending on the request . If the page param was passed and the action allows paging page the results . Otherwise set the request body to all records .
23,609
def evaluate_in ( context , periods = [ ] ) sandbox = Sandbox . new context , periods sandbox . instance_eval & @equation_block end
evaluate the equation in the passed context
23,610
def all ( opts = { } ) opts = opts . dup path = adjust ( '_all_docs' ) opts [ :include_docs ] = true if opts [ :include_docs ] . nil? adjust_params ( opts ) keys = opts . delete ( :keys ) return [ ] if keys && keys . empty? res = if keys opts [ :cache ] = :with_body if opts [ :cache ] . nil? @http . post ( path , { 'ke...
Returns all the docs in the current database .
23,611
def attach ( doc_id , doc_rev , attachment_name , data , opts = nil ) if opts . nil? opts = data data = attachment_name attachment_name = doc_rev doc_rev = doc_id [ '_rev' ] doc_id = doc_id [ '_id' ] end attachment_name = attachment_name . gsub ( / \/ / , '%2F' ) ct = opts [ :content_type ] raise ( ArgumentError . new ...
Attaches a file to a couch document .
23,612
def detach ( doc_id , doc_rev , attachment_name = nil ) if attachment_name . nil? attachment_name = doc_rev doc_rev = doc_id [ '_rev' ] doc_id = doc_id [ '_id' ] end attachment_name = attachment_name . gsub ( / \/ / , '%2F' ) path = adjust ( "#{doc_id}/#{attachment_name}?rev=#{doc_rev}" ) @http . delete ( path ) end
Detaches a file from a couch document .
23,613
def on_change ( opts = { } , & block ) query = { 'feed' => 'continuous' , 'heartbeat' => opts [ :heartbeat ] || 20_000 } query [ 'include_docs' ] = true if block . arity > 2 query = query . map { | k , v | "#{k}=#{v}" } . join ( '&' ) socket = TCPSocket . open ( @http . host , @http . port ) auth = @http . options [ :b...
Watches the database for changes .
23,614
def nuke_design_documents docs = get ( '_all_docs' ) [ 'rows' ] views = docs . select { | d | d [ 'id' ] && DESIGN_PATH_REGEX . match ( d [ 'id' ] ) } views . each { | v | delete ( v [ 'id' ] , v [ 'value' ] [ 'rev' ] ) } end
A development method . Removes all the design documents in this couch database .
23,615
def query ( path , opts = { } ) opts = opts . dup raw = opts . delete ( :raw ) path = if DESIGN_PATH_REGEX . match ( path ) path else doc_id , view = path . split ( ':' ) path = "_design/#{doc_id}/_view/#{view}" end path = adjust ( path ) adjust_params ( opts ) keys = opts . delete ( :keys ) res = if keys opts [ :cache...
Queries a view .
23,616
def query_for_docs ( path , opts = { } ) res = query ( path , opts . merge ( :include_docs => true ) ) if res . nil? nil elsif opts [ :raw ] res else res . collect { | row | row [ 'doc' ] } . uniq end end
A shortcut for
23,617
def send_appreciation! ( user_id , opts = { } ) params = { "toUserID" => user_id } params [ "companyValueID" ] = opts [ :company_value_id ] if opts [ :company_value_id ] params [ "amount" ] = opts [ :amount ] if opts [ :amount ] params [ "note" ] = opts [ :note ] if opts [ :note ] params [ "privateAppreciation" ] = opt...
sends appreciation to another User raises BalanceError if insufficient funds exist
23,618
def define ( & block ) if block && block . arity > 0 block . call @ns elsif block @ns . instance_eval ( & block ) end @ns end
define the parent ns using the given block
23,619
def extension_id raise Tay :: PrivateKeyNotFound . new unless private_key_exists? public_key = OpenSSL :: PKey :: RSA . new ( File . read ( full_key_path ) ) . public_key . to_der hash = Digest :: SHA256 . hexdigest ( public_key ) [ 0 ... 32 ] hash . unpack ( 'C*' ) . map { | c | c < 97 ? c + 49 : c + 10 } . pack ( 'C*...
Calculate the extension s ID from the key Core concepts from supercollider . dk
23,620
def write_new_key File . open ( full_key_path , 'w' ) do | f | f . write OpenSSL :: PKey :: RSA . generate ( 1024 ) . export ( ) end end
Generate a key with OpenSSL and write it to the key path
23,621
def traverse ( element , visitor , context = Visitor :: Context . new ) ns_bindings = namespace_bindings_from_defs ( element . namespace_definitions ) context . ns_stack . push ( ns_bindings ) eelement , eattrs = explode_element ( element ) begin visitor . element ( context , eelement , eattrs , ns_bindings ) do elemen...
pre - order traversal of the Nokogiri Nodes calling methods on the visitor with each Node
23,622
def config_file_create ( global_options , options ) config_directory_create ( global_options ) file = "#{global_options[:directory]}/config" options . store ( :fenton_server_url , global_options [ :fenton_server_url ] ) content = config_generation ( options ) File . write ( file , content ) [ true , 'ConfigFile' : [ 'c...
Creates the configuration file
23,623
def config_generation ( options ) config_contents = { } config_options = options . keys . map ( & :to_sym ) . sort . uniq config_options . delete ( :password ) config_options . each do | config_option | config_contents . store ( config_option . to_sym , options [ config_option ] ) end config_contents . store ( :default...
Generates the configuration file content
23,624
def format_with_bang ( message ) return message if ! message . is_a? ( String ) return '' if message . to_s . strip == '' " ! " + message . encode ( 'utf-8' , 'binary' , invalid : :replace , undef : :replace ) . split ( "\n" ) . join ( "\n ! " ) end
Add a bang to an error message
23,625
def to_table ( data , headers ) column_lengths = [ ] gutter = 2 table = '' headers . each { | header | width = data . map { | _ | _ [ header ] } . max_by ( & :length ) . length width = header . length if width < header . length column_lengths << width } format_row_entry = lambda { | entry , i | entry + ( ' ' * ( column...
format some data into a table to then be displayed to the user
23,626
def clear_strategies_cache! ( * args ) scope , opts = _retrieve_scope_and_opts ( args ) @winning_strategies . delete ( scope ) @strategies [ scope ] . each do | k , v | v . clear! if args . empty? || args . include? ( k ) end end
Clear the cache of performed strategies so far . Warden runs each strategy just once during the request lifecycle . You can clear the strategies cache if you want to allow a strategy to be run more than once .
23,627
def set_user ( user , opts = { } ) scope = ( opts [ :scope ] ||= @config . default_scope ) opts = ( @config [ :scope_defaults ] [ scope ] || { } ) . merge ( opts ) opts [ :event ] ||= :set_user @users [ scope ] = user if opts [ :store ] != false && opts [ :event ] != :fetch options = env [ ENV_SESSION_OPTIONS ] options...
Manually set the user into the session and auth proxy
23,628
def env_from_profile ( aws_profile ) data = YAML . load_file ( "#{Lono.root}/config/settings.yml" ) env = data . find do | _env , setting | setting ||= { } profiles = setting [ 'aws_profiles' ] profiles && profiles . include? ( aws_profile ) end env . first if env end
Do not use the Setting class to load the profile because it can cause an infinite loop then if we decide to use Lono . env from within settings class .
23,629
def require ( * keys ) permitted_keys . merge keys required_keys = keys . to_set unless ( missing_keys = required_keys - hash_keys ) . empty? error "required #{terms} #{missing_keys.to_a} missing" + postscript end self end
Specifies keys that must exist
23,630
def datatype if instance_variable_defined? ( :@datatype ) @datatype else @datatype = if literal? rdf_uri = Redland . librdf_node_get_literal_value_datatype_uri ( rdf_node ) rdf_uri . null? ? XmlSchema . datatype_of ( "" ) : URI . parse ( Redland . librdf_uri_to_string ( rdf_uri ) ) else nil end end end
Datatype URI for the literal node or nil
23,631
def value if resource? uri elsif blank? Redland . librdf_node_get_blank_identifier ( rdf_node ) . force_encoding ( "UTF-8" ) else v = Redland . librdf_node_get_literal_value ( rdf_node ) . force_encoding ( "UTF-8" ) v << "@#{lang}" if lang XmlSchema . instantiate ( v , datatype ) end end
Value of the literal node as a Ruby object instance .
23,632
def delete ( identifier ) RecordDeleter . new ( identifier : identifier , dao : dao , factory : factory ) . delete end
Remove a record from the underlying DAO whose slug matches the passed - in identifier .
23,633
def window base = @collection . offset high = base + @collection . per_page high = @collection . total_entries if high > @collection . total_entries tag ( :span , " #{base + 1} - #{high} of #{@collection.total_entries} " , :class => WillPaginateRenderers . pagination_options [ :gmail_window_class ] ) end
Renders the x - y of z text
23,634
def news ( options = { results : 1 } ) response = get_response ( results : options [ :results ] , name : @name ) response [ :news ] . collect do | b | Blog . new ( name : b [ :name ] , site : b [ :site ] , url : b [ :url ] ) end end
This appears to be from more reputable sources?
23,635
def list_links ( args = { } ) if args . empty? links else links . select { | link | link . match? args } end end
List links that match the attributes
23,636
def merge_links_on ( attribute , concat_string = ',' ) links_group_by ( attribute ) . select { | key , link_list | links . size > 1 } . map do | key , link_list | merge_attributes = Link :: ATTRS - [ attribute ] link_list . first . update ( Hash [ extract_columns ( link_list , merge_attributes ) . map { | c | c . uniq ...
Merge links based on the provided attribue to one link by combining the values . The first link will be updated and the obsolete links are deleted and will be returned
23,637
def links_group_by ( attribute , linkz = links ) linkz . map { | link | { key : link . send ( attribute ) , link : link } } . group_by { | entry | entry [ :key ] } . each { | key , link | link . map! { | l | l [ :link ] } } end
Groups the links on the provided attribute . If no links array is provided the links from self are used
23,638
def links_duplicate_on ( attribute , separator ) links . map do | link | link . send ( attribute ) . split ( separator ) . collect do | value | link . dup . update ( Hash [ attribute , value ] ) end end . flatten end
Create multiple Links based on the attribute provided . The specified spearator will splitt the attribute value in distinct values and for each different value a Link will be created
23,639
def link_attribute_list ( attribute , separator = nil ) links . map { | link | link . send ( attribute ) . split ( separator ) } . flatten . uniq . sort end
List all attributes of the links
23,640
def run @started_at = Time . now max_cycles = 1 while true do if @cycle < max_cycles step else diff = Time . now - @started_at max_cycles = ( diff * @clock_cycle ) end end end
Run in endless loop
23,641
def wk_api_info ( api_method = '' ) api_method ||= '' fail 'Invalid wukong api' unless api_method == '' || api_method =~ WK_API_FORMAT if api_method . size > 0 m = api_method . to_s . match ( / / ) method_group = m [ 1 ] . singularize method_name = m [ 2 ] end apis = api_method . size > 0 ? API_LIST . select { | a | a ...
api detail info include request url & arguments
23,642
def update_counter_cache self . discussion . reply_count = Post . where ( :discussion_id => self . discussion . id ) . count - 1 self . discussion . save end
Custom counter cache . Does not include the first post of a discussion .
23,643
def anonymous_or_user_attr ( attr ) unless self . user_id . nil? mthd = "user_#{attr.to_s}" self . user . send ( attr ) else case attr when :cornerstone_name self . send ( :name ) when :cornerstone_email self . send ( :email ) end end end
Returns the requested attribute of the user if it exists or post s attribute
23,644
def export ( ) super f = new_output_file ( 'obo_nomenclature.obo' ) f . puts 'format-version: 1.2' f . puts "date: #{@time}" f . puts 'saved-by: someone' f . puts 'auto-generated-by: Taxonifi' f . puts 'synonymtypedef: COMMONNAME "common name"' f . puts 'synonymtypedef: MISSPELLING "misspelling" EXACT' f . puts 'synony...
Writes the file .
23,645
def has_unique_name invalid = false if template invalid ||= template . common_fields . any? { | field | field . name . downcase == self . name . downcase && field != self } invalid ||= template . default_fields . any? { | field | field . name . downcase == self . name . downcase && field != self } else scope = self . c...
Checks the current template and the common fields for any field with the same name
23,646
def disambiguate_fields if name_changed? fields = self . class . specific . where ( "LOWER(name) = LOWER(?)" , self . name ) fields . update_all ( :disambiguate => fields . many? ) end if name_was fields = self . class . specific . where ( "LOWER(name) = LOWER(?)" , self . name_was ) fields . update_all ( :disambiguate...
Finds all fields with the same name and ensures they know there is another field with the same name thus allowing us to have them a prefix that lets us identify them in a query string
23,647
def app_routes_as_hash Rails . application . routes . routes . each do | route | controller = route . defaults [ :controller ] next if controller . nil? key = controller . split ( '/' ) . map ( & :camelize ) . join ( '::' ) routes [ key ] ||= [ ] routes [ key ] << route . defaults [ :action ] end end
Routes from routes . rb
23,648
def get_statement ( start_date = '2016-08-29' , end_date = '2016-09-01' ) return nil unless @access_token @timestamp = Time . now . iso8601 ( 3 ) @start_date = start_date . to_s @end_date = end_date . to_s @path = "/banking/v3/corporates/" @relative_url = "#{@path}#{@corporate_id}/accounts/#{@account_number}/statements...
Get your BCA Bisnis account statement for a period up to 31 days .
23,649
def balance return nil unless @access_token begin @timestamp = Time . now . iso8601 ( 3 ) @relative_url = "/banking/v3/corporates/#{@corporate_id}/accounts/#{@account_number}" response = RestClient . get ( "#{@base_url}#{@relative_url}" , "Content-Type" : 'application/json' , "Authorization" : "Bearer #{@access_token}"...
Get your BCA Bisnis account balance information
23,650
def geocode! ( address , options = { } ) response = call_geocoder_service ( address , options ) if response . is_a? ( Net :: HTTPOK ) return JSON . parse response . body else raise ResponseError . new response end end
raise ResponseError exception on error
23,651
def find_location ( address ) result = geocode ( address ) if result [ 'status' ] == 'OK' return result [ 'results' ] [ 0 ] [ 'geometry' ] [ 'location' ] else latlon_regexp = / \. \d \. \. \d \. / if address =~ latlon_regexp location = $& . split ( ',' ) . map { | e | e . to_f } return { "lat" => location [ 0 ] , "lng"...
if geocoding fails then look for lat lng string in address
23,652
def object ( object_name ) object = objects . find do | obj | obj [ 'name' ] == object_name end if ! object raise "Database #{name} does not have an object named '#{object_name}'." end klass = PSQL . const_get object [ 'type' ] . capitalize klass . new object [ 'name' ] , name end
Finds a database object by name . Objects are tables views or sequences .
23,653
def delete ( options = { } ) return each ( { match : '*' , count : 500 , max_iterations : 1_000_000 , batch_size : 500 } . merge ( options ) ) do | keys | @connection . del ( * keys ) end end
Deletes all keys created by the factory . By defaults will iterate at most of 500 million keys
23,654
def script ( script , ** options ) return Redstruct :: Script . new ( script : script , connection : @connection , ** options ) end
Creates using this factory s connection
23,655
def crop_with_focuspoint ( width = nil , height = nil ) if self . respond_to? "resize_to_limit" begin x = model . focus_x || 0 y = - ( model . focus_y || 0 ) manipulate! do | img | orig_w = img [ 'width' ] orig_h = img [ 'height' ] ratio = width . to_f / height orig_ratio = orig_w . to_f / orig_h x_offset = 0 y_offset ...
Performs cropping with focuspoint
23,656
def report ( title , columns , rows ) table = capture_table ( [ columns ] + rows ) title = "=== #{title} " title << "=" * [ ( table . split ( $/ ) . max { | a , b | a . size <=> b . size } . size - title . size ) , 3 ] . max puts title puts table end
Print a table with a title and a top border of matching width .
23,657
def capture_table ( table ) return 'none' if table . size == 1 $stdout = StringIO . new print_table ( table . map { | row | row . map ( & :to_s ) } ) output = $stdout $stdout = STDOUT return output . string end
capture table in order to determine its width
23,658
def to_io ( package_type , traversal = :each ) package_type . open do | package | package . add_directory ( @initial_version ) send ( traversal ) do | child | case child when File package . add_file ( child ) when Directory package . add_directory ( child ) end end end end
Returns this + Archive + as a package of the given + package_type +
23,659
def czech_html ( input ) coder = HTMLEntities . new encoded = coder . encode ( input , :named , :decimal ) czech_diacritics . each { | k , v | encoded . gsub! ( k , v ) } encoded end
Escapes string to readable Czech HTML entities .
23,660
def call ( text ) output = [ ] file = Tempfile . new ( 'foo' , encoding : 'utf-8' ) begin file . write ( text ) file . close stdin , stdout , stderr = Open3 . popen3 ( command ( file . path ) ) Timeout :: timeout ( @timeout ) { until ( line = stdout . gets ) . nil? output << line . chomp end message = stderr . readline...
Initializes the client
23,661
def action? ( resource , action ) resource = resource . to_sym action = action . to_sym return false unless resource? ( resource ) _resources . find ( resource ) . actions . names . include? action end
Whether an action is defined on a resource on the version .
23,662
def marc4j_to_rubymarc ( marc4j ) rmarc = MARC :: Record . new rmarc . leader = marc4j . getLeader . marshal marc4j . getControlFields . each do | marc4j_control | rmarc . append ( MARC :: ControlField . new ( marc4j_control . getTag ( ) , marc4j_control . getData ) ) end marc4j . getDataFields . each do | marc4j_data ...
Get a new coverter Given a marc4j record return a rubymarc record
23,663
def rubymarc_to_marc4j ( rmarc ) marc4j = @factory . newRecord ( rmarc . leader ) rmarc . each do | f | if f . is_a? MARC :: ControlField new_field = @factory . newControlField ( f . tag , f . value ) else new_field = @factory . new_data_field ( f . tag , f . indicator1 . ord , f . indicator2 . ord ) f . each do | sf |...
Given a rubymarc record return a marc4j record
23,664
def require_marc4j_jar ( jardir ) unless defined? JRUBY_VERSION raise LoadError . new , "MARC::MARC4J requires the use of JRuby" , nil end if jardir Dir . glob ( "#{jardir}/*.jar" ) do | x | require x end else Dir . glob ( File . join ( DEFAULT_JAR_RELATIVE_DIR , "*.jar" ) ) do | x | require x end end end
Try to get the specified jarfile or the bundled one if nothing is specified
23,665
def mkdir ( option = { } ) mode = option [ :mode ] || 0700 path = create ( option ) path . mkdir ( mode ) return path end
Create a temporary directory .
23,666
def touch ( option = { } ) mode = option [ :mode ] || 0600 path = create ( option ) path . open ( "w" , mode ) return path end
Create a empty file .
23,667
def up_vote ( votable ) is_votable? ( votable ) vote = get_vote ( votable ) if vote if vote . up_vote raise Exceptions :: AlreadyVotedError . new ( true ) else vote . up_vote = true votable . down_votes -= 1 self . down_votes -= 1 if has_attribute? ( :down_votes ) end else vote = Vote . create ( :votable => votable , :...
Up vote any votable object . Raises an AlreadyVotedError if the voter already voted on the object .
23,668
def up_vote! ( votable ) begin up_vote ( votable ) success = true rescue Exceptions :: AlreadyVotedError success = false end success end
Up vote any votable object without raising an error . Vote is ignored .
23,669
def down_vote! ( votable ) begin down_vote ( votable ) success = true rescue Exceptions :: AlreadyVotedError success = false end success end
Down vote a votable object without raising an error . Vote is ignored .
23,670
def up_voted? ( votable ) is_votable? ( votable ) vote = get_vote ( votable ) return false if vote . nil? return true if vote . has_attribute? ( :up_vote ) && vote . up_vote false end
Returns true if the voter up voted the votable .
23,671
def check_types ( key = 'root' , expected = TYPES , actual = self , opts = { } ) bad_type ( key , expected , actual , opts ) unless actual . is_a? expected . class case actual when Hash then actual . each { | k , v | check_types ( k , expected [ k ] , v ) } when Enumerable then actual . each { | v | check_types ( key ,...
Checks that the given hash has the valid types for each value if they exist .
23,672
def next_generation_cell ( left , middle , right ) case [ left , middle , right ] when [ 1 , 1 , 1 ] then @binary_string [ 0 ] . to_i when [ 1 , 1 , 0 ] then @binary_string [ 1 ] . to_i when [ 1 , 0 , 1 ] then @binary_string [ 2 ] . to_i when [ 1 , 0 , 0 ] then @binary_string [ 3 ] . to_i when [ 0 , 1 , 1 ] then @binar...
Returns 0 or 1 .
23,673
def call ( issue ) status = decode_status ( issue ) { key : issue . key , type : issue . issuetype . name , priority : issue . priority . name , status : status , summary : issue . summary , created_date : issue . created , closed_date : issue . resolutiondate } end
WIP ATM mapper serialises issue to JSON We might consider using objects
23,674
def path if @parent :: File . join ( @parent . path , name ) else if name != '.' :: File . join ( '.' , name ) else name end end end
This + Directory + s path
23,675
def | ( other ) if ! other . is_a? ( Directory ) raise ArgumentError , "#{other} is not a Directory" end dup . tap do | directory | other . files . each do | file | directory . add_file ( file . dup ) end other . directories . each do | new_directory | existing_directory = @directories [ new_directory . name ] if exist...
Computes the union of this + Directory + with another + Directory + . If the two directories have a file path in common the file in the + other + + Directory + takes precedence . If the two directories have a sub - directory path in common the union s sub - directory path will be the union of those two sub - directorie...
23,676
def each ( & block ) files . each ( & block ) directories . each do | subdirectory | block . call ( subdirectory ) subdirectory . each ( & block ) end end
Iterates through this + Directory + s children depth - first
23,677
def slice ( * keep ) inject ( Characterizable :: BetterHash . new ) do | memo , ary | if keep . include? ( ary [ 0 ] ) memo [ ary [ 0 ] ] = ary [ 1 ] end memo end end
I need this because otherwise it will try to do self . class . new on subclasses which would get 0 for 1 arguments error with Snapshot among other things
23,678
def method_missing ( * args , & block ) Thread . pass until defined? ( @result ) case @result when Exception def self . method_missing ( * args , & block ) ; raise @result ; end else def self . method_missing ( * args , & block ) ; @result . send ( * args , & block ) ; end end self . method_missing ( * args , & block )...
Allows the job to behave as the return value of the block .
23,679
def enumerate_by ( attribute = :name , options = { } ) options . reverse_merge! ( :cache => true ) options . assert_valid_keys ( :cache ) extend EnumerateBy :: ClassMethods extend EnumerateBy :: Bootstrapped include EnumerateBy :: InstanceMethods cattr_accessor :enumerator_attribute self . enumerator_attribute = attrib...
Indicates that this class is an enumeration .
23,680
def typecast_enumerator ( enumerator ) if enumerator . is_a? ( Array ) enumerator . flatten! enumerator . map! { | value | typecast_enumerator ( value ) } enumerator else enumerator . is_a? ( Symbol ) ? enumerator . to_s : enumerator end end
Typecasts the given enumerator to its actual value stored in the database . This will only convert symbols to strings . All other values will remain in the same type .
23,681
def root_elements ( yield_name = 'main' ) ret = elements . where ( 'container_id IS NULL and page_yield_name = ?' , yield_name . to_s ) . order ( 'position ASC' ) unless siblings . empty? ret += Humpyard :: Element . where ( 'container_id IS NULL and page_id in (?) and page_yield_name = ? and shared_state = ?' , siblin...
Return the elements on a yield container . Includes shared elemenents from siblings or parents
23,682
def child_pages options = { } if content_data . is_humpyard_dynamic_page? content_data . child_pages else if options [ :single_root ] and is_root_page? Page . where ( [ "parent_id = ? or parent_id IS NULL and NOT id = ?" , id , id ] ) else children end end end
Find the child pages
23,683
def last_modified options = { } changed_at = [ Time . zone . at ( :: File . new ( "#{Rails.root}" ) . mtime ) , created_at , updated_at , modified_at ] if ( options [ :include_pages ] ) changed_at << Humpyard :: Page . select ( 'updated_at' ) . order ( 'updated_at DESC' ) . first . updated_at end ( changed_at - [ nil ]...
Return the logical modification time for the page suitable for http caching generational cache keys etc .
23,684
def url_for ( path , opts = { } ) path = absolute ( path ) ( opts [ :expires ] ? storage . media ( path ) : storage . shares ( path ) ) [ 'url' ] end
Only option is expires and it s a boolean
23,685
def attribute_match? ( attribute , value ) hash_obj_matcher = lambda do | obj , k , v | value = obj . send ( k ) if ! value . nil? && v . is_a? ( Hash ) v . all? { | k2 , v2 | hash_obj_matcher . call ( value , k2 , v2 ) } else value == v end end hash_obj_matcher . call ( self , attribute , value ) end
checks if the square matches the attributes passed .
23,686
def included ( base ) my_injector = injector injector_holder = Module . new do define_method :__dio_injector__ do my_injector end end base . extend ( ClassMethods , injector_holder ) base . include ( InstanceMethods ) end
Add some methods to a class which includes Dio module .
23,687
def send_sms ( options ) raise ArgumentError , 'an options Hash is required' if ! options . instance_of? ( Hash ) raise ArgumentError , ':sender_address is required' if options [ :sender_address ] . nil? && @sender_address . nil? raise ArgumentError , ':address is required' if options [ :address ] . nil? raise Argument...
Intantiate a new class to work with OneAPI
23,688
def method_missing ( method , * args ) if method . to_s . match / / if args . size == 2 @subscriptions . send method , args [ 0 ] , args [ 1 ] else @subscriptions . send method , args [ 0 ] end else if method == :delivery_status || method == :retrieve_sms || method == :search_sms @reporting . send method , args [ 0 ] e...
Dispatches method calls to other objects for subscriptions and reporting
23,689
def amplify! ( user ) user . portals << @portal unless user . portals . include? ( @portal ) user . default_portal = @portal unless user . default_portal user end
Adds the configured portal to the user if necessary .
23,690
def decode self . raw_splits . each do | split | self . modules . each do | m | m . decode_split ( split ) end end end
Decode all string fragments
23,691
def sbyc ( super_domain = Object , & pred ) Class . new ( super_domain ) { extend SByC . new ( super_domain , pred ) } end
Creates a domain through specialization by constraint
23,692
def get_or_create ( key ) @lock . synchronize do if @store . include? ( key ) @store [ key ] elsif block_given? @store [ key ] = yield else raise Wireless :: KeyError . new ( "#{@type} not found: #{key}" , key : key ) end end end
Retrieve a value from the store . If it doesn t exist and a block is supplied create and return it ; otherwise raise a KeyError .
23,693
def transition_state ( state ) authorize @contribution @initiative = @contribution . initiative @user = @contribution . user state = state . to_sym transition = @contribution . transition_by_state ( state ) initial_state = @contribution . state_name resource_name = @contribution . class . model_name . human if @contrib...
This method authorizes
23,694
def rack_options symbolized_options ( :port , :host , :server , :daemonize , :pid ) . tap do | rack_options | rack_options [ :environment ] = environment rack_options [ :Port ] = rack_options . delete :port rack_options [ :Host ] = rack_options . delete :host rack_options [ :app ] = machined end end
Returns the options needed for setting up the Rack server .
23,695
def symbolized_options ( * keys ) @symbolized_options ||= begin opts = { } . merge ( options ) opts . merge! saved_options if saved_options? opts . symbolize_keys end @symbolized_options . slice ( * keys ) end
Returns a mutable options hash with symbolized keys . Optionally returns only the keys given .
23,696
def look_up_table ( lut_key , options = { } , & block ) options = { :batch_size => 10000 , :prefix => "#{self.name}/" , :read_on_init => false , :use_cache => true , :sql_mode => true , :where => nil } . merge ( options ) self . lut_set_proc ( lut_key , block ) self . lut_set_options ( lut_key , options ) self . lut ( ...
== Defining LookUpTables
23,697
def lut ( lut_key = nil , lut_item_key = nil ) @lut ||= { } if lut_key . nil? hash = { } self . lut_keys . each { | key | hash [ key ] = self . lut ( key ) } return hash end @lut [ lut_key . intern ] ||= lut_read ( lut_key ) || { } if lut_key . respond_to? ( :intern ) self . lut_deep_hash_call ( :lut , @lut , lut_key ,...
== Calling LookUpTables
23,698
def lut_reload ( lut_key = nil ) if lut_key lut_reset ( lut_key ) lut ( lut_key ) else lut_keys . each { | k | lut_reload ( k ) } end lut_keys end
Reading LUT and writing cache again
23,699
def lut_read ( name ) return nil unless options = lut_options ( name ) if options [ :use_cache ] lut_read_from_cache ( name ) else lut_read_without_cache ( name ) end end
Reads a single lut