idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
17,700 | def to_h details . reject do | key | ! KEYS . include? ( key ) end . deep_transform_keys { | key | key . to_s . camelize } end | Converts hash keys to Pascal case and rejects invalid keys . |
17,701 | def graph_block ( graph_filter ) block = Proc . new { | components | components << Scruffy :: Components :: Grid . new ( :grid , :position => [ 10 , 0 ] , :size => [ 90 , 89 ] ) components << Scruffy :: Components :: ValueMarkers . new ( :value_markers , :position => [ 0 , 2 ] , :size => [ 8 , 89 ] ) components << Scru... | Returns a typical graph layout . |
17,702 | def job_flow_step ( job_config ) jar = job_config [ 'jar' ] max_files = self . job . max_files step_args = [ ] step_args [ 0 ] = job_config [ 'class' ] step_args [ 1 ] = self . input_paths step_args [ 2 ] = self . output_path step_args [ 3 ] = max_files . to_s if max_files . present? step = Elasticity :: CustomJarStep ... | Returns a custom jar step that is configured with the jar location class name and input and output paths . |
17,703 | def set_step_name case self . job . type when 'Elasticrawl::ParseJob' if self . crawl_segment . present? max_files = self . job . max_files || 'all' "#{self.crawl_segment.segment_desc} Parsing: #{max_files}" end when 'Elasticrawl::CombineJob' paths = self . input_paths . split ( ',' ) "Combining #{paths.count} jobs" en... | Sets the Elastic MapReduce job flow step name based on the type of job it belongs to . |
17,704 | def found_gids ( data = result ) [ ] . tap do | ids | case data when Hash ids . concat ( Array ( data [ 'id' ] ) ) ids . concat ( found_gids ( data . values ) ) when Array data . each { | datum | ids . concat ( found_gids ( datum ) ) } end end end | The GIDs from this frame s results . |
17,705 | def secondary_sort ( start_index , end_index ) @job . set_partitioner_class ( Hadoop :: Mapreduce :: Lib :: Partition :: BinaryPartitioner ) Hadoop :: Mapreduce :: Lib :: Partition :: BinaryPartitioner . set_offsets ( @job . configuration , start_index , end_index ) @job . set_grouping_comparator_class ( Humboldt :: Ja... | Configures the job for secondary sort on the specified slice of the mapper output key . |
17,706 | def render ( svg , options ) setup_variables ( options ) coords = generate_coordinates ( options ) draw ( svg , coords , options ) end | Returns a new Base object . |
17,707 | def setup_variables ( options = { } ) @color = ( preferred_color || options . delete ( :color ) ) @outline = ( preferred_outline || options . delete ( :outline ) ) @width , @height = options . delete ( :size ) @min_value , @max_value = options [ :min_value ] , options [ :max_value ] @opacity = options [ :opacity ] || 1... | Sets up several variables that almost every graph layer will need to render itself . |
17,708 | def to_h details . deep_transform_keys do | key | pascal_key = key . to_s . camelize if SPECIAL_CASES . has_key? ( key ) pascal_key = SPECIAL_CASES [ key ] end pascal_key end end | Converts hash keys to Pascal case and handles special cases . |
17,709 | def gem ( * args ) options = extract_options! ( args ) name , version = args parts , message = [ name . inspect ] , name if version ||= options . delete ( :version ) parts << version . inspect message << " (#{version})" end message = options [ :git ] if options [ :git ] say_status :gemfile , message options . each do |... | Adds an entry into Gemfile for the supplied gem . |
17,710 | def application ( data = nil , & block ) data = block . call if ! data && block_given? data = "\n#{data}" unless data =~ / \n / data << "\n" unless data =~ / \n / inject_into_file 'boot.rb' , data , :after => / \. \n / end | Appends a line inside the TinyRailsApp class on boot . rb . |
17,711 | def to_mysql_belongs_to ( name , options = { } ) field "#{name}_id" , type : Integer object_class = options [ :class ] || name . to_s . titleize . delete ( ' ' ) . constantize self . instance_eval do define_method ( name ) do | reload = false | if reload self . instance_variable_set ( "@#{name}" , nil ) end if self . i... | Connection methods from mongoid to mysql |
17,712 | def build_query GraphQL . parse ( BASE_QUERY ) . tap do | d_ast | selections = d_ast . definitions . first . selections . first . selections node_types . each do | type | selections << inline_fragment_ast ( type ) if include? ( type ) end selections . compact! end end | Build a query for our relay schema that selects an inline fragment for every node type . For every inline fragment we select the ID of every node field and connection . |
17,713 | def inline_fragment_ast ( type , with_children : true ) selections = [ ] if with_children type . all_fields . each do | field | field_type = field . type . unwrap if node_field? ( field ) && include? ( field_type ) selections << node_field_ast ( field ) elsif connection_field? ( field ) && include? ( field_type ) selec... | Make an inline fragment AST . |
17,714 | def field_ast ( field , arguments = { } , & blk ) type = field . type . unwrap required_args_are_present = field . arguments . all? do | arg_name , arg | arguments . key? ( arg_name ) || valid_input? ( arg . type , nil ) end if ! required_args_are_present nil else f_alias = field . name == 'id' ? nil : random_alias f_a... | Make a field AST . |
17,715 | def node_field_ast ( field ) f_ast = field_ast ( field ) return nil if f_ast . nil? type = field . type . unwrap selections = f_ast . selections . dup if type . kind . object? selections << field_ast ( type . get_field ( 'id' ) ) else possible_node_types ( type ) . each do | if_type | selections << inline_fragment_ast ... | Make a field AST for a node field . |
17,716 | def edges_field_ast ( field ) f_ast = field_ast ( field ) return nil if f_ast . nil? node_fields = [ node_field_ast ( field . type . unwrap . get_field ( 'node' ) ) ] if f_ast . respond_to? ( :merge ) f_ast . merge ( selections : f_ast . selections + node_fields ) else f_ast . selections . concat ( node_fields ) f_ast ... | Make a field AST for an edges field . |
17,717 | def connection_field_ast ( field ) f_ast = field_ast ( field , connection_arguments ) return nil if f_ast . nil? edges_fields = [ edges_field_ast ( field . type . unwrap . get_field ( 'edges' ) ) ] if f_ast . respond_to? ( :merge ) f_ast . merge ( selections : f_ast . selections + edges_fields ) else f_ast . selections... | Make a field AST for a connection field . |
17,718 | def node_field? ( field ) type = field . type . unwrap kind = type . kind if kind . object? node_types . include? ( type ) elsif kind . interface? || kind . union? possible_node_types ( type ) . any? end end | Is this field for a relay node? |
17,719 | def connection_field? ( field ) type = field . type . unwrap if edges_field = type . get_field ( 'edges' ) edges = edges_field . type . unwrap if node_field = edges . get_field ( 'node' ) return node_field? ( node_field ) end end false end | Is this field for a relay connection? |
17,720 | def possible_types ( type ) if type . kind . interface? schema . possible_types ( type ) elsif type . kind . union? type . possible_types end end | Get the possible types of a union or interface . |
17,721 | def rules return [ ] if result [ :rules ] . nil? Array . wrap ( result [ :rules ] [ :rule_compliance_response ] ) . map do | rule | ComplianceRule . new ( rule ) end end | Wraps the + RuleComplianceResponse + nodes with ComplianceRule . |
17,722 | def request ( order_Id , amount , billing_cust_name , billing_cust_address , billing_cust_city , billing_zip_code , billing_cust_state , billing_cust_country , billing_cust_email , billing_cust_tel , billing_cust_notes = "" , delivery_cust_name = "" , delivery_cust_address = "" , delivery_cust_city = "" , delivery_zip_... | constructer to one time initialze genric keys request CCAvenue encrypted data |
17,723 | def response ( response ) raw_response = CGI :: parse ( decrypt_data ( response , @working_Key , "AES-128-CBC" ) ) auth_desc = raw_response [ "AuthDesc" ] [ 0 ] order_id = raw_response [ "Order_Id" ] [ 0 ] amount = raw_response [ "Amount" ] [ 0 ] checksum = raw_response [ "Checksum" ] [ 0 ] verification = verifyChecksu... | calling response method to check if everything went well |
17,724 | def verifyChecksum ( order_Id , amount , authDesc , checksum ) String str = @merchant_Id + "|" + order_Id + "|" + amount + "|" + authDesc + "|" + @working_Key String newChecksum = Zlib :: adler32 ( str ) . to_s return ( newChecksum . eql? ( checksum ) ) ? true : false end | verify checksum response |
17,725 | def hextobin ( hexstring ) length = hexstring . length binString = "" count = 0 while count < length do substring = hexstring [ count , 2 ] substring = [ substring ] packedString = substring . pack ( 'H*' ) if count == 0 binString = packedString else binString += packedString end count += 2 end return binString end | hex - to - bin |
17,726 | def walk ( from_id : , except : nil , only : nil , variables : { } , context : { } ) query_string = GraphQL :: Relay :: Walker . query_string ( schema , except : except , only : only ) walker_query = parse ( query_string ) GraphQL :: Relay :: Walker . walk ( from_id : from_id ) do | frame | response = query ( walker_qu... | Walk this client s graph from the given GID . |
17,727 | def player PLAYERS . each do | player | player_load ( player ) || next instance = player_class ( player ) . new player_on_platform? ( instance ) || next return instance if player_launched? ( instance ) end nil end | Returns an instance of the first music player that s launched |
17,728 | def bounds_for ( canvas_size , position , size ) return nil if ( position . nil? || size . nil? ) bounds = { } bounds [ :x ] = canvas_size . first * ( position . first / 100 . to_f ) bounds [ :y ] = canvas_size . last * ( position . last / 100 . to_f ) bounds [ :width ] = canvas_size . first * ( size . first / 100 . to... | Converts percentage values into actual pixel values based on the known render size . |
17,729 | def route_format ( target , idx , options = { } ) args = [ target , idx , options ] if respond_to? ( :format ) send :format , * args [ 0 ... self . method ( :format ) . arity ] elsif respond_to? ( :format! ) send :format! , * args [ 0 ... self . method ( :format! ) . arity ] target else raise NameError , "Formatter sub... | Called by the value marker component . Routes the format call to one of a couple possible methods . |
17,730 | def format ( target , idx , options ) my_precision = @precision if @precision == :auto my_precision = options [ :all_values ] . inject ( 0 ) do | highest , current | cur = current . to_f . to_s . split ( "." ) . last . size cur > highest ? cur : highest end my_precision = @precision_limit if my_precision > @precision_l... | Returns a new Number formatter . |
17,731 | def format ( target , idx , options ) @separator = "" unless @precision > 0 begin parts = number_with_precision ( target , @precision ) . split ( '.' ) if @special_negatives && ( target . to_f < 0 ) number = "(" + @unit + parts [ 0 ] . to_i . abs . to_s . gsub ( / \d \d \d \d \d / , "\\1#{@delimiter}" ) + @separator + ... | Returns a new Currency class . |
17,732 | def format ( target ) begin number = number_with_precision ( target , @precision ) parts = number . split ( '.' ) if parts . at ( 1 ) . nil? parts [ 0 ] + "%" else parts [ 0 ] + @separator + parts [ 1 ] . to_s + "%" end rescue target end end | Returns new Percentage formatter . |
17,733 | def openbabel descriptor , compound obdescriptor = OpenBabel :: OBDescriptor . find_type descriptor obmol = OpenBabel :: OBMol . new obconversion = OpenBabel :: OBConversion . new obconversion . set_in_format 'smi' obconversion . read_string obmol , compound . smiles { "#{library.capitalize}.#{descriptor}" => fix_value... | Calculate OpenBabel descriptors |
17,734 | def neighbours offsets = ( - 1 .. 1 ) . to_a . product ( ( - 1 .. 1 ) . to_a ) offsets . map do | lat , lng | begin neighbour ( lat : lat , lng : lng ) rescue ArgumentError nil end end . compact end | return neighbouring tiles to the north northeast and east |
17,735 | def stamp_class ( path , opt = { } ) Cog . activate_language opt [ :language ] do l = Cog . active_language raise Errors :: ActiveLanguageDoesNotSupportSeeds . new :language => l if l . nil? || l . seed_extension . nil? @in_header = false @header_path = if l . seed_header "#{path}.#{l.seed_header}" end stamp "cog/#{l.k... | Render the class in the currently active language |
17,736 | def draw ( svg , coords , options = { } ) coords . each_with_index do | coord , idx | x , y , bar_height = ( coord . first ) , coord . last , 1 valh = max_value + min_value * - 1 maxh = max_value * height / valh minh = min_value * height / valh svg . line ( :x1 => x + @bar_width / 2 , :x2 => x + @bar_width / 2 , :y1 =>... | Draw box plot . |
17,737 | def copy_keeps ( original , scratch ) Cog . activate_language ( :filename => original ) do original = scratch unless File . exists? original keeps = gather_keeps original , scratch keeps . each_pair do | hook , c | result = update c , :type => 'keep' do | c | c . keep_body end raise Errors :: UnrecognizedKeepHook . new... | Copy keep bodies from the original file to the scratch file |
17,738 | def render ( svg , options = { } ) layers . each_with_index do | layer , i | layer_options = options . dup layer_options [ :num_bars ] = layers . size layer_options [ :position ] = i layer_options [ :color ] = layer . preferred_color || layer . color || options [ :theme ] . next_color layer . render ( svg , layer_optio... | Returns new Multi graph . |
17,739 | def draw ( svg , coords , options = { } ) coords . each_with_index do | coord , idx | next if coord . nil? x , y , bar_height = ( coord . first ) , coord . last , 1 valh = max_value + min_value * - 1 maxh = max_value * height / valh minh = min_value * height / valh if points [ idx ] > 0 bar_height = points [ idx ] * ma... | Draw bar graph . Now handles positive and negative values gracefully . |
17,740 | def stamp ( template_path , destination = nil , opt = { } ) opt , destination = destination , nil if destination . is_a? Hash r = find_and_render template_path , opt r = filter_through r , opt [ :filter ] return r if destination . nil? write_scratch_file ( destination , r , opt [ :absolute_destination ] ) do | path , s... | Stamp a template into a file or return it as a string |
17,741 | def embed ( hook , & block ) eaten = 0 Embeds . find ( hook ) do | c | c . eaten = eaten if Embeds . update c , & block eaten += 1 if c . once? STDOUT . write "Updated #{c.path.relative_to_project_root} - #{(c.index + 1).ordinalize} occurrence of embed '#{c.hook}'\n" . color :white end end end | Provide a value for embeds with the given hook |
17,742 | def set_input_jobs ( input_jobs ) segment_count = 0 input_paths = [ ] input_jobs . each do | job_name | input_job = Job . where ( :job_name => job_name , :type => 'Elasticrawl::ParseJob' ) . first_or_initialize step_count = input_job . job_steps . count if step_count > 0 segment_count += step_count input_paths << set_i... | Takes in an array of parse jobs that are to be combined . Creates a single job step whose input paths are the outputs of the parse jobs . |
17,743 | def run emr_config = job_config [ 'emr_config' ] job_flow_id = run_job_flow ( emr_config ) if job_flow_id . present? self . job_flow_id = job_flow_id self . save self . result_message end end | Runs the job by calling the Elastic MapReduce API . |
17,744 | def set_input_path ( input_job ) job_name = input_job . job_name input_filter = job_config [ 'input_filter' ] s3_path = "/data/1-parse/#{job_name}/segments/*/#{input_filter}" build_s3_uri ( s3_path ) end | Returns the S3 location for reading a parse job . A wildcard is used for the segment names . The input filter depends on the output file type of the parse job and what type of compression is used . |
17,745 | def load_config ( config_file ) if dir_exists? begin config_file = File . join ( config_dir , "#{config_file}.yml" ) config = YAML :: load ( File . open ( config_file ) ) rescue StandardError => e raise FileAccessError , e . message end else raise ConfigDirMissingError , 'Config dir missing. Run init command' end end | Loads a YAML configuration file . |
17,746 | def load_database if dir_exists? config = { 'adapter' => 'sqlite3' , 'database' => File . join ( config_dir , DATABASE_FILE ) , 'pool' => 5 , 'timeout' => 5000 } begin ActiveRecord :: Base . establish_connection ( config ) ActiveRecord :: Migrator . migrate ( File . join ( File . dirname ( __FILE__ ) , '../../db/migrat... | Loads the sqlite database . If no database exists it will be created and the database migrations will be run . |
17,747 | def bucket_exists? ( bucket_name ) begin s3 = AWS :: S3 . new s3 . buckets [ bucket_name ] . exists? rescue AWS :: S3 :: Errors :: SignatureDoesNotMatch => e raise AWSCredentialsInvalidError , 'AWS access credentials are invalid' rescue AWS :: Errors :: Base => s3e raise S3AccessError . new ( s3e . http_response ) , s3... | Checks if a S3 bucket name is in use . |
17,748 | def create_bucket ( bucket_name ) begin s3 = AWS :: S3 . new s3 . buckets . create ( bucket_name ) rescue AWS :: Errors :: Base => s3e raise S3AccessError . new ( s3e . http_response ) , s3e . message end end | Creates a bucket using the S3 API . |
17,749 | def delete_bucket ( bucket_name ) begin s3 = AWS :: S3 . new bucket = s3 . buckets [ bucket_name ] bucket . delete! rescue AWS :: Errors :: Base => s3e raise S3AccessError . new ( s3e . http_response ) , s3e . message end end | Deletes a bucket and its contents using the S3 API . |
17,750 | def deploy_templates ( bucket_name ) begin Dir . mkdir ( config_dir , 0755 ) if dir_exists? == false TEMPLATE_FILES . each do | template_file | FileUtils . cp ( File . join ( File . dirname ( __FILE__ ) , TEMPLATES_DIR , template_file ) , File . join ( config_dir , template_file ) ) end save_config ( 'jobs' , { 'BUCKET... | Creates config directory and copies config templates into it . Saves S3 bucket name to jobs . yml and AWS credentials to aws . yml . |
17,751 | def save_aws_config env_key = ENV [ 'AWS_ACCESS_KEY_ID' ] env_secret = ENV [ 'AWS_SECRET_ACCESS_KEY' ] creds = { } creds [ 'ACCESS_KEY_ID' ] = @access_key_id unless @access_key_id == env_key creds [ 'SECRET_ACCESS_KEY' ] = @secret_access_key unless @secret_access_key == env_secret save_config ( 'aws' , creds ) end | Saves AWS access credentials to aws . yml unless they are configured as environment variables . |
17,752 | def save_config ( template , params ) config_file = File . join ( config_dir , "#{template}.yml" ) config = File . read ( config_file ) params . map { | key , value | config = config . gsub ( key , value ) } File . open ( config_file , 'w' ) { | file | file . write ( config ) } end | Saves config values by overwriting placeholder values in template . |
17,753 | def delete_config_dir begin FileUtils . rm_r ( config_dir ) if dir_exists? rescue StandardError => e raise FileAccessError , e . message end end | Deletes the config directory including its contents . |
17,754 | def status_message ( bucket_name , state ) message = [ '' , "Bucket s3://#{bucket_name} #{state}" ] message << "Config dir #{config_dir} #{state}" state = 'complete' if state == 'created' message << "Config #{state}" message . join ( "\n" ) end | Notifies user of results of init or destroy commands . |
17,755 | def exec_migration ( migration , is_up ) migration_dir = self . migration_dir ( migration ) result = @lang . exec_migration ( migration_dir , is_up ) if @lang . ext != "sql" puts result end Log . info ( "Updating current version number..." ) version = migration [ "version" ] is_up ? @db . log_up ( version ) : @db . log... | will execute single migration by running up or down script |
17,756 | def exec_migrations ( is_up = true ) Log . info ( "Executing migrations..." ) migrations = yield @db . current_version if migrations . count == 0 Log . warn ( "Migrations not found" ) return end migrations . each do | migration | self . exec_migration ( migration , is_up ) end Log . success ( "Migrations executed. Curr... | will execute range of migrations |
17,757 | def run ( * args ) if args . empty? || ( args . size == 1 && %w( -h --help ) . include? ( args . first ) ) puts help else sparkline = Sparkline . new ( args . map ( & :to_f ) ) puts sparkline . to_s end end | Runs sparkr with the given + args + |
17,758 | def fingerprint type = DEFAULT_FINGERPRINT unless fingerprints [ type ] return [ ] unless self . smiles if type == "MP2D" fp = obconversion ( smiles , "smi" , "mpd" ) . strip . split ( "\t" ) name = fp . shift fingerprints [ type ] = fp . uniq elsif type == "MNA" level = 2 fp = obconversion ( smiles , "smi" , "mna" , "... | Create chemical fingerprint |
17,759 | def smarts_match smarts , count = false obconversion = OpenBabel :: OBConversion . new obmol = OpenBabel :: OBMol . new obconversion . set_in_format ( 'smi' ) obconversion . read_string ( obmol , self . smiles ) smarts_pattern = OpenBabel :: OBSmartsPattern . new smarts . collect do | sma | smarts_pattern . init ( sma ... | Match a SMARTS substructure |
17,760 | def svg if self . svg_id . nil? svg = obconversion ( smiles , "smi" , "svg" ) file = Mongo :: Grid :: File . new ( svg , :filename => "#{id}.svg" , :content_type => "image/svg" ) update ( :svg_id => $gridfs . insert_one ( file ) ) end $gridfs . find_one ( _id : self . svg_id ) . data end | Get SVG image |
17,761 | def png if self . png_id . nil? png = obconversion ( smiles , "smi" , "_png2" ) file = Mongo :: Grid :: File . new ( Base64 . encode64 ( png ) , :filename => "#{id}.png" , :content_type => "image/png" ) update ( :png_id => $gridfs . insert_one ( file ) ) end Base64 . decode64 ( $gridfs . find_one ( _id : self . png_id ... | Get png image |
17,762 | def generate_coordinates ( options = { } ) key_layer = layers . find { | layer | layer . relevant_data? } options [ :point_distance ] = width / ( key_layer . points . size - 1 ) . to_f coords = [ ] key_layer . points . each_with_index do | layer , idx | sum , objects = points . inject ( [ 0 , 0 ] ) do | arr , elem | if... | Override default generate_coordinates method to iterate through the layers and generate coordinates based on the average data points . |
17,763 | def resolve_snippet_path ( context , tag ) if tag . has_repo? pkg = find_package_by_tag ( tag ) pkg . snippet_path tag . path else new_context = context . clone new_context . dirname + "/" + tag . filename end end | Resolve snippet path by context and tag |
17,764 | def find_package_by_tag ( tag ) if tag . has_ref? find_package ( tag . repo , tag . ref ) else find_package ( tag . repo ) end end | Find repository by tag |
17,765 | def find_package ( name , ref = nil ) repo = find_repository ( name ) ref ||= repo . latest_package_version || repo . current_ref raise "invalid references" unless repo . has_ref? ( ref ) Models :: Package . find_by ( :repo_name => name , :rev_hash => repo . rev_hash [ ref ] , ) end | Find repository by repo name |
17,766 | def remove_image ( params = { } ) raise ArgumentError , 'Invalid arguments.' unless check_arguments ( params , 'name' ) path = '/images/' + params [ :name ] query = { } query [ :force ] = true if params . key? ( :force ) res = JSON . parse ( Hyperb :: Request . new ( self , path , query , 'delete' ) . perform ) downcas... | remove an image |
17,767 | def inspect_image ( params = { } ) raise ArgumentError , 'Invalid arguments.' unless check_arguments ( params , 'name' ) path = '/images/' + params [ :name ] + '/json' res = JSON . parse ( Hyperb :: Request . new ( self , path , { } , 'get' ) . perform ) downcase_symbolize ( res ) end | inspect an image |
17,768 | def add_child ( name ) child = self . class . new ( name , self ) yield child if block_given? children << child child end | Creates a child adds it to children and returns the child |
17,769 | def [] ( key ) selected_child = children . select { | child | child . name == key } selected_child . size . eql? ( 1 ) ? selected_child . first : selected_child end | Lookup a child node by its name |
17,770 | def respond_with_with_storage ( * args , & block ) @responded_with = args . last . is_a? ( Hash ) ? args - [ args . last ] : args respond_with_without_storage ( * args , & block ) end | Custom respond_with wich stores resources for later use |
17,771 | def fmt formated = { } attrs . each_key do | key | formated [ camelize ( key ) ] = attrs [ key ] end formated end | returns a hash containing formated host config data |
17,772 | def to_pdf ( * args ) options = extract_options! ( args ) datasource = args [ 0 ] _JasperPrint = Rjb . import ( 'net.sf.jasperreports.engine.JasperPrint' ) _JasperExportManager = Rjb . import ( 'net.sf.jasperreports.engine.JasperExportManager' ) _JasperExportManager . _invoke ( 'exportReportToPdf' , 'Lnet.sf.jasperrepo... | Constructor for a report generator Export report to PDF with given datasource |
17,773 | def to_file ( format , * args ) options = extract_options! ( args ) datasource = args [ 0 ] path = options [ :path ] || File . join ( Dir . tmpdir , "beardley_#{Time.now.to_i.to_s(36)}_#{rand(100_000_000_000).to_s(36)}.#{format}" ) if format == :pdf _JasperPrint = Rjb . import ( 'net.sf.jasperreports.engine.JasperPrint... | Generic method to export to some format like ODT and DOCX as file in the given place |
17,774 | def to ( format , * args ) options = extract_options! ( args ) datasource = args [ 0 ] file = Tempfile . new ( "to_#{format}" ) exporter = Beardley . with_warnings { Rjb . import ( Beardley . exporters [ format ] ) } . new _JRExporterParameter = Rjb . import ( 'net.sf.jasperreports.engine.JRExporterParameter' ) exporte... | Generic method to export to some format like ODT and DOCX |
17,775 | def prepare ( datasource = nil ) if @source_file && ( ( ! @object_file . exist? && @source_file . exist? ) || ( @source_file . exist? && @source_file . mtime > @object_file . mtime ) ) _JasperCompileManager = Rjb . import ( 'net.sf.jasperreports.engine.JasperCompileManager' ) _JasperCompileManager . compileReportToFile... | Create object file if not exist and load datasource |
17,776 | def prepare_params _HashMap = Rjb . import ( 'java.util.HashMap' ) _JavaString = Rjb . import ( 'java.lang.String' ) params = _HashMap . new Beardley . config [ :report_params ] . each do | k , v | params . put ( k , v ) end @parameters . each do | key , value | params . put ( _JavaString . new ( key . to_s ) , paramet... | Build the default parameters Hash for printing |
17,777 | def load_datasource ( datasource = nil ) jasper_params = prepare_params if datasource _InputSource = Rjb . import ( 'org.xml.sax.InputSource' ) _StringReader = Rjb . import ( 'java.io.StringReader' ) _JRXmlUtils = Rjb . import ( 'net.sf.jasperreports.engine.util.JRXmlUtils' ) _JRXPathQueryExecuterFactory = Beardley . w... | Load parseable XML datasource with java component |
17,778 | def fill_report ( params , datasource = nil ) _JasperFillManager = Rjb . import ( 'net.sf.jasperreports.engine.JasperFillManager' ) if datasource return _JasperFillManager . fillReport ( @object_file . to_s , params ) else _JREmptyDataSource = Rjb . import ( 'net.sf.jasperreports.engine.JREmptyDataSource' ) return _Jas... | Fill the report with valid method depending on datasource |
17,779 | def fields ( new_fields = nil ) if new_fields . nil? fields = { } self . class . fields . each do | field | fields [ field ] = public_send ( field ) end fields else self . fields = new_fields end end | Returns a hash of the defined fields . |
17,780 | def fields = ( new_fields ) new_fields . each do | field , value | public_send ( field , value ) if respond_to? ( field ) end end | Assigns the values of the given hash . |
17,781 | def validate_fields self . class . required_fields . each do | field | value = public_send ( field ) if value . nil? || value . respond_to? ( :empty? ) && value . empty? raise Outbox :: MissingRequiredFieldError , "Missing required field: #{field}" end end end | Checks the current values of the fields and raises errors for any validation issues . |
17,782 | def serialize ( path , data ) mkpath_to path File . open ( path , "w" ) do | f | f . puts data . to_json end end | serialize a ruby object to a file in json |
17,783 | def unserialize ( path ) if File . exists? ( path ) && ! File . zero? ( path ) begin return JSON . parse ( IO . binread ( path ) ) rescue JSON :: ParserError => e puts e end end end | unserialize a json file to a ruby object |
17,784 | def translate ( string ) @string = string @max = array . length SoundSequence . new ( array . each_index . map do | index | @index = index instance_eval ( & @rules ) end . flatten . compact ) ensure @max = 0 @string = nil @array = nil @index = nil @last_sound = nil end | Translate orthorgraphy to IPA |
17,785 | def semantic_date_time_tag ( date_time , options = { } ) SemanticDateTimeTags :: Tag :: DateTime . new ( date_time , options ) . to_html end | accepts only datetime |
17,786 | def semantic_time_tag ( time , options = { } ) SemanticDateTimeTags :: Tag :: Time . new ( time , options ) . to_html end | accepts datetime and time |
17,787 | def register_inheritance_handler synchronize do return if defined? ( Object . inherited_with_lumber_registry ) Object . class_eval do class << self def inherited_with_lumber_registry ( subclass ) inherited_without_lumber_registry ( subclass ) if Lumber :: InheritanceRegistry [ subclass . name ] subclass . send ( :inclu... | Adds a inheritance handler to Object so we can add loggers for registered classes |
17,788 | def index_for objects , html_options = { } , & block html_options = html_options . dup objects = fetch_objects objects , html_options tag = html_options [ :table_tag ] || IndexFor . table_tag klass = html_options [ :klass ] || objects . try ( :klass ) || objects . first . class html_options [ :id ] ||= index_for_id ( k... | Creates a table around the objects and yields a builder . |
17,789 | def index_for_actions object , * action_names , & block html_options = action_names . extract_options! action_names = [ :show , :edit , :destroy ] if action_names == [ :all ] builder = html_options [ :action_builder ] || IndexFor :: ActionBuilder builder = builder . new ( object , html_options , self ) content = captur... | Create action links and yields a builder . |
17,790 | def show_for object , html_options = { } , & block html_options = html_options . dup tag = html_options [ :list_tag ] || IndexFor . list_tag html_options [ :id ] ||= show_for_id ( object ) html_options [ :class ] = show_for_class ( object , html_options ) builder = html_options [ :builder ] || IndexFor :: ListColumnBui... | Creates a desc list around the object and yields a builder . |
17,791 | def post ( api_method , parameters = { } ) parameters . merge! ( { "token" => @token } ) body = { } body . merge! ( { :method => api_method } ) body . merge! ( { :params => parameters } ) self . class . post ( @write_api_url , { :body => { :json => JSON . generate ( body ) } } ) end | Make an HTTP POST call to the Brightcove API for a particular API method . |
17,792 | def load_resource @page = Hicube :: Page . unscoped . find ( params [ :page_id ] ) @content = @page . content . find_or_create_by ( name : params [ :id ] ) end | Nested attributes are currently not handled in basecontroller |
17,793 | def rooms_create ( name , owner_user_id , privacy = 'public' , topic = '' , guest_access = 0 ) self . class . post ( hipchat_api_url_for ( 'rooms/create' ) , :body => { :auth_token => @token , :name => name , :owner_user_id => owner_user_id , :topic => topic , :privacy => privacy , :guest_access => guest_access } ) end | Creates a new room . |
17,794 | def rooms_message ( room_id , from , message , notify = 0 , color = 'yellow' , message_format = 'html' ) self . class . post ( hipchat_api_url_for ( 'rooms/message' ) , :body => { :auth_token => @token , :room_id => room_id , :from => from , :message => message , :notify => notify , :color => color , :message_format =>... | Send a message to a room . |
17,795 | def users_create ( email , name , title , is_group_admin = 0 , password = nil , timezone = 'UTC' ) self . class . post ( hipchat_api_url_for ( 'users/create' ) , :body => { :auth_token => @token , :email => email , :name => name , :title => title , :is_group_admin => is_group_admin , :password => password , :timezone =... | Create a new user in your group . |
17,796 | def parse_video unless / \A \s \d \d \s \z / =~ content env . warn 'can not parse \video content, should be "#{WIDTH}x#{HEIGHT} #{URL}"' return end case url when / \. / unless id = url [ / \? \w / ] || url [ / \/ \w / ] || url [ / \. \/ \w / ] env . warn 'can not parse youtube id' return end %Q|<iframe width="#{width}"... | embed video calculates embed iframe by urls from various simple formats but not accept iframe code |
17,797 | def create_tree ( vupper , vlower , & block ) @root = Node . new ( vupper , vlower , @depth ) @root . create_children & block end | The block is passed node itself as parent and the vector midpoints of its children to be . |
17,798 | def array_data_to_hash ( array_data ) array_data . each_with_object ( { } ) do | node , memo | memo [ node [ 'Address' ] . to_i ] = clean_node ( node ) end end | Asi . new reads in the source file for the ASIObjectDictionary and creates an internal Hash |
17,799 | def start_monitor ( interval = 10 ) t = MonitorThread . new do loop do break if Thread . current . should_exit begin activate_levels rescue => e $stderr . puts "Failure activating log levels: #{e}" end sleep interval end end at_exit { t . should_exit = true } t end | Convenience method for starting a thread to watch for changes in log levels and apply them . You don t need to use this if you are manually calling activate levels at all your entry points . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.